climate indices tool for E-OBS data (used only with ecad_indices_stations)
For an example of how to add indices from climind into gridclimind you can have a look at the 7d185d65 commit in gridclimind (‘Added last three compound indices…etc’). In general, adding an index you will have to take the following steps:
-
Add a function to
climindwhich uses the correct interface, i.e.:function(ci, freq=c("annual”), cur_sub)Where:
ciis the input object, this will be provided bygridlcimind.freqthe supported list of time resolutions. Typically this will befreq=c("monthly", "annual", "halfyear", "seasonal”).- additional arguments needed. Note that in general these can only be static arguments either having a default value or a static value defined in the json file.
-
Add the metadata information to eobs.json (
inst/extdata/metadata_config_filesin the gridclimind project) in theindex.metadatalist. For example:"csdi": { "long.name": "Cold Spell Duration Index", "units": "days", "base.period.attr": true, "standard.name": "cold_spell_duration_index", "calculation.function.name": "climdex.csdi", "additional_arguments": { "spells.can.span.years": false }, "supported.time.resolutions": "annual", "include.time.prefix.in.long.name": true, "required.variables": "tmin" }Note that:
-
additional_argumentsis optional. These extra input arguments are fed to the listedcalculation.function.name, i.e. the new function we created in step 1. -
supported.time.resolutionsandrequired.variablescan also be a list of values, e.g.:"ww": { "long.name": "Warm-wet days", "units": "", "base.period.attr": false, "standard.name": "warm_wet_days", "calculation.function.name": "climdex.wd", "additional_arguments": { "precip.thresh": "q75", "precip.op": ">", "temp.thresh": "q75", "temp.op": ">" }, "supported.time.resolutions": ["annual", "monthly", "seasonal", "halfyear"], "include.time.prefix.in.long.name": true, "required.variables": ["prec", "tavg"] }
-
-
Add the index file to the test suite:
-
Run the test manually.
-
Go to the output directory, this is listed in the
output_data_pathvariable, e.g.:output_data_path [1] "/var/folders/dm/smk5_rf53bg057ql34rmhnq80000gn/T//RtmpphG0Nw"Copy the nc file for the index you added to
/your/installation/of/gridclimind/tests/testthat/reference_ncfiles/generate_all_indices_test/. This could be up to 4 files, depended on the supported time resolutions. -
The reference rds files for the metadata test will change probably. After checking that the change is really related to the addition of a new index, simply delete the offending rds files and rerun the test. This will generate new reference files which contain the new index.
-
Commit the changes in the gridlcimind package to git.
-
The list of variables that gridclimind is aware of is stored in the metadata json file under generic.metadata$variable.name.map. There you list how each of the possible input variables is called in the input NetCDF files. Some important notes:
- the names you use in the
variable.name.mapon the left hand side need to match those used ingridclimindandclimind. A good resource here is theclimind::climdexInput.rawfunction which uses all of these names. - If a variable is not supported by
climind::climdexInput.rawthere is no way to calculate the indices. You can read the data from the input NetCDF files, but there will be no way to build the input data object for the indices. So, you need to add support for a variable toclimindfirst and then add it to thegridclimindvariable.name.map.