From 9654c01c6d99434bdc47eff14162e0eda0d9b11d Mon Sep 17 00:00:00 2001
From: David Hoese <davidh@ssec.wisc.edu>
Date: Tue, 21 Aug 2012 21:37:29 +0000
Subject: [PATCH] Fixed array_convert so its vectorized and is mask agnostic
 Fixed buoy quicklooks so it uses numpy.isnan to mask nans instead of for
 loops

---
 metobs/data/__init__.py | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/metobs/data/__init__.py b/metobs/data/__init__.py
index 6e69baa..401a47c 100644
--- a/metobs/data/__init__.py
+++ b/metobs/data/__init__.py
@@ -317,39 +317,33 @@ def array_convert(arr, sunits, cunits):
     """
     if sunits == cunits: return arr
     if not isinstance(arr, ndarray): raise ValueError("Array must be of type numpy.ndarray, not %r" % (type(arr),))
-    shape = arr.shape
-    a = arr.flatten()
     if sunits == 'c':
         if cunits == 'f':
-            a = array([ c2f(x) for x in a ])
-            return a.reshape(shape)
+            a = c2f(arr)
+            return a
     elif sunits == 'f':
         if cunits == 'c':
-            a = array([ f2c(x) for x in a ])
-            return a.reshape(shape)
+            a = f2c(arr)
+            return a
     elif sunits == 'm/s':
         if cunits == 'knots':
-            a = array([ mps2knots(x) for x in a ])
-            return a.reshape(shape)
+            a = mps2knots(arr)
+            return a
     elif sunits == 'knots':
         if cunits == 'm/s':
-            a = array([ knots2mps(x) for x in a ])
-            return a.reshape(shape)
-    elif sunits == 'hpa':
-        return a.reshape(a)
-    elif sunits == 'deg':
-        return a.reshape(a)
+            a = knots2mps(arr)
+            return a
     elif sunits == 'in':
         if cunits == 'mm':
-            a = array([ in2mm(x) for x in a ])
-            return a.reshape(shape)
+            a = in2mm(arr)
+            return a
     elif sunits == 'mm':
         if cunits == 'in':
-            a = array([ mm2in(x) for x in a ])
-            return a.reshape(shape)
-    elif sunits == 'w/m2':
-        return a.reshape(a)
+            a = mm2in(arr)
+            return a
+
     raise ValueError("sunits or cunits was not an acceptable unit")
+
 if __name__ == '__main__':
     import doctest
     doctest.testmod()
-- 
GitLab