mshumko / asilib

An open source package providing data access and analysis tools for the world's all-sky imager (ASI) data.
https://aurora-asi-lib.readthedocs.io/
GNU General Public License v3.0
10 stars 4 forks source link

BUG: error in time slicing in the get_points() function #15

Closed ktdavidson closed 11 months ago

ktdavidson commented 11 months ago

Describe the issue:

I'm trying to get the pixel intensities at specific (lat,lon) points across a time range from a single THEMIS ASI imager. Whether using either a time range or a single time in the aurora.asi.themis() function, I get an error in the get_points() function stating that the time slicing cannot be 0. I do NOT have an error using a time or time range in the aurora.asi.themis() function when plotting a keogram, only when trying to get the pixel intensities.

Reproduce the code example:

import asilib
import asilib.asi

location_code = 'FYKN'
map_alt_km = 150
min_elevation = 2
time = datetime.datetime(2012,2,15,6,0,0)
time_range = [datetime.datetime(2012,2,15,6,0,0),datetime.datetime(2012,2,15,12,0,0)]

_imagers = asilib.asi.themis(location_code,time=time,alt=map_alt_km)
asis = asilib.Imagers(_imagers)

lat_lon_points,intensities = asis.get_points(min_elevation=min_elevation)
print(lat_lon_points)
print(intensities)
print(lat_lon_points.shape)

Error message:

Traceback (most recent call last):
  File "/Users/kat/Documents/UAH_Research/python_summary/asi_data.py", line 34, in <module>
    lat_lon_points,intensities = asis.get_points(min_elevation=min_elevation)
  File "/Users/kat/miniconda3/lib/python3.10/site-packages/asilib/imagers.py", line 217, in get_points
    if len(self.imagers[0].meta['resolution']) == 3: # RGB
  File "/Users/kat/miniconda3/lib/python3.10/site-packages/asilib/imager.py", line 1122, in __getitem__
    start_time, end_time = self._convert_slice(_slice)
  File "/Users/kat/miniconda3/lib/python3.10/site-packages/asilib/imager.py", line 1198, in _convert_slice
    raise ValueError(f'The slice must be [time] or [start_time:end_time], not {_slice}.')
ValueError: The slice must be [time] or [start_time:end_time], not 0.

Runtime information:

0.20.4 3.10.10 (main, Mar 21 2023, 13:41:39) [Clang 14.0.6 ] macOS-10.15.7-x86_64-i386-64bit

Context for the issue:

No response

mshumko commented 11 months ago

Hi @ktdavidson,

Thank you for the bug report. The bug comes about when you passed a single Imager into Imagers. Imagers expects a tuple of asilib.Imager objects, not a single asilib.Imager object.

Given that the get_points() method is in Imagers, this is an appropriate way for you to use it. I fixed the bug in Imagers and I will release it soon. In the meanwhile, a quick fix is to wrap your _imagers variable as a tuple: asis = asilib.Imagers((_imagers, )). The example below implements this fix.

import datetime

import asilib
import asilib.asi

location_code = 'FYKN'
map_alt_km = 150
min_elevation = 2
time = datetime.datetime(2012,2,15,6,0,0)

_imagers = asilib.asi.themis(location_code,time=time,alt=map_alt_km)
asis = asilib.Imagers((_imagers, ))

lat_lon_points,intensities = asis.get_points(min_elevation=min_elevation)
print(lat_lon_points)
print(intensities)
print(lat_lon_points.shape)
ktdavidson commented 11 months ago

Thank you! This fixed the problem.

mshumko commented 11 months ago

Great! I released an update so you can now use your original code once you update the library via

python3 -m pip install aurora-asi-lib==0.20.5