Skip to content

Commit

Permalink
support for staging
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Oct 9, 2023
1 parent 87f463d commit b7176d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ai_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

__version__ = "0.2.8"
__version__ = "0.2.9"
8 changes: 7 additions & 1 deletion ai_models/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,16 @@ def _main():
)

parser.add_argument(
"--hindcast-reference-date",
"--hindcast-reference-year",
help="For encoding hincast-like outputs",
)

parser.add_argument(
"--staging-dates",
help="For encoding hincast-like outputs",
)

# TODO: deprecate that option
parser.add_argument(
"--model-version",
default="latest",
Expand Down
8 changes: 8 additions & 0 deletions ai_models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ def _datetimes(self, dates):
return result

def datetimes(self):
if self.staging_dates:
dates = []
with open(self.staging_dates) as f:
for line in f:
dates.append(datetime.datetime.fromisoformat(line.strip()))

return self._datetimes(dates)

date = self.date
assert isinstance(date, int)
if date <= 0:
Expand Down
8 changes: 6 additions & 2 deletions ai_models/outputs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ def write(self, *args, **kwargs):
else:
date = kwargs["template"]["date"]

assert len(str(date)) == 8
date = int(date)
referenceDate = self.owner.hindcast_reference_year * 10000 + date % 10000

kwargs.pop("date", None)
kwargs["referenceDate"] = self.owner.hindcast_reference_date
kwargs["referenceDate"] = referenceDate
kwargs["hdate"] = date
return self.output.write(*args, **kwargs)

Expand All @@ -69,7 +73,7 @@ def write(self, *args, **kwargs):

def get_output(name, owner, *args, **kwargs):
result = OUTPUTS[name](owner, *args, **kwargs)
if owner.hindcast_reference_date is not None:
if owner.hindcast_reference_year is not None:
result = HindcastReLabel(owner, result)
return result

Expand Down

0 comments on commit b7176d8

Please sign in to comment.