Return-Path: X-Original-To: apmail-climate-commits-archive@minotaur.apache.org Delivered-To: apmail-climate-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8494817CBC for ; Thu, 23 Apr 2015 20:48:57 +0000 (UTC) Received: (qmail 48634 invoked by uid 500); 23 Apr 2015 20:48:57 -0000 Delivered-To: apmail-climate-commits-archive@climate.apache.org Received: (qmail 48592 invoked by uid 500); 23 Apr 2015 20:48:57 -0000 Mailing-List: contact commits-help@climate.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@climate.apache.org Delivered-To: mailing list commits@climate.apache.org Received: (qmail 48578 invoked by uid 99); 23 Apr 2015 20:48:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2015 20:48:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 460B7E17F5; Thu, 23 Apr 2015 20:48:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: whitehall@apache.org To: commits@climate.apache.org Date: Thu, 23 Apr 2015 20:48:57 -0000 Message-Id: <1d38a848e1c6448c9c681a8859323353@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] climate git commit: CLIMATE-623 - Allow propogation of 2D arrays - update subset function in DSP to subset 2D (lat, lon) arrays - update Dataset class to allow 2D (lat, lon) arrays - update associated test in test_dataset.py to allow 2D arrays Repository: climate Updated Branches: refs/heads/master b258cce24 -> f836d76ef CLIMATE-623 - Allow propogation of 2D arrays - update subset function in DSP to subset 2D (lat,lon) arrays - update Dataset class to allow 2D (lat,lon) arrays - update associated test in test_dataset.py to allow 2D arrays Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/126631db Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/126631db Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/126631db Branch: refs/heads/master Commit: 126631dbe078e372ee36a41695152af28a2f99e0 Parents: b258cce Author: Kim Whitehall Authored: Tue Apr 21 16:07:39 2015 -0700 Committer: Kim Whitehall Committed: Tue Apr 21 16:07:39 2015 -0700 ---------------------------------------------------------------------- ocw/dataset.py | 24 ++++++++++------ ocw/dataset_processor.py | 62 ++++++++++++++++++++++++++++-------------- ocw/tests/test_dataset.py | 2 +- 3 files changed, 58 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/126631db/ocw/dataset.py ---------------------------------------------------------------------- diff --git a/ocw/dataset.py b/ocw/dataset.py index d219d52..b5358f9 100644 --- a/ocw/dataset.py +++ b/ocw/dataset.py @@ -180,17 +180,23 @@ class Dataset: err_msg = "Longitude Array should be 1 dimensional. %s dimensions found." % lon_dim elif time_dim != 1: err_msg = "Time Array should be 1 dimensional. %s dimensions found." % time_dim - elif value_dim != 3: - err_msg = "Value Array should be 3 dimensional. %s dimensions found." % value_dim + elif value_dim < 2: + err_msg = "Value Array should be at least 2 dimensional. %s dimensions found." % value_dim # Finally check that the Values array conforms to the proper shape - elif values.shape != (time_count, lat_count, lon_count): + if value_dim == 2 and values.shape != (lat_count, lon_count): err_msg = """Value Array must be of shape (times, lats, lons). -Expected shape (%s, %s, %s) but received (%s, %s, %s)""" % (time_count, - lat_count, - lon_count, - values.shape[0], - values.shape[1], - values.shape[2]) + Expected shape (%s, %s, %s) but received (%s, %s, %s)""" % (lat_count, + lon_count, + values.shape[0], + values.shape[1]) + if value_dim == 3 and values.shape != (time_count, lat_count, lon_count): + err_msg = """Value Array must be of shape (times, lats, lons). + Expected shape (%s, %s, %s) but received (%s, %s, %s)""" % (time_count, + lat_count, + lon_count, + values.shape[0], + values.shape[1], + values.shape[2]) if err_msg: logger.error(err_msg) raise ValueError(err_msg) http://git-wip-us.apache.org/repos/asf/climate/blob/126631db/ocw/dataset_processor.py ---------------------------------------------------------------------- diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py index ec00262..76da817 100644 --- a/ocw/dataset_processor.py +++ b/ocw/dataset_processor.py @@ -184,26 +184,48 @@ def subset(subregion, target_dataset, subregion_name=None): subregion_name = target_dataset.name # Build new dataset with subset information - return ds.Dataset( - # Slice the lats array with our calculated slice indices - target_dataset.lats[dataset_slices["lat_start"]: - dataset_slices["lat_end"] + 1], - # Slice the lons array with our calculated slice indices - target_dataset.lons[dataset_slices["lon_start"]: - dataset_slices["lon_end"] + 1], - # Slice the times array with our calculated slice indices - target_dataset.times[dataset_slices["time_start"]: - dataset_slices["time_end"]+ 1], - # Slice the values array with our calculated slice indices - target_dataset.values[ - dataset_slices["time_start"]:dataset_slices["time_end"] + 1, - dataset_slices["lat_start"]:dataset_slices["lat_end"] + 1, - dataset_slices["lon_start"]:dataset_slices["lon_end"] + 1], - variable=target_dataset.variable, - units=target_dataset.units, - name=subregion_name, - origin=target_dataset.origin - ) + if target_dataset.values.ndim == 2: + return ds.Dataset( + # Slice the lats array with our calculated slice indices + target_dataset.lats[dataset_slices["lat_start"]: + dataset_slices["lat_end"] + 1], + # Slice the lons array with our calculated slice indices + target_dataset.lons[dataset_slices["lon_start"]: + dataset_slices["lon_end"] + 1], + # Slice the times array with our calculated slice indices + target_dataset.times[dataset_slices["time_start"]: + dataset_slices["time_end"]+ 1], + # Slice the values array with our calculated slice indices + target_dataset.values[ + dataset_slices["lat_start"]:dataset_slices["lat_end"] + 1, + dataset_slices["lon_start"]:dataset_slices["lon_end"] + 1], + variable=target_dataset.variable, + units=target_dataset.units, + name=subregion_name, + origin=target_dataset.origin + ) + if target_dataset.values.ndim == 3: + return ds.Dataset( + # Slice the lats array with our calculated slice indices + target_dataset.lats[dataset_slices["lat_start"]: + dataset_slices["lat_end"] + 1], + # Slice the lons array with our calculated slice indices + target_dataset.lons[dataset_slices["lon_start"]: + dataset_slices["lon_end"] + 1], + # Slice the times array with our calculated slice indices + target_dataset.times[dataset_slices["time_start"]: + dataset_slices["time_end"]+ 1], + # Slice the values array with our calculated slice indices + target_dataset.values[ + dataset_slices["time_start"]:dataset_slices["time_end"] + 1, + dataset_slices["lat_start"]:dataset_slices["lat_end"] + 1, + dataset_slices["lon_start"]:dataset_slices["lon_end"] + 1], + variable=target_dataset.variable, + units=target_dataset.units, + name=subregion_name, + origin=target_dataset.origin + ) + def safe_subset(subregion, target_dataset, subregion_name=None): '''Safely subset given dataset with subregion information http://git-wip-us.apache.org/repos/asf/climate/blob/126631db/ocw/tests/test_dataset.py ---------------------------------------------------------------------- diff --git a/ocw/tests/test_dataset.py b/ocw/tests/test_dataset.py index bd9dbd6..777d07e 100644 --- a/ocw/tests/test_dataset.py +++ b/ocw/tests/test_dataset.py @@ -86,7 +86,7 @@ class TestInvalidDatasetInit(unittest.TestCase): Dataset(self.lat, self.lon, self.time, self.value, 'prec') def test_bad_values_shape(self): - self.value = np.array([[1, 2], [2, 3], [3, 4], [4, 5]]) + self.value = np.array([1, 2, 3, 4, 5]) with self.assertRaises(ValueError): Dataset(self.lat, self.lon, self.time, self.value, 'prec')