Skip to content

Commit cfa8c95

Browse files
committed
lazy opening of output files
1 parent 1dc415e commit cfa8c95

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

ai_models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# granted to it by virtue of its status as an intergovernmental organisation
66
# nor does it submit to any jurisdiction.
77

8-
__version__ = "0.4.0"
8+
__version__ = "0.4.1"

ai_models/outputs/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import itertools
99
import logging
10+
from functools import cached_property
1011

1112
import climetlab as cml
1213
import numpy as np
@@ -24,17 +25,21 @@ def __init__(self, owner, path, metadata, **kwargs):
2425
LOG.info("Writing results to %s.", path)
2526
self.path = path
2627
self.owner = owner
28+
self.metadata = metadata
2729

28-
edition = metadata.pop("edition", 2)
30+
@cached_property
31+
def output(self):
32+
33+
edition = self.metadata.pop("edition", 2)
2934

3035
self.grib_keys = dict(
3136
edition=edition,
3237
generatingProcessIdentifier=self.owner.version,
3338
)
34-
self.grib_keys.update(metadata)
39+
self.grib_keys.update(self.metadata)
3540

36-
self.output = cml.new_grib_output(
37-
path,
41+
return cml.new_grib_output(
42+
self.path,
3843
split_output=True,
3944
**self.grib_keys,
4045
)

0 commit comments

Comments
 (0)