From a0d705794f4bb2ba682a306b0e618d5feab78ef8 Mon Sep 17 00:00:00 2001 From: huikyole Date: Tue, 8 Sep 2015 23:03:30 -0700 Subject: [PATCH 1/3] CLIMATE-667 - OCW spatial_boundaries bug - ocw.dataset.spatial_boundaries uses np.min and np.max instead of min and max --- ocw/dataset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocw/dataset.py b/ocw/dataset.py index e4329284..342e370e 100644 --- a/ocw/dataset.py +++ b/ocw/dataset.py @@ -89,8 +89,8 @@ def spatial_boundaries(self): :class:`float`, :class:`float`). ''' - return (float(min(self.lats)), float(max(self.lats)), - float(min(self.lons)), float(max(self.lons))) + return (float(numpy.min(self.lats)), float(numpy.max(self.lats)), + float(numpy.min(self.lons)), float(numpy.max(self.lons))) def time_range(self): From d3b9bb5b3b294051043ce0e127dd4396ca0d7cf8 Mon Sep 17 00:00:00 2001 From: huikyole Date: Tue, 8 Sep 2015 23:53:59 -0700 Subject: [PATCH 2/3] 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. --- ocw/dataset.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ocw/dataset.py b/ocw/dataset.py index 342e370e..80be53c8 100644 --- a/ocw/dataset.py +++ b/ocw/dataset.py @@ -111,16 +111,20 @@ def time_range(self): 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) From 998df0cbe543d76b5f4261aa919d07300ecd85fa Mon Sep 17 00:00:00 2001 From: huikyole Date: Tue, 8 Sep 2015 23:59:39 -0700 Subject: [PATCH 3/3] 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. - suggested changes in CLIMATE-667 are removed --- ocw/dataset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocw/dataset.py b/ocw/dataset.py index 80be53c8..e6b0bc67 100644 --- a/ocw/dataset.py +++ b/ocw/dataset.py @@ -89,8 +89,8 @@ def spatial_boundaries(self): :class:`float`, :class:`float`). ''' - return (float(numpy.min(self.lats)), float(numpy.max(self.lats)), - float(numpy.min(self.lons)), float(numpy.max(self.lons))) + return (float(min(self.lats)), float(max(self.lats)), + float(min(self.lons)), float(max(self.lons))) def time_range(self):