diff --git a/PSILARTEMP.py b/PSILARTEMP.py index b3fd6c1ab72109fd2ffdcdd12f80b7b150c0bcbf..6f7158ad563975e7872c36a894bd0b3caecf2d64 100755 --- a/PSILARTEMP.py +++ b/PSILARTEMP.py @@ -32,6 +32,7 @@ config = configparser.ConfigParser() config.read("PSILARTEMP.cfg") year = os.getenv("YEAR") +recurring_start_date = os.getenv("RECURRING_START_DATE") weatherdata_path = os.getenv("WEATHER_DATA_DIR") tmp_path = "tmp/" out_path = os.getenv("DATA_DIR") @@ -39,11 +40,17 @@ out_path = os.getenv("DATA_DIR") # TODO: Put timezone out in .env local_timezone = pytz.timezone("Europe/Oslo") +# If we are before the recurring start date, exit nicely +start_time = datetime.strptime(f"{year}-{recurring_start_date}","%Y-%m-%d") +if datetime.now() <= start_time: + print(f"Today is before the configured start time of {start_time}. Exiting.") + exit(0) + # """ # Calculate cumulated degree days above 5 degrees after 1st of April # Remove all values before April 1st subprocess.run( - f"cdo -selname,TM -seldate,{year}-04-01T00:00:00,{year}-12-31T00:00:00 {weatherdata_path}met_1_0km_nordic-{year}.nc {tmp_path}TM_from_april.nc", + f"cdo -selname,TM -seldate,{year}-{recurring_start_date}T00:00:00,{year}-12-31T00:00:00 {weatherdata_path}met_1_0km_nordic-{year}.nc {tmp_path}TM_from_april.nc", shell=True, ) # Subtracting 5 deg C from all cells diff --git a/env-sample b/env-sample index 03888741aadefd402ce984960ddf29f7f479cc30..e0f2cad3d82eff856d6ae045a5d097f0680e5ff2 100644 --- a/env-sample +++ b/env-sample @@ -2,6 +2,8 @@ # Year to run for YEAR=2024 +# Recurring start date (MM-DD) +RECURRING_START_DATE=04-01 # Where your application resides HOME_DIR=/home/foo/ # Path to the weather data diff --git a/mapfile/template.j2 b/mapfile/template.j2 index 40a4a6f0677a1480b98058e786c04502cd17bca7..2376534f27a7ea028dd114847d3691cdd810cdc8 100644 --- a/mapfile/template.j2 +++ b/mapfile/template.j2 @@ -45,7 +45,7 @@ WEB <p> Kartet viser beregnet <a href=\"https://www.vips-landbruk.no/forecasts/models/PSILARTEMP/\" target=\"new\">svermetidspunkt for gulrotflue 1. generasjon</a>. Varslene beregnes i rutenett a 1x1km med akkumulerte - <span itemprop=\"DD\">døgngrader</span> basert på reanalyserte data og værvarsler fra + <span itemprop=\"DD\">døgngrader</span> basert på reanalyserte data og værprognoser fra Meteorologisk institutt. Varslene oppdateres en gang per døgn. Visning av varsler startes 1. april og skrus av 1. oktober. Modellen for svermetidspunkt for gulrotflue beregnes også med data fra værstasjoner, hvor mer detaljerte beregninger kan hentes opp via visningen i kartet på VIPS-forsida. @@ -59,11 +59,11 @@ WEB "wms_abstract.en" " <p>The warning system model «Carrot rust fly temperature» is based on a Finnish temperature-based model (Markkula <em>et al</em>, 1998; Tiilikkala & Ojanen, 1999; Markkula <em>et al</em>, 2000). The model determines the start of the flight period for the 1st and 2nd generation of carrot rust fly based on accumuleted degree-days (day-degrees) over a base temperature of 5,0 °C. VIPS uses the model for the 1st generation only.</p> <p>Standard air temperature (temperature measured 2 m above ground) is used in the model. <span itemprop=\"DD\">Degree-days</span> are defined for this model as the sum of the difference between a base temperature of 5,0 °C and the mean temperature for all days with a temperature >5,0 °C, in other words (daily mean temperature – 5,0 °C) from 1 March (beginning when the ground has thawed).</p> - <p>< href=\"https://www.vips-landbruk.no/forecasts/models/PSILARTEMP/\" target=\"new\">Complete model description</a></p> + <p><a href=\"https://www.vips-landbruk.no/forecasts/models/PSILARTEMP/\" target=\"new\">Complete model description</a></p> " "wms_enable_request" "*" "wms_title.en" "Carrot rust fly (Psila rosae) temperature model" - "wms_title.nb" "Gulrotflue svermetidspunktmodell" + "wms_title.nb" "Gulrotflue svermetid 1. generasjon" "wms_getfeatureinfo_formatlist" "text/plain,text/html,text/xml" "wms_accessconstraints" "none" "wms_addresstype" "" diff --git a/run_PSILARTEMP.sh b/run_PSILARTEMP.sh index b1e17f2b2e899a5ac2431cc59c22162380d8e604..9b2c45642e732ea431476d3f5e11e58ef2f11e82 100755 --- a/run_PSILARTEMP.sh +++ b/run_PSILARTEMP.sh @@ -53,8 +53,8 @@ cd $APP_PATH # Create and activate the virtual environment python3 -m venv .venv . .venv/bin/activate -python3 -m pip install --upgrade pip -pip install -r $REQUIREMENTS +python3 -m pip install -q --upgrade pip +pip install -q -r $REQUIREMENTS # Run the model echo "==== `date`: Running model" &>> "$LOG_FILE"