Skip to content

Commit c17e832

Browse files
committed
Fixed two bugs that had to deal with crop_end_type is harvest/earliest.
1 parent 301f6ac commit c17e832

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

pcse/agromanager.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,21 @@ def __call__(self, day):
156156

157157
# end of the crop cycle
158158
finish_type = None
159-
# Check if crop_end_date is reached for CROP_END_TYPE harvest/earliest
160-
if self.crop_end_type in ["harvest", "earliest"]:
161-
if day == self.crop_end_date:
162-
finish_type = "harvest"
159+
if self.in_crop_cycle:
160+
# Check if crop_end_date is reached for CROP_END_TYPE harvest/earliest
161+
if self.crop_end_type in ["harvest", "earliest"]:
162+
if day == self.crop_end_date:
163+
finish_type = "harvest"
163164

164-
# Check for forced stop because maximum duration is reached
165-
if self.in_crop_cycle and self.duration == self.max_duration:
166-
finish_type = "max_duration"
165+
# Check for forced stop because maximum duration is reached
166+
if self.in_crop_cycle and self.duration == self.max_duration:
167+
finish_type = "max_duration"
167168

168169
# If finish condition is reached send a signal to finish the crop
169170
if finish_type is not None:
170171
self.in_crop_cycle = False
171172
self._send_signal(signal=signals.crop_finish, day=day,
172-
finish=finish_type, crop_delete=True)
173+
finish_type=finish_type, crop_delete=True)
173174

174175
def _on_CROP_FINISH(self):
175176
"""Register that crop has reached the end of its cycle.

pcse/crop/phenology.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def _next_stage(self, day):
466466
s.DOM = day
467467
if p.CROP_END_TYPE in ["maturity","earliest"]:
468468
self._send_signal(signal=signals.crop_finish,
469-
day=day, finish="maturity",
469+
day=day, finish_type="maturity",
470470
crop_delete=True)
471471
elif s.STAGE == "mature":
472472
msg = "Cannot move to next phenology stage: maturity already reached!"
@@ -485,7 +485,7 @@ def _on_CROP_FINISH(self, day, finish_type=None):
485485
strictly related to phenology (but to management) this is the most
486486
logical place to put it.
487487
"""
488-
if finish_type == 'harvest':
488+
if finish_type in ['harvest', 'earliest']:
489489
self._for_finalize["DOH"] = day
490490

491491

0 commit comments

Comments
 (0)