R Wo k low o Gene a ing he SWAT a mR Inpu
File
This eposi o y p o ides an au oma ed R wo k low o combine ield-scale c op- o a ion da a wi h c op-speci ic
and gene ic managemen schedules. Ou pu o his wo k low is he ile a mR_inpu .cs , which can be di ec ly
used wi hin he SWAT a mR (h ps://ch isschue z.gi hub.io/SWAT a mR/) package o gene a e SWAT+
managemen iles ( managemen .sch , plan .ini ).
The p ocedu e is desc ibed in mo e de ail in Chap e 4 o he OPTAIN SWAT+ Modelling P o ocol (Schü z e al.,
2022; DOI: 10.5281/zenodo.7463395 (h ps://doi.o g/10.5281/zenodo.7463395)).
Download and unpack SWAT a mR_inpu .zip , adap all equi ed inpu iles and un he wo k low as desc ibed in
he ollowing.
Requi ed Inpu Files
All inpu iles should be placed in he ./inpu _da a/ di ec o y.
File naming can be cus omized in he main R sc ip ( w i e_SWAT a mR_inpu .R ).
(1) Land-use C op Map
A polygon shape ile ( my_lu_c ops.shp ) ep esen ing all ield-scale HRUs (Hyd ologic Response Uni s) ha
include c opland and non-c opland land uses.
Requi ed a ibu es:
Column Desc ip ion
lu Unique land-use o ield iden i ie .
y_2012 … y_2020 C op o land-use name o each yea (as in managemen ables).
Addi ional ields (op ional) May include subbasin IDs, a ea, o HRU names.
Requi emen s:
Field HRUs should ha e a consis en p e ix (e.g. ield_ ) de ined in he sc ip as h u_c ops <- ' ield' .
Each c op name used in he yea columns mus exac ly ma ch en ies in my_mg _c ops.cs .
Non-c opland a eas (e.g. pas u e, o es ) should use names ma ching he my_mg _gene ic.cs able.
(2) C op-speci ic Managemen Schedules
A able ( my_mg _c ops.cs ) desc ibing single-yea ep esen a i e managemen schedules o each c op.
Each ow ep esen s one ope a ion (e.g., illage, sowing, e ilize , ha es ).
Typical s uc u e:
c op_mg mon_1 day_1 mon_2 day_2 ope a ion op_da a1 op_da a2 op_da a3
wwh 9 15 10 7 e ilize elem_p b oadcas 25
wwh 9 16 10 8 illage cul i 25
wwh 9 24 10 9 illage ha ow7
wwh 9 25 10 10 pln wwh
wwh skip
wwh 3 3 3 17 e ilize elem_n b oadcas 78
wwh 4 23 5 7 e ilize elem_n b oadcas 50
wwh 5 25 6 8 e ilize elem_n b oadcas 15
c op_mg mon_1 day_1 mon_2 day_2 ope a ion op_da a1 op_da a2 op_da a3
wwh 7 25 8 17 ha es _only wwh g ain
wwh 7 25 8 17 kill_only wwh
wwh 7 26 8 19 illage ldcul10
Rules and cons ain s:
Each schedule mus con ain a leas one plan and one kill_only ope a ion.
Use ha es _only (no ha es _kill ) when a c op should su i e ha es (impo an o model e i ica ion
in SWATdoc R (h ps://gi .u z.de/schue z/swa doc /) package).
Include one skip line o ma k he end o each yea . The skip line mus no be he las en y.
Ope a ions mus be ch onologically o de ed (by mon h/day wi hin he yea ).
Mul i-yea c ops:
Fo c ops ha pe sis mul iple yea s (e.g. g assland), c ea e mul iple schedules: g ass_1y , g ass_2y ,
g ass_3y , … up o g ass_maxy .
I a summe c op ollows a pe ennial (e.g., ba ley a e g ass), p o ide a hal -yea e sion o he summe
c op schedule (e.g. ba l_0.5y ) o ep esen sp ing-only managemen (and no au umn illage).
(3) Gene ic Land-use Managemen
A able ( my_mg _gene ic.cs ) de ining ep esen a i e schedules o non-c opland land uses such as pas u e,
meadow, o o es .
These a e ea ed sepa a ely because hey do no equi e c op- o a ion logic and will be epea ed in each
simula ion yea .
Typical s uc u e:
c op_mg mon_1 day_1 mon_2 day_2 ope a ion op_da a1 op_da a2 op_da a3
pas ini ial_plan esc 1, 1000, 0, 0, 1,
1000
pas 3 1 3 31 e ilize elem_n b oadcas 60
pas 3 1 3 31 e ilize elem_p b oadcas 25
pas 5 25 6 5 ha es _only esc hay_cu _low
pas 6 7 6 15 e ilize elem_n b oadcas 40
pas 8 10 8 25 ha es _only esc hay_cu _low
No es:
No skip lines a e used in hese ables.
The i s ope a ion mus be ini ial_plan , de ining ege a ion pa ame e s o SWAT+ plan .ini .
op_da a1 = plan communi y name ( om plan s.pl )
op_da a2 = comma-sepa a ed ini ializa ion pa ame e s:
lai_ini , bm_ini , phu_ini , pln _pop, y s_ini , sd_ini
Ope a ions can include g azing , e ilize , i iga ion , o ha es _only as applicable.
Running he Wo k low
Open SWAT a mR_inpu .p oj in RS udio
Load w i e_SWAT a mR_inpu .R : This is he main use sc ip — edi only inpu pa hs and se ings, hen un
i line by line.
unc ions_w i e_SWAT a mR_inpu .R is sou ced a he beginning. I con ains helpe unc ions o building
and checking he schedules.
# Load unc ions and packages -------------------------------------------------------
sou ce('./ unc ions_w i e_SWAT a mR_inpu .R')
oo1(c("s " , " idy e se" , "lub ida e", " eshape2", " emo es", "dply ", "da a. able"))
oo2("HighF eq")
# De ine inpu iles-----------------------------------------------------------------
lu_shp <- './inpu _da a/my_lu_c ops.shp' # land-use c op map shape ile
mg _cs <- './inpu _da a/my_mg _c ops.cs ' # c op managemen .cs able
lu_gene ic_cs <- './inpu _da a/my_mg _gene ic.cs ' # gene ic land use managemen .cs able
# De ine a iables-------------------------------------------------------------------
## Simula ion pe iod
s a _y <- 2009 #s a ing yea (conside a leas 3 yea s o wa m-up!)
end_y <- 2020 #ending yea
## P e ix o c opland h us (all names o h us wi h a c op o a ion mus begin
## wi h his p e ix in column 'lu' o you land use map)
h u_c ops <- ' ield'
## Mul i-yea a mland g ass
## Did you de ine any mul i-yea a mland g ass schedules? 'y' (yes), 'n' (no)
m_y _sch_exis ing <- 'y'
## I yes, de ine also he ollowing a iables. I no , skip nex ou lines
c op_my <- 'akgs' # p e ix o mul i-yea schedules in managemen ile
# mul iple en ies should ha e he same numbe o cha ac e s, e.g.: c op_my <- c('akgs', 'bs
g')
max_y <- 5 # maximum numbe o yea s a mland g ass can g ow be o e i is killed (should be <8)
## Do you mul i-yea a mland g ass schedules conside he ype o he ollowing c op (summe o
win e c op)?
## (e.g., a '_1.5y ' schedule wi h a kill op in sp ing allows o plan ing a summe c op immedia
ely a e wa ds)
## I yes, you mus de ine you summe c ops
c op_s <- c('sgb ','csil','ba l')
## Do you summe c op schedules usually s a wi h an ope a ion in au umn (e.g. illage)?
## To combine hem wi h a mland g ass, i is necessa y ha you p o ide 'hal -yea -schedules'
## ('hal -yea -schedules' a e addi ional summe c op schedules wi hou ope a ions in au umn)
## The adap ed schedules should be added o he c op managemen able wi h su ix '_0.5y ' (e.g.
'csil_0.5y ')
## I addi ional 'hal -yea -schedules' a e no needed, because you no mal summe c op schedules
## do no s a in au umn, ype 'n'
addi ional_h_y _sch_exis ing <- 'y' # 'y' (yes), 'n' (no)
# Read inpu da a ----------------------------------------------------------------
## Read land-use c op map shape ile and d op geome y
lu <- s _d op_geome y( ead_s (lu_shp))
## Read c op managemen .cs able
## Make su e i includes all c ops o you lu map
mg _c op <- ead.cs (mg _cs , as.is=T)
## Read gene ic land use managemen .cs able
## Make su e i includes all non-c opland classes wi h a ege a ion co e
mg _gene ic <- ead.cs (lu_gene ic_cs , as.is=T)
# Check o co ec posi ioning o 'skip' line ------------------------------------
check_skip <- check_skip_posi ion()
# Check o da e con lic s wi hin single c op schedules -------------------------------
check_da e_con lic s1()
# Build schedules o c op sequences ----------------------------------------------
o a_schedules <- build_ o a ion_schedules()
# Check o da e con lic s in combined ( o a ion) schedule --------------------------
check_da e_con lic s2()
# Sol e mino da e con lic s (whe e only a ew days/weeks a e o e lapping)---------
o a_schedules <- sol e_da e_con lic s()
## check again o da e con lic s -------------------------------------------------
check_da e_con lic s2()
## w i e he SWAT a mR inpu able -----------------------------------------------
w i e_ a mR_inpu ()
Diagnos ic iles
check_skip.cs — lis s c ops wi h missing o misplaced skip lines
c op_comb_con lic .cs — iden i ies o e lapping c op combina ions
mg _con lic .cs — de ails speci ic da e con lic s be ween ope a ions
Ou pu ile
a mR_inpu .cs — his ile can be used di ec ly wi h he SWAT a mR unc ion:
SWAT a mR::w i e_managemen _sch(" a mR_inpu .cs ")
o p oduce he inal SWAT+ managemen .sch and plan .ini iles.
No es and Good P ac ices
Always e iew he diagnos ic iles be o e p oceeding o SWAT+.
Regene a e a mR_inpu .cs o each simula ion pe iod.
Cus omize he il e and cond ields in he CSV o loca ion-speci ic managemen ules - de ails can be ound
in he desc ip ion o he SWAT a mR (h ps://ch isschue z.gi hub.io/SWAT a mR/) package.
Main ain ch onological ope a ion o de ; he sc ip assumes inc easing day-o -yea o de .
Keep helpe unc ions unchanged unless debugging.
Ci a ion
This wo k low is desc ibed in mo e de ail in:
Schü z C., e al. (2022). SWAT+ Modelling P o ocol o he Assessmen o Wa e and Nu ien Re en ion Measu es
in Small Ag icul u al Ca chmen s. Zenodo. DOI: 10.5281/zenodo.7463395