spedas / pyspedas

Python-based Space Physics Environment Data Analysis Software
https://pyspedas.readthedocs.io/
MIT License
143 stars 58 forks source link

Crash in erg_hep_get_dist #893

Closed jameswilburlewis closed 9 hours ago

jameswilburlewis commented 1 week ago

When generating particle products for the HEP instrument, there is a crash in erg_hep_get_dist:


    def test_hep_theta(self):
        del_data('*')
        # Load HEP-e Lv.2 3-D flux data
        timespan('2017-04-05 21:45:00', 2.25, keyword='hours')
        pyspedas.erg.hep( trange=[ '2017-04-05 21:45:00', '2017-04-05 23:59:59'], datatype='3dflux' )
        # Calculate and plot energy spectrum
        vars = erg_hep_part_products( 'erg_hep_l2_FEDU_L', outputs='theta', trange=[ '2017-04-05 21:45:00', '2017-04-05 
23:59:59'] )
Traceback (most recent call last):
  File "/Users/jwl/PycharmProjects/pyspedas/pyspedas/erg/tests/hep_part_products.py", line 21, in test_hep_theta
    vars = erg_hep_part_products( 'erg_hep_l2_FEDU_L', outputs='theta', trange=[ '2017-04-05 21:45:00', '2017-04-05 23:59:59'] )
  File "/Users/jwl/PycharmProjects/pyspedas/pyspedas/erg/satellite/erg/particle/erg_hep_part_products.py", line 123, in erg_hep_part_products
    dist_all_time_range =  erg_hep_get_dist(in_tvarname, time_indices, species=species, units=units_lc, exclude_azms= not include_allazms)
  File "/Users/jwl/PycharmProjects/pyspedas/pyspedas/erg/satellite/erg/particle/erg_hep_get_dist.py", line 348, in erg_hep_get_dist
    phi0_1_reform = np.reshape(phissi.T, [1, 1, dim_array[2], n_times])
  File "/Users/jwl/PycharmProjects/pyspedas/venv/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 285, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/Users/jwl/PycharmProjects/pyspedas/venv/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 59, in _wrapfunc
    return bound(*args, **kwds)
ValueError: cannot reshape array of size 160635 into shape (1,1,15,1013)
jameswilburlewis commented 1 day ago

It works if you don't pass a trange argument to hep_part_products(). There seems to be some confusion about whether n_times should be the number of samples of the original input variable, or the number of samples after applying the time range. In IDL, this step uses the full range of the variable, while in Python it uses the reduced sample count after applying the trange.

jameswilburlewis commented 9 hours ago

Fixed an indexing problem with phi and elevation angle arrays (needed to be trimmed to number of samples actually being processed)