Skip to content
Snippets Groups Projects
Commit 747128b6 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Check weatherdata source files for timesteps. Close a file.

parent 950dba94
No related branches found
No related tags found
No related merge requests found
......@@ -73,6 +73,14 @@ for file_path in weatherdata_files:
# Only process files from the three last days (if this is not a work from scratch)
if start_date is not None and wh_sum_date < start_date:
continue
# Check that the file has at least 23 timesteps
with nc.Dataset(file_path, 'r') as weatherdata_file:
file_timesteps = len(weatherdata_file.variables["time"])
if file_timesteps < 23:
print(f"{file_path} has {file_timesteps} timesteps. Skipping it.")
continue
# Produce daily files with WH_SUM, which is the number of "Wet hours" (WH) for a given day
# WH is defined as RR > 0.2 || UM > 88.0
wh_sum_date_str = wh_sum_date.strftime("%Y-%m-%d")
......@@ -98,6 +106,7 @@ for timestep in timesteps:
print(f"ERROR: Missing weather data between {previous_timestep_str} and {timestep_str}. Exiting.", file=sys.stderr)
exit(1)
previous_timestep = timestep
wh_daysum.close()
# From here, no additive calculation; we calculate from the beginning of the w_daysum.nc file every time.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment