Skip to content

Irrigation system

An irrigation system.

  • Class: IrrigationSystem
  • Import: from skcomplex.systems.engineering.processes import IrrigationSystem
  • Field: engineering/processes
  • Topics: water resources, agriculture, stocks and flows, system dynamics, ode
  • References:
    • Bala et al. 2017

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.engineering.processes import IrrigationSystem

trajectory = IrrigationSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
river_inflow 0.5
seasonality 0.9
reservoir_capacity 80.0
potential_et 0.4
canal_loss 0.2
pump_capacity 0.2
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time continuous
Space none
Laws rate
Randomness deterministic
Domains real
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class IrrigationSystem(BaseSystem):
    """An irrigation system.

    A reservoir and an aquifer keep the root zone of the crops supplied. A river fills the reservoir with a yearly
    cycle, and the reservoir loses water to evaporation and spills above its capacity. The irrigation demand is the
    potential crop evapotranspiration plus the refill of the root zone towards a target fraction of its field capacity.
    The reservoir releases the demand grossed up for the canal losses, as far as its stock allows, and the losses seep
    into the aquifer. When the release falls short, the farmers pump the unmet demand from the aquifer up to the pump
    capacity. The crops draw water from the root zone at the potential rate scaled by a water-stress table, and the root
    zone percolates to the aquifer, which drains as baseflow. Water is conserved, so in the dry season the reservoir
    falls, the pumping rises, and the aquifer is drawn down. The structure follows the irrigation example of Bala,
    Arshad and Noh (2017, Section 4.11), with illustrative parameters in millions of cubic metres and days.

    The system has the water stocks `scheme.reservoir`, `scheme.soil`, and `scheme.groundwater`, and the flows
    `scheme.inflow`, `scheme.reservoir_evaporation`, `scheme.spill`, `scheme.irrigation`, `scheme.seepage`,
    `scheme.groundwater_pumping`, `scheme.crop_water`, `scheme.deep_percolation`, and `scheme.baseflow` per day,
    over days. The observables of the system are `scheme.demand`, `scheme.release`, and `scheme.pumping`.

    Args:
        river_inflow:
            The mean river inflow to the reservoir, per day.

        seasonality:
            The relative amplitude of the yearly inflow cycle.

        reservoir_capacity:
            The capacity of the reservoir.

        potential_et:
            The crop water requirement, the potential evapotranspiration of the irrigated area per day.

        canal_loss:
            The fraction of the release lost from the canals to the aquifer.

        pump_capacity:
            The largest groundwater pumping per day.

        label:
            The label of the system, which names it when it is nested in another one.

        solver:
            The solver of the problem, or `'auto'` for the one the system chooses.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.

    Examples:
        >>> from skcomplex.systems.engineering.processes import IrrigationSystem
        >>> IrrigationSystem(pump_capacity=0.0).prepare().system_.elements[0].pump_capacity
        0.0
    """

    field = 'engineering/processes'
    topics = ('water resources', 'agriculture', 'stocks and flows', 'system dynamics', 'ode')
    references = ('Bala et al. 2017',)
    until = 730.0
    dt = 1.0
    observables = (
        Observable('demand', IrrigationSchemeInteraction._get_demand, element='scheme'),
        Observable('release', IrrigationSchemeInteraction._get_reservoir_release, element='scheme'),
        Observable('pumping', IrrigationSchemeInteraction._get_pumping, element='scheme'),
    )

    def __init__(
        self,
        *,
        river_inflow: float = 0.5,
        seasonality: float = 0.9,
        reservoir_capacity: float = 80.0,
        potential_et: float = 0.4,
        canal_loss: float = 0.2,
        pump_capacity: float = 0.2,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.river_inflow = river_inflow
        self.seasonality = seasonality
        self.reservoir_capacity = reservoir_capacity
        self.potential_et = potential_et
        self.canal_loss = canal_loss
        self.pump_capacity = pump_capacity

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set `system_` to the components of the system built from its model parameters."""
        super()._prepare(context)
        scheme = IrrigationSchemeElement(
            'scheme',
            river_inflow=self.river_inflow,
            seasonality=self.seasonality,
            reservoir_capacity=self.reservoir_capacity,
            potential_et=self.potential_et,
            canal_loss=self.canal_loss,
            pump_capacity=self.pump_capacity,
        )
        self.system_ = System(
            self.label,
            elements=[scheme],
            interactions=[IrrigationSchemeInteraction('flows', target='scheme')],
        )

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • IrrigationSchemeElement, from Element

Interactions:

  • IrrigationSchemeInteraction, from Interaction
class IrrigationSchemeElement(Element):
    """Irrigation scheme that moves water between its reservoirs.

    The water moves between a reservoir, the root zone of crops, and an aquifer.
    """

    def __init__(
        self,
        label: str,
        *,
        reservoir: Annotated[object, RealSet.closed_open(0, oo), Quantity('water')] = 50.0,
        soil: Annotated[object, RealSet.closed_open(0, oo), Quantity('water')] = 12.0,
        groundwater: Annotated[object, RealSet.closed_open(0, oo), Quantity('water')] = 100.0,
        river_inflow: Annotated[object, RealSet.closed_open(0, oo)] = 0.5,
        seasonality: Annotated[object, RealSet.closed_open(0, oo)] = 0.9,
        reservoir_capacity: Annotated[object, RealSet.open(0, oo)] = 80.0,
        evaporation: Annotated[object, RealSet.closed_open(0, oo)] = 0.001,
        spill_time: Annotated[object, RealSet.open(0, oo)] = 1.0,
        release_time: Annotated[object, RealSet.open(0, oo)] = 10.0,
        canal_loss: Annotated[object, RealSet.closed_open(0, oo)] = 0.2,
        potential_et: Annotated[object, RealSet.closed_open(0, oo)] = 0.4,
        field_capacity: Annotated[object, RealSet.open(0, oo)] = 20.0,
        target: Annotated[object, RealSet.closed_open(0, oo)] = 0.7,
        refill_time: Annotated[object, RealSet.open(0, oo)] = 5.0,
        percolation: Annotated[object, RealSet.closed_open(0, oo)] = 0.005,
        pump_capacity: Annotated[object, RealSet.closed_open(0, oo)] = 0.2,
        pump_time: Annotated[object, RealSet.open(0, oo)] = 10.0,
        baseflow_time: Annotated[object, RealSet.open(0, oo)] = 500.0,
    ) -> None:
        super().__init__(label)
        self.reservoir = reservoir
        self.soil = soil
        self.groundwater = groundwater
        self.river_inflow = river_inflow
        self.seasonality = seasonality
        self.reservoir_capacity = reservoir_capacity
        self.evaporation = evaporation
        self.spill_time = spill_time
        self.release_time = release_time
        self.canal_loss = canal_loss
        self.potential_et = potential_et
        self.field_capacity = field_capacity
        self.target = target
        self.refill_time = refill_time
        self.percolation = percolation
        self.pump_capacity = pump_capacity
        self.pump_time = pump_time
        self.baseflow_time = baseflow_time

class IrrigationSchemeInteraction(Interaction):
    """Flows of water between the reservoir, the soil, and the groundwater of an irrigation scheme.

    The flows read the stocks and the parameters of the element the role `target` binds.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the element that holds the stocks and the parameters.

    Examples:
        >>> from skcomplex.systems.engineering.processes import IrrigationSchemeInteraction
        >>> IrrigationSchemeInteraction('flows', target='scheme').target
        'scheme'
    """

    law_classes = (RateLaw,)

    def __init__(self, label: str, *, target: Role) -> None:
        super().__init__(label)
        self.target = target

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the flows of the stocks of the target.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        s = SimpleNamespace(t=context.t, **vars(context.target))
        self.laws_: list[BaseLaw] = IrrigationSchemeInteraction._get_irrigation_laws(s)

    @staticmethod
    def _get_demand(s: SimpleNamespace) -> Expression:
        """Return the water demand of the crops.

        It is their evapotranspiration and the refill of the root zone.
        """
        return clip(s.potential_et + (s.target * s.field_capacity - s.soil) / s.refill_time, 0)

    @staticmethod
    def _get_reservoir_release(s: SimpleNamespace) -> Expression:
        """Return the release of the reservoir.

        It is the demand before the canal losses, limited by the reservoir.
        """
        return minimum(IrrigationSchemeInteraction._get_demand(s) / (1 - s.canal_loss), s.reservoir / s.release_time)

    @staticmethod
    def _get_pumping(s: SimpleNamespace) -> Expression:
        """Return the pumping of groundwater.

        It is the demand the release leaves, limited by the pumps and the aquifer.
        """
        unmet = IrrigationSchemeInteraction._get_demand(s) - (
            1 - s.canal_loss
        ) * IrrigationSchemeInteraction._get_reservoir_release(s)
        return minimum(clip(unmet, 0), minimum(s.pump_capacity, s.groundwater / s.pump_time))

    @staticmethod
    def _get_irrigation_laws(s: SimpleNamespace) -> list[BaseLaw]:
        """Return the water balance of a reservoir, the root zone, and the aquifer.

        The root zone is that of the irrigated crops, and the aquifer is below them.
        """
        release = IrrigationSchemeInteraction._get_reservoir_release(s)
        crop_water = s.potential_et * series(s.soil / s.field_capacity, *WATER_STRESS)
        spill = clip(s.reservoir - s.reservoir_capacity, 0) / s.spill_time
        return [
            RateLaw(
                {s.reservoir: +1},
                RiceMillInteraction._get_season(s.river_inflow, s.seasonality, s.t, DAYS_PER_YEAR),
                label='inflow',
            ),
            RateLaw({s.reservoir: -1}, s.evaporation * s.reservoir, label='reservoir_evaporation'),
            RateLaw({s.reservoir: -1}, spill, label='spill'),
            RateLaw({s.reservoir: -1, s.soil: +1}, (1 - s.canal_loss) * release, label='irrigation'),
            RateLaw({s.reservoir: -1, s.groundwater: +1}, s.canal_loss * release, label='seepage'),
            RateLaw(
                {s.groundwater: -1, s.soil: +1},
                IrrigationSchemeInteraction._get_pumping(s),
                label='groundwater_pumping',
            ),
            RateLaw({s.soil: -1}, crop_water, label='crop_water'),
            RateLaw({s.soil: -1, s.groundwater: +1}, s.percolation * s.soil, label='deep_percolation'),
            RateLaw({s.groundwater: -1}, s.groundwater / s.baseflow_time, label='baseflow'),
        ]

Equations

The equations are those that symbolic returns for the system with its default parameters.

scheme.reservoir: diff(reservoir_scheme(t), t) == (seasonality_scheme*sin(0.01721420632103996*t) + 1)*river_inflow_scheme - evaporation_scheme*reservoir_scheme(t) + (canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) - canal_loss_scheme*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) - where(-reservoir_capacity_scheme + reservoir_scheme(t) < 0, 0, -reservoir_capacity_scheme + reservoir_scheme(t))/spill_time_scheme
scheme.soil: diff(soil_scheme(t), t) == -percolation_scheme*soil_scheme(t) - potential_et_scheme*where(soil_scheme(t)/field_capacity_scheme < 0.0, 0.0, where(soil_scheme(t)/field_capacity_scheme < 0.6, 1.6666666666666667*soil_scheme(t)/field_capacity_scheme, 1.0)) - (canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) + where(where(groundwater_scheme(t)/pump_time_scheme < pump_capacity_scheme, groundwater_scheme(t)/pump_time_scheme, pump_capacity_scheme) < where((canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) + where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme) < 0, 0, (canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) + where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)), where(groundwater_scheme(t)/pump_time_scheme < pump_capacity_scheme, groundwater_scheme(t)/pump_time_scheme, pump_capacity_scheme), where((canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) + where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme) < 0, 0, (canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) + where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)))
scheme.groundwater: diff(groundwater_scheme(t), t) == percolation_scheme*soil_scheme(t) + canal_loss_scheme*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) - groundwater_scheme(t)/baseflow_time_scheme - where(where(groundwater_scheme(t)/pump_time_scheme < pump_capacity_scheme, groundwater_scheme(t)/pump_time_scheme, pump_capacity_scheme) < where((canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) + where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme) < 0, 0, (canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) + where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)), where(groundwater_scheme(t)/pump_time_scheme < pump_capacity_scheme, groundwater_scheme(t)/pump_time_scheme, pump_capacity_scheme), where((canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) + where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme) < 0, 0, (canal_loss_scheme - 1)*where(reservoir_scheme(t)/release_time_scheme < -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1), reservoir_scheme(t)/release_time_scheme, -where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)/(canal_loss_scheme - 1)) + where(potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme < 0, 0, potential_et_scheme + (field_capacity_scheme*target_scheme - soil_scheme(t))/refill_time_scheme)))