CLIMATE-488 - Change Dataset.time_range to Dataset.temporal_boundaries
Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/e823b03c Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/e823b03c Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/e823b03c Branch: refs/heads/CLIMATE-825 Commit: e823b03c9ba732f42909ad7b5e5b1a41fa321824 Parents: 442a9b2 Author: Ibrahim Jarif <jarifibra...@gmail.com> Authored: Sun Jul 24 23:19:41 2016 +0530 Committer: Ibrahim Jarif <jarifibra...@gmail.com> Committed: Sun Jul 24 23:19:41 2016 +0530 ---------------------------------------------------------------------- RCMES/cli_app.py | 8 ++++---- 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 | 2 +- ocw-ui/backend/tests/test_processing.py | 2 +- ocw/dataset.py | 16 ++++++++-------- ocw/dataset_processor.py | 4 ++-- ocw/tests/test_dataset.py | 18 +++++++++--------- ocw/tests/test_dataset_processor.py | 4 ++-- ocw/utils.py | 4 ++-- ocw_config_runner/configuration_parsing.py | 2 +- ocw_config_runner/configuration_writer.py | 4 ++-- .../example/time_series_plot_example.yaml | 2 +- ocw_config_runner/plot_generation.py | 4 ++-- ocw_config_runner/tests/test_config_writer.py | 4 ++-- 16 files changed, 40 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/RCMES/cli_app.py ---------------------------------------------------------------------- diff --git a/RCMES/cli_app.py b/RCMES/cli_app.py index be46de8..10ea6c4 100644 --- a/RCMES/cli_app.py +++ b/RCMES/cli_app.py @@ -457,8 +457,8 @@ def load_esgf_obs_screen(header): 'database':"{0}".format(netCDF_path), 'dataset_id':"esgf".format(esgf_variable), 'parameter_id':"{0}".format(esgf_variable), - 'start_date': obs_dataset.time_range()[0].strftime("%Y-%m-%d"), - 'end_date':obs_dataset.time_range()[1].strftime("%Y-%m-%d"), + 'start_date': obs_dataset.temporal_boundaries()[0].strftime("%Y-%m-%d"), + 'end_date':obs_dataset.temporal_boundaries()[1].strftime("%Y-%m-%d"), #'bounding_box':obs['bounding_box'], 'timestep':"monthly", 'min_lat':obs_dataset.spatial_boundaries()[0], @@ -798,8 +798,8 @@ def get_models_temp_bound(): models_start_time = [] models_end_time = [] for model in model_datasets: - models_start_time.append(model.time_range()[0]) - models_end_time.append(model.time_range()[1]) + models_start_time.append(model.temporal_boundaries()[0]) + models_end_time.append(model.temporal_boundaries()[1]) return models_start_time, models_end_time http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/RCMES/test/test.py ---------------------------------------------------------------------- diff --git a/RCMES/test/test.py b/RCMES/test/test.py index bbb8095..5071187 100644 --- a/RCMES/test/test.py +++ b/RCMES/test/test.py @@ -83,7 +83,7 @@ print("Calculating the Maximum Overlap in Time for the datasets") cru_start = datetime.datetime.strptime(cru_31['start_date'], "%Y-%m-%d") cru_end = datetime.datetime.strptime(cru_31['end_date'], "%Y-%m-%d") -knmi_start, knmi_end = knmi_dataset.time_range() +knmi_start, knmi_end = knmi_dataset.temporal_boundaries() # Grab the Max Start Time start_time = max([cru_start, knmi_start]) # Grab the Min End Time http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/docs/source/ocw/overview.rst ---------------------------------------------------------------------- diff --git a/docs/source/ocw/overview.rst b/docs/source/ocw/overview.rst index 9ef94da..5aa0ff8 100644 --- a/docs/source/ocw/overview.rst +++ b/docs/source/ocw/overview.rst @@ -12,7 +12,7 @@ The Apache Open Climate Workbench toolkit aims to provide a suit of tools to mak Common Data Abstraction ----------------------- -The OCW :class:`dataset.Dataset` class is the primary data abstraction used throughout OCW. It facilitates the uniform handling of data throughout the toolkit and provides a few useful helper functions such as :func:`dataset.Dataset.spatial_boundaries` and :func:`dataset.Dataset.time_range`. Creating a new dataset object is straightforward but generally you will want to use an OCW data source to load the data for you. +The OCW :class:`dataset.Dataset` class is the primary data abstraction used throughout OCW. It facilitates the uniform handling of data throughout the toolkit and provides a few useful helper functions such as :func:`dataset.Dataset.spatial_boundaries` and :func:`dataset.Dataset.temporal_boundaries`. Creating a new dataset object is straightforward but generally you will want to use an OCW data source to load the data for you. Data Sources ------------ http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/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 e37e887..c6aa327 100644 --- a/examples/knmi_to_cru31_full_bias.py +++ b/examples/knmi_to_cru31_full_bias.py @@ -83,7 +83,7 @@ print("Calculating the Maximum Overlap in Time for the datasets") cru_start = datetime.datetime.strptime(cru_31['start_date'], "%Y-%m-%d") cru_end = datetime.datetime.strptime(cru_31['end_date'], "%Y-%m-%d") -knmi_start, knmi_end = knmi_dataset.time_range() +knmi_start, knmi_end = knmi_dataset.temporal_boundaries() # Grab the Max Start Time start_time = max([cru_start, knmi_start]) # Grab the Min End Time http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/examples/model_ensemble_to_rcmed.py ---------------------------------------------------------------------- diff --git a/examples/model_ensemble_to_rcmed.py b/examples/model_ensemble_to_rcmed.py index a9303dd..14b92b9 100644 --- a/examples/model_ensemble_to_rcmed.py +++ b/examples/model_ensemble_to_rcmed.py @@ -99,7 +99,7 @@ print("Calculating the Maximum Overlap in Time for the datasets") cru_start = datetime.datetime.strptime(cru_31['start_date'], "%Y-%m-%d") cru_end = datetime.datetime.strptime(cru_31['end_date'], "%Y-%m-%d") -knmi_start, knmi_end = knmi_dataset.time_range() +knmi_start, knmi_end = knmi_dataset.temporal_boundaries() # Set the Time Range to be the year 1989 start_time = datetime.datetime(1989,1,1) end_time = datetime.datetime(1989,12,1) http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw-ui/backend/tests/test_processing.py ---------------------------------------------------------------------- diff --git a/ocw-ui/backend/tests/test_processing.py b/ocw-ui/backend/tests/test_processing.py index cc26b26..a1234de 100644 --- a/ocw-ui/backend/tests/test_processing.py +++ b/ocw-ui/backend/tests/test_processing.py @@ -88,7 +88,7 @@ class TestRCMEDDatasetLoad(unittest.TestCase): def test_valid_load(self): dataset = bp._load_rcmed_dataset_object(self.dataset_info, self.eval_bounds) lat_min, lat_max, lon_min, lon_max = dataset.spatial_boundaries() - start_time, end_time = dataset.time_range() + start_time, end_time = dataset.temporal_boundaries() self.assertTrue(self.eval_bounds['lat_min'] <= lat_min) self.assertTrue(self.eval_bounds['lat_max'] >= lat_max) http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw/dataset.py ---------------------------------------------------------------------- diff --git a/ocw/dataset.py b/ocw/dataset.py index 78e6c14..f9c344e 100644 --- a/ocw/dataset.py +++ b/ocw/dataset.py @@ -91,7 +91,7 @@ class Dataset: 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): + def temporal_boundaries(self): '''Calculate the temporal range :returns: The start and end date of the Dataset's temporal range as @@ -200,16 +200,16 @@ class Dataset: def __str__(self): lat_min, lat_max, lon_min, lon_max = self.spatial_boundaries() - start, end = self.time_range() + start, end = self.temporal_boundaries() lat_range = "({}, {})".format(lat_min, lon_min) lon_range = "({}, {})".format(lon_min, lon_min) - time_range = "({}, {})".format(start, end) + temporal_boundaries = "({}, {})".format(start, end) formatted_repr = ( "<Dataset - name: {}, " "lat-range: {}, " "lon-range: {}, " - "time_range: {}, " + "temporal_boundaries: {}, " "var: {}, " "units: {}>" ) @@ -218,7 +218,7 @@ class Dataset: self.name if self.name != "" else None, lat_range, lon_range, - time_range, + temporal_boundaries, self.variable, self.units ) @@ -363,17 +363,17 @@ class Bounds(object): def __str__(self): lat_range = "({}, {})".format(self._lat_min, self._lat_max) lon_range = "({}, {})".format(self._lon_min, self._lon_max) - time_range = "({}, {})".format(self._start, self._end) + temporal_boundaries = "({}, {})".format(self._start, self._end) formatted_repr = ( "<Bounds - " "lat-range: {}, " "lon-range: {}, " - "time_range: {}> " + "temporal_boundaries: {}> " ) return formatted_repr.format( lat_range, lon_range, - time_range, + temporal_boundaries, ) http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw/dataset_processor.py ---------------------------------------------------------------------- diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py index 70323f3..bfcad00 100755 --- a/ocw/dataset_processor.py +++ b/ocw/dataset_processor.py @@ -504,7 +504,7 @@ def safe_subset(subregion, target_dataset, subregion_name=None): ''' lat_min, lat_max, lon_min, lon_max = target_dataset.spatial_boundaries() - start, end = target_dataset.time_range() + start, end = target_dataset.temporal_boundaries() if subregion.lat_min < lat_min: subregion.lat_min = lat_min @@ -1372,7 +1372,7 @@ def _are_bounds_contained_by_dataset(bounds, dataset): a ValueError otherwise ''' lat_min, lat_max, lon_min, lon_max = dataset.spatial_boundaries() - start, end = dataset.time_range() + start, end = dataset.temporal_boundaries() errors = [] # TODO: THIS IS TERRIBLY inefficent and we need to use a geometry http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw/tests/test_dataset.py ---------------------------------------------------------------------- diff --git a/ocw/tests/test_dataset.py b/ocw/tests/test_dataset.py index dcf6490..8b666c1 100644 --- a/ocw/tests/test_dataset.py +++ b/ocw/tests/test_dataset.py @@ -137,9 +137,9 @@ class TestDatasetFunctions(unittest.TestCase): self.test_dataset.spatial_boundaries(), (min(self.lat), max(self.lat), min(self.lon), max(self.lon))) - def test_time_range(self): + def test_temporal_boundaries(self): self.assertEqual( - self.test_dataset.time_range(), + self.test_dataset.temporal_boundaries(), (dt.datetime(2000, 1, 1), dt.datetime(2000, 12, 1))) def test_spatial_resolution(self): @@ -187,16 +187,16 @@ class TestDatasetFunctions(unittest.TestCase): def test_str_(self): dataset = self.test_dataset lat_min, lat_max, lon_min, lon_max = dataset.spatial_boundaries() - start, end = dataset.time_range() + start, end = dataset.temporal_boundaries() lat_range = "({}, {})".format(lat_min, lon_min) lon_range = "({}, {})".format(lon_min, lon_min) - time_range = "({}, {})".format(start, end) + temporal_boundaries = "({}, {})".format(start, end) formatted_repr = ( "<Dataset - name: {}, " "lat-range: {}, " "lon-range: {}, " - "time_range: {}, " + "temporal_boundaries: {}, " "var: {}, " "units: {}>" ) @@ -205,7 +205,7 @@ class TestDatasetFunctions(unittest.TestCase): dataset.name if dataset.name != "" else None, lat_range, lon_range, - time_range, + temporal_boundaries, dataset.variable, dataset.units ) @@ -313,19 +313,19 @@ class TestBounds(unittest.TestCase): def test__str__(self): lat_range = "({}, {})".format(self.bounds.lat_min, self.bounds.lat_max) lon_range = "({}, {})".format(self.bounds.lon_min, self.bounds.lon_max) - time_range = "({}, {})".format(self.bounds.start, self.bounds.end) + temporal_boundaries = "({}, {})".format(self.bounds.start, self.bounds.end) formatted_repr = ( "<Bounds - " "lat-range: {}, " "lon-range: {}, " - "time_range: {}> " + "temporal_boundaries: {}> " ) output = formatted_repr.format( lat_range, lon_range, - time_range, + temporal_boundaries, ) self.assertEqual(str(self.bounds), output) http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw/tests/test_dataset_processor.py ---------------------------------------------------------------------- diff --git a/ocw/tests/test_dataset_processor.py b/ocw/tests/test_dataset_processor.py index 9060070..cc8d6d8 100644 --- a/ocw/tests/test_dataset_processor.py +++ b/ocw/tests/test_dataset_processor.py @@ -556,7 +556,7 @@ class TestSafeSubset(unittest.TestCase): def test_partial_temporal_overlap(self): '''Ensure that safe_subset can handle out of bounds temporal values''' ds = dp.safe_subset(self.temporal_out_of_bounds, self.target_dataset) - temporal_bounds = ds.time_range() + temporal_bounds = ds.temporal_boundaries() start = datetime.datetime(2000, 1, 1) end = datetime.datetime(2009, 12, 1) @@ -566,7 +566,7 @@ class TestSafeSubset(unittest.TestCase): def test_entire_bounds_overlap(self): ds = dp.safe_subset(self.everything_out_of_bounds, self.target_dataset) spatial_bounds = ds.spatial_boundaries() - temporal_bounds = ds.time_range() + temporal_bounds = ds.temporal_boundaries() start = datetime.datetime(2000, 1, 1) end = datetime.datetime(2009, 12, 1) http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw/utils.py ---------------------------------------------------------------------- diff --git a/ocw/utils.py b/ocw/utils.py index cb47efe..2fab66f 100755 --- a/ocw/utils.py +++ b/ocw/utils.py @@ -374,8 +374,8 @@ def get_temporal_overlap(dataset_array): start_time = [] end_time = [] for dataset in dataset_array: - start_time.append(dataset.time_range()[0]) - end_time.append(dataset.time_range()[1]) + start_time.append(dataset.temporal_boundaries()[0]) + end_time.append(dataset.temporal_boundaries()[1]) return np.max(start_time), np.min(end_time) http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw_config_runner/configuration_parsing.py ---------------------------------------------------------------------- diff --git a/ocw_config_runner/configuration_parsing.py b/ocw_config_runner/configuration_parsing.py index 5c28249..89eab62 100644 --- a/ocw_config_runner/configuration_parsing.py +++ b/ocw_config_runner/configuration_parsing.py @@ -239,7 +239,7 @@ def _valid_plot_config_data(plot_config_data): ]) elif plot_type == 'time_series': required_keys = set([ - 'time_range' + 'temporal_boundaries' ]) elif plot_type == 'portrait': required_keys = set([ http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw_config_runner/configuration_writer.py ---------------------------------------------------------------------- diff --git a/ocw_config_runner/configuration_writer.py b/ocw_config_runner/configuration_writer.py index 8fc9242..5bbbb08 100644 --- a/ocw_config_runner/configuration_writer.py +++ b/ocw_config_runner/configuration_writer.py @@ -199,7 +199,7 @@ def _extract_rcmed_dataset_info(dataset): dataset_info = {'optional_args': {}} min_lat, max_lat, min_lon, max_lon = dataset.spatial_boundaries() - start_time, end_time = dataset.time_range() + start_time, end_time = dataset.temporal_boundaries() dataset_info['data_source'] = 'rcmed' dataset_info['dataset_id'] = dataset.origin['dataset_id'] @@ -279,7 +279,7 @@ def _calc_subset_config(datasets): for ds in datasets: ds_lat_min, ds_lat_max, ds_lon_min, ds_lon_max = ds.spatial_boundaries() - ds_start, ds_end = ds.time_range() + ds_start, ds_end = ds.temporal_boundaries() if ds_lat_min < lat_min: lat_min = ds_lat_min http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw_config_runner/example/time_series_plot_example.yaml ---------------------------------------------------------------------- diff --git a/ocw_config_runner/example/time_series_plot_example.yaml b/ocw_config_runner/example/time_series_plot_example.yaml index b5599cc..5e45229 100644 --- a/ocw_config_runner/example/time_series_plot_example.yaml +++ b/ocw_config_runner/example/time_series_plot_example.yaml @@ -24,7 +24,7 @@ metrics: plots: - type: time_series - time_range: monthly + temporal_boundaries: monthly subregions: - [-10.0, 0.0, -19.0, 19.0] http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw_config_runner/plot_generation.py ---------------------------------------------------------------------- diff --git a/ocw_config_runner/plot_generation.py b/ocw_config_runner/plot_generation.py index 392331d..938553e 100644 --- a/ocw_config_runner/plot_generation.py +++ b/ocw_config_runner/plot_generation.py @@ -141,11 +141,11 @@ def _draw_portrait_diagram(evaluation, plot_config): def _draw_time_series_plot(evaluation, plot_config): """""" - time_range_info = plot_config['time_range'] + temporal_boundaries_info = plot_config['temporal_boundaries'] ref_ds = evaluation.ref_dataset target_ds = evaluation.target_datasets - if time_range_info == 'monthly': + if temporal_boundaries_info == 'monthly': ref_ds.values, ref_ds.times = utils.calc_climatology_monthly(ref_ds) for t in target_ds: http://git-wip-us.apache.org/repos/asf/climate/blob/e823b03c/ocw_config_runner/tests/test_config_writer.py ---------------------------------------------------------------------- diff --git a/ocw_config_runner/tests/test_config_writer.py b/ocw_config_runner/tests/test_config_writer.py index c961447..ed22417 100644 --- a/ocw_config_runner/tests/test_config_writer.py +++ b/ocw_config_runner/tests/test_config_writer.py @@ -535,7 +535,7 @@ class TestEvaluationSettingsGeneration(unittest.TestCase): subset = out['subset'] ds_lat_min, ds_lat_max, ds_lon_min, ds_lon_max = self.dataset.spatial_boundaries() - start, end = self.dataset.time_range() + start, end = self.dataset.temporal_boundaries() self.assertEqual(ds_lat_min, subset[0]) self.assertEqual(ds_lat_max, subset[1]) @@ -557,7 +557,7 @@ class TestEvaluationSettingsGeneration(unittest.TestCase): subset = out['subset'] ds_lat_min, ds_lat_max, ds_lon_min, ds_lon_max = self.dataset.spatial_boundaries() - start, end = self.dataset.time_range() + start, end = self.dataset.temporal_boundaries() self.assertEqual(ds_lat_min, subset[0]) # Check that we actually used the different max lat value that we