Skip to content

Commit

Permalink
Merge pull request #88 from ninahakansson/handle_vgac_broken_time_info
Browse files Browse the repository at this point in the history
Handle some broken time information in VGAC files
  • Loading branch information
ninahakansson authored Aug 14, 2024
2 parents df8234f + 2c796e5 commit 0cab9b7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions level1c4pps/vgac2pps_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

"""Functions to convert VGAC level-1c data to a NWCSAF/PPS level-1c formatet netCDF/CF file."""

import numpy as np
import os
import time
from satpy.scene import Scene
Expand Down Expand Up @@ -187,9 +188,14 @@ def get_midnight_line_nr(scene):
start_date = scene["M05"].attrs["start_time"].strftime("%Y-%m-%d")
end_date = scene["M05"].attrs["end_time"].strftime("%Y-%m-%d")
start_fine_search = len(scene['scanline_timestamps']) - 1 # As default start the fine search from end of time array
file_contain_bad_time_info = False
for ind in range(0, len(scene['scanline_timestamps']), 100):
# Search from the beginning in large chunks (100) and break when we
# pass midnight.
if np.isnan(scene['scanline_timestamps'].values[:][ind]):
# Sometimes time info is wrong 10^36 hours since ...
file_contain_bad_time_info = True
continue
dt_obj = dt64_to_datetime(scene['scanline_timestamps'].values[:][ind])
date_linei = dt_obj.strftime("%Y-%m-%d")
if date_linei == end_date:
Expand All @@ -198,12 +204,16 @@ def get_midnight_line_nr(scene):
break
for indj in range(start_fine_search, start_fine_search - 100, -1):
# Midnight is in one of the previous 100 lines.
if np.isnan(scene['scanline_timestamps'].values[:][indj]):
raise ValueError("Error in time information in VGAC file.")
dt_obj = dt64_to_datetime(scene['scanline_timestamps'].values[:][indj])
date_linei = dt_obj.strftime("%Y-%m-%d")
if date_linei == start_date:
# We just passed midnight this is the last line for previous day.
midnight_linenr = indj
break
if file_contain_bad_time_info and indj == start_fine_search - 99:
raise ValueError("Error in time information in VGAC file.")
return midnight_linenr


Expand Down

0 comments on commit 0cab9b7

Please sign in to comment.