Skip to content

Commit a9ca18a

Browse files
author
Scott Wales
authored
Mule mask (#12)
1 parent 2c5faf7 commit a9ca18a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/coecms/grid.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import xarray
2121
import numpy
2222
import iris
23+
import mule
24+
import os
25+
2326

2427
"""
2528
Different grid types
@@ -178,11 +181,17 @@ def to_scrip(self):
178181
class UMGrid(LonLatGrid):
179182
@classmethod
180183
def from_mask(cls, mask_path):
181-
mask = iris.load_cube(mask_path, iris.AttributeConstraint(STASH='m01s00i030'))
182-
mask.coord('latitude').var_name = 'lat'
183-
mask.coord('longitude').var_name = 'lon'
184+
umfile = mule.load_umfile(mask_path)
185+
mask_field = None
186+
for f in umfile.fields:
187+
if f.lbuser4 == 30:
188+
mask_field = f
189+
break
190+
191+
mask = xarray.DataArray(mask_field.get_data(), dims=['lat', 'lon'], name=os.path.basename(mask_path))
192+
mask.coords['lon'] = mask_field.bzx + (1+numpy.arange(mask.shape[1])) * mask_field.bdx
193+
mask.coords['lat'] = mask_field.bzy + (1+numpy.arange(mask.shape[0])) * mask_field.bdy
184194

185-
mask = xarray.DataArray.from_iris(mask).load()
186195
mask = mask.where(mask == 0)
187196

188197
mask.lon.attrs['standard_name'] = 'longitude'

0 commit comments

Comments
 (0)