The grammar of a HydroModPy file#
One TOML file describes a run. Its sections are listed in TOML parameters; this page gives the rules they all share: tables, inheritance, quantities, dates, paths, free keys and profiles. The rules are written by hand. Every key this page cites and every TOML block it shows is checked against the models of the code.
Tables and arrays of tables#
A section is a TOML table: [flow]. A table can sit inside another one: the header
[flow.param.K.field] opens the table field of the table K of param. You do not
need to write [flow] first.
A request that you may repeat is an array of tables, written with double brackets. Each
[[export]] block is one export, in the order of the file. The same form holds the
sources of a data variable, the processes of a simulation, the observation points, the
stages of a calibration and its objective blocks.
1[[simulation.process]] 2id = "flow_main" 3kind = "flow" 4solvers = ["modflow6"] 5 6[flow.param.K.field] 7kind = "homogeneous" 8unit = "m/s" 9value = 5e-5 10 11[[export]] 12variable = "watershed" 13 14[[export]] 15variable = ["watertable_depth", "seepage_mask"] 16time = "last"
Three rules hold for the whole file.
A file has only the top-level sections listed in TOML parameters. A name that is not one of them is refused:
Unknown top-level TOML section(s): flows.A key that the table does not know is refused, and the message names the table:
Unknown TOML key(s) in [flow]: flow_regme.Three things are required in every file:
workflow.mode, which says whathmp rundoes, a[site]withsite.namewhen the file models a real catchment, and[geographic]. In its standard mode,[geographic]needs[geographic.catchment]withgeographic.catchment.kind, andkind = "dem"needs a DEM declared indata.dem.sources. With these keys,hmp checkaccepts the file. A file written before 2.0.1 that leaves out the mode runs the one its sections imply, with a warning. A file never writes the project root: it is the folder that holdsproject.toml.
base_config: start from another file#
A file can inherit every table of another one. It writes only what changes.
1base_config = "base.toml" 2 3[simulation] 4name = "nancon_daily" 5 6[simulation.time] 7step_value = "1 day"
base_config is a top-level key, so it goes before the first table header. Its value is a
path, or a list of paths, each read from the folder of the file that holds it. An absolute
path works, and ~ is expanded. The parent can have its own base_config: the chain is read
from the oldest ancestor down, and a loop stops with Detected circular base_config chain.
Once the files are merged, base_config is gone, and the merged result is what the schema
validates.
Several bases#
A file can inherit several files at once, when base_config is a list. One site and one
experiment then meet in a file of one line, where a chain would need a file for each pair.
1base_config = ["sites/nancon.toml", "experiments/steady.toml"]
Each base may have its own base_config, and a file that two bases inherit, such as a
model.toml both of them name, is read once. The files make a graph, and one rule merges it
at any depth: for each key, the most derived file that writes it wins. A file overrides
every file it inherits, directly or not. If experiments/steady.toml sets
flow.param.K.field.value, its value wins over the one of model.toml, even though
sites/nancon.toml inherits model.toml too, because the site does not write the key
itself.
Two files that do not inherit each other must agree on each key they both write. When they
disagree, the file is refused with both names and both values, and the order of the list never
decides. Write the key in the file that names both bases, or keep it in one of them. The items
two such files add with __append are all kept, in the order of the files, bases first. A list
written plainly in one of them and extended with __append in the other gives the plain list,
then the items.
Outside a project, relative paths are read from the folder of the first root file, the one
reached by following the first base of each file. Inside a project they are read from the
project root, whatever the file. hmp config resolve <file> --origin writes each value of the
merged file on its own line, with the file that set it and the files that added to it.
Overlays and --set#
hmp run and hmp calibrate add two more layers on top of the chain, in this order: files given with
--overlay, then values given with --set. Environment variables named HMP_SET_* come
last. An overlay is read as a file that inherits the run file, so it and its own bases override
the run file.
hmp run run.toml --overlay daily.toml
hmp run run.toml --set simulation.name=my_run
hmp calibrate calibration.toml --set calibration.seed=7 --case calage_seed7
HMP_SET_simulation__name=my_run hmp run run.toml
A --set value is read as TOML when it can be, and as a plain string otherwise: 200 is
a number and my_run is a string. In an environment variable name, two underscores stand
for a dot and the case is the case of the key: HMP_SET_flow__param__K__field__value=3e-5
sets flow.param.K.field.value.
Each file, each overlay and each --set value is read under today’s key names before the
merge. So a key an overlay writes under an old name wins over the same key its base writes
under the new name. A warning names the file that holds the old key, and
hmp doctor --fix-config <file> rewrites that file and the files it inherits, then prints
what changed in each one. It writes nothing when a rewrite of the files one by one would
change what they read together, and it names those keys.
Merging: tables, lists, __append, __merge, __delete#
The same merge applies to the files of the chain, to overlays and to --set values. A table
merges key by key. Any other value replaces the parent’s value, and this holds for lists too,
whatever their lengths. Three suffixes on a key change this rule for that key.
The child writes |
The result holds |
|---|---|
a table the parent also has |
both tables, merged key by key down to the leaves |
a number, a string, a boolean |
the child’s value |
a list of values, |
the child’s list, which replaces the parent’s |
|
the parent’s list, then the child’s items |
|
the parent’s key or table removed, with all that is under it |
|
the child’s blocks, which replace the parent’s, whatever their number |
|
the parent’s blocks, then the child’s |
|
each block merged with the parent’s block of the same identity, the other blocks as they are |
Inside one table, the merge runs in three passes: the deletions, then the keys the file
writes, then the merges and the appends. A key that is deleted and written again in the same
table starts from nothing: this is why sources__delete = true, followed by a new list of
sources, does not inherit the old keys. key__delete needs the literal true, key__append
needs a list, and key__merge needs an inherited list of tables and is refused next to the
plain key. No key of the schema holds two underscores, so a suffix never collides with a
key. A name you choose yourself must not end with one of the three suffixes. To see the file
a chain resolves to, before validation, run hmp config resolve <file>.
1base_config = "base.toml" 2 3[flow.param.K.field] 4value = 1e-4 # kind and unit are inherited 5 6[display] 7figure__append = [{ variable = "discharge", type = "distribution", cumulative = true }] 8 9[[export__append]] 10variable = "watershed_dem" 11 12[data.hydrography] 13sources__delete = true # drop the inherited list 14 15[[data.hydrography.sources]] 16source = "bdtopage"
__merge pairs blocks by their identity, which is the first of id, name and source that
every block on both sides holds. So simulation.process and observation.points
pair by id, calibration.phases and calibration.objective_blocks by name, and
the sources of a data variable by source. A parent can insert a block at its head, and each
child still reaches the block it names. The child writes only the blocks it changes, and the
list keeps the order of the parent.
1base_config = "project.toml" 2 3[[simulation.process__merge]] 4id = "flow_main" 5solvers = ["modflow_nwt"]
Four cases are refused, and the message says what to write.
A block whose identity the parent does not hold. Correct it, or add the block with
[[x__append]].Two blocks of one side with the same identity. Give each one its own, or replace the list with
[[x]].Blocks with no identity, as in
exportandmesh.refinement_zone. Write the whole list with[[x]], or add blocks with[[x__append]]. Position does not pair them, because two lists of the same length can still be two different lists. The one exception is a list of one block on each side, since there is only one way to pair them.[[x__merge]]next to a plain[[x]]in one file.
Two traps come from inheritance, not from the merge itself.
A list that other keys depend on. In
[flow], every table ofparammust be named inflow.param_list. A child that adds[flow.param.Ss.field]and does not touch the inherited list is refused:flow.param contains ids not declared in flow.param_list: Ss. Writeparam_list__append = ["Ss"]. Or leaveparam_listout of every file: it is then taken from the tables.A table that changes shape.
valuebelongs tokind = "homogeneous",valuesto"heterogeneous"andmapto"raster". A child that switches the kind must remove the old key withvalue__delete = true, or the file is refused withExtra inputs are not permitted.
An empty string is not a value: a key written "" is dropped when the file is read, as if
it were absent, and the default of the model applies.
Quantities and units#
Many fields take a length, a duration or a rate. The form of a field says how: number or "<n> m" reads a bare number, or a string made of a number, a space and a unit. Write the
string in quotes: snap_dist = "150 m". Unquoted, 150 m is not valid TOML.
The registry counts 87 fields typed as a quantity. They come in five kinds. In each, a
bare number is in the unit shown, and a string needs a unit: "150" is refused.
Kind of field |
A bare number is in |
Strings read |
Examples |
|---|---|---|---|
a length |
meters |
|
|
a length in millimeters |
mm |
|
|
a duration in days |
days |
|
|
a volumetric flow |
m3/s |
|
|
a flux density |
m/s |
|
For a volumetric flow, write m^3/s or m³/s. The shorthand m3/s, which the form of
the field shows, is refused today.
The value of a flow parameter, flow.param.K.field.value, works another way. Its
unit sits in the sibling key flow.param.K.field.unit, or inside the string:
unit = "m/day" with value = 4.3, or value = "4.3 m/day" alone. Both at once are
accepted when they agree, and refused when they differ. Left out, the unit is the SI one of
the name: m/s for K, - for Sy, m-1 for Ss, and - for any other name. The
accepted units are -, m/s, m/day, m/h, cm/s, cm/day, cm/h, mm/s,
mm/day, mm/h, m-1 and cm-1. The validated file keeps the value as written, with its
unit. It is converted to SI when the parameter is built: 0.36 in m/h becomes 1e-4
in m/s.
1[geographic.catchment] 2snap_dist = "150 m" 3buff_area = "10%" 4 5[domain.depth_model] 6thickness = "30.0 m" 7 8[flow.param.K.field] 9unit__delete = true 10value = "4.3 m/day"
Three more cases. geographic.catchment.buff_area is the only field that reads a
percentage: "10%" enlarges the catchment area by 10 %, "500 m" or "2 km"
is a distance, and "10% of sqrt(area)" is the rule of version 1 written out. A bare number
reads as that same rule, so buff_area = 10 and buff_area = "10% of sqrt(area)" give the
same distance. Some keys carry the unit in a sibling key, as in
flow.sinks_sources.lakes.<name>.bedleak_unit.
And a field that takes a list of values takes one value too: variable = "budget" and
variable = ["head", "budget"] are both read by export.variable.
A bare number keeps the unit it always had#
A bare number has no unit of its own. It is read in the unit its table has always read, and
no release changes that meaning. To write another unit, write a string with the unit, or the
sibling unit key where the table has one. The table gives the unit by section.
Section |
A bare number is in |
|---|---|
|
meters |
|
meters |
|
mm/day |
|
mm/day, as its |
|
millimeters |
|
m3/s |
|
m3/s |
a head boundary |
meters |
a flux boundary forcing in |
m/s |
|
the unit of the name ( |
|
meters |
|
days |
|
seconds, the clock of the two solvers |
|
the |
|
the unit the target declares |
The unit of each field in the generated reference repeats this when the code states it. A
field whose unit depends on the model, such as the closure criteria of the solvers, has no
unit in the reference, and its description says what it reads.
Dates and durations#
The simulated window is simulation.time.start_datetime and
simulation.time.end_datetime, with a step. Both dates are required once the table
exists. The end date is inclusive: end_datetime = "2002-12-31" ends the run at the
end of that day. The window must end on a step boundary, and the run refuses it
otherwise: a monthly step cannot end on the 15th.
1[simulation.time] 2start_datetime = "2000-01-01" 3end_datetime = "2002-12-31" 4step_value = "1 month"
simulation.time.step_value is a positive whole number with a unit among hour,
day, month and year: "1 month", "1 day", "6 hour". A bare number needs
step_unit beside it. A unit that disagrees with step_unit is refused, and so is
"1 week".
Write dates as quoted strings, "2002-10-15". A TOML date without quotes is read by some
fields and refused by others: simulation.time.start_datetime accepts it, and the
date_start of the data tables does not.
An instant is a date, "first" or "last". A date selects the stress period that holds
it, so the same date names the same month on a monthly or a daily run. The key
export.time also takes a list of instants.
A window has two spellings. A two-item list, ["2001-01-01", "2002-12-31"], is the form
of export.period. A table with start and end is the form of
metrics.window and calibration.window. The data tables take a
date_start and a date_end; left out, they use the simulated window.
1[[display.figure]] 2variable = "watertable_depth" 3time = "2002-10-15" 4 5[[export__append]] 6variable = "discharge" 7period = ["2001-01-01", "2002-12-31"] 8 9[[export__append]] 10variable = "watertable_depth" 11time = "last"
Paths#
A path in a file is read from the project root, the folder that holds project.toml
at or above the file. Outside a project, it is the folder of the oldest file of the
base_config chain. It is not read from the folder of the file that wrote it: a file in
plan/<hash>/ or in runs/<case>/ names the same inputs/dem.tif as project.toml does. The
loader merges the files first, then resolves the paths, so a path written in a parent, in an
--overlay file or in a --set value is read from the same root.
Written as |
Read from |
|---|---|
|
|
|
the folder |
|
refused with |
|
the project root |
|
as written, with |
the value of |
the folder of the file that holds it |
the |
|
a relative |
the |
The workspace is found in this order: [workspace] with root or data_dir, the environment
variable HMP_WORKSPACE, the layout <workspace>/projects/<name>/project.toml beside a data/
folder, and last the project folder itself. A bare file name is not looked up there. A file of
the data folder is named with workspace:, so path = "workspace:regional_dem_aber.tif" in
[[data.dem.sources]] reads data/dem/regional_dem_aber.tif, whatever the depth of the project
in the workspace. The data folder is [workspace] data_dir when it is set, else data/ of the
workspace. A name never leaves the folder of its role, so "workspace:../geology/map.gpkg" is
refused. A run writes every file of data/<role>/ in this form in its frozen configuration and
in its manifest, even when the file wrote ../../data/<role>/<name>.
Free keys: <id> and <name>#
Some tables are keyed by a name. The reference writes the name as <id> or <name>, and
you write the name itself. A key like this is free, or it is drawn from a list, or it must
match a name written elsewhere.
Table |
The key is |
It must match |
|---|---|---|
a parameter name: |
an entry of |
|
one of |
nothing: the table turns the boundary on, even empty, and |
|
|
a name you choose |
for a lake, the |
a name you choose |
|
|
|
|
|
a name you choose |
|
One name can appear in three places. Here a support called geology_zones is declared,
filled from a geology file, and used by K:
1[domain.supports.geology_zones] 2kind = "geology" 3 4[data] 5types = ["geology"] 6 7[data.geology] 8id = "geology_zones" 9 10[[data.geology.sources]] 11source = "file" 12path = "inputs/geology.gpkg" 13code_field = "zone" 14 15[flow.param.K.field] 16kind = "heterogeneous" 17unit = "m/s" 18field_spatial_id = "geology_zones" 19values = { zone_1 = 1e-5, zone_2 = 3e-4 } 20value__delete = true
The links of this site accept both spellings: flow.param.K.field.value and
flow.param.<id>.field.value lead to the same card. The whole file as a tree shows every key of
the file as a tree.
One rule switches a boundary on#
A boundary, a sink or a source is active when its table says enabled = true, and
enabled = false keeps the table and switches it off. The key is required, so a table never
switches itself on by being written, and there is no list of what is active. A table with
nothing else to say holds this one key:
[flow.bc.drainage] # drains at the top, conductance from K
enabled = true
[flow.sinks_sources.recharge] # the rate comes from [data.recharge]
enabled = true
[flow.bc.ocean] # kept for later, builds nothing
enabled = false
value = 0.0
The tables are flow.bc.<name>, [flow.sinks_sources.recharge], [flow.sinks_sources.etp],
one table per entry of wells, lakes, sfr and flow_barriers, and the cutoff_wall of a
lake. The steps of [geographic] that are off by default, river_network, enforce_lakes,
crossings and bed_regularization, write enabled as soon as their table writes another
key. A file written before 2.0.1 that leaves the key out is read as it was meant then, on for a
boundary and off for a geographic step, with a warning that names the line to write, and
hmp doctor --fix-config writes it.
Profiles#
Every key has a profile: user, dev or expert. Of the 1760 keys of the registry, 1058 are
user, 607 are dev and 95 are expert. The profile says who needs the key. It does not
forbid anything: a file that writes a dev key, such as
simulation.time.substeps_per_period, is valid. The profile decides what the
reference shows by default, and what the terminal prints:
hmp config template --profile user
hmp config schema --section flow --profile dev
One case needs care. A choice can require keys of a higher profile: kind = "tabulated"
of flow.param.<id>.field_vertical_profile.kind needs depths and factors, and
both are tagged dev. The profile key of [workflow] is unrelated: it times a run.
Check a file#
hmp check loads the file, follows base_config, checks the merged result section
by section and prints every diagnostic at once. Each one gives its severity, the key it
reaches, the line of that key when the file writes it, a phrase that says what kind of fault
it is, and on the next line what the check said about this case.
$ hmp check typo.toml
Config invalid: /home/me/project/typo.toml
error flow: This value is refused by the check of its key or its table. The detail says why.
Unknown TOML key(s) in [flow]: flow_regme
$ hmp check conflict.toml
Config invalid: /home/me/project/conflict.toml
error flow.param.K.field.homogeneous:3: This value is refused by the check of its key or its table. The detail says why.
Value error, K.value mixes conflicting units: 'm/h' and 'm/s'.
The second file wrote value = "0.36 m/h" under a parent that had unit = "m/s". The key
unit was inherited, so the two units disagreed. hmp config targets <file> lists the
names a calibration can move, with their value, unit and path.