Commit ed7f78f9 authored by CEVAER's avatar CEVAER
Browse files

Add checks if API returns an empty set

parent 24e34266
......@@ -47,9 +47,14 @@ def get_track_points_from_database(session, date):
def get_track_points_from_api(date):
min_date = date.strftime("%Y-%m-%d")
max_date = (date + datetime.timedelta(days=2)).strftime("%Y-%m-%d")
df = pd.read_csv(f"https://cyclobs.ifremer.fr/app/api/track?min_date={min_date}&max_date={max_date}")
df["date"] = pd.to_datetime(df["date"])
df = df[df["date"] >= date]
req = f"http://derive.ifremer.fr/app/api/track?min_date={min_date}&max_date={max_date}"
try:
df = pd.read_csv(req)
df["date"] = pd.to_datetime(df["date"])
df = df[df["date"] >= date]
except pd.errors.EmptyDataError as e:
logger.warning(f"Empty data from API (req : {req}")
df = pd.DataFrame()
return df
......@@ -401,6 +406,11 @@ def process_file(session, file, output_path, extract_date_func, attrs, var_to_de
track_points = get_track_points_from_api(file_date)
logger.debug(f"Number of track point found : {len(track_points)}")
# If no track points
if len(track_points.index) == 0:
logger.warning("No track points, skipping this file.")
return
track_points["lon"] = track_points["lon"].apply(lambda x: shape360(x, 0)[0])
dataset = xarray.open_dataset(file)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment