Skip to content

Commit 6e10179

Browse files
committed
split supergrid file
1 parent c52562e commit 6e10179

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/access_mopper/ocean_supergrid.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import numpy as np
24
import xarray as xr
35

@@ -7,8 +9,14 @@ class Supergrid(object):
79
# https://gist.github.com/rbeucher/b67c2b461557bc215a70017ea8dd337b
810

911
def __init__(self, supergrid_file):
10-
self.supergrid_file = supergrid_file
11-
self.supergrid = xr.open_dataset(supergrid_file)
12+
if isinstance(supergrid_file, list):
13+
self.supergrid_file_list = supergrid_file
14+
self.supergrid = xr.open_mfdataset(self.supergrid_file_list)
15+
elif os.path.isfile(supergrid_file):
16+
self.supergrid_file = supergrid_file
17+
self.supergrid = xr.open_dataset(supergrid_file)
18+
else:
19+
raise ValueError("Couldn't find supergrid file")
1220

1321
# T point locations
1422
self.xt = self.supergrid["x"][1::2, 1::2]

tests/data/om3/supergrid/x.nc

50.2 MB
Binary file not shown.

tests/data/om3/supergrid/y.nc

50.2 MB
Binary file not shown.

tests/test_mop.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import glob
12
import importlib.resources as resources
23
from pathlib import Path
34

@@ -139,7 +140,7 @@ def test_cmorise_OM3_2d(model_om3, cmor_name):
139140
DATA_DIR / f"om3/2d/access-om3.mom6.2d.{cmor_name}.1mon.mean.1902_01.nc"
140141
)
141142
try:
142-
model_om3.supergrid = DATA_DIR / "supergrid/ocean_hgrid.nc"
143+
model_om3.supergrid = glob.glob(str(DATA_DIR / "om3/supergrid/*.nc"))
143144
model_om3.cmorise(
144145
file_paths=file_pattern,
145146
compound_name="Omon." + cmor_name,
@@ -158,7 +159,7 @@ def test_cmorise_OM3_3d(model_om3, cmor_name):
158159
DATA_DIR / f"om3/3d/access-om3.mom6.3d.{cmor_name}.1mon.mean.1924_01.nc"
159160
)
160161
try:
161-
model_om3.supergrid = DATA_DIR / "supergrid/ocean_hgrid.nc"
162+
model_om3.supergrid = glob.glob(str(DATA_DIR / "om3/supergrid/*.nc"))
162163
model_om3.cmorise(
163164
file_paths=file_pattern,
164165
compound_name="Omon." + cmor_name,

0 commit comments

Comments
 (0)