From b44e94a50f0f1a793000aa7ea9f1e8b8e7cb1420 Mon Sep 17 00:00:00 2001
From: "R.K.Garcia" <rkgarcia@wisc.edu>
Date: Thu, 28 Sep 2017 15:33:01 -0500
Subject: [PATCH] caching of navigation speeds up cmi_changer a LOT

---
 himawari/ahi2cmi.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/himawari/ahi2cmi.py b/himawari/ahi2cmi.py
index 163d8bc..d94598f 100644
--- a/himawari/ahi2cmi.py
+++ b/himawari/ahi2cmi.py
@@ -51,6 +51,9 @@ class HimawariAHIasCMIP(object):
     _data_name = DEFAULT_CMIP_NAME
     _projection_name = DEFAULT_CMIP_PROJECTION_NAME
     _when = None
+    y = None
+    x = None
+    shape_m = None
 
     def __init__(self, path, as_radiances=False, data_name=None):
         """
@@ -68,6 +71,10 @@ class HimawariAHIasCMIP(object):
             data_name = DEFAULT_CMIP_NAME if not as_radiances else DEFAULT_CMIP_RAD_NAME
         self._data_name = data_name
         self._when = datetime.utcnow()
+        # cache the y and x angles
+        self.y = self._y
+        self.x = self._x
+        self.shape_m = self._shape_m
 
     def p(self, *strings):
         return (self.path,) + tuple(strings)
@@ -590,7 +597,7 @@ class HimawariAHIasCMIP(object):
         return self._hs.radiances()
 
     @property
-    def y(self):
+    def _y(self):
         """
         negate y values to match PUG convention
         also see yx_pvda regarding negation of scale_factor and add_offset to keep monotonic increasing unscaled values
@@ -600,7 +607,7 @@ class HimawariAHIasCMIP(object):
         return -y.squeeze()
 
     @property
-    def x(self):
+    def _x(self):
         _, x = self._hs.coords(lines=1)
         return x.squeeze()
 
@@ -633,7 +640,7 @@ class HimawariAHIasCMIP(object):
         return np.require(self.x, dtype=np.float64) * self.perspective_point_height
 
     @property
-    def shape_m(self):
+    def _shape_m(self):
         """
         :return: (y, x) nadir-meters nominal size of a cell
         """
@@ -641,7 +648,9 @@ class HimawariAHIasCMIP(object):
         h = self.perspective_point_height
         return mb.my * h, mb.mx * h
 
-    cell_size = shape_m
+    @property
+    def cell_size(self):
+        return self.shape_m
 
     @property
     def origin(self):
-- 
GitLab