Skip to content

Coupling adapters for model component temporal mismatch #119

Open
@cpritcha

Description

@cpritcha

I've been working adapting SimpleCrop to be PyMT compatible and was wondering how you usually dealt with temporal mismatch between model components. The SimpleCrop model (as a wrapper around the command line interface at least) operates on a yearly basis. It takes in weather and irrigation data for each day of the year as well as some cross sectional soil and plant data. It returns plant and soil data for each day of the year. How would you deal with this mismatch? I was thinking that this could be made easier by having some generic memory components to build up results in. I was thinking of something like

from simplecrop.models import Weather, Irrigation, Crop
# may need to choose a different storage strategy in many model timesteps don't fit into memory
from pymt.storage import Memory
from pymt.model_adapters import TimeAggregator


# the weather and models crop operate on a daily basis but are converted to yearly components
weather = TimeAggregator(Weather(), to = 'year', storage = Memory())
# you may specify a keep option so that only model state used by other models is kept  
irrigation = TimeAggregator(Irrigation(), to = 'year', storage = Memory(), keep = ['irrigation_volume__total'])

weather.initialize(*weather.setup())
irrigation.initialize(*irrigation.setup())

# the crop model operates on a yearly basis
crop = Crop()

crop.initialize(*crop.setup())

# run the model for five years
for time in range(5):
    weather.update()
    irrigation.update()
    crop.set_value('irrigation_volume__total', irrigation.get_value('irrigation_volume__total'))
    crop.set_value('soil_temperature__max', weather.get_value('soil_temperature__max'))
    crop.set_value('soil_temperature__min', weather.get_value('soil_temperature__min'))
    crop.set_value(
        'soil_top_surface_raditation~incoming__energy_flux',
        weather.get_value('soil_top_surface_raditation~incoming__energy_flux'))
    crop.update()

What do you think? How do you currently handle differences in temporal range and resolution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions