- Demo_Main.R
- Runfiles
- Parameters
- Rfunctions
- DataOS
- InitialCond
- Schematisation
- ModelOutput
- Visualisation
- Preprocessing
- rawdata
- Figures
- Tracer
The model is written in R. The main script (Demo_Main.R) is located in the root. The input and output is stored in different subdirectories. The folowing subdirectories are directly used by the model:
- Runfiles: contains the files with the specific model settings;
- Parameters: Directory with model parameters as *.txt files;
- Rfunctions: Directory with R-scripts containing the functions used by the model. The name of the file corresponds to the name of the function;
- DataOS: Directory with inputdata for the model (bathymetry, KNMI and water quality data). Files are stored as Rdata files (*.rds);
- InitialCond: Directory with *.txt files with the initial conditions for the model;
- Schematization: Directory with the schematizations as Rdata files. Schemes are stored as SpatialPolygonsDataFrame;
- ModelOutput: Directory with model output as Rdata files (*.rds). Each model run results in four output files;
- Visualisation: Shiny application for visualisation of model results.
The other subdirectories contain scripts and data used for the preprocessing:
- Preprocessing: Directory with R-scripts to generate the datafiles in the directory DataOS. Data are read from the Directory rawdata;
- rawdata: Directory with raw data. Data are read from R script files in the directory Preprocessing;
- Figures: Directory with output in the form of *.png files;
- Tracer: Directory with the results of the tracer calculations to estimate exchange rates.
Demo_Main.R
This file contains the code for the main script of the model. From this file the working directory is set and the functions in the subdirectory “./Rfunctions/” are sourced. The specific runfile is read from the directory “./Runfiles/”. The runfile contains the specific settings for the model simulation. Required model parameters are read, model scheme is set and boundary conditions are defined based on water quality data. Forcing functions for light and water temperature are created and initial conditions of the state variables are set. Finally, the simulation period is defined. The model is run using the function ode() from the package deSolve. The output of the model is processed by the function post_proc() and results are stored in the subdirectory “./ModelOutput/”.
Runfiles
The runfiles are located in the subdirectory “./Runfiles/”. This file is read by the function “Read_Runfile()”. This file contains the specific information for the model run
- Type: Type of model to run (NPZ, Tracer or Salinity
- Scheme: Schematization of the model (0D, 4Comp, 28Comp)
- StartDate: Start date of the model run
- EndDate: End date of the model run
- Intervals: Number of time intervals in the model output
- Prog_bar: Show progress bar during silmulation? (T or F).
- Parfile: Name of *.txt file containing the model parameters, located in the subdirectory “./Parameters/”
- RealForcing: Real measured forcing (T) or average seasonal forcing (F)"
- WQfile: Name of the R data (*.rds) file containing water quality file, located in the subdirectory “./DataOS/WQData”
- Init_manual: Initial conditions from text file (T) or previous model (F)
- Init_file: Text file with Initial conditions (used if Init_manual is T), located in the subdirectory “./InitialCond/”.
- Init_model: Model run used for initial conditions (used if Init_manual is F).
- Lightfile: Name of the R data (*.rds) file containing data on irradiation, located in the subdirectory “./DataOS/KNMI”
- Tempfile: Name of the R data (*.rds) file containing data on water temperature, located in subdirectory “./DataOS/WQData”
Parameters
The parameters used by the model are *.txt files located in the subdirectory “./Parameters/”. Parameter files can be created for the NPZ model as well as for the Tracer and Sanility model. In the Runfile, the reference should be provided to the correct parameter file.
Rfunctions
The model functions are located as R scripts in the subdirectory "./Rfunctions/". The name of the script corresponds to the name of the function.
DataOS
The input data for the model can be found in the subdirectory “./DataOS/”. In this directory data are stored as R-data files (*.rds). In the folder data folowing data can be found:
- Water quality and water temperature (subdirectory “./DataOS/WQData/");
- Irradiation (subdirectory “./DataOS/KNMI/");
- Bathymetry (subdirectory “./DataOS/Bathymetry/”) ;
- Shellfish (subdirectory “./DataOS/Shellfish/")
Data is stored in R-data files. The data can be updated when new data become available. New data can be given new names.
Water quality and water temperature
In the subdirectory “./DataOS/WQData/”, the R-data files (*.rds) with the water temperature and nutrient concentrations are located. The names of the required files for the model run is defined as the parameters “Tempfile” and “WQfile”, respectively in the Runfile*.txt. For the water temperature, the measurements from Rijkswaterstaat for the location Marollegat is used. For the periods where data are missing, data from the NIOZ measurements are used. The temperature data is available for the model at each moment through the r-function approxfun() as Temp_forc (time). The nutrient concentrations and the concentrations of phytoplankton for the Rijkswaterstaat monitoring locations in the Oosterschelde (LODSGT, ZIJPE, WISSKKE and HAMMOT), the Voordelta (WALCRN2) and Volkerak-Zoommeer (STEENBGN and OESTDM) are derived from Rijkswaterstaat.
Irradiation
In the subdirectory “./DataOS/KNMI/”, the R-data files (*.rds) with the daily irradiation [W d-2] are located. The name of the required file for the model run is defined as the parameter “Lightfile” in the Runfile*.txt. The data is available for the model through the r-function approxfun() as Light_forc(time). The file with the KNMI data can be updated with the R-script “KNMI_Data.R” in the subdirectory “./Preprocessing/”. The raw meteo-data can be downloaded from the site http://projects.knmi.nl/klimatologie/daggegevens/selectie.cgi/ and placed in the subdirectory “./rawdata/KNMI/”.
Bathymetry
In the subdirectory “./DataOS/Bathymetry/” bathymetric data is stored as a raster in a R-data file (Depth.rds). The grid has a resolution of 20x20 meter and water depth is in meters below NAP. The file is created by the R-script Bathymetry.R which is located in the subdirectory “./Preprocessing/”.
Shellfish
In the subdirectory “./DataOS/Shellfish/” data on shellfish biomass (mussels, cockles and oysters) for a number of years is stored in a R-data file (*.rds). The file is created by the R-script Shellfish.R which is located in the subdirectory “./Preprocessing/”.
InitialCond
In the subdirectory "./InitialCond/" contain text files with initial conditions used in the NPZ, Salinity and Tracer models. The reference to the correct file is given in the Runfile (Init_file). The file is used for initial conditions if the parameter Init_manual = T in the Runfile. Else initial conditions from a previous modelrun (Init_model) is used as initial conditions.
Schematisation
The subdirectory “./Schematisation/” contains the three different schematisations that can be used by the model (0D, 4-Comp and 28 Comp).
ModelOutput
The output of the model simulation is placed in the subdirectory “./ModelOutput/” as R data files (*.rds). Each model simulation creates three output files: “out__.rds”, “run__.rds”, “agg_*.rds” and “init_*.rds”, with * is the name of the runfile (*.txt) that was used to run the model.
- out_*.rds: time series of the model results. The file contains the values of the state variables and other calculated variables for each output time step and each compartment.
- run_*.rds: this file contains the settings for the model run as set in the runfile.
- agg_*.rds: This file contains the yearly aggegated data such as yearly primary production for each compartment. The variables in the dataframe “out” contains the time series of the model results with a record for each output time step (set in “Runfile*.txt”). Time information is given in the output variable time (days since 1-jan-1970, set in “Runfile*.txt” as RefDate) and in the variable Date (date format). The values of all state variables is given for each compartment. Variable names ending with “_xt” (e.g.: Chla_xt) indicate variables that vary over time and over space. Variable names ending with “tt” (e.g.: Temp_tt) indicate variables that vary only over time. The data in “agg*.rds” contains yearly aggregated data for each compartment. For example the column “NPPy_2016” presents the nett primary production in 2016 for each compartment.
- var_*.rds: array with names of the variables in the out-file
- init_*.rds: this file values of the state variables at end of simulation. Data can be used as initial conditions for new model simulations.
Visualisation
A shiny app is created to visualise the results of the model. The app is located in the subdirectory “./Visualisation/” and contains three files: ui.R, server.R and global.R. With the application the model results can be visualized as time series per compartment and spatially as interactive maps. The model results can be compared to observations and other model runs.
Preprocessing
In the subdirectory "./Preprocessing/" a number of R-scripts are stored to process new data that is used by the model. Preprocessing can be done if new data become available. The scripts read data from the directory "./rawdata/". Data are processed and analyzed and the results are stored as Rdata files in subdirectories of the directory "./DataOS/".
rawdata
The subdirectory "./rawdata/" contains the raw data that are used by the scripts in the subdirectory "./Preprocessing/" to generate data in "./DataOS/" that are used by the model..
Figures
The subdirectory "./Figures/" contains a number of subdirectories with figures in *.png format. Most of the figures are generated by the preprocessing scripts located in the subdirectory "./Preprocessing/". Figures include time series of water quality data, temperature and irradiation. Also maps with bathymetry, locations of monitoring stations and model schematizations are present. Figures are not used by the model.
Tracer
The subdirectory "./Tracer/" contains a number of scripts that are used for the generation of the tracer data.