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
16 stars 2 forks source link

Add spacecraft location and instrument pointing coordinates to returned data #1

Open jgieseler opened 2 years ago

jgieseler commented 2 years ago

The original CDF files (at least HET level 2) contain spacecraft location coordinates (R, heliocentric latitude & longitude), these should be contained in the returned data. In addition the pointing direction of the instrument is given as (time-independent?) variable XYZ, which will be very useful for calculation pitch-angles.

print(t_cdf_file.varattsget('HCI_R'))

{'FIELDNAM': 'S/C Radial Distance', 'CATDESC': 'Spacecraft radial distance from the Sun', 'FILLVAL': array([-1.e+31], dtype=float32), 
'LABLAXIS': 'r', 'UNITS': 'au', 'VALIDMIN': array([0.], dtype=float32), 'VALIDMAX': array([1.2], dtype=float32), 'SCALEMIN': array([0.], 
dtype=float32), 'SCALEMAX': array([1.2], dtype=float32), 'VAR_TYPE': 'support_data', 'SCALETYP': 'linear', 'VAR_NOTES': ' ', 
'DEPEND_0': 'EPOCH_6', 'FORMAT': 'F6.4', 'SI_CONVERSION': '1.495978E11>m'}
jgieseler commented 2 years ago
>>> import cdflib
>>> from sunpy.net import Fido
>>> from sunpy.net import attrs as a
>>> from sunpy.io.cdf import read_cdf

>>> trange = a.Time('2021/07/28', '2021/07/28')
>>> dataset = a.cdaweb.Dataset('SOLO_L2_EPD-EPT-SUN-RATES')
>>> result = Fido.search(trange, dataset)
>>> downloaded_files = Fido.fetch(result)

>>> # ts = TimeSeries(downloaded_files, concatenate=True)
>>> # df = ts.to_dataframe()
>>> data = read_cdf(downloaded_files[0])

>>> data[2].to_dataframe()
                        RTN_0     RTN_1     RTN_2
EPOCH_2                                          
2021-07-28 00:00:00  0.819152 -0.573575  0.001057
2021-07-28 00:01:00  0.819153 -0.573574  0.001055
2021-07-28 00:02:00  0.819152 -0.573575  0.001057
2021-07-28 00:03:00  0.819152 -0.573576  0.001056
2021-07-28 00:04:00  0.819151 -0.573576  0.001056
...                       ...       ...       ...
2021-07-28 23:56:00  0.819152 -0.573577  0.000617
2021-07-28 23:57:00  0.819155 -0.573573  0.000615
2021-07-28 23:58:00  0.819152 -0.573576  0.000616
2021-07-28 23:59:00  0.819154 -0.573573  0.000616
2021-07-29 00:00:00  0.819152 -0.573576  0.000611

[1441 rows x 3 columns]

>>> data[3].to_dataframe()
                      HCI_Lat     HCI_Lon     HCI_R
EPOCH_3                                            
2021-07-28 00:00:00 -2.002322  132.171082  0.796568
2021-07-28 01:00:00 -2.002417  132.223343  0.796338
2021-07-28 02:00:00 -2.002511  132.275635  0.796109
2021-07-28 03:00:00 -2.002603  132.327957  0.795879
2021-07-28 04:00:00 -2.002693  132.380310  0.795649
2021-07-28 05:00:00 -2.002782  132.432693  0.795419
2021-07-28 06:00:00 -2.002870  132.485107  0.795189
2021-07-28 07:00:00 -2.002955  132.537552  0.794958
2021-07-28 08:00:00 -2.003039  132.590027  0.794728
2021-07-28 09:00:00 -2.003122  132.642532  0.794497
2021-07-28 10:00:00 -2.003202  132.695068  0.794266
2021-07-28 11:00:00 -2.003282  132.747635  0.794036
2021-07-28 12:00:00 -2.003359  132.800232  0.793804
2021-07-28 13:00:00 -2.003435  132.852859  0.793573
2021-07-28 14:00:00 -2.003509  132.905518  0.793342
2021-07-28 15:00:00 -2.003582  132.958206  0.793110
2021-07-28 16:00:00 -2.003653  133.010925  0.792879
2021-07-28 17:00:00 -2.003722  133.063675  0.792647
2021-07-28 18:00:00 -2.003789  133.116470  0.792415
2021-07-28 19:00:00 -2.003855  133.169281  0.792183
2021-07-28 20:00:00 -2.003920  133.222122  0.791950
2021-07-28 21:00:00 -2.003982  133.274994  0.791718
2021-07-28 22:00:00 -2.004043  133.327896  0.791485
2021-07-28 23:00:00 -2.004103  133.380829  0.791253
2021-07-29 00:00:00 -2.004160  133.433807  0.791020

>>> cdf = cdflib.CDF(downloaded_files[0])
>>> cdf.varattsget("XYZ")
{'FIELDNAM': 'Flow direction XYZ',
 'CATDESC': 'Particle flow direction (unit vector) in spacecraft XYZ coordinates',
 'UNITS': ' ',
 'VALIDMIN': array([-1.], dtype=float32),
 'VALIDMAX': array([1.], dtype=float32),
 'VAR_TYPE': 'support_data',
 'VAR_NOTES': ' ',
 'FORMAT': 'F6.3',
 'LABL_PTR_1': 'XYZ_Labels'}
>>> cdf.varget("XYZ")
array([-0.81915206,  0.57357645,  0.        ], dtype=float32)