climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From huiky...@apache.org
Subject [2/4] climate git commit: CLIMATE-668 - ocw.dataset_spatial_resolution needs to be fixed
Date Thu, 10 Sep 2015 16:45:18 GMT
CLIMATE-668 - ocw.dataset_spatial_resolution needs to be fixed

- without this fix, ocw.dataset.spatial_resolution cannot handle two dimensional latitudes
and longitudes
- for curvilinear latitudes and longitudes, the output of ocw.dataset.spatial_resolution is
approximate.


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/d3b9bb5b
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/d3b9bb5b
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/d3b9bb5b

Branch: refs/heads/master
Commit: d3b9bb5b3b294051043ce0e127dd4396ca0d7cf8
Parents: a0d7057
Author: huikyole <huikyole@argo.jpl.nasa.gov>
Authored: Tue Sep 8 23:53:59 2015 -0700
Committer: huikyole <huikyole@argo.jpl.nasa.gov>
Committed: Tue Sep 8 23:53:59 2015 -0700

----------------------------------------------------------------------
 ocw/dataset.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/d3b9bb5b/ocw/dataset.py
----------------------------------------------------------------------
diff --git a/ocw/dataset.py b/ocw/dataset.py
index 342e370..80be53c 100644
--- a/ocw/dataset.py
+++ b/ocw/dataset.py
@@ -111,16 +111,20 @@ class Dataset:
     def spatial_resolution(self):
         '''Calculate the latitudinal and longitudinal spatial resolution.
 
-        .. warning:: This only works with properly gridded data.
-
+           If self.lats and self.lons are from curvilinear coordinates, 
+           the output resolutions are approximate values.
         :returns: The Dataset's latitudinal and longitudinal spatial resolution
             as a tuple of the form (lat_resolution, lon_resolution).
         :rtype: (:class:`float`, :class:`float`)
         '''
-        sorted_lats = numpy.sort(list(set(self.lats)))
-        sorted_lons = numpy.sort(list(set(self.lons)))
-        lat_resolution = sorted_lats[1] - sorted_lats[0]
-        lon_resolution = sorted_lons[1] - sorted_lons[0]
+        if self.lats.ndim == 1 and self.lons.ndim ==1:
+            sorted_lats = numpy.sort(list(set(self.lats)))
+            sorted_lons = numpy.sort(list(set(self.lons)))
+            lat_resolution = sorted_lats[1] - sorted_lats[0]
+            lon_resolution = sorted_lons[1] - sorted_lons[0]
+        if self.lats.ndim == 2 and self.lons.ndim ==2:
+            lat_resolution = self.lats[1,1] - self.lats[0,0]
+            lon_resolution = self.lons[1,1] - self.lons[0,0]
 
         return (lat_resolution, lon_resolution)
 


Mime
View raw message