Example Script 01

This example was generated 2024-04-05

Example data from Beatenberg is located in subfolder examples/. WSL is acknowledged for providing the input data (see section Acknowledgments).

To run your own simulations: follow the step-by-step instructions below.

Setup and run simulation

# How to work with a Julia script in a new environment
# create a new folder: "pgm"
# a) start `julia` -> `]` -> activate . -> add LWFBrook90
# b) in VSCode -> click at bottom and select "pgm" as Julia env
# c) run the code
# alternatively right-click on the folder in VSCode
#   -> Change to this Directory and Activate this environment

# Load packages:
using LWFBrook90

# `using LWFBrook90` brings the following exported functions into scope:
# - `loadSPAC()`                   # to define and run a simulation
# - `setup()`                      # to define and run a simulation
# - `simulate!()`                  # to define and run a simulation
# - `remakeSPAC()`                 # to define and run a simulation
# - `SPAC()`                       # to define and run a simulation
# - `DiscretizedSPAC()`            # to define and run a simulation
# - `get_states()`                 # to postprocess a simulation
# - `get_fluxes()`                 # to postprocess a simulation
# - `get_forcing()`                # to postprocess a simulation
# - `get_soil_()`                  # to postprocess a simulation
# - `get_water_partitioning()`     # to postprocess a simulation
# - `RelativeDaysFloat2DateTime()` # a helper function for time
# - `prepare_for_LWFBrook90R()`    # a helper function

Documentation can be accessed by typing: ?loadSPAC, ?setup, ?simulate!, ?plotisotopes, etc.

Define simulation model by reading in system definition and input data from input files. When printed, the generated SPAC model gives a summary.

# Read in input data
input_path = "../../../examples/DAV2020-full/"; input_prefix = "DAV2020-full"; # make sure to get the path correct relative to `pwd()``
# input_path = "examples/DAV2020-full/"; input_prefix = "DAV2020-full";
# input_path = "examples/isoBEAdense2010-18-reset-FALSE-input/"; input_prefix = "isoBEAdense2010-18-reset-FALSE";
model = loadSPAC(input_path, input_prefix; simulate_isotopes = false);
model = loadSPAC(input_path, input_prefix; simulate_isotopes = true);
model
SPAC model:
===== DATES:===============

===== METEO FORCING:===============
GLOBRAD (MJ/m2/day): avg:  13.90, range:   1.04 to  32.40
PREC       (mm/day): avg:   2.61, range:   0.00 to  35.40
TMAX           (°C): avg:   9.00, range:  -8.90 to  26.60
TMIN           (°C): avg:  -0.79, range: -18.80 to  12.90
VAPPRES       (kPa): avg:   0.64, range:   0.11 to   1.37
WIND          (m/s): avg:   2.59, range:   0.70 to   4.90
δ18O            (‰): avg: -13.26, range: -22.60 to  -6.87
δ2H             (‰): avg: -95.98, range:-171.53 to -44.68

===== CANOPY EVOLUTION:===============
model.pars.canopy_evolution was loaded form meteoveg.csv

===== INITIAL CONDITIONS:===============
Soil   IC: soil_discretization.csv
Scalar IC: 3×6 DataFrame
 Row  u_GWAT_init_mm  u_INTS_init_mm  u_INTR_init_mm  u_SNOW_init_mm  u_CC_in ⋯
     │ Float64         Float64         Float64         Float64         Float64 ⋯
─────┼──────────────────────────────────────────────────────────────────────────
   1 │            1.0             0.0             0.0             0.0          ⋯
   2 │          -13.0           -13.0           -13.0           -13.0
   3 │          -95.0           -95.0           -95.0           -95.0
                                                               2 columns omitted

===== MODEL PARAMETRIZATION:===============
         VXYLEM_mm =>     20.0 |             RHOTP =>      2.0 |                TH =>     40.0 |
   DISPERSIVITY_mm =>     40.0 |                NN =>      2.5 |             MXKPL =>     15.6 |
           LAT_DEG =>     47.0 |          FRINTLAI =>      0.1 |            MXRTLN =>   3000.0 |
        ESLOPE_DEG =>      0.0 |          FSINTLAI =>      0.0 |          INITRLEN =>     12.0 |
        ASPECT_DEG =>      0.0 |          FRINTSAI =>      0.1 |          INITRDEP =>      0.2 |
               ALB =>      0.2 |          FSINTSAI =>      0.0 |          RGRORATE =>      0.0 |
             ALBSN =>      0.5 |            CINTRL =>      0.1 |           RGROPER =>     30.0 |
                C1 =>      0.2 |            CINTRS =>      0.1 |            FXYLEM =>      0.5 |
                C2 =>      0.5 |            CINTSL =>      0.6 |             PSICR =>     -1.0 |
                C3 =>      0.2 |            CINTSS =>      0.6 |             RTRAD =>      0.3 |
            WNDRAT =>      0.3 |            RSTEMP =>     -0.5 |            NOOUTF =>      1.0 |
             FETCH =>   5000.0 |            MELFAC =>      1.5 |          IDEPTH_m =>      0.4 |
               Z0W =>      0.0 |             CCFAC =>      0.3 |          QDEPTH_m =>      0.0 |
                ZW =>      2.0 |            LAIMLT =>      0.2 |              RSSA =>    795.3 |
            MAXLAI =>      3.0 |            SAIMLT =>      0.5 |              RSSB =>      1.0 |
  DENSEF_baseline_ =>      1.0 |            GRDMLT =>      0.3 |            INFEXP =>      0.5 |
     SAI_baseline_ =>      1.0 |            MAXLQF =>      0.1 |             BYPAR =>      0.0 |
  AGE_baseline_yrs =>    100.0 |             KSNVP =>      0.3 |             QFPAR =>      1.0 |
 HEIGHT_baseline_m =>     25.0 |            SNODEN =>      0.3 |              QFFC =>      0.0 |
            LWIDTH =>      0.1 |             GLMAX =>      0.0 |            IMPERV =>      0.0 |
               Z0G =>      0.0 |             GLMIN =>      0.0 |            DSLOPE =>      0.0 |
               Z0S =>      0.0 |                CR =>      0.5 |      LENGTH_SLOPE =>    200.0 |
               LPC =>      4.0 |                RM =>   1000.0 |             DRAIN =>      0.5 |
               CZS =>      0.1 |                R5 =>    287.0 |               GSC =>      0.0 |
               CZR =>      0.1 |              CVPD =>      2.0 |               GSP =>      0.0 |
                HS =>      1.0 |                TL =>      0.0 |                               |
                HR =>     10.0 |                T1 =>     10.0 |                               |
             ZMINH =>      2.0 |                T2 =>     30.0 |                              

