def _draw_time_series_plot(evaluation, plot_config): """""" time_range_info = plot_config['time_range'] ref_ds = evaluation.ref_dataset target_ds = evaluation.target_datasets if time_range_info == 'monthly': ref_ds.values, ref_ds.times = utils.calc_climatology_monthly(ref_ds) for t in target_ds: t.values, t.times = utils.calc_climatology_monthly(t) else: logger.error('Invalid time range provided. Only monthly is supported ' 'at the moment') return if evaluation.subregions: for bound_count, bound in enumerate(evaluation.subregions): results = [] labels = [] subset = dsp.subset(bound, ref_ds, subregion_name="R{}_{}".format( bound_count, ref_ds.name)) results.append(utils.calc_time_series(subset)) labels.append(subset.name) for t in target_ds: subset = dsp.subset(bound, t, subregion_name="R{}_{}".format( bound_count, t.name)) results.append(utils.calc_time_series(subset)) labels.append(subset.name) plots.draw_time_series(np.array(results), ref_ds.times, labels, 'R{}'.format(bound_count), **plot_config.get('optional_args', {})) else: results = [] labels = [] results.append(utils.calc_time_series(ref_ds)) labels.append(ref_ds.name) for t in target_ds: results.append(utils.calc_time_series(t)) labels.append(t.name) plots.draw_time_series(np.array(results), ref_ds.times, labels, 'time_series', **plot_config.get('optional_args', {}))
def test_calc_climatology_monthly(self): expected_result = np.ones(300).reshape(12, 5, 5) expected_times = np.array([datetime.datetime(1, 1, 1) + relativedelta(months = x) for x in range(12)]) actual_result, actual_times = utils.calc_climatology_monthly(self.dataset) np.testing.assert_array_equal(actual_result, expected_result) np.testing.assert_array_equal(actual_times, expected_times)
member]) target_datasets[member] = dsp.normalize_dataset_datetimes( target_datasets[member], 'monthly') print("... spatial regridding") new_lats = np.arange(LAT_MIN, LAT_MAX, gridLatStep) new_lons = np.arange(LON_MIN, LON_MAX, gridLonStep) CRU31 = dsp.spatial_regrid(CRU31, new_lats, new_lons) for member, each_target_dataset in enumerate(target_datasets): target_datasets[member] = dsp.spatial_regrid( target_datasets[member], new_lats, new_lons) # find climatology monthly for obs and models CRU31.values, CRU31.times = utils.calc_climatology_monthly(CRU31) for member, each_target_dataset in enumerate(target_datasets): target_datasets[member].values, target_datasets[ member].times = utils.calc_climatology_monthly(target_datasets[member]) # make the model ensemble target_datasets_ensemble = dsp.ensemble(target_datasets) target_datasets_ensemble.name = "ENS" # append to the target_datasets for final analysis target_datasets.append(target_datasets_ensemble) """ Step 4: Subregion stuff """ list_of_regions = [ Bounds(-10.0, 0.0, 29.0, 36.5),
def test_invalid_time_shape(self): flat_array = np.array(range(350)) self.dataset.values = flat_array.reshape(14, 5, 5) with self.assertRaises(ValueError): utils.calc_climatology_monthly(self.dataset)
target_datasets[member] = dsp.water_flux_unit_conversion( target_datasets[member]) target_datasets[member] = dsp.normalize_dataset_datetimes( target_datasets[member], 'monthly') print("... spatial regridding") new_lats = np.arange(LAT_MIN, LAT_MAX, gridLatStep) new_lons = np.arange(LON_MIN, LON_MAX, gridLonStep) CRU31 = dsp.spatial_regrid(CRU31, new_lats, new_lons) for member, each_target_dataset in enumerate(target_datasets): target_datasets[member] = dsp.spatial_regrid(target_datasets[member], new_lats, new_lons) #find climatology monthly for obs and models CRU31.values, CRU31.times = utils.calc_climatology_monthly(CRU31) for member, each_target_dataset in enumerate(target_datasets): target_datasets[member].values, target_datasets[ member].times = utils.calc_climatology_monthly(target_datasets[member]) #make the model ensemble target_datasets_ensemble = dsp.ensemble(target_datasets) target_datasets_ensemble.name = "ENS" #append to the target_datasets for final analysis target_datasets.append(target_datasets_ensemble) """ Step 4: Subregion stuff """ list_of_regions = [ Bounds(-10.0, 0.0, 29.0, 36.5), Bounds(0.0, 10.0, 29.0, 37.5),
def test_calc_climatology_monthly(self): expected_result = np.ones(300).reshape(12, 5, 5) actual_result = utils.calc_climatology_monthly(self.dataset) np.testing.assert_array_equal(actual_result, expected_result)
def _draw_time_series_plot(evaluation, plot_config): """""" time_range_info = plot_config['time_range'] ref_ds = evaluation.ref_dataset target_ds = evaluation.target_datasets if time_range_info == 'monthly': ref_ds.values, ref_ds.times = utils.calc_climatology_monthly(ref_ds) for t in target_ds: t.values, t.times = utils.calc_climatology_monthly(t) else: logger.error( 'Invalid time range provided. Only monthly is supported ' 'at the moment' ) return if evaluation.subregions: for bound_count, bound in enumerate(evaluation.subregions): results = [] labels = [] subset = dsp.subset( bound, ref_ds, subregion_name="R{}_{}".format(bound_count, ref_ds.name) ) results.append(utils.calc_time_series(subset)) labels.append(subset.name) for t in target_ds: subset = dsp.subset( bound, t, subregion_name="R{}_{}".format(bound_count, t.name) ) results.append(utils.calc_time_series(subset)) labels.append(subset.name) plots.draw_time_series(np.array(results), ref_ds.times, labels, 'R{}'.format(bound_count), **plot_config.get('optional_args', {})) else: results = [] labels = [] results.append(utils.calc_time_series(ref_ds)) labels.append(ref_ds.name) for t in target_ds: results.append(utils.calc_time_series(t)) labels.append(t.name) plots.draw_time_series(np.array(results), ref_ds.times, labels, 'time_series', **plot_config.get('optional_args', {}))