@@ -27,6 +27,6 @@ The script first downloads LPJmL outputs for the historical time period from the
In a second step, outputs from LPJmL crop yield forecast simulations are downloaded for all weather options available on the remote server for the specified combination of `irrigation_scenario`, `fertilizer_scenario` and `sowing_scenario`. Forecasted yield during the `forecast_year` is calculated for each crop and and grid cell and compared against the historical reference yield. This risk of yield loss is calculated for each crop and grid cell as the fraction of weather options that show a yield loss (compared to reference yield) of at least `yield_loss` percent.
To do: Grid-cell level risks are aggregated to the country level by summing grid cells where the risk of yield loss is at least `loss_probability` percent. The area at risk at the country level will be specified as absolute area (in hectare) as well as in percent of total crop area (e.g. 25% of all rainfed wheat areas in the country).
To do: Confirm format of returned risk indicator with CauseMos.
The script returns two output variables:
1.`yield_loss_risk`: The risk that yields fall at least `yield_loss` percent below historical reference yield for each crop and grid cell
2.`harvested_area_at_risk`: Harvested area affected by yield loss of at least `yield_loss` percent, grouped into 5 risk categories (0-20%, 20-40%, 40-60%, 60-80%, 80-100%), for each crop and grid cell
stop(paste0("avg_startyear ",sQuote(avg_startyear)," or avg_endyear ",sQuote(avg_endyear)," outside of time period covered covered by file ",filename," (",paste(range(timevals),collapse=("-")),")"))
if(length(avg_steps)<1){
stop(
paste0(
"avg_startyear ",sQuote(avg_startyear),
" or avg_endyear ",sQuote(avg_endyear),
" outside of time period covered covered by file ",filename,
" (",paste(range(timevals),collapse="-"),")"
)
)
}
}else{
# need to convert timevals into year values using origin and origin_unit
stop(paste0("Start year ",sQuote(avg_startyear)," or end year ",sQuote(avg_endyear)," outside of time period covered covered by file ",filename," (",paste(range(year_timeval),collapse=("-")),")"))
}
# set timevals to year values
# Need to convert timevals into year values using origin and origin_unit
stop(paste("Cannot determine source file from contents of source directory:",toString(sQuote(unname(sapply(sapply(remote_contents,strsplit,split=" "),function(indata)return(indata[length(indata)])))))))
remote_contents<-system2(
rsync_command,
args=c(rsync_args,rsync_url),
stdout=TRUE
)
dir_entries<-unname(
sapply(
sapply(remote_contents,strsplit,split=" "),
function(indata)return(indata[length(indata)])
)
)
source_file<-grep(".nc$",dir_entries,value=TRUE)
if(length(source_file)!=1){
stop(
paste(
"Cannot determine source file from contents of source directory:",