jgieseler / solo-epd-loader

Data loader (and downloader) for Solar Orbiter/EPD energetic charged particle sensors EPT, HET, and STEP. Supports level 2 and low latency data provided by ESA's Solar Orbiter Archive.
BSD 3-Clause "New" or "Revised" License
15 stars 2 forks source link

Make compatible to cdflib 1.0 #27

Closed jgieseler closed 1 year ago

jgieseler commented 1 year ago

cdflib has released a new major version 1.0 that contains a number of breaking changes (https://cdflib.readthedocs.io/en/latest/changelog.html). Some of them affect cdf loading with solo-epd-loader (that is, when loading EPT or HET data):

>>> import datetime as dt
>>> from solo_epd_loader import epd_load
>>> startdate = dt.datetime(2020, 12, 10)
>>> df_protons_sun, df_electrons_sun, energies = epd_load(sensor='ept', startdate=startdate, viewing='sun', autodownload=True)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 5
      3 startdate = dt.datetime(2020, 12, 10)
      4 enddate = dt.datetime(2020, 12, 11)
----> 5 df_protons_sun, df_electrons_sun, energies = epd_load(sensor='ept', startdate=startdate, viewing='sun', autodownload=True)

File ~/anaconda3/envs/cdflib/lib/python3.9/site-packages/solo_epd_loader/__init__.py:560, in epd_load(sensor, startdate, enddate, level, viewing, path, autodownload, only_averages, contamination_threshold)
    557     energies_dict = []
    558 else:
    559     df_epd_p, df_epd_e, energies_dict = \
--> 560         _read_epd_cdf(sensor, viewing, level, startdate, enddate, path,
    561                       autodownload)
    562 return df_epd_p, df_epd_e, energies_dict

File ~/anaconda3/envs/cdflib/lib/python3.9/site-packages/solo_epd_loader/__init__.py:664, in _read_epd_cdf(sensor, viewing, level, startdate, enddate, path, autodownload)
    659 t_cdf_file = cdflib.CDF(filelist[0])
    661 # p intensities:
    662 flux_p_channels = \
    663     [protons+f'_Flux_{i}' for i in
--> 664      range(t_cdf_file.varinq(protons+'_Flux')['Dim_Sizes'][0])]
    665 # p errors:
    666 if level.lower() == 'll':

TypeError: 'VDRInfo' object is not subscriptable

For the time being, cdflib version has been fixed to <1.0 with solo-epd-loader 0.2.3, but the code needs to be adjusted to the new cdflib version. This might be affected by fixing https://github.com/jgieseler/solo-epd-loader/issues/26!