Skip to content

Commit 51ae2d3

Browse files
committed
fix time_bnds issue
1 parent 77d2538 commit 51ae2d3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/access_moppy/ocean.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ def _get_dim_rename(self):
5555
def select_and_process_variables(self):
5656
"""Select and process variables for the CMOR output."""
5757
input_vars = self.mapping[self.cmor_name]["model_variables"]
58+
time_bnds = ["time_bnds"]
5859
calc = self.mapping[self.cmor_name]["calculation"]
5960

60-
required_vars = set(input_vars)
61+
required_vars = set(input_vars + time_bnds)
6162
self.load_dataset(required_vars=required_vars)
63+
64+
dim_rename = self._get_dim_rename()
6265
self.sort_time_dimension()
6366

6467
if calc["type"] == "direct":
@@ -70,7 +73,6 @@ def select_and_process_variables(self):
7073
else:
7174
raise ValueError(f"Unsupported calculation type: {calc['type']}")
7275

73-
dim_rename = self._get_dim_rename()
7476

7577
dims_to_rename = {
7678
k: v for k, v in dim_rename.items() if k in self.ds[self.cmor_name].dims
@@ -88,11 +90,14 @@ def select_and_process_variables(self):
8890

8991
self.grid_type, self.symmetric = self.infer_grid_type()
9092
# Drop all other data variables except the CMOR variable
91-
self.ds = self.ds[[self.cmor_name]]
93+
self.ds = self.ds[[self.cmor_name,time_bnds[0]]]
9294

9395
# Drop unused coordinates
9496
used_coords = set()
95-
for dim in self.ds[self.cmor_name].dims:
97+
dims = list(self.ds[self.cmor_name].dims)
98+
if time_bnds[0] in self.ds:
99+
dims = list(dict.fromkeys(dims + list(self.ds[time_bnds[0]].dims)))
100+
for dim in dims:
96101
if dim in self.ds.coords:
97102
used_coords.add(dim)
98103
else:
@@ -102,6 +107,7 @@ def select_and_process_variables(self):
102107
used_coords.add(coord)
103108
self.ds = self.ds.drop_vars([c for c in self.ds.coords if c not in used_coords])
104109

110+
105111
def update_attributes(self):
106112
grid_type = self.grid_type
107113
arakawa = self.arakawa

0 commit comments

Comments
 (0)