contrailcirrus / pycontrails

Python library for modeling contrails and other aviation climate impacts
https://py.contrails.org/
Apache License 2.0
59 stars 18 forks source link

Error when creating `Fleet` from sequence with empty `Flight`s #149

Closed thabbott closed 9 months ago

thabbott commented 10 months ago

Opening an issue to note an error that I found difficult to debug. I'll assign myself and work on an improvement.

The error appears when creating a Fleet from a sequence of Flights, some of which are missing data:

import pandas as pd
import numpy as np
from pycontrails import Flight, Fleet

df = pd.DataFrame()
df["longitude"] = np.linspace(0, 50, 100)
df["latitude"] = np.linspace(0, 10, 100)
df["altitude"] = 11000
df["time"] = pd.date_range("2022-03-01 00:00:00", "2022-03-01 02:00:00", periods=100)

flights = [Flight(df, flight_id=1), Flight(flight_id=2)]
Fleet.from_seq(flights)

results in ValueError: Unexpected flight_id(s) {2} in fl_attrs. This simple example is not too hard to debug, but I ran into this error when resample_and_fill dropped a small fraction of a large number of flights to 0 length, and it took me a while to figure out what the problem was. I think we probably want to catch this case earlier on and provide a more informative error.