===== SOIL DOMAIN:===============
Root distribution:       soil_discretization.csv
Soil layer properties:   3×3 DataFrame
 Row  Upper_m  Lower_m  shp                                                                                Float64  Float64  MualemVa…                                                                         
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │    0.0     -0.03  (θ from θr=0.000 to θs=0.379, Ks =  2854.9, STONEF=0.2, l=-3.3, n=1.2, α=   20.4)
   2 │   -0.03    -0.4   (θ from θr=0.000 to θs=0.379, Ks =  2854.9, STONEF=0.4, l=-3.3, n=1.2, α=   20.4)
   3 │   -0.4     -1.1   (θ from θr=0.000 to θs=0.379, Ks =  2854.9, STONEF=0.8, l=-3.3, n=1.2, α=   20.4)
Soil discretized into N=5 layers, Δz layers: (avg, min, max) = (0.220,0.030,0.400)m.
[-0.03, -0.1, -0.4, -0.8, -1.1]

===== SOLVER OPTIONS:===============
(compute_intermediate_quantities = true, simulate_isotopes = true, DTIMAX = 0.5, DSWMAX = 0.05, DPSIMAX = 0.0005)

If wanted, arguments can be supplied to modify the loaded SPAC (e.g. for parameter estimation), hence requiring less input CSVs. Warnings are output (see below) to signal to the user that existing input CSVs might be ignored.

# Read in providing arguments, requiring less CSVs
model_modified =
    loadSPAC(input_path, input_prefix;
        simulate_isotopes = true,
        Δz_thickness_m    = [fill(0.04, 5); # grid spacing (heterogenous), meter (N=21)
                             fill(0.05, 5); # write Δ in VSCode by typing \Delta and hit shift
                             fill(0.06, 5);
                             fill(0.07, 5);
                             fill(0.10, 1)],
        root_distribution = (beta = 0.98, z_rootMax_m=-0.5),
        IC_soil           = (PSIM_init_kPa = -7.0,
                            delta18O_init_permil = -9.0,
                            delta2H_init_permil = -11.0),
        canopy_evolution  = (DENSEF_rel = 100,
                             HEIGHT_rel = 100,
                             SAI_rel    = 100,
                             LAI_rel = (DOY_Bstart = 120,
                                     Bduration  = 21,
                                     DOY_Cstart = 270,
                                     Cduration  = 60,
                                     LAI_perc_BtoC = 100,
                                     LAI_perc_CtoB = 55)),
        storm_durations_h = [5.44, 5.44, 5.44, 5.44, 5.44, 5.44,
                             5.44, 5.44, 5.44, 5.44, 5.44, 5.44],
        IC_scalar         = (amount = (u_GWAT_init_mm = 1.,
                                       u_INTS_init_mm = 13.7,
                                       u_INTR_init_mm = 0.,
                                       u_SNOW_init_mm = 22.222,
                                       u_CC_init_MJ_per_m2 = 0.101010,
                                       u_SNOWLQ_init_mm =  0.),
                            d18O    = (u_GWAT_init_permil = -11.111,
                                       u_INTS_init_permil = -12.222,
                                       u_INTR_init_permil = -13.333,
                                       u_SNOW_init_permil = -14.444),
                            d2H     = (u_GWAT_init_permil = -95.111,
                                       u_INTS_init_permil = -95.222,
                                       u_INTR_init_permil = -95.333,
                                       u_SNOW_init_permil = -95.444)));
┌ Warning: Isotopic signature of precipitation is available for the period (2020-12-16T00:00:00 - 2021-11-04T00:00:00), i.e. (days -16.0 - 307.0)
         Whereas the other meteorologic inputs are available for (2021-01-01T00:00:00 - 2021-12-31T00:00:00), i.e. (days 0.0 - 364.0).
         Isotopic signatures will be extrapolated with constant values before and after the available period.
@ LWFBrook90 ~/work/LWFBrook90.jl/LWFBrook90.jl/src/func_read_inputData.jl:938
┌ Warning: Requested to overwrite storm durations. Values in ../../../examples/DAV2020-full/DAV2020-full_meteo_storm_durations.csv are ignored.
@ LWFBrook90 ~/work/LWFBrook90.jl/LWFBrook90.jl/src/func_read_inputData.jl:687
┌ Warning: Received canopy_evolution in loadSPAC(), overwriting values from `meteoveg.csv`.
@ LWFBrook90 ~/work/LWFBrook90.jl/LWFBrook90.jl/src/func_read_inputData.jl:142
┌ Warning: Requested to overwrite initial conditions. Values in ../../../examples/DAV2020-full/DAV2020-full_initial_conditions.csv are ignored.
@ LWFBrook90 ~/work/LWFBrook90.jl/LWFBrook90.jl/src/func_read_inputData.jl:172
┌ Warning: loadSPAC(...; Δz_thickness_m = ...) provided. Ignoring `soil_discretization.csv`, i.e. also overwriting root distribution and initial conditions.
@ LWFBrook90 ~/work/LWFBrook90.jl/LWFBrook90.jl/src/func_read_inputData.jl:202
┌ Warning: Spatial domain soil discretization is larger than the provided soil horizon information. Lowest soil horizon will be extended.

Lowest soil horizon from -0.4m to -1.1m will be extended down to -1.2000000000000006m.
@ LWFBrook90 ~/work/LWFBrook90.jl/LWFBrook90.jl/src/func_discretize_soil_domain.jl:84

Documentation can be accessed by typing: ?loadSPAC, ?setup, ?simulate!, ?plotisotopes, etc.

The objects model and model_modified are instances of a SPAC() (soil-plant-atmosphere continuum) and contain fully specified simulations. To run them they need to be transformed into a system of ODES (setup()) and solved (simulate()):

# Setup and run simulation
simulation     = setup(model)
simulation_mod = setup(model_modified)
# Inputs can be checked with:
# `plot_inputs(simulation)`. Note: NOT YET IMPLEMENTED

simulate!(simulation_mod)
simulate!(simulation_mod) # Run it a second time to showcase shorter runtime
# The computed solution is stored within the object.
# When using VSCode a progress bar is shown in the status bar.
┌ Info:   Start of simulation at 2024-04-05T13:46:40.622.
        Saving intermediate results (`saveat=`) between: (0.0, 365.0) days
 runtime: 13.541669 seconds (20.97 M allocations: 1.394 GiB, 5.77% gc time, 94.15% compilation time)
[ Info:   Time steps for solving: 9088 (9088 accepted out of 9122 total)
[ Info:   End of simulation at 2024-04-05T13:46:54.297.
┌ Info:   Start of simulation at 2024-04-05T13:46:54.348.
        Saving intermediate results (`saveat=`) between: (0.0, 365.0) days
 runtime: 0.755181 seconds (3.23 M allocations: 263.580 MiB, 9.08% gc time)
[ Info:   Time steps for solving: 9088 (9088 accepted out of 9122 total)
[ Info:   End of simulation at 2024-04-05T13:46:55.104.

Notice that the very first time a model is simulated, the runtime is longer because it includes compilation. This compilation is not needed for any subsequent run.

Postprocessing results

These simulations can then be post-processed with predefined functions as shown below. Alternatively the following variables contain the simuation results for user-defined post-processing:

simulation_mod.ODESolution;
simulation_mod.ODESolution_datetime;
typeof(simulation_mod.ODESolution);
propertynames(simulation_mod.ODESolution)
# HINT: To get these names, type `simulation_mod.` and wait for the autocomplete!
(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :stats, :alg_choice, :retcode)

simulation_mod.ODESolution is a ODESolution object: documentation how to access under: https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/ and more generally: https://docs.sciml.ai/Overview/stable/ simulationmod.ODESolution.t simulationmod.ODESolution.u simulationmod.ODESolution.retcode simulationmod.ODESolution.destats

Note that it is possible to use R Code from within Julia, e.g ggplot: https://stackoverflow.com/a/70073193/3915004

Postprocessing: Extract values

Below illustrative code how to extract states and fluxes:

# Get simulation output (states, fluxes, forcing) as DataFrames

The three functions: get_states(), get_fluxes(), and get_forcing() return DataFrames` with daily values of all the state variables, fluxes, and the input forcing.

get_states(simulation_mod)
get_fluxes(simulation_mod)
get_forcing(simulation_mod)

get_states(simulation_mod; days_to_read_out_d = 0:30:360) # specific days relative to simulation.parametrizedSPAC.reference_date can be specified
13×102 DataFrame
RowdatesGWAT_mmINTS_mmINTR_mmSNOW_mmCC_MJm2SNOWLQ_mmSWAT_mmGWAT_d18OINTS_d18OINTR_d18OSNOW_d18OXYLEM_d18OGWAT_d2HINTS_d2HINTR_d2HSNOW_d2HXYLEM_d2Hd18O_permil_40mmd18O_permil_80mmd18O_permil_120mmd18O_permil_160mmd18O_permil_200mmd18O_permil_250mmd18O_permil_300mmd18O_permil_350mmd18O_permil_400mmd18O_permil_450mmd18O_permil_510mmd18O_permil_570mmd18O_permil_630mmd18O_permil_690mmd18O_permil_750mmd18O_permil_820mmd18O_permil_890mmd18O_permil_960mmd18O_permil_1030mmd18O_permil_1100mmd18O_permil_1200mmd2H_permil_40mmd2H_permil_80mmd2H_permil_120mmd2H_permil_160mmd2H_permil_200mmd2H_permil_250mmd2H_permil_300mmd2H_permil_350mmd2H_permil_400mmd2H_permil_450mmd2H_permil_510mmd2H_permil_570mmd2H_permil_630mmd2H_permil_690mmd2H_permil_750mmd2H_permil_820mmd2H_permil_890mmd2H_permil_960mmd2H_permil_1030mmd2H_permil_1100mmd2H_permil_1200mmθ_m3m3_40mmθ_m3m3_80mmθ_m3m3_120mmθ_m3m3_160mmθ_m3m3_200mmθ_m3m3_250mmθ_m3m3_300mmθ_m3m3_350mmθ_m3m3_400mmθ_m3m3_450mmθ_m3m3_510mmθ_m3m3_570mmθ_m3m3_630mmθ_m3m3_690mmθ_m3m3_750mmθ_m3m3_820mmθ_m3m3_890mmθ_m3m3_960mmθ_m3m3_1030mmθ_m3m3_1100mmθ_m3m3_1200mmψ_kPa_40mmψ_kPa_80mmψ_kPa_120mmψ_kPa_160mmψ_kPa_200mmψ_kPa_250mmψ_kPa_300mmψ_kPa_350mmψ_kPa_400mmψ_kPa_450mmψ_kPa_510mmψ_kPa_570mmψ_kPa_630mmψ_kPa_690mmψ_kPa_750mmψ_kPa_820mmψ_kPa_890mmψ_kPa_960mmψ_kPa_1030mmψ_kPa_1100mmψ_kPa_1200mm
DateTimeFloat64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64
12021-01-01T00:00:001.013.70.022.2220.101010.090.2641-11.111-12.222-13.333-14.444-9.0-95.111-95.222-95.333-95.444-11.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-9.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.0-11.00.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.2005870.200587-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0-7.0
22021-01-31T00:00:001.01.093680.392421158.2950.07.91476103.182-9.00086-18.86-18.86-18.86-9.02106-11.0329-139.79-139.79-139.79-11.3164-15.346-14.3139-13.3697-12.601-12.0126-11.5212-11.1661-10.8978-10.621-10.2329-9.7563-9.40562-9.20879-9.1058-9.05224-9.02286-9.00926-9.00353-9.00126-9.00042-9.0001-95.4348-82.206-69.9365-59.798-51.9218-45.2561-40.3967-36.7233-32.9859-27.86-21.554-16.847-14.1243-12.6372-11.8298-11.3705-11.1522-11.0585-11.021-11.0071-11.00170.2222490.2255940.2284740.2309530.2330970.2352350.2374230.2397350.2425570.2438250.2392240.2336470.2281660.2233990.219770.217240.216140.2163760.2176740.2198770.223659-4.42579-4.13508-3.90212-3.71345-3.55852-3.41118-3.26743-3.12278-2.95573-2.88388-3.15416-3.51998-3.92633-4.32324-4.65629-4.90605-5.01934-4.99477-4.86207-4.64607-4.30045
32021-03-02T00:00:001.00.00.0104.0960.05.20478117.624-11.891-10.11-10.11-10.11-10.1396-50.227-62.4-62.4-62.4-27.1479-12.563-13.198-13.7049-14.087-14.3531-14.5373-14.6138-14.6135-14.585-14.5941-14.5639-14.4899-14.3773-14.2266-14.0359-13.782-13.4762-13.1326-12.7619-12.3831-11.9707-83.8894-89.2242-93.237-95.958-97.4743-97.9856-97.3506-95.9984-94.5171-93.7145-92.3726-90.4939-88.152-85.3438-82.0442-77.8908-73.1252-67.9673-62.5581-57.147-51.34420.2315950.2349770.2380720.24110.2441970.2479040.2525160.2579490.2646560.2703330.2709360.2716770.2724740.2733350.2742750.2754170.2769160.2789550.2821460.2878860.302522-3.66629-3.42865-3.22613-3.04071-2.86316-2.66528-2.43937-2.19898-1.93575-1.738-1.71819-1.69419-1.66871-1.64163-1.61255-1.57787-1.53346-1.47493-1.38753-1.24216-0.929603
42021-04-01T00:00:001.00.00.071.50810.03.5754137.369-14.0999-14.42-14.42-14.42-10.9482-86.7765-102.2-102.2-102.2-42.5366-14.2381-14.1653-14.0874-14.0093-13.9366-13.8664-13.8163-13.7901-13.7809-13.7745-13.7769-13.7904-13.8146-13.8487-13.8918-13.947-14.0069-14.0622-14.1042-14.1238-14.1116-100.274-99.4953-98.6503-97.7827-96.9376-96.0624-95.3217-94.7694-94.3629-94.0349-93.699-93.3812-93.0839-92.7979-92.5101-92.1685-91.7404-91.1568-90.3303-89.2161-87.46530.2744510.279520.2833250.2865160.2894380.2927470.2970870.3033340.3141340.3249410.3248650.3248080.3247470.3246640.3245540.324370.3239560.3229140.320240.314890.311285-1.60714-1.45909-1.35644-1.27553-1.20526-1.12979-1.03696-0.91437-0.728848-0.570732-0.571756-0.572536-0.573362-0.574488-0.575981-0.578492-0.584155-0.598567-0.636531-0.716973-0.774848
52021-05-01T00:00:001.00.00.00.00.00.0104.664-14.1231-15.66-15.66-15.66-12.2597-99.5033-109.29-109.29-109.29-66.366-15.0546-14.8858-14.7794-14.7078-14.6552-14.6082-14.5669-14.5305-14.4958-14.4572-14.4169-14.3835-14.3544-14.3267-14.2994-14.2697-14.2397-14.2104-14.1821-14.1555-14.1289-110.949-111.052-110.756-110.227-109.579-108.799-107.997-107.261-106.645-106.219-105.712-105.165-104.598-104.012-103.408-102.736-102.055-101.395-100.767-100.19-99.62490.206710.2101870.2134470.2165230.219460.2226940.2262870.2300610.2341960.2375460.2381860.2389150.2396840.2405960.2417380.2433040.245520.2484370.2523390.2577160.267311-6.12691-5.6882-5.30989-4.97959-4.68608-4.38574-4.07757-3.78011-3.48192-3.25958-3.2189-3.17328-3.12593-3.07074-3.00321-2.91314-2.79076-2.63804-2.44767-2.20878-1.84062
62021-05-31T00:00:001.00.00.00.00.00.097.3131-14.7015-10.43-10.43-10.43-13.8122-107.627-72.59-72.59-72.59-93.4353-12.7238-13.2286-13.6589-13.9756-14.2011-14.3769-14.4958-14.575-14.634-14.678-14.7313-14.7862-14.8332-14.8695-14.8921-14.9001-14.8887-14.8602-14.8184-14.7693-14.7136-91.4779-95.6035-99.1178-101.699-103.534-104.969-105.949-106.615-107.118-107.494-107.951-108.422-108.828-109.144-109.344-109.418-109.323-109.073-108.7-108.252-107.7390.181570.1844760.1876250.1909410.1943640.1983060.2026960.2070710.2113940.2155590.2198650.2244110.2284630.2321590.2356190.239250.2431810.2474040.2522890.2584130.268751-10.8302-10.1065-9.38671-8.69415-8.04232-7.36227-6.68362-6.07948-5.54454-5.0805-4.64724-4.23533-3.90297-3.62538-3.38547-3.15255-2.92013-2.69109-2.44999-2.17966-1.79099
72021-06-30T00:00:001.00.00.00.00.00.061.4898-14.7897-6.87-6.87-6.87-12.2641-108.434-45.57-45.57-45.57-88.6848-7.74638-8.40224-9.23155-10.0457-10.7017-11.2381-11.694-12.1313-12.8404-14.7186-14.8055-14.8497-14.8581-14.8738-14.8807-14.8819-14.8738-14.8585-14.8378-14.8155-14.796-52.8693-58.2593-64.9581-71.4085-76.5421-80.7354-84.3033-87.6938-93.1703-107.917-108.601-108.965-109.049-109.184-109.246-109.256-109.187-109.052-108.867-108.667-108.4920.1467740.1376730.1285180.1212350.1165560.1139160.1132950.1138710.114910.1162530.1230630.1325450.1406960.1475930.1534480.1589140.1638280.1679660.1714170.1742220.176869-27.1228-35.6846-47.9007-61.4614-72.7118-80.1822-82.0757-80.3156-77.2622-73.523-57.6558-41.9785-32.5148-26.4833-22.4085-19.2763-16.9055-15.1797-13.9019-12.9583-12.138
82021-07-30T00:00:001.00.00.00.00.00.0118.668-12.3845-8.63-8.63-8.63-10.146-88.9076-63.31-63.31-63.31-71.6336-8.81982-8.89355-8.97042-9.04911-9.12927-9.21952-9.31228-9.40315-9.48959-9.55796-9.65268-9.77242-9.91288-10.0756-10.2636-10.5015-10.7829-11.1033-11.4594-11.8331-12.2689-64.0676-64.365-64.6797-65.0087-65.3538-65.7574-66.1971-66.6551-67.1139-67.4959-68.0424-68.7655-69.659-70.7512-72.0806-73.8414-76.0079-78.5424-81.4026-84.4283-87.9670.2224370.2275820.2326250.2375820.2425080.2481520.2547050.2619380.2703890.2778030.2800710.2823130.2841060.2854470.2863230.2867560.2866040.2860660.2858450.2876450.297088-4.4088-3.97267-3.59202-3.25725-2.95854-2.65256-2.33938-2.03829-1.73612-1.50773-1.44379-1.38307-1.33623-1.30214-1.28029-1.26963-1.27337-1.28669-1.29217-1.24796-1.03694
92021-08-29T00:00:001.00.00.00.00.00.098.4307-9.31308-12.51-12.51-12.51-9.03339-63.61-88.72-88.72-88.72-59.9056-8.88676-8.47391-8.42277-8.46304-8.52557-8.60183-8.67703-8.74284-8.79344-8.76519-8.80515-8.86354-8.921-8.9763-9.03036-9.08786-9.14339-9.19369-9.23758-9.2739-9.30587-56.7457-53.2166-52.9087-53.4156-54.1213-54.9672-55.8064-56.5483-57.136-57.0224-57.5179-58.1778-58.8272-59.4599-60.087-60.7639-61.4306-62.0494-62.6052-63.0801-63.51130.2038770.2050060.2059480.2069350.2080640.2095490.2115110.2137890.2163820.2184120.2189680.2200660.2214910.2231790.2250950.2274170.230250.2335140.2373710.2420770.249431-6.51379-6.35628-6.22819-6.09737-5.95146-5.76588-5.53088-5.27199-4.99413-4.78849-4.73382-4.62807-4.49486-4.34268-4.17701-3.98584-3.76586-3.52922-3.2708-2.98345-2.58809
102021-09-28T00:00:001.00.00.00.00.00.094.5777-9.13005-10.6-10.6-10.6-9.73641-61.2659-75.17-75.17-75.17-65.0038-10.4559-10.3972-10.3275-10.2414-10.1403-10.0152-9.88587-9.76824-9.66069-9.5454-9.41766-9.29745-9.19739-9.1213-9.06996-9.03879-9.03041-9.03978-9.06105-9.08808-9.11942-72.1959-71.2875-70.4499-69.5682-68.6149-67.4885-66.3618-65.3645-64.4582-63.4032-62.3087-61.3517-60.595-60.059-59.7476-59.6319-59.7241-59.9718-60.3194-60.7049-61.12580.1982460.2009260.2031710.2050040.2064820.2078430.209130.2104430.2120320.213050.2118630.211060.2106440.2106860.2111750.212130.21360.2154590.2177210.2204690.224619-7.37211-6.94788-6.61467-6.35652-6.15706-5.97969-5.81757-5.65733-5.47034-5.35441-5.48992-5.58396-5.63338-5.6283-5.57031-5.45907-5.29285-5.09101-4.85739-4.58994-4.21746
112021-10-28T00:00:001.00.00.00.00.00.081.1802-9.09324-22.6-22.6-22.6-10.0599-60.3635-171.53-171.53-171.53-68.3045-10.7563-10.6274-10.5274-10.4468-10.3701-10.2844-10.1862-10.0916-10.0003-9.90606-9.81138-9.70938-9.61455-9.52221-9.43408-9.34603-9.26688-9.20276-9.15452-9.12158-9.09857-75.3572-74.1068-73.0519-72.1706-71.3514-70.4716-69.5105-68.6126-67.7614-66.892-66.023-65.0966-64.2519-63.4503-62.7089-61.9946-61.3864-60.9302-60.6262-60.4575-60.37650.159450.1608330.1623350.163930.1655960.1675390.1697490.1719920.1742450.1767770.1803330.1841460.1876780.1909950.1941490.1974460.2008720.2042310.2075710.2109350.21515-18.9991-18.3054-17.5864-16.8604-16.1404-15.3477-14.5025-13.7016-12.9506-12.1654-11.1571-10.1857-9.37518-8.68338-8.08142-7.50456-6.95627-6.46393-6.01471-5.59866-5.12397
122021-11-27T00:00:001.00.00.01.25920.006890340.097.8706-13.8754-22.6-22.6-22.6-11.2929-99.7581-171.53-171.53-171.53-78.5307-21.5881-21.3264-21.0166-20.6839-20.3303-19.9218-19.4915-19.0903-18.7589-18.5361-18.2748-17.9781-17.6549-17.3036-16.9223-16.4744-15.9886-15.4858-14.9772-14.4871-13.9897-163.267-161.135-158.605-155.884-152.99-149.644-146.116-142.824-140.103-138.271-136.12-133.678-131.014-128.118-124.971-121.272-117.257-113.097-108.886-104.826-100.7060.19610.1980120.1999430.2019360.2040110.2064550.2093110.2123280.2155240.2182840.2198470.2216320.2234910.2254340.2274830.2298640.2327040.2359620.239840.2446450.25231-7.73392-7.41055-7.10009-6.79558-6.49491-6.16059-5.79515-5.43637-5.08413-4.80111-4.64891-4.48192-4.31517-4.14844-3.98053-3.79503-3.58635-3.36267-3.11639-2.83841-2.449
132021-12-27T00:00:001.00.00.024.88010.00.21144393.3393-15.525-22.6-22.6-22.6-11.7107-113.42-171.53-171.53-171.53-81.9713-21.9172-21.7058-21.4724-21.2203-20.9503-20.6305-20.2893-19.9612-19.6699-19.4461-19.1888-18.9141-18.6318-18.3387-18.0303-17.6728-17.2839-16.8773-16.4613-16.0573-15.6416-165.948-164.225-162.32-160.26-158.053-155.437-152.644-149.957-147.569-145.734-143.623-141.367-139.047-136.636-134.097-131.15-127.943-124.587-121.153-117.817-114.3850.192610.1942470.1958280.19740.1989870.2008140.2029190.2051290.2074760.2093560.2099350.2106510.2114620.2123850.2134410.2147590.2164460.218470.2209240.223930.228506-8.36878-8.0636-7.78133-7.51236-7.25189-6.96504-6.65125-6.33935-6.02688-5.78956-5.71877-5.63245-5.53659-5.42985-5.31063-5.16596-4.98755-4.78276-4.54737-4.27683-3.89965

Below an illustrative code snippet how to export certain depths into a *.csv:

using CSV, DataFrames

# Single soil variables: How to get θ, or ψ, or δ18Os?
get_soil_(:θ, simulation_mod;
    depths_to_read_out_mm = nothing, days_to_read_out_d = nothing)
depth_to_read_out_mm = [10, 150, 500, 1000, 1150]
get_soil_(:θ, simulation_mod;
    depths_to_read_out_mm = depth_to_read_out_mm, days_to_read_out_d = nothing)
get_soil_(:θ, simulation_mod;
    depths_to_read_out_mm = depth_to_read_out_mm)
get_soil_(:ψ, simulation_mod;
    depths_to_read_out_mm = depth_to_read_out_mm)
get_soil_(:δ18O, simulation_mod;
    depths_to_read_out_mm = depth_to_read_out_mm)

# How to export θ as CSV?
# Only every day, provide days_to_read_out
days_to_read_out = range(simulation_mod.ODESolution.prob.tspan...)
dates_to_read_out = LWFBrook90.RelativeDaysFloat2DateTime.(
    days_to_read_out, simulation_mod.parametrizedSPAC.reference_date)
df_out_daily = get_soil_(:θ, simulation_mod;
    depths_to_read_out_mm = depth_to_read_out_mm, days_to_read_out_d = days_to_read_out)

insertcols!(df_out_daily, 1, :dates => dates_to_read_out);
show(df_out_daily)
##plot(df_out_daily[:,:dates], Matrix(df_out_daily[:,Not([:dates, :time])]))
##CSV.write(
#    joinpath(out_dir, fname * "_θ_depths_daily.csv"),
#    df_out_daily)
366×7 DataFrame
 Row  dates                time     θ_m3m3_10mm  θ_m3m3_150mm  θ_m3m3_500mm   ⋯
     │ DateTime             Float64  Float64      Float64       Float64        ⋯
─────┼──────────────────────────────────────────────────────────────────────────
   1 │ 2021-01-01T00:00:00      0.0     0.200587      0.200587      0.200587   ⋯
   2 │ 2021-01-02T00:00:00      1.0     0.195189      0.199116      0.203679
   3 │ 2021-01-03T00:00:00      2.0     0.19362       0.197972      0.205324
   4 │ 2021-01-04T00:00:00      3.0     0.192807      0.197298      0.206038
   5 │ 2021-01-05T00:00:00      4.0     0.192393      0.19691       0.20635    ⋯
   6 │ 2021-01-06T00:00:00      5.0     0.192124      0.196648      0.206501
   7 │ 2021-01-07T00:00:00      6.0     0.192024      0.196533      0.206607
   8 │ 2021-01-08T00:00:00      7.0     0.191919      0.196427      0.206691
  ⋮  │          ⋮              ⋮          ⋮            ⋮             ⋮         ⋱
 360 │ 2021-12-26T00:00:00    359.0     0.192669      0.197482      0.210105   ⋯
 361 │ 2021-12-27T00:00:00    360.0     0.19261       0.1974        0.209935
 362 │ 2021-12-28T00:00:00    361.0     0.192623      0.197387      0.209798
 363 │ 2021-12-29T00:00:00    362.0     0.192725      0.19746       0.209726
 364 │ 2021-12-30T00:00:00    363.0     0.280244      0.284455      0.244632   ⋯
 365 │ 2021-12-31T00:00:00    364.0     0.25555       0.267545      0.302739
 366 │ 2022-01-01T00:00:00    365.0     0.245386      0.257208      0.295146
                                                  2 columns and 351 rows omitted

Postprocessing: Plotting (using provided functions)

Below an example script using the provided plot recipes that plot a) amounts, b) isotopes, or c) forcing and states as an additional internal check:

using Plots, Measures; gr();
pl1 = plotamounts(simulation_mod, :above_and_belowground, :showRWUcentroid)
pl1
Example block output
pl2 = plotisotopes(simulation_mod, :d18O, (d18O = :auto, d2H = :auto), :showRWUcentroid)
pl2
Example block output
pl3 = plotforcingandstates(simulation_mod)
pl3

# Use of additional arguments to `plotisotopes` is illustrated here.
# Note that typing `?plotisotopes` provides the documentation to the function.
# plotisotopes(simulation_mod, :d2H)
# plotisotopes(simulation_mod, :d18O)
# plotisotopes(simulation_mod;
#              xlim = (DateTime("2010-01-01"), DateTime("2010-03-31")))
# plotisotopes(simulation_mod, :d2H, (d18O = :auto, d2H = :auto), :showRWUcentroid;
#              xlim = (DateTime("2010-01-01"), DateTime("2010-08-30")))
Example block output

Saving plots can be done with savefig

# using Dates: today;
# out_dir = joinpath("gitignored","out", string(today()))
# mkpath(out_dir)

# fname = input_prefix
# savefig(pl1, joinpath(out_dir, fname*"_plotRecipe_AMT.png"))
# savefig(pl2, joinpath(out_dir, fname*"_plotRecipe_ISO.png"))
# savefig(pl3, joinpath(out_dir, fname*"_plotRecipe_CHECK.png"))

Postprocessing: Plotting (using your own functions)

Below an example script using the manually written code to plot the simulation_mod.#

simstates = getstates(simulation) # this gives an error since it has not been simulated!

sim_states = get_states(simulation_mod)
sim_fluxes = get_fluxes(simulation_mod)

names(sim_states) # show column names
names(sim_fluxes) # show column names
53-element Vector{String}:
 "dates"
 "cum_d_prec"
 "cum_d_sfal"
 "cum_d_sthr"
 "cum_d_sint"
 "cum_d_rfal"
 "cum_d_rint"
 "cum_d_rthr"
 "cum_d_rsno"
 "cum_d_rnet"
 ⋮
 "TRANI_mmday_630mm"
 "TRANI_mmday_690mm"
 "TRANI_mmday_750mm"
 "TRANI_mmday_820mm"
 "TRANI_mmday_890mm"
 "TRANI_mmday_960mm"
 "TRANI_mmday_1030mm"
 "TRANI_mmday_1100mm"
 "TRANI_mmday_1200mm"

plot some of the scalar states

states_to_plot = ["INTS_mm", "INTR_mm", "SNOW_mm", "GWAT_mm", "SWAT_mm"]
sim_states_to_plot = sim_states[:, states_to_plot]
plot(sim_states[:,"dates"], Matrix(sim_states_to_plot),
    labels=permutedims(names(sim_states_to_plot)), legend=:topleft, ylabel = "-")
Example block output

plot the fates of water partitioning

fluxes_to_plot = ["flow", "seep", "evap"]
sim_fluxes_to_plot = sim_fluxes[:, fluxes_to_plot]
plot(sim_fluxes[:,"dates"], Matrix(sim_fluxes_to_plot),
    labels=permutedims(names(sim_fluxes_to_plot)), legend=:topleft, ylabel = "mm/day")
Example block output

plot internal fluxes

fluxes_to_plot = [
    "cum_d_prec", "cum_d_rnet", "cum_d_smlt",
    "cum_d_tran",
    "srfl", "slfl", "byfl", "dsfl", "gwfl", "vrfln"]
sim_fluxes_to_plot = sim_fluxes[:, fluxes_to_plot]
plot(sim_fluxes[:,"dates"], Matrix(sim_fluxes_to_plot),
    labels=permutedims(names(sim_fluxes_to_plot)), legend=:topleft, ylabel = "mm/day")
Example block output

plot isotope signatures of fluxes

fluxes_to_plot = ["RWU_d18O", "RWU_d2H", "PREC_d18O", "PREC_d2H"]
sim_fluxes_to_plot = sim_fluxes[:, fluxes_to_plot]
plot(sim_fluxes[:,"dates"], Matrix(sim_fluxes_to_plot),
    labels=permutedims(names(sim_fluxes_to_plot)), legend=:topleft, ylabel = "mm/day")
Example block output

Belowground quantities (θ,ψ,δ of soil water)

if you want some specific depths: use getsoil(): e.g depthtoreadoutmm = [150, 500, 800, 1500] dfδsoil = getsoil([:δ18O, :δ2H], simulationmod; depthstoreadoutmm = depthtoreadoutmm) dfθψ = getsoil([:θ, :ψ], simulationmod, depthstoreadoutmm = depthtoreadoutmm)

if we use depths that are already contained in sim_states we can use those:

@show propertynames(sim_states[:,r"(d18O)|(d2H)"]);
df_δsoil = sim_states[:, ["d18O_permil_160mm", "d18O_permil_510mm",
                          "d18O_permil_820mm", "d18O_permil_1200mm",
                          "d2H_permil_160mm", "d2H_permil_510mm",
                          "d2H_permil_820mm", "d2H_permil_1200mm"]]
df_θψ    = sim_states[:, ["θ_m3m3_160mm", "θ_m3m3_510mm",
                          "θ_m3m3_820mm", "θ_m3m3_1200mm",
                          "ψ_kPa_160mm", "ψ_kPa_510mm",
                          "ψ_kPa_820mm", "ψ_kPa_1200mm"]]
pl_θ = plot(sim_states.dates,
    Matrix(select(df_θψ, r"θ_")),
    labels = permutedims(names(select(df_θψ, r"θ_"))),
    xlabel = "Date",
    ylabel = "θ\n[-]",
    legend = :outerright)
pl_ψ = plot(sim_states.dates,
    # Matrix(select(df_θψ, r"ψ_")),
    log10.(-Matrix(select(df_θψ, r"ψ_"))), yflip = true,
    labels = permutedims(names(select(df_θψ, r"ψ_"))),
    xlabel = "Date",
    ylabel = "log10(ψ\n[kPa])",
    legend = :outerright);
pl_δ18O = plot(sim_states.dates,
    Matrix(select(df_δsoil, r"d18O_")),
    labels = permutedims(names(select(df_δsoil, r"d18O_"))),
    xlabel = "Date",
    ylabel = "δ¹⁸O soil\n[‰]",
    legend = :outerright);
pl_δ2H = plot(sim_states.dates,
    Matrix(select(df_δsoil, r"d2H_")),
    labels = permutedims(names(select(df_δsoil, r"d2H_"))),
    xlabel = "Date",
    ylabel = "δ²H soil\n[‰]",
    legend = :outerright);
# add precipitation to soil δ
PREC_color = :black
plot!(pl_δ18O, sim_fluxes.dates, sim_fluxes.PREC_d18O,
    labels = "PREC", color = PREC_color, linestyle = :dot);
plot!(pl_δ2H, sim_fluxes.dates, sim_fluxes.PREC_d2H,
    labels = "PREC", color = PREC_color, linestyle = :dot);


pl_PREC = plot(
    sim_fluxes.dates,
    sim_fluxes.cum_d_prec,
    t = :bar, color=PREC_color,
    legend = :outerright, labels = "PREC    ", # whitespace for hardcoded alignment of legend
    ylabel = "PREC\n[mm]");

plot(plot(pl_PREC, xlab = "", xticks = :none, topmargin = 5mm, bottommargin = 0mm),
    plot(pl_θ;     xlab = "", xticks = :none, topmargin = 0mm, bottommargin = 0mm),
    plot(pl_ψ;     xlab = "", xticks = :none, topmargin = 0mm, bottommargin = 0mm),
    plot(pl_δ18O;  xlab = "", xticks = :none, topmargin = 0mm, bottommargin = 0mm),
    plot(pl_δ2H;   xtick_direction=:out     , topmargin = 0mm, bottommargin = 5mm),
    link = :x,
    layout = grid(5, 1, heights=[0.1, 0.25 ,0.25, 0.2, 0.2]),
    size=(600,500), dpi = 300, margin = 5mm)
Example block output

####################


This page was generated using Literate.jl.