climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jarifibra...@apache.org
Subject [2/5] climate git commit: Normallze subset function parameter ordering
Date Thu, 28 Jul 2016 14:14:58 GMT
Normallze subset function parameter ordering


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

Branch: refs/heads/master
Commit: fb5392f3bf6cdf01d3ac04d7533cc55024343aca
Parents: 5024b1c
Author: Ibrahim Jarif <jarifibrahim@gmail.com>
Authored: Tue Jul 26 13:00:10 2016 +0530
Committer: Ibrahim Jarif <jarifibrahim@gmail.com>
Committed: Thu Jul 28 19:41:09 2016 +0530

----------------------------------------------------------------------
 RCMES/run_RCMES.py                      |  4 ++--
 RCMES/test/test.py                      |  2 +-
 docs/source/ocw/overview.rst            |  2 +-
 examples/knmi_to_cru31_full_bias.py     |  2 +-
 examples/model_ensemble_to_rcmed.py     |  4 ++--
 examples/multi_model_evaluation.py      |  2 +-
 examples/multi_model_taylor_diagram.py  |  2 +-
 examples/subregions_portrait_diagram.py |  2 +-
 examples/taylor_diagram_example.py      |  4 ++--
 examples/time_series_with_regions.py    |  8 +++++---
 ocw/dataset_processor.py                |  2 +-
 ocw/evaluation.py                       |  9 +++++----
 ocw/tests/test_dataset_processor.py     | 20 ++++++++++----------
 ocw_config_runner/plot_generation.py    |  4 ++--
 14 files changed, 35 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/RCMES/run_RCMES.py
----------------------------------------------------------------------
diff --git a/RCMES/run_RCMES.py b/RCMES/run_RCMES.py
index bb4f5d5..cd69bc4 100644
--- a/RCMES/run_RCMES.py
+++ b/RCMES/run_RCMES.py
@@ -146,11 +146,11 @@ if ref_data_info['data_source'] == 'rcmed':
     max_lon = np.min([max_lon, ref_dataset.lons.max()])
 bounds = Bounds(min_lat, max_lat, min_lon, max_lon, start_time, end_time)
 
-ref_dataset = dsp.subset(bounds,ref_dataset)
+ref_dataset = dsp.subset(ref_dataset, bounds)
 if ref_dataset.temporal_resolution() != temporal_resolution:
     ref_dataset = dsp.temporal_rebin(ref_dataset, temporal_resolution)
 for idata,dataset in enumerate(model_datasets):
