Skip to content
Snippets Groups Projects

Add temp threshold

Merged Tor-Einar Skog requested to merge add_temp_threshold into main
1 file
+ 7
2
Compare changes
  • Side-by-side
  • Inline
+ 7
2
@@ -52,8 +52,11 @@ tmpfile_path = "tmp/"
# Names of weather parameters in NetCDF files
RR = os.getenv("RR")
UM = os.getenv("UM")
TM = os.getenv("TM")
local_timezone = pytz.timezone(os.getenv("LOCAL_TIMEZONE"))
TEMPERATURE_THRESHOLD = 8.0
DEBUG = False if os.getenv("DEBUG") is None or os.getenv("DEBUG").lower() == "false" else True
@@ -103,7 +106,7 @@ for file_path in sorted(weatherdata_files):
wh_sum_date_str = wh_sum_date.strftime("%Y-%m-%d")
wh_sum_hour_str = wh_sum_date.strftime("%H")
subprocess.run(
f'cdo -s -O -setdate,{wh_sum_date_str} -settime,{wh_sum_hour_str}:00:00 -chname,WH,WH_DAYSUM -timsum -selname,WH -aexpr,"WH = {RR} > 0.2 || {UM} > 88.0 ? 1 : 0;" {file_path} {tmpfile_path}wh_{wh_sum_date_str}.nc',
f'cdo -s -O -setdate,{wh_sum_date_str} -settime,{wh_sum_hour_str}:00:00 -chname,WH,WH_DAYSUM -timsum -selname,WH -aexpr,"WH = ({TM} >= {TEMPERATURE_THRESHOLD} && ({RR} > 0.2 || {UM} > 88.0)) ? 1 : 0;" {file_path} {tmpfile_path}wh_{wh_sum_date_str}.nc',
shell=True
)
@@ -175,6 +178,8 @@ subprocess.run(f'cdo -s -seltimestep,1/{number_of_timesteps_to_keep} {tmpfile_pa
# 40 <= WHS --> Red
subprocess.run(f'cdo -s -aexpr,"WARNING_STATUS = WHS <= 0 ? 0 : -1; WARNING_STATUS = WHS < 20 && WARNING_STATUS == -1 ? 2 : WARNING_STATUS; WARNING_STATUS = WHS < 40 && WARNING_STATUS == -1 ? 3 : WARNING_STATUS; WARNING_STATUS = WHS >= 40 && WARNING_STATUS == -1 ? 4 : WARNING_STATUS" {tmpfile_path}wh_3daysum.nc {tmpfile_path}result_unmasked.nc', shell=True)
subprocess.run(f"rm {tmpfile_path}result.nc", shell=True)
# Mask results using a CSV file with polygons
# Env variable MASK_FILE must be set
if os.getenv("MASK_FILE") is not None:
@@ -247,5 +252,5 @@ with open(f"{mapfile_outdir}/{model_id}.map", 'w') as f:
# Remove all temporary/intermediary files
subprocess.run(f"rm {tmpfile_path}wh_3daysum*.nc", shell=True)
subprocess.run(f"rm {tmpfile_path}result*.nc", shell=True)
subprocess.run(f"rm {tmpfile_path}result_*.nc", shell=True)
subprocess.run(f"rm {tmpfile_path}result*.tif", shell=True)
Loading