k.IM models and embedded expressions¶
A k.IM namespace (.kim) tells k.LAB how an observation can be obtained. One model can expose the meaning of an existing source. Another can describe a computation and request its inputs by meaning.
namespace examples.hydrology
using imod, earth, hydrology
version 1.0
;
model public.data:hydrology:climate:rainfall
as hydrology:RainfallVolume in mm
;
The namespace organizes the declaration. The resource URN identifies a source and the as clause states its semantic output. The URN is illustrative. Substitute a resource available on your Resources service and verify its physical unit and time support before publishing the association.
| Construct | Use |
|---|---|
model … as … |
Associate resource-backed output with an observable. |
observing … named … |
Request a dependency by meaning. An optional alias gives it a local name in the model. |
| A scenario namespace | Offer alternatives selected under the applicable scenario. State which scenario was active when reporting a result. |
Refer to an observable by name¶
For a simple observable, drop the namespace and write the local concept name in lower case with underscores between words. hydrology:StoredVolume gives stored_volume. This works for an output or an input, both as an explicit action target and inside a scalar expression. The unit is separate from the name.
Writing hydrology:StoredVolume named storage gives the port the local identifier storage. Use a lower-case letter first, followed by lower-case letters, digits or underscores. Give distinct aliases to inputs with the same local name from different namespaces, or to two observations of the same quantity with different bearers or units. A compound observable includes its semantic qualifiers in its derived name. An alias such as storage gives the formula a stable, usable identifier. Within a scalar assignment or integral, self refers to its target quality. With set to, that is the first output.
Choose a model action¶
| Clause | What it means |
|---|---|
set to [value] |
Evaluate the value at each state of the first quality output. For hydrology:WaterBalance, the explicit form is set water_balance to [value]. |
set storage to [value] |
Evaluate the expression at each state of the declared target quality. A process can use this for a quality it affects or creates, listed among its outputs or observing dependencies. |
do [action] |
Run the procedure once per invocation, regardless of how many cells or shards the observation has. Its return value is discarded. A bare [action] in clause position is also procedural. |
integrate storage as [rate] |
At each state of the named numeric quality, add the rate in target units per second multiplied by the elapsed seconds to the prior stock. |
For example, suppose water routing affects the stored volume in a reservoir. The following process assigns the next volume provided by another model.
model hydrology:WaterRouting, hydrology:StoredVolume named storage
observing hydrology:NextStoredVolume named next_storage
set storage to [next_storage]
;
When the input supplies a rate, use integrate storage as [inflow_rate]. Request a rate in the target unit per second or convert it in the formula. Each state takes a forward Euler step using that interval's actual duration. For storage in cubic metres, an inflow of 2 m³/s for 10 s adds 20 m³. An affected quality starts from its committed value. A quality first created by the integral starts at zero. Later invocations, including after a restart, start from the last committed stock. Worked process model
In do [scope.info("Routing " + self.urn)], self is the whole process observation. Named ports are observation objects, and time gives the interval of the scheduler event. The process runs the procedure when its transition is due. A failed invocation can be retried. A completed transition is skipped on replay.
The grammar accepts an on phase or event prefix on set. A bracketed expression before as in a model head supplies a value.
Exercise the model in Modeler with a known subject, then request its observable to check discovery. Worked water-balance model · Resolver
A k.IM model or observation definition can also attach a k.Actors actor to each individual it creates. Bind a behavior to a field observer
Full language guide · Kim grammar · Groovy expression reference