From c344a8feaf081d9b571522906e08b52c9f5f9fc1 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Tue, 14 Jan 2025 18:06:50 +0200 Subject: [PATCH 1/2] Enhance wind3dp_download and wind3dp_load functions to improve error handling and data retrieval --- seppy/loader/wind.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/seppy/loader/wind.py b/seppy/loader/wind.py index 0cdfec6..03bc662 100644 --- a/seppy/loader/wind.py +++ b/seppy/loader/wind.py @@ -180,6 +180,9 @@ def wind3dp_download(dataset, startdate, enddate, path=None, **kwargs): if not os.path.exists(f): # downloaded_file = Fido.fetch(result[0][i], path=path, max_conn=max_conn) downloaded_file = wind3dp_single_download(files[i], path=path) + if downloaded_file == []: + print('Trying download from CDAWeb...') + downloaded_file = Fido.fetch(result[0][i], path=path) #, max_conn=max_conn) except (RuntimeError, IndexError): print(f'Unable to obtain "{dataset}" data for {startdate}-{enddate}!') @@ -288,13 +291,18 @@ def wind3dp_load(dataset, startdate, enddate, resample="1min", multi_index=True, energies['Bins_Text']= np.around(e_low/1e3, 2).astype('string') +' - '+ np.around(e_high/1e3, 2).astype('string') + ' keV' meta = {'channels_dict_df': energies, - 'APPROX_ENERGY_LABELS': metacdf.varget('APPROX_ENERGY_LABELS'), 'ENERGY_UNITS': metacdf.varattsget('ENERGY')['UNITS'], 'FLUX_UNITS': metacdf.varattsget('FLUX')['UNITS'], 'FLUX_FILLVAL': metacdf.varattsget('FLUX')['FILLVAL'], - 'FLUX_LABELS': metacdf.varget('FLUX_ENERGY_LABL'), } + # for SFSP, SOSP, SFPD, SFSP: + try: + meta['APPROX_ENERGY_LABELS'] = metacdf.varget('APPROX_ENERGY_LABELS') + meta['FLUX_LABELS'] = metacdf.varget('FLUX_ENERGY_LABL') + except: + pass + # create multi-index data frame of flux if multi_index: if dataset == 'WI_SFPD_3DP' or dataset == 'WI_SOPD_3DP': From 30860dbfd536db64d04186c107b845707207c256 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Wed, 15 Jan 2025 14:54:10 +0200 Subject: [PATCH 2/2] Refine energy delta calculations based on dataset type --- seppy/loader/wind.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/seppy/loader/wind.py b/seppy/loader/wind.py index 03bc662..de802ff 100644 --- a/seppy/loader/wind.py +++ b/seppy/loader/wind.py @@ -282,9 +282,13 @@ def wind3dp_load(dataset, startdate, enddate, resample="1min", multi_index=True, metacdf = cdflib.CDF(path_to_metafile) e_mean = df.filter(like='ENERGY_').mean() - # ∼30% ΔE/E => ΔE = 0.3*E # from Table 3 of Wilson et al. 2021, https://doi.org/10.1029/2020RG000714 - delta_e = 0.3 * e_mean + # ∼30% ΔE/E => ΔE = 0.3*E + if dataset in ['WI_SFSP_3DP', 'WI_SFPD_3DP', 'WI_SOSP_3DP', 'WI_SOPD_3DP']: + delta_e = 0.3 * e_mean + # ∼20% ΔE/E => ΔE = 0.2*E + elif dataset in ['WI_ELSP_3DP', 'WI_ELPD_3DP', 'WI_EHSP_3DP', 'WI_EHPD_3DP']: + delta_e = 0.2 * e_mean e_low = e_mean - delta_e e_high = e_mean + delta_e energies = pd.concat([e_mean, delta_e, e_low, e_high], axis=1, keys=['mean_E', 'DE', 'lower_E', 'upper_E'])