Write a semantic model¶
A model explains how to obtain an observable under stated conditions. Start with the scientific question. Identify the bearer of the quantity, the intended unit, the spatial and temporal support, and a source or method that can actually produce it. This lets someone request the meaning without having to know your dataset's address.
Expose a resource through k.IM¶
The following teaching example associates a rainfall resource with an observable in millimetres. Replace the illustrative resource URN and ontology term with a published resource and a declaration accessible in your worldview.
namespace examples.hydrology
using imod, earth, hydrology
version 1.0
;
model public.data:hydrology:climate:rainfall
as hydrology:RainfallVolume in mm
;
The left side of the model identifies the source. The as clause states the meaning and unit offered to resolution. Check that the definition of the quantity and its time support match the source, particularly when a file contains an accumulated amount and the intended observable is a rate. A new label cannot correct that mismatch.
Declare a computation's inputs¶
A model can also request its dependencies by meaning. This example follows the water-balance declaration in the services language guide.
model hydrology:WaterBalance
observing
hydrology:PrecipitationVolume named precipitation,
hydrology:EvapotranspirationVolume named evapotranspiration
set to [precipitation - evapotranspiration]
;
set to writes the first output, here water balance. The expression reads the two inputs at each covered position. If two cells receive 10 and 4 units of precipitation and lose 3 and 2 units to evapotranspiration, their balances are 7 and 2. Compare quantities in the same volume unit, over the same area and time interval.
named precipitation gives the first input a short local name. To write the same model without any aliases, use the code names derived from the simple concept names.
model hydrology:WaterBalance
observing hydrology:PrecipitationVolume, hydrology:EvapotranspirationVolume
set water_balance to [precipitation_volume - evapotranspiration_volume]
;
water_balance explicitly selects the same first output. The Resolver uses the full observable declarations to find both inputs. Local names are how your formula refers to the resulting observations. Action targets, process effects and change rates
Accumulate a changing quantity¶
Suppose a water-routing process affects the volume stored at each reservoir. Request the net inflow in litres per second and integrate it over each scheduled month.
@time(step=1.month)
model hydrology:WaterRouting, hydrology:StoredVolume in L named storage
observing hydrology:NetInflowRate in L/s named inflow_rate
integrate storage as [inflow_rate]
;
At a location holding 100 L, an inflow of 2 L/s sustained for 10 seconds produces 120 L. A second location with an outflow of 1 L/s loses 10 L over that interval. Each uses its own starting volume and rate. A monthly schedule uses the actual seconds between its boundaries. Choose a step short enough for the sampled rate to represent what happens during the interval.
Give an affected stock an initial observation. For a stock the process creates, the first integral starts at zero. Advance the twin a second step and inspect the same quality to see the accumulation. This example uses the Resolver and Runtime implementation of inline process actions in the December 2026 development tree.
Align repeated spatial observations¶
When several areal results must share a lattice, a project can define a named grid. The grid declares a working projection, an anchor point and a positive cell span. For a projected CRS the anchor coordinates must be expressed in that CRS. Install the grid definition in the twin before requesting the observations that should use it. It applies to new areal observations and preserves their original shape coverage. Previously computed observations retain their geometry.
Verify the contribution¶
Save the namespace and resolve its diagnostics. Use a known subject in a twin with coverage for the resource or dependencies. Drag the model onto the twin panel to exercise that model specifically. Inspect the result's units, extent, activity and dataflow. Then request the observable through the composer to see whether it is discoverable in the intended context. Record which project, source version, area and time you used. Project validation ยท Read the evidence