Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/diffwofost/physical_models/crop/phenology.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,12 @@ class StateVariables(TensorStatesTemplate):
DVS = Tensor(-99.0)
TSUM = Tensor(-99.0)
TSUME = Tensor(-99.0)
DOS = Tensor(-99.0)
DOE = Tensor(-99.0)
DOA = Tensor(-99.0)
DOM = Tensor(-99.0)
DOH = Tensor(-99.0)
STAGE = Tensor(-99.0)
DOS = Tensor(-99, dtype=int)
DOE = Tensor(-99, dtype=int)
DOA = Tensor(-99, dtype=int)
DOM = Tensor(-99, dtype=int)
DOH = Tensor(-99, dtype=int)
STAGE = Tensor(-99, dtype=int)

def initialize(self, day, kiosk, parvalues, shape=None):
""":param day: start date of the simulation
Expand Down Expand Up @@ -429,9 +429,9 @@ def initialize(self, day, kiosk, parvalues, shape=None):
DVS=DVS,
DOS=DOS,
DOE=DOE,
DOA=-1.0, # not yet occurred
DOM=-1.0, # not yet occurred
DOH=-1.0, # not yet occurred
DOA=-1, # not yet occurred
DOM=-1, # not yet occurred
DOH=-1, # not yet occurred
STAGE=STAGE,
shape=shape,
)
Expand All @@ -458,7 +458,7 @@ def _get_initial_stage(self, day):
if p.CROP_START_TYPE == "emergence":
STAGE = 1 # 1 = vegetative
DOE = day_ordinal
DOS = -1.0 # Not applicable
DOS = -1 # Not applicable
DVS = p.DVSI

# send signal to indicate crop emergence
Expand All @@ -467,7 +467,7 @@ def _get_initial_stage(self, day):
elif p.CROP_START_TYPE == "sowing":
STAGE = 0 # 0 = emerging
DOS = day_ordinal
DOE = -1.0 # Not yet occurred
DOE = -1 # Not yet occurred
DVS = -0.1

else:
Expand Down Expand Up @@ -654,10 +654,8 @@ def integrate(self, day, delt=1.0):
s.DOM = torch.where(should_mature, day_ordinal, s.DOM)
s.DVS = torch.where(should_mature, torch.minimum(s.DVS, p.DVSEND), s.DVS)

# Send crop_finish signal if maturity reached for one.
# assumption is that all elements mature simultaneously
# TODO: revisit this when fixing engine for agromanager, see issue #60
if torch.any(should_mature) and p.CROP_END_TYPE in ["maturity", "earliest"]:
# Send crop_finish signal if maturity reached for all.
if torch.all(s.STAGE == 3) and p.CROP_END_TYPE in ["maturity", "earliest"]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from torch.any(...) to torch.all(...) here is fine as this is the work in progress. But please note that the reason that tests are passing is that we assumed that STAGE is the same for all inputs, if STAGE is an array we select the first item, see get_variable in tests. The reason is that currently in Engine there is no mechanism to handle none weather data when a matured crop is waiting for others.

self._send_signal(
signal=signals.crop_finish,
day=day,
Expand All @@ -668,7 +666,6 @@ def integrate(self, day, delt=1.0):
msg = "Finished state integration for %s"
self.logger.debug(msg % day)

# TODO: revisit this when fixing engine for agromanager, see issue #60
def _on_CROP_FINISH(self, day, finish_type=None):
"""Handle external crop finish signal to set harvest date.

Expand All @@ -680,7 +677,7 @@ def _on_CROP_FINISH(self, day, finish_type=None):
- If finish_type in ('harvest','earliest'): registers DOH for finalization.

Notes:
Maturity-driven finish is triggered internally in _next_stage; this
Maturity-driven finish is triggered internally as part of integrate; this
handler captures management-induced harvests.

"""
Expand Down
Loading