Commit a79f7394 authored by R.K.Garcia's avatar R.K.Garcia
Browse files

implement band_id dimension when as_cmi is requested

parent 0c8fbff0
......@@ -525,12 +525,16 @@ class HimawariAHIasCMIP(object):
else: # return floating point values
return line, column
def walk(self, extra_data_attrs={}):
def walk(self, extra_data_attrs={}, as_cmi=False):
"""
iterate PVDA frames equivalent to a PUG nc_walk
"""
BAND_ID_DIM = 'band_id'
# root
yield self.p(), None, self._pug_global_dims, self._pug_global_attrs
gdims = OrderedDict(self._pug_global_dims)
if as_cmi:
gdims[BAND_ID_DIM] = 1
yield self.p(), None, gdims, self._pug_global_attrs
# nav structure
yield self.p(self._projection_name), np.int32(0), {}, self.nav
......@@ -538,6 +542,10 @@ class HimawariAHIasCMIP(object):
# band_wavelength in µm
yield self.p('band_wavelength'), np.float64(self.central_wavelength), {}, {}
# band number, primarily for CMI
if as_cmi:
yield self.p('band_id'), np.array([self.band], dtype=np.int8), OrderedDict({BAND_ID_DIM: gdims[BAND_ID_DIM]}), {}
# y and x variables and friends
for each in self.pvda_yx():
yield each
......@@ -550,8 +558,13 @@ class HimawariAHIasCMIP(object):
yield each
# we almost forgot! the data itself
v = self.data
d = self.data_dims
if not as_cmi: # SCMI has no band_id dimension
v = self.data
d = self.data_dims
else:
v = self.data.reshape((1,) + tuple(self.data.shape))
d = OrderedDict({BAND_ID_DIM: gdims[BAND_ID_DIM]})
d.update(self.data_dims)
a = dict(self.data_attrs)
a.update(extra_data_attrs)
yield self.p(self._data_name), v, d, a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment