Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Wind/3Dp data handling #67

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions seppy/loader/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}!')
Expand Down Expand Up @@ -279,22 +282,31 @@ 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'])
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':
Expand Down
Loading