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: Keogram not acceptating datetime.datetime objects #16

Closed CassandraAuri closed 6 months ago

CassandraAuri commented 7 months ago

Describe the issue:

When putting in a datetime to keogram, it errors.

Reproduce the code example:

from datetime import datetime
import asilib
import asilib.asi

time_range = [datetime(2021, 3, 18, 8), datetime(2021, 3, 18, 9)]
axes, img1 = asilib.plot_keogram("rego", "fsmi", time_range, map_alt=110)

Error message:

Traceback (most recent call last):
  File "c:/Users/1101w/Clone/Programming-8/Summer 2023/keogram_test.py", line 10, in <module>
    axes, img1 = asilib.plot_keogram("rego", "fsmi", time_range, map_alt=110)
  File "C:\Users\1101w\anaconda3\lib\site-packages\asilib\plot\plot_keogram.py", line 105, in plot_keogram
    keo_df = keogram(asi_array_code, location_code, time_range, map_alt, path=path, aacgm=aacgm)
  File "C:\Users\1101w\anaconda3\lib\site-packages\asilib\analysis\keogram.py", line 62, in keogram
    return keo.keogram(map_alt, path, aacgm)
  File "C:\Users\1101w\anaconda3\lib\site-packages\asilib\analysis\keogram.py", line 232, in keogram
    [
  File "C:\Users\1101w\anaconda3\lib\site-packages\asilib\analysis\keogram.py", line 233, in <listcomp>
    (f - i).total_seconds()
AttributeError: 'numpy.timedelta64' object has no attribute 'total_seconds'

Runtime information:

0.20.5 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] Windows-10-10.0.19041-SP0

Context for the issue:

Can't use keograms with existing code and probably an easy fix.

mshumko commented 7 months ago

Hi @CassandraAuri

I am unable to replicate this error on my end and I see the attached plot. What version of numpy and pandas do you have installed? I suspect that it has something to do with that.

If you run this command it may shed some light on what is going on

>>> import numpy, pandas  
>>> print(f'{numpy.__version__=}, {pandas.__version__=}') 
numpy.__version__='1.24.3', pandas.__version__='1.5.3'

P.S. Your code example uses the deprecated asilib interface. Have you tried creating a keogram using the following code? It should be equivilant.

from datetime import datetime

import matplotlib.pyplot as plt
import asilib
import asilib.asi

time_range = [datetime(2021, 3, 18, 8), datetime(2021, 3, 18, 9)]
asi = asilib.asi.rego( "fsmi", time_range, alt=110)
asi.plot_keogram()
plt.show()

20210318_rego_fsmi_keogram