xoolive / traffic

A toolbox for processing and analysing air traffic data
https://traffic-viz.github.io/
MIT License
361 stars 80 forks source link

accept ICAO 24-bit addresses with uppercase letters (at least) in opensky.history() #450

Closed espinielli closed 3 months ago

espinielli commented 3 months ago

opensky.history() accepts icao24 for a a string or a list of strings identifying the transponder code of the aircraft. This value is used to query OpenSky historical data where the hexadecimal strings are stored in lowercase: this is an implementation detail. It would be nice to automagically lowercase whatever the use submits, because 4BB272 and 4bb272 are the same hex.

The rationale for this is my surprise to get no flights when I was passing an ICAO 24-bit in uppercase 😁


Please follow these steps to make it more efficient to respond to your feature request.

xoolive commented 3 months ago

This is rather a pyopensky issue, but should be covered already. Would appreciate an example code where it fails.

espinielli commented 3 months ago

Hi Xavier, please find below a reproducible example

setup

# mute annoying warnings
import warnings
from tqdm import TqdmExperimentalWarning

warnings.filterwarnings("ignore", category=TqdmExperimentalWarning)
warnings.filterwarnings("ignore", category=FutureWarning)

from pyopensky.trino import Trino

trino = Trino()

Using icao24 with uppercase letters returns None

wef = "2023-01-01 16:19:00"
til = "2023-01-01 18:50:45"
icao = "485A35"

df = trino.history(
    wef,
    til,
    icao24=icao,
)
df

Let's make it lowercase

df = trino.history(
    wef,
    til,
    icao24=icao.lower(),
)
df

...and we get a pandas dataframe of position reports

                          time  icao24        lat       lon    velocity  \
0    2023-01-01 18:00:01+00:00  485a35  47.720398  0.610016  277.382652   
1    2023-01-01 18:00:02+00:00  485a35  47.720398  0.610016  277.382652   
2    2023-01-01 18:00:03+00:00  485a35  47.720398  0.610016  277.382652   
3    2023-01-01 18:00:04+00:00  485a35  47.731476  0.617569  277.382652   
4    2023-01-01 18:00:05+00:00  485a35  47.733765  0.619148  277.382652   
...                        ...     ...        ...       ...         ...   
8162 2023-01-01 17:59:55+00:00  485a35  47.710236  0.603149  277.382652   
8163 2023-01-01 17:59:56+00:00  485a35  47.713623  0.605415  277.382652   
8164 2023-01-01 17:59:57+00:00  485a35  47.714722  0.606171  277.382652   
8165 2023-01-01 17:59:58+00:00  485a35  47.718046  0.608403  277.382652   
8166 2023-01-01 17:59:59+00:00  485a35  47.720398  0.610016  277.382652   

        heading  vertrate callsign  onground  alert    spi squawk  \
0     24.663815       0.0   KLM78Y     False  False  False   1000   
1     24.663815       0.0   KLM78Y     False  False  False   1000   
2     24.663815       0.0   KLM78Y     False  False  False   1000   
3     24.663815       0.0   KLM78Y     False  False  False   1000   
4     24.663815       0.0   KLM78Y     False  False  False   1000   
...         ...       ...      ...       ...    ...    ...    ...   
8162  24.663815       0.0   KLM78Y     False  False  False   1000   
8163  24.663815       0.0   KLM78Y     False  False  False   1000   
8164  24.663815       0.0   KLM78Y     False  False  False   1000   
8165  24.663815       0.0   KLM78Y     False  False  False   1000   
8166  24.663815       0.0   KLM78Y     False  False  False   1000   

      baroaltitude  geoaltitude  lastposupdate   lastcontact  \
0          11582.4     11689.08   1.672596e+09  1.672596e+09   
1          11582.4     11689.08   1.672596e+09  1.672596e+09   
2          11582.4     11689.08   1.672596e+09  1.672596e+09   
3          11582.4     11689.08   1.672596e+09  1.672596e+09   
4          11582.4     11689.08   1.672596e+09  1.672596e+09   
...            ...          ...            ...           ...   
8162       11582.4     11689.08   1.672596e+09  1.672596e+09   
8163       11582.4     11689.08   1.672596e+09  1.672596e+09   
8164       11582.4     11689.08   1.672596e+09  1.672596e+09   
8165       11582.4     11689.08   1.672596e+09  1.672596e+09   
8166       11582.4     11689.08   1.672596e+09  1.672596e+09   

                                                serials  \
0     [1408237446, -1408236405, -1408237044, -140823...   
1     [1408237446, -1408236405, -1408237044, -140823...   
2     [1408237446, -1408236405, -1408237044, -140823...   
3     [1408237446, -1408236405, -1408237044, -140823...   
4     [1408237446, -1408236405, -1408237044, -140823...   
...                                                 ...   
8162  [1408237446, -1408236405, -1408237044, -140823...   
8163  [1408237446, -1408236405, -1408237044, -140823...   
8164  [1408237446, -1408236405, -1408237044, -140823...   
8165  [1408237446, -1408236405, -1408237044, -140823...   
8166  [1408237446, -1408236405, -1408237044, -140823...   

                          hour  
0    2023-01-01 18:00:00+00:00  
1    2023-01-01 18:00:00+00:00  
2    2023-01-01 18:00:00+00:00  
3    2023-01-01 18:00:00+00:00  
4    2023-01-01 18:00:00+00:00  
...                        ...  
8162 2023-01-01 17:00:00+00:00  
8163 2023-01-01 17:00:00+00:00  
8164 2023-01-01 17:00:00+00:00  
8165 2023-01-01 17:00:00+00:00  
8166 2023-01-01 17:00:00+00:00  

[8167 rows x 18 columns]
xoolive commented 3 months ago

hi enrico, it's already fixed in pyopensky HEAD will run a release then