Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8abe5e0

Browse files
committed
add multiindex option to epd_load function and update related logic
1 parent 652e2b2 commit 8abe5e0

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

solo_epd_loader/__init__.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def _autodownload_cdf(startdate, enddate, sensor, level, path):
562562
def epd_load(sensor, startdate, enddate=None, level='l2', viewing=None,
563563
path=None, autodownload=False, only_averages=False,
564564
old_step_loading=False, pos_timestamp='center',
565-
old_ept_het_loading=True):
565+
multiindex=False, old_ept_het_loading=True):
566566
"""
567567
Load SolO/EPD data
568568
@@ -601,6 +601,9 @@ def epd_load(sensor, startdate, enddate=None, level='l2', viewing=None,
601601
autodownload : bool, optional
602602
If True, will try to download missing data files from SOAR, by default
603603
False.
604+
multiindex : bool, optional
605+
If True, will provide multi-index DataFrames as output as was the case
606+
for older solo-epd-loader version. By default False.
604607
only_averages : bool, optional
605608
If True, will for STEP only return the averaged fluxes, and not the data
606609
of each of the 15 Pixels. This will reduce the memory consumption. By
@@ -718,7 +721,7 @@ def epd_load(sensor, startdate, enddate=None, level='l2', viewing=None,
718721
# _read_epd_cdf_old(sensor=sensor, viewing=view, level=level, startdate=startdate, enddate=enddate, path=path, autodownload=autodownload)
719722
# elif not old_ept_het_loading:
720723
t_data_dict, energies_dict, metadata_dict = \
721-
_read_epd_cdf(sensor=sensor, viewing=view, level=level, startdate=startdate, enddate=enddate, path=path, autodownload=autodownload)
724+
_read_epd_cdf(sensor=sensor, viewing=view, level=level, startdate=startdate, enddate=enddate, path=path, autodownload=autodownload, multiindex=multiindex)
722725
# adjusting the position of the timestamp manually. original SolO/EPD data hast timestamp at 'start' of interval
723726
# adjusting the position of the timestamp manually. original SolO/EPD data hast timestamp at 'start' of interval
724727
if pos_timestamp == 'center' and level.lower() != 'll' and len(t_data_dict[[*t_data_dict.keys()][0]]) > 0:
@@ -752,7 +755,7 @@ def epd_load(sensor, startdate, enddate=None, level='l2', viewing=None,
752755
# _read_epd_cdf_old(sensor=sensor, viewing=viewing, level=level, startdate=startdate, enddate=enddate, path=path, autodownload=autodownload)
753756
# elif not old_ept_het_loading:
754757
data_dict, energies_dict, metadata_dict = \
755-
_read_epd_cdf(sensor=sensor, viewing=viewing, level=level, startdate=startdate, enddate=enddate, path=path, autodownload=autodownload)
758+
_read_epd_cdf(sensor=sensor, viewing=viewing, level=level, startdate=startdate, enddate=enddate, path=path, autodownload=autodownload, multiindex=multiindex)
756759
# adjusting the position of the timestamp manually. original SolO/EPD data hast timestamp at 'start' of interval
757760
if pos_timestamp == 'center' and level.lower() != 'll' and len(data_dict[[*data_dict.keys()][0]]) > 0:
758761
for key in data_dict.keys(): # e.g. df_p, df_e, df_rtn, df_hci, ...
@@ -2064,6 +2067,7 @@ def create_multiindex(df):
20642067
return df
20652068

20662069

2070+
# TODO: adjust to new data structure without multiindex dataframe
20672071
def combine_channels(df, energies, en_channel, sensor, viewing=None, species=None):
20682072
"""
20692073
Average the fluxes of several adjacent energy channels of one sensor into
@@ -2278,11 +2282,17 @@ def shift_index_start2center(df, delta_epoch_name=None):
22782282
# Shift index by half the cadence
22792283
df.loc[df[de]==cadence, 'Time'] = df.loc[df[de]==cadence, 'Time'] + pd.Timedelta(f'{cadence/2}s')
22802284
elif type(df[de]) is pd.core.frame.DataFrame:
2281-
for cadence in df[de][de].unique():
2282-
# skip nan's
2283-
if not np.isnan(cadence):
2284-
# Shift index by half the cadence
2285-
df.loc[df[de][de]==cadence, 'Time'] = df.loc[df[de][de]==cadence, 'Time'] + pd.Timedelta(f'{cadence/2}s')
2285+
if df[de].columns.get_level_values(0).str.startswith('DELTA_EPOCH').sum() != 1:
2286+
custom_warning(f"DELTA_EPOCH column not available or not unique in DataFrame containing {df.columns[0]}, aborting. Try using pos_timestamp='start' instead.")
2287+
return
2288+
else:
2289+
# Obtain second-level DELTA_EPOCH column name
2290+
de2 = df[de].columns.get_level_values(0)[df[de].columns.get_level_values(0).str.startswith('DELTA_EPOCH')][0]
2291+
for cadence in df[de][de2].unique():
2292+
# skip nan's
2293+
if not np.isnan(cadence):
2294+
# Shift index by half the cadence
2295+
df.loc[df[de][de2]==cadence, 'Time'] = df.loc[df[de][de2]==cadence, 'Time'] + pd.Timedelta(f'{cadence/2}s')
22862296

22872297
# Overwrite index
22882298
df.set_index('Time', drop=True, inplace=True)

0 commit comments

Comments
 (0)