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

Add testing

parent 7d5fa65e
Branches
Tags
1 merge request!3Add temp threshold
Showing
with 898 additions and 0 deletions
*.nc *.nc
!test/weather_data/*_cropped.nc
*.tif *.tif
*.tif.aux.xml *.tif.aux.xml
.env .env
.venv .venv
mapfile/*.map mapfile/*.map
last_run_timestamp last_run_timestamp
.~lock.input_data_test.ods#
# Testing the model
Lacking proper pytest design, here's how to test any changes made to the model
## 1. Get weather data from a single point
In the `weather_data` folder, very small weather data files are available. They are 9x9 grids. You can get weather data in CSV format for a single grid point ([0,0]) by running e.g.
```bash
$ python3 ./test_util.py printweather > test_input_data.csv
```
## 2. Calculate the expected WHS
This has been done in the example file `input_data_test.ods`
## 3. Compare the spreadsheet calculations with the output from the model
Run the model on the test data. Remember to set `WEATHER_DATA_DIR=test/` in your .env file
```bash
$ cd ../ && ./run_SEPTREFHUM.sh && cd test/
```
You can print out the results for the grid point ([0,0]) using
```bash
$ python3 ./test_util.py printwhs
```
Example output (from 2024-05-16):
```csv
Date,WHS
2024-04-02 00:00:00+00:00,0.0
2024-04-03 00:00:00+00:00,0.0
2024-04-04 00:00:00+00:00,0.0
2024-04-05 00:00:00+00:00,0.0
2024-04-06 00:00:00+00:00,0.0
2024-04-07 00:00:00+00:00,0.0
2024-04-08 00:00:00+00:00,6.0
2024-04-09 00:00:00+00:00,6.0
2024-04-10 00:00:00+00:00,6.0
2024-04-11 00:00:00+00:00,9.0
2024-04-12 00:00:00+00:00,10.0
2024-04-13 00:00:00+00:00,10.0
2024-04-14 00:00:00+00:00,1.0
2024-04-15 00:00:00+00:00,0.0
2024-04-16 00:00:00+00:00,0.0
2024-04-17 00:00:00+00:00,0.0
2024-04-18 00:00:00+00:00,0.0
2024-04-19 00:00:00+00:00,0.0
2024-04-20 00:00:00+00:00,0.0
2024-04-21 00:00:00+00:00,0.0
2024-04-22 00:00:00+00:00,0.0
2024-04-23 00:00:00+00:00,0.0
2024-04-24 00:00:00+00:00,0.0
2024-04-25 00:00:00+00:00,0.0
2024-04-26 00:00:00+00:00,0.0
2024-04-27 00:00:00+00:00,0.0
2024-04-28 00:00:00+00:00,0.0
2024-04-29 00:00:00+00:00,1.0
2024-04-30 00:00:00+00:00,1.0
2024-05-01 00:00:00+00:00,1.0
```
\ No newline at end of file
File added
This diff is collapsed.
#!/usr/bin/python3
"""
Copyright (C) 2023 NIBIO <https://www.nibio.no/>.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import sys
import glob
import pytz
import netCDF4 as nc
from datetime import datetime
local_timezone = pytz.timezone("UTC")
def printusage():
print("Usage: test_util.py [printweather|printwhs]")
if len(sys.argv) < 2:
printusage()
exit(1)
if sys.argv[1] == "printweather":
parameters = ["air_temperature_2m","hourly_precipitation","relative_humidity_2m","wind_speed_10m"]
print("time,%s" % ",".join(parameters))
weather_data_files = glob.glob(f"weather_data/daily_archive_*.nc")
weather_data_files.sort()
for filename in weather_data_files:
current_daily_archive = nc.Dataset(filename)
timestep_idx = 0
for timestep in current_daily_archive.variables["time"][:]:
timestep_date = datetime.fromtimestamp(timestep).astimezone(local_timezone)
param_values_for_hour = []
for parameter in parameters:
param_values_for_hour.append(current_daily_archive.variables[parameter][timestep_idx][0][0][0])
print(f"{timestep_date},{",".join(map(str,param_values_for_hour))}")
timestep_idx = timestep_idx + 1
#print (timestep[0][0][0])
current_daily_archive.close()
elif sys.argv[1] == "printwhs":
result = nc.Dataset(f'../tmp/result.nc', 'r')
timestep_idx = 0
print("Date,WHS")
for timestep in result.variables["time"][:]:
timestep_date = datetime.fromtimestamp(timestep).astimezone(local_timezone)
print(f"{timestep_date},{result.variables["WHS"][timestep_idx][0][0][0]}")
timestep_idx = timestep_idx + 1
result.close()
else:
printusage()
\ No newline at end of file
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment