forked from JamesSample/enviro_mod_notes
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSimplyP_Development_Log.txt
107 lines (64 loc) · 8.53 KB
/
SimplyP_Development_Log.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
SimplyP summary of development history
-------------------------------------------------------------
Initial model developed autumn-winter 2015. Released as v0.1A
#############################################################################
Subsequent changes to v0.1A (also implemented in v0.2):
Bug fix: Flow into the current reach from upstream reaches had incorrect area scaling. Now corrected (affects variables Qr0 the first time it is defined, and Qr_US_i)
Bug fix: Fraction of newly converted land was missing from a number of ODEs, now added in. i.e. replaced f_A, f_S, f_Ar, f_IG with (f_A + f_NC_A), etc. Affects equations: dQg_dt, dVg_dt, dQr_dt, dVr_dt, dMsus_dt. This bug would only have affected model setups with newly-converted land.
Changed dataframe indexing - replaced ambiguous .ix with .loc in most cases. Also added two parameters to the parameter file which are not yet implemented, but which are built into the model for future use. This prevents a FutureWarning from appearing when the code is run.
#############################################################################
Autumn 2018 onwards, started working on new release v0.2A
As of 02/2019, this is the main release version.
The main changes compared to v0.1A are summarised below.
------------------------------------------------------------------------
Changes to parameter excel file:
- Added new sheet Reach_structure
- Added parameter SC_Qr0 to ‘Constant’ sheet, a setup parameter which describes which reach the initial discharge value is provided for
- New parameter f_TDP in 'Constant' sheet to specify relation between SRP and TDP
- f_Ar, f_IG, f_S, f_NC_Ar, f_NC_IG, f_NC_S parameter definitions have changed slightly (see parameter sheet for new definitions)
Will only affect setups which have newly-converted land
------------------------------------------------------------------------
Changes to input and output files:
- Input meteorology file: rename column ‘Pptn’ to ‘Precipitation’
PET is no longer a required input. If it is not specified, it is calculated by the model from air temperature
- Reach output files: Columns renamed to include units
------------------------------------------------------------------------
General changes:
- Repackaged as a module with sub-modules, to split functions into different groups for ease of further development & debugging
- Added new functions to __init__ file
- Improved documentation of functions
- Added more print statements to keep track of outputs
- Added a text file describing input and output data
- Created a log to keep track of model changes (text will be almost the same as the GitHub commits text)
- Small changes in syntax throughout so runs in Python 3.6. Note, there are now a couple of issues with the plotting functions if you try to run with Python 2.7
------------------------------------------------------------------------
Changes to functions in inputs.py file:
- Added Thornthwaite PET calculation, using functions copied from pyET0. If PET is not a column in the input meteorology data file, then it is calculated. N.B. Thornthwaite requires whole years, so if calculating PET the model can only be run for whole calendar years.
- Moved PET and snowmelt calculations from the main run model function into inputs.py. Therefore also removed inc_snowmelt parameter from run_simplyP function.
- read reach structure parameters into new parameter dataframe p_struc
- Q and chem observations are now only read in if a filepath is provided in the parameter file. Can now leave these cells blank if don't want to read in obs
------------------------------------------------------------------------
Main changes in model.py:
- Soil labile P and soil water TDP were stiff equations, and made run times very slow if dynamic soil processes were turned on. Remove them from the ODE solver and discretize the change with time (function ‘discretized_soilP’, called at the end of each time step). Use a Poincare map to estimate the gradient over the time step. Comparison with ode results shows insignificant changes over a 30 year test period (always less than 0.04% difference).
- Define a control function (f_x) for limiting soil water flow below field capacity. This is a piecewise polynomial and replaces the sigmoid control function used previously. Removes issue of negative flows when soil water volume was close to field capacity.
- Groundwater flow, Qg, also limited to the minimum user-specified parameter through use of a (differentiable) control function f_x.
- Soil water and groundwater flow ODEs replaced with explicit calculations of Q: Qs = (Vs - fc) * f_x(Vs, fc, 0.01) / T_s. Both Qs and Qg are then calculated within ode_f, within the sub-catchment loop before starting the time loop to provide initial conditions for other equations, and at the end of the time loop to provide output. Produces exactly the same results as before, with similar run times, but is simpler.
- Added in-stream SRP calculation as a simple function of simulated in-stream TDP: SRP = m * TDP, where m is a user-supplied parameter. New parameter added to parameter file. Associated plots and goodness of fit stats updated.
- Added logic so no change in soil water TDP mass if user decides to keep soil water TDP constant (dynamic EPC0 = 'n'). The TDP soil water mass is then constant but the concentration wouldn't be due to change in soil water volume, so replace mass/volume with a concentration parameter in the in-stream TDP equation. Concentration parameter is equal to EPC0 if user wants soil water TDP concentration to stay constant
- Moved PET and snowmelt calculations from the main run model function into inputs.py
- Bug fix: Moved definition of initial conditions VsA0, VsS0, QsA0, QsS0, Qg0, Vg0 from outside the sub-catchment loop into the sub-catchment loop. Otherwise, only being set correctly for the first sub-catchment. Subsequent SCs’ initial conditions were the last time step from the previous SC, oops.
- new argument p_struc (defined in inputs.py), to define the reach structure parameters. Before loop over met data: define list of upstream reaches, upstream_SCs, from the p_struc parameter dataframe
- Replace calculation of upstream inputs as inputs from a single upstream reach, to calculate inputs from however many reaches are directly upstream. Affects: Qr_US_i, Msus_US_i, TDPr_US_i, PPr_US_i
- Define new function sum_to_waterbody(). Takes input reach structure from the excel file, and sums discharge and masses from desired reaches to produce inputs to a receiving waterbody (e.g. lake, estuary).
- Initial reach flow (Qr0) used to be calculated only for SC1, the topmost reach, and initial reach discharges for other reaches were set to the output for the previous day for up-stream reaches. Changed to: user specifies the reach an initial value is provided for (e.g. most data-rich). Then convert the units to mm/day and it then is applied to all reaches (area-scaling involved in converting units means this is ok if hydrology is similar). Qr0 definition has therefore been moved up to after QsS0.
- Add calculation of reach SRP and TP fluxes to function derived_P_species (previously only concentrations were calculated) and output in reach results dataframes
- Newly-converted land parameters re-defined so that f_Ar, f_IG and f_S are now the total areas of arable, improved grassland and semi-natural land in the catchment (including newly-converted land). And f_NC_Ar, f_NC_IG, f_NC_S is the proportion of Ar, IG or S land that is newly-converted. Equations within ode_f altered to reflect this (e.g. previously the total area of agricultural land in the catchment was f_Ar+f_NC_Ar, whereas now it is just f_Ar). Updated calculation of f_NC_A and checks for user errors in input params
- Logic added so soil labile P mass, soil water TDP mass and EPC0 never go negative
------------------------------------------------------------------------
Changes in visualise_results.py:
- Bug fix in the goodness-of-fit function, it wasn't correctly accounting for variables/reaches without data
- No plotting of soil P results if dynamic EPC0 is turned off
- Added PET to terrestrial compartment plot
- plot_in_stream function: fixed bug in plotting multiple reaches (p_SU.plot_reaches wasn’t being read in correctly if it was a list). Added reach title to plots.
- Added new function plot_instream_summed to plot the results from summing reach inputs to look at simulated total discharge and averaged concentrations to receiving waterbody.
- goodness_of_fit_stats: don’t try to calculate if don’t have any observations (len(obs_dict)<=0).