From 1cecdb0a6f657e2d4d81f6b283529bbdb4b76987 Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Tue, 13 Oct 2015 10:56:06 +0200 Subject: [PATCH 1/3] Switch to nullterm string in msg_hdf for nr products. Signed-off-by: Martin Raspaud --- mpop/satin/msg_hdf.py | 48 ++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/mpop/satin/msg_hdf.py b/mpop/satin/msg_hdf.py index f0bb811b..e18ad76b 100644 --- a/mpop/satin/msg_hdf.py +++ b/mpop/satin/msg_hdf.py @@ -1384,6 +1384,18 @@ def ctype_procflags2pps(data): # return ctype_lut, phase_lut, quality_lut +def add_nullterm_attr(obj, key, val): + import h5py + atype = h5py.h5t.C_S1 + tid = h5py.h5t.TypeID.copy(h5py.h5t.C_S1) + tid.set_size(len(val) + 1) + tid.set_strpad(h5py.h5t.STR_NULLTERM) + sid = h5py.h5s.create(h5py.h5s.SCALAR) + aid = h5py.h5a.create(obj.id, key, tid, sid) + blob = np.string_(val) + aid.write(np.array(val)) + + class NordRadCType(object): """Wrapper aroud the msg_ctype channel. @@ -1406,18 +1418,23 @@ def save(self, filename, **kwargs): # What what = h5f.create_group("what") - what.attrs["object"] = np.string_("IMAGE") + #what.attrs["object"] = np.string_("IMAGE") + add_nullterm_attr(what, "object", "IMAGE") what.attrs["sets"] = np.int(1) - what.attrs["version"] = np.string_("H5rad 1.2") + #what.attrs["version"] = np.string_("H5rad 1.2") + add_nullterm_attr(what, "version", "H5rad 1.2") yyyymmdd = self.datestr[0:8] hourminsec = self.datestr[8:12] + '00' - what.attrs["date"] = np.string_(yyyymmdd) - what.attrs["time"] = np.string_(hourminsec) + #what.attrs["date"] = np.string_(yyyymmdd) + add_nullterm_attr(what, "date", yyyymmdd) + #what.attrs["time"] = np.string_(hourminsec) + add_nullterm_attr(what, "time", hourminsec) # Where where = h5f.create_group("where") - where.attrs["projdef"] = np.string_(msgctype.area.proj4_string) + #where.attrs["projdef"] = np.string_(msgctype.area.proj4_string) + add_nullterm_attr(where, "projdef", msgctype.area.proj4_string) where.attrs["xsize"] = np.int(msgctype.num_of_columns) where.attrs["ysize"] = np.int(msgctype.num_of_lines) where.attrs["xscale"] = np.float(msgctype.xscale) @@ -1429,7 +1446,8 @@ def save(self, filename, **kwargs): # How how = h5f.create_group("how") - how.attrs["area"] = np.string_(msgctype.region_name) + #how.attrs["area"] = np.string_(msgctype.region_name) + add_nullterm_attr(how, "area", msgctype.region_name) # image1 image1 = h5f.create_group("image1") @@ -1437,13 +1455,19 @@ def save(self, filename, **kwargs): compression="gzip", compression_opts=COMPRESS_LVL) what = image1.create_group("what") - what.attrs["product"] = np.string_('MSGCT') + #what.attrs["product"] = np.string_('MSGCT') + add_nullterm_attr(what, "product", 'MSGCT') what.attrs["prodpar"] = np.float(0.0) - what.attrs["quantity"] = np.string_("ct") - what.attrs["startdate"] = np.string_(yyyymmdd) - what.attrs["starttime"] = np.string_(hourminsec) - what.attrs["enddate"] = np.string_(yyyymmdd) - what.attrs["endtime"] = np.string_(hourminsec) + #what.attrs["quantity"] = np.string_("ct") + add_nullterm_attr(what, "quantity", "ct") + #what.attrs["startdate"] = np.string_(yyyymmdd) + add_nullterm_attr(what, "startdate", yyyymmdd) + #what.attrs["starttime"] = np.string_(hourminsec) + add_nullterm_attr(what, "starttime", hourminsec) + #what.attrs["enddate"] = np.string_(yyyymmdd) + add_nullterm_attr(what, "enddate", yyyymmdd) + #what.attrs["endtime"] = np.string_(hourminsec) + add_nullterm_attr(what, "endtime", hourminsec) what.attrs["gain"] = np.float(1.0) what.attrs["offset"] = np.float(0.0) what.attrs["nodata"] = np.float(0.0) From 9ca357289498696f1e6b9996925df810b96efa41 Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Tue, 13 Oct 2015 11:05:29 +0200 Subject: [PATCH 2/3] Use builtin sunzen_corr for overview_sun. Signed-off-by: Martin Raspaud --- mpop/instruments/visir.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/mpop/instruments/visir.py b/mpop/instruments/visir.py index af3d4bef..4f6096a4 100644 --- a/mpop/instruments/visir.py +++ b/mpop/instruments/visir.py @@ -28,11 +28,6 @@ import numpy as np -try: - from pyorbital.astronomy import sun_zenith_angle as sza -except ImportError: - sza = None - # pylint: disable=W0612 # remove warnings for unused prerequisites @@ -152,15 +147,8 @@ def overview_sun(self, stretch='linear', gamma=1.6): lonlats = self[10.8].area.get_lonlats() - sunz = sza(self.time_slot, lonlats[0], lonlats[1]) - sunz = np.ma.masked_outside(sunz, 0.0, 88.0) - sunzmask = sunz.mask - sunz = sunz.filled(88.) - - costheta = np.cos(np.deg2rad(sunz)) - - red = np.ma.masked_where(sunzmask, self[0.635].data / costheta) - green = np.ma.masked_where(sunzmask, self[0.85].data / costheta) + red = self[0.635].sunzen_corr(self.time_slot, lonlats, limit=88.) + green = self[0.85].sunzen_corr(self.time_slot, lonlats, limit=88.) blue = -self[10.8].data img = geo_image.GeoImage((red, green, blue), From e5b1f96f77014ced1da1d7c6fdacc4e233982c0f Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Tue, 13 Oct 2015 11:59:14 +0200 Subject: [PATCH 3/3] Bugfix overview_sun. Signed-off-by: Martin Raspaud --- mpop/instruments/visir.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mpop/instruments/visir.py b/mpop/instruments/visir.py index 4f6096a4..62820f1e 100644 --- a/mpop/instruments/visir.py +++ b/mpop/instruments/visir.py @@ -147,8 +147,8 @@ def overview_sun(self, stretch='linear', gamma=1.6): lonlats = self[10.8].area.get_lonlats() - red = self[0.635].sunzen_corr(self.time_slot, lonlats, limit=88.) - green = self[0.85].sunzen_corr(self.time_slot, lonlats, limit=88.) + red = self[0.635].sunzen_corr(self.time_slot, lonlats, limit=88.).data + green = self[0.85].sunzen_corr(self.time_slot, lonlats, limit=88.).data blue = -self[10.8].data img = geo_image.GeoImage((red, green, blue),