Niche Configuration file

Simple model

Instead of running Niche interactively, it can be used with a configuration file. For a simple NICHE model this could look like this:

model_options:
  full_model: False
  output_dir: _output

input_layers:
  mhw: data/mhw_small.asc
  mlw: data/mlw_small.asc
  soil_code: data/soil_code_small.asc

The file specifies the input layers, the output directory(output_dir), and other model options. In this case, as we have a simple model (Vereenvoudigd model), as specified in the model options.

Full model

For a full model, more input layers must be specified:

Possible input layers for a Full Niche model

key

simple model

full model

documentation

soil_code

X

X

Bodemklasse soil_code

mhw

X

X

GHG (Gemiddeld hoogste grondwaterstand) mhw

mlw

X

X

GLG (gemiddeld laagste grondwaterstand) mlw

msw

X

GVG (gemiddeld voorjaarsgrondwaterstand) msw

seepage

X

Kwel seepage

inundation_acidity

X

Overstroming_zuurgraad inundation_acidity

inundation_nutrient

X

Overstroming_trofie inundation_nutrient

nitrogen_atmospheric

X

Atmosferische depositie nitrogen_atmospheric

nitrogen_animal

X

Dierlijke bemesting nitrogen_animal

nitrogen_fertilizer

X

Kunstmest nitrogen_fertilizer

management

X

Beheer management

conductivity

X

Mineraalrijkdom minerality

rainwater

X

Regenlens rainwater

inundation_vegetation

(X)

Overstroming Vegetatie inundation_vegetation

management_vegetation

(X)

Beheer management

acidity

abiotic

Berekening zuurgraad acidity

nutrient_level

abiotic

Berekening trofie nutrient_level

The values for inundation_vegetation and management_vegetation are optional.

An example configuration file for a full model is given below.

model_options:
  deviation: false
  full_model: true
  name: 'full'

input_layers:
  inundation_acidity: ../testcase/zwarte_beek/input/inundation.asc
  inundation_nutrient: ../testcase/zwarte_beek/input/inundation.asc
  management: ../testcase/zwarte_beek/input/management.asc
  mhw: ../testcase/zwarte_beek/input/mhw.asc
  minerality: ../testcase/zwarte_beek/input/minerality.asc
  mlw: ../testcase/zwarte_beek/input/mlw.asc
  msw: ../testcase/zwarte_beek/input/msw.asc
  seepage: ../testcase/zwarte_beek/input/seepage.asc
  soil_code: ../testcase/zwarte_beek/input/soil_code.asc
  nitrogen_animal: 0
  nitrogen_atmospheric: 0
  nitrogen_fertilizer: 0
  rainwater: 0

As the option full_model=True is given (it is enabled by default, so can be omitted) all input layers are used. The other model options correspond to the parameters that could be given to the niche_vlaanderen.Niche.run() method.

Abiotic and/or deviation

Using a configuration file, it is also possible to use abiotic values, like previously demonstrated in Using abiotic grids.

To do this the values acidity or nutrient_level must be specified.

The option deviation creates deviation maps, which show the difference between the borders specified in the niche table and the actual values of mhw and mlw for every soil type, as discussed in Creating deviation maps.

Flooding module

If you want to calculate a niche object combined with a Flooding model, this is possible by adding a flooding block. Different scenarios can be specified. They need a single name. The output of the module will be written to the same directory as the output specified in the model options.

flooding:
  - name: T25-winter
    depth: T25.tif
    frequency: T25
    duration: short
    period: winter
  - name: T25-zomer
    ....

Generating a config file in interactive mode

When running Niche in interactive mode, representing the model will show the corresponding configuration file. This was demonstrated in Showing the model configuration.

Also when writing a grid using the write method a “log.txt” file will be written. This file itself is also a valid configuration file for a next run. The list with generated files will be ignored.

Running a config file in interactive mode

When using Niche in interactive mode, you can load all data from a config file using the niche_vlaanderen.Niche.read_config_file() method, or you can run all by using the niche_vlaanderen.Niche.run_config_file() method.

Running a config file from the command line

After opening the anaconda prompt (and starting the environment) you can also run niche from a command line using a config file. This is done by running the niche application.

niche example.yml

Note

If you don’t specify an output directory, nothing will be written - in command line mode this makes no sense

Full example

We offer a full example (included below) which contains all possible options and some documentation. This file may be a good starting point for creating your own configuration files.

This full example can be generated from the command line by running niche --example

# Niche Vlaanderen configuration file
#
# input_layers take the values for every input of the niche model. It is
# possible to specify a grid file or directory, or to specify a constant number
#
# Files can be specified using absolute or relative paths.
# eg:
#   soil_code: c:\project\dijle\mhw.tif
#
# Relative paths are relative to the configuration file path.
#
# Different grid types are supported. Recommended types are geotiff (.tif) and
# .asc (which is human readable).
#
# Arcgis grid sets can be specified using their directory or one of the .adf
# files below them.
# eg:
#   mlw: c:\project\niche\TestCase_GroteNete\InputSnapBodem\dd2_glg
# or:
#   mlw: c:\project\niche\TestCase_GroteNete\InputSnapBodem\dd2_glg\w001001.adf
#
# More information on the different options are explained in the documentation:
# https://inbo.github.io/niche_vlaanderen/cli.html


# model_options sets the options for running the model. The only required field
# is output_dir. The other options are optional and will use default values
# if not defined.
#

model_options:
  # output_dir: directory to which the model output files have to be written.
  output_dir: _output
  # simple_model: default is False. If true only mhw, mlw and soil_code are
  # used for prediction.
  simple_model: False
  # deviation: default is False. Create maps on the deviation between the niche
  # required mhw/mlw and the actual mhw/mlw.
  deviation: True
  # abiotic: default is False. Use abiotic values specified for the Full model
  # rather than calculating them.
  abiotic: False
  # strict_checks: default is True. Validate that no invalid combinations
  # of MHW, MLW and MSW occur.
  strict_checks: True
  # name: you can specify a name for the model. This name will be added to
  # the output files and will be used when plotting/comparing results.
  name: example
  # overwrite_files: by default Niche will not write any file if a file
  # with the same name already exists.
  overwrite_files: True

input_layers:
  # These three input layers always have to be defined
  soil_code: data/small/soil_code.asc
  mhw: data/small/mhw.asc
  mlw: data/small/mlw.asc
  # These input layers have to be defined when running a full model
  # When running a simple model they can be omitted.
  # note that instead of a full grid a constant value can be given
  msw: data/small/msw.asc
  seepage: 0
  inundation_acidity: 0
  inundation_nutrient: 0
  nitrogen_atmospheric: 30
  nitrogen_animal: 0
  nitrogen_fertilizer: 0
  management: 1
  minerality: 0
  rainwater: 0
  # Both layers below are optional in a full model, but will be used if
  # specified
  # management_vegetation:
  # inundation_vegetation:

# optionally code tables can be overwritten
# code_tables:
#  ct_vegetation: adjusted_niche.csv

# flooding module
flooding:
  # Different scenario's can be specified - each requiring a seperate name.
  - name: T25-winter
    depth: data/small/T25.asc
    frequency: T25
    duration: 1
    period: winter