-    model_datasets[idata] = dsp.subset(bounds,dataset)
+    model_datasets[idata] = dsp.subset(dataset, bounds)
     if dataset.temporal_resolution() != temporal_resolution:
         model_datasets[idata] = dsp.temporal_rebin(dataset, temporal_resolution)
 

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/RCMES/test/test.py
----------------------------------------------------------------------
diff --git a/RCMES/test/test.py b/RCMES/test/test.py
index 5071187..677a13f 100644
--- a/RCMES/test/test.py
+++ b/RCMES/test/test.py
@@ -112,7 +112,7 @@ print("Our two datasets have a mis-match in time. We will subset on time
to %s y
 
 # Create a Bounds object to use for subsetting
 new_bounds = Bounds(min_lat, max_lat, min_lon, max_lon, start_time, end_time)
-knmi_dataset = dsp.subset(new_bounds, knmi_dataset)
+knmi_dataset = dsp.subset(knmi_dataset, new_bounds)
 
 print("CRU31_Dataset.values shape: (times, lats, lons) - %s" % (cru31_dataset.values.shape,))
 print("KNMI_Dataset.values shape: (times, lats, lons) - %s \n" % (knmi_dataset.values.shape,))

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/docs/source/ocw/overview.rst
----------------------------------------------------------------------
diff --git a/docs/source/ocw/overview.rst b/docs/source/ocw/overview.rst
index 5aa0ff8..a77f954 100644
--- a/docs/source/ocw/overview.rst
+++ b/docs/source/ocw/overview.rst
@@ -35,7 +35,7 @@ Subsetting is a great way to speed up your processing and keep useless data
out
 
 >>> import ocw.dataset_processor as dsp
 >>> new_bounds = Bounds(min_lat, max_lat, min_lon, max_lon, start_time, end_time)
->>> knmi_dataset = dsp.subset(new_bounds, knmi_dataset)
+>>> knmi_dataset = dsp.subset(knmi_dataset, new_bounds)
 
 Temporally re-binning a dataset is great when the time step of the data is too fine grain
for the desired use. For instance, perhaps we want to see a yearly trend but we have daily
data. We would need to make the following call to adjust our dataset::
 

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/examples/knmi_to_cru31_full_bias.py
----------------------------------------------------------------------
diff --git a/examples/knmi_to_cru31_full_bias.py b/examples/knmi_to_cru31_full_bias.py
index c6aa327..4c0abd9 100644
--- a/examples/knmi_to_cru31_full_bias.py
+++ b/examples/knmi_to_cru31_full_bias.py
@@ -112,7 +112,7 @@ print("Our two datasets have a mis-match in time. We will subset on time
to %s y
 
 # Create a Bounds object to use for subsetting
 new_bounds = Bounds(min_lat, max_lat, min_lon, max_lon, start_time, end_time)
-knmi_dataset = dsp.subset(new_bounds, knmi_dataset)
+knmi_dataset = dsp.subset(knmi_dataset, new_bounds)
 
 print("CRU31_Dataset.values shape: (times, lats, lons) - %s" % (cru31_dataset.values.shape,))
 print("KNMI_Dataset.values shape: (times, lats, lons) - %s \n" % (knmi_dataset.values.shape,))

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/examples/model_ensemble_to_rcmed.py
----------------------------------------------------------------------
diff --git a/examples/model_ensemble_to_rcmed.py b/examples/model_ensemble_to_rcmed.py
index 14b92b9..fef1f9d 100644
--- a/examples/model_ensemble_to_rcmed.py
+++ b/examples/model_ensemble_to_rcmed.py
@@ -131,8 +131,8 @@ cru31_dataset = dsp.temporal_rebin(cru31_dataset, temporal_resolution
= 'annual'
 new_bounds = Bounds(min_lat, max_lat, min_lon, max_lon, start_time, end_time)
 
 # Subset our model datasets so they are the same size
-knmi_dataset = dsp.subset(new_bounds, knmi_dataset)
-wrf311_dataset = dsp.subset(new_bounds, wrf311_dataset)
+knmi_dataset = dsp.subset(knmi_dataset, new_bounds)
+wrf311_dataset = dsp.subset(wrf311_dataset, new_bounds)
 
 """ Spatially Regrid the Dataset Objects to a 1/2 degree grid """
 # Using the bounds we will create a new set of lats and lons on 1/2 degree step

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/examples/multi_model_evaluation.py
----------------------------------------------------------------------
diff --git a/examples/multi_model_evaluation.py b/examples/multi_model_evaluation.py
index a09c526..0755279 100644
--- a/examples/multi_model_evaluation.py
+++ b/examples/multi_model_evaluation.py
@@ -91,7 +91,7 @@ CRU31 = dsp.water_flux_unit_conversion(CRU31)
 CRU31 = dsp.temporal_rebin(CRU31, datetime.timedelta(days=30))
 
 for member, each_target_dataset in enumerate(target_datasets):
-  target_datasets[member] = dsp.subset(EVAL_BOUNDS, target_datasets[member])
+  target_datasets[member] = dsp.subset(target_datasets[member], EVAL_BOUNDS)
   target_datasets[member] = dsp.water_flux_unit_conversion(target_datasets[member])
   target_datasets[member] = dsp.temporal_rebin(target_datasets[member], datetime.timedelta(days=30))
   
     

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/examples/multi_model_taylor_diagram.py
----------------------------------------------------------------------
diff --git a/examples/multi_model_taylor_diagram.py b/examples/multi_model_taylor_diagram.py
index 57dabdd..9ba8746 100644
--- a/examples/multi_model_taylor_diagram.py
+++ b/examples/multi_model_taylor_diagram.py
@@ -86,7 +86,7 @@ CRU31 = dsp.temporal_rebin(CRU31, temporal_resolution = 'monthly')
 for member, each_target_dataset in enumerate(target_datasets):
 	target_datasets[member] = dsp.water_flux_unit_conversion(target_datasets[member])
 	target_datasets[member] = dsp.temporal_rebin(target_datasets[member], temporal_resolution
= 'monthly') 
-	target_datasets[member] = dsp.subset(EVAL_BOUNDS, target_datasets[member])	
+	target_datasets[member] = dsp.subset(target_datasets[member], EVAL_BOUNDS)
 	
 #Regrid
 print("... regrid")

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/examples/subregions_portrait_diagram.py
----------------------------------------------------------------------
diff --git a/examples/subregions_portrait_diagram.py b/examples/subregions_portrait_diagram.py
index d8d982f..525cb26 100644
--- a/examples/subregions_portrait_diagram.py
+++ b/examples/subregions_portrait_diagram.py
@@ -76,7 +76,7 @@ print("... on units")
 CRU31 = dsp.water_flux_unit_conversion(CRU31)
 
 for member, each_target_dataset in enumerate(target_datasets):
-	target_datasets[member] = dsp.subset(EVAL_BOUNDS, target_datasets[member])	
+	target_datasets[member] = dsp.subset(target_datasets[member], EVAL_BOUNDS)
 	target_datasets[member] = dsp.water_flux_unit_conversion(target_datasets[member])
 	target_datasets[member] = dsp.normalize_dataset_datetimes(target_datasets[member], 'monthly')
		
 		

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/examples/taylor_diagram_example.py
----------------------------------------------------------------------
diff --git a/examples/taylor_diagram_example.py b/examples/taylor_diagram_example.py
index 90c6708..66ca175 100644
--- a/examples/taylor_diagram_example.py
+++ b/examples/taylor_diagram_example.py
@@ -62,8 +62,8 @@ wrf_dataset = dsp.normalize_dataset_datetimes(wrf_dataset, 'monthly')
 # make a Bounds object and use it to subset our datasets.
 ################################################################################
 subset = Bounds(-45, 42, -24, 60, datetime.datetime(1989, 1, 1), datetime.datetime(1989,
12, 1))
-knmi_dataset = dsp.subset(subset, knmi_dataset)
-wrf_dataset = dsp.subset(subset, wrf_dataset)
+knmi_dataset = dsp.subset(knmi_dataset, subset)
+wrf_dataset = dsp.subset(wrf_dataset, subset)
 
 # Temporally re-bin the data into a monthly timestep.
 ################################################################################

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/examples/time_series_with_regions.py
----------------------------------------------------------------------
diff --git a/examples/time_series_with_regions.py b/examples/time_series_with_regions.py
index ec9516d..8d9e5c0 100644
--- a/examples/time_series_with_regions.py
+++ b/examples/time_series_with_regions.py
@@ -74,7 +74,7 @@ CRU31 = dsp.water_flux_unit_conversion(CRU31)
 CRU31 = dsp.normalize_dataset_datetimes(CRU31, 'monthly')
 
 for member, each_target_dataset in enumerate(target_datasets):
-	target_datasets[member] = dsp.subset(EVAL_BOUNDS, target_datasets[member])
+	target_datasets[member] = dsp.subset(target_datasets[member], EVAL_BOUNDS)
 	target_datasets[member] = dsp.water_flux_unit_conversion(target_datasets[member])
 	target_datasets[member] = dsp.normalize_dataset_datetimes(target_datasets[member], 'monthly')
 		
 	
@@ -122,7 +122,7 @@ for regions in region_list:
 	firstTime = True
 	subset_name = regions[0]+"_CRU31"
 	#labels.append(subset_name) #for legend, uncomment this line
-	subset = dsp.subset(list_of_regions[region_counter], CRU31, subset_name)
+	subset = dsp.subset(CRU31, list_of_regions[region_counter], subset_name)
 	tSeries = utils.calc_time_series(subset)
 	results.append(tSeries)
 	tSeries=[]
@@ -130,7 +130,9 @@ for regions in region_list:
 	for member, each_target_dataset in enumerate(target_datasets):
 		subset_name = regions[0]+"_"+target_datasets[member].name
 		#labels.append(subset_name) #for legend, uncomment this line
-		subset = dsp.subset(list_of_regions[region_counter],target_datasets[member],subset_name)
+		subset = dsp.subset(target_datasets[member],
+							list_of_regions[region_counter],
+							subset_name)
 		tSeries = utils.calc_time_series(subset)
 		results.append(tSeries)
 		tSeries=[]

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/ocw/dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py
index 9837746..6702e54 100755
--- a/ocw/dataset_processor.py
+++ b/ocw/dataset_processor.py
@@ -362,7 +362,7 @@ def ensemble(datasets):
     return ensemble_dataset
 
 
-def subset(subregion, target_dataset, subregion_name=None):
+def subset(target_dataset, subregion, subregion_name=None):
     '''Subset given dataset(s) with subregion information
 
     :param subregion: The Bounds with which to subset the target Dataset.

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/ocw/evaluation.py
----------------------------------------------------------------------
diff --git a/ocw/evaluation.py b/ocw/evaluation.py
index 8f01a68..cd06450 100644
--- a/ocw/evaluation.py
+++ b/ocw/evaluation.py
@@ -272,11 +272,11 @@ class Evaluation(object):
 
     def _run_subregion_evaluation(self):
         results = []
-        new_refs = [DSP.subset(s, self.ref_dataset) for s in self.subregions]
+        new_refs = [DSP.subset(self.ref_dataset, s) for s in self.subregions]
 
         for target in self.target_datasets:
             results.append([])
-            new_targets = [DSP.subset(s, target) for s in self.subregions]
+            new_targets = [DSP.subset(target, s) for s in self.subregions]
 
             for metric in self.metrics:
                 results[-1].append([])
@@ -313,10 +313,11 @@ class Evaluation(object):
     def _run_subregion_unary_evaluation(self):
         unary_results = []
         if self.ref_dataset:
-            new_refs = [DSP.subset(s, self.ref_dataset) for s in self.subregions]
+            new_refs = [DSP.subset(self.ref_dataset, s)
+                        for s in self.subregions]
 
         new_targets = [
-            [DSP.subset(s, t) for s in self.subregions]
+            [DSP.subset(t, s) for s in self.subregions]
             for t in self.target_datasets
         ]
 

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/ocw/tests/test_dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset_processor.py b/ocw/tests/test_dataset_processor.py
index bdbfa06..3510463 100644
--- a/ocw/tests/test_dataset_processor.py
+++ b/ocw/tests/test_dataset_processor.py
@@ -450,7 +450,7 @@ class TestSubset(unittest.TestCase):
         )
 
     def test_subset(self):
-        subset = dp.subset(self.subregion, self.target_dataset)
+        subset = dp.subset(self.target_dataset, self.subregion)
         self.assertEqual(subset.lats.shape[0], 82)
         self.assertSequenceEqual(list(np.array(range(-81, 82, 2))),
                                  list(subset.lats))
@@ -459,12 +459,12 @@ class TestSubset(unittest.TestCase):
         self.assertEqual(subset.values.shape, (37, 82, 162))
 
     def test_subset_name(self):
-        subset = dp.subset(self.subregion, self.target_dataset)
+        subset = dp.subset(self.target_dataset, self.subregion)
         self.assertEqual(subset.name, self.name)
 
     def test_subset_name_propagation(self):
         subset_name = 'foo_subset_name'
-        subset = dp.subset(self.subregion, self.target_dataset, subset_name)
+        subset = dp.subset(self.target_dataset, self.subregion, subset_name)
         self.assertEqual(subset.name, subset_name)
 
     def test_subset_using_non_exact_spatial_bounds(self):
@@ -494,7 +494,7 @@ class TestSubset(unittest.TestCase):
             -81, 81,
             -161, 161,
         )
-        subset = dp.subset(self.subregion, self.target_dataset)
+        subset = dp.subset(self.target_dataset, self.subregion)
         times = np.array([datetime.datetime(year, month, 1)
                           for year in range(2000, 2010)
                           for month in range(1, 13)])
@@ -594,32 +594,32 @@ class TestFailingSubset(unittest.TestCase):
     def test_out_of_dataset_bounds_lat_min(self):
         self.subregion.lat_min = -90
         with self.assertRaises(ValueError):
-            dp.subset(self.subregion, self.target_dataset)
+            dp.subset(self.target_dataset, self.subregion)
 
     def test_out_of_dataset_bounds_lat_max(self):
         self.subregion.lat_max = 90
         with self.assertRaises(ValueError):
-            dp.subset(self.subregion, self.target_dataset)
+            dp.subset(self.target_dataset, self.subregion)
 
     def test_out_of_dataset_bounds_lon_min(self):
         self.subregion.lon_min = -180
         with self.assertRaises(ValueError):
-            dp.subset(self.subregion, self.target_dataset)
+            dp.subset(self.target_dataset, self.subregion)
 
     def test_out_of_dataset_bounds_lon_max(self):
         self.subregion.lon_max = 180
         with self.assertRaises(ValueError):
-            dp.subset(self.subregion, self.target_dataset)
+            dp.subset(self.target_dataset, self.subregion)
 
     def test_out_of_dataset_bounds_start(self):
         self.subregion.start = datetime.datetime(1999, 1, 1)
         with self.assertRaises(ValueError):
-            dp.subset(self.subregion, self.target_dataset)
+            dp.subset(self.target_dataset, self.subregion)
 
     def test_out_of_dataset_bounds_end(self):
         self.subregion.end = datetime.datetime(2011, 1, 1)
         with self.assertRaises(ValueError):
-            dp.subset(self.subregion, self.target_dataset)
+            dp.subset(self.target_dataset, self.subregion)
 
 
 class TestNetCDFWrite(unittest.TestCase):

http://git-wip-us.apache.org/repos/asf/climate/blob/fb5392f3/ocw_config_runner/plot_generation.py
----------------------------------------------------------------------
diff --git a/ocw_config_runner/plot_generation.py b/ocw_config_runner/plot_generation.py
index 938553e..3fc3adb 100644
--- a/ocw_config_runner/plot_generation.py
+++ b/ocw_config_runner/plot_generation.py
@@ -163,8 +163,8 @@ def _draw_time_series_plot(evaluation, plot_config):
             labels = []
 
             subset = dsp.subset(
-                bound,
                 ref_ds,
+                bound,
                 subregion_name="R{}_{}".format(bound_count, ref_ds.name)
             )
 
@@ -173,8 +173,8 @@ def _draw_time_series_plot(evaluation, plot_config):
 
             for t in target_ds:
                 subset = dsp.subset(
-                    bound,
                     t,
+                    bound,
                     subregion_name="R{}_{}".format(bound_count, t.name)
                 )
                 results.append(utils.calc_time_series(subset))


Mime
View raw message