Exemplo n.º 1
0
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', {}))
    for dataset in model_dataset
]
model_dataset_season = [
    dsp.temporal_subset(dataset,
                        month_start,
                        month_end,
                        average_each_year=True)
    for dataset in model_dataset_subset
]
""" Spatial subset of obs_dataset and generate time series """
obs_timeseries = np.zeros([nyear, n_region
                           ])  # region index 0-6: NW, SW, NGP, SGP, MW, NE, SE
model_timeseries = np.zeros([nmodel, nyear, n_region])

for iregion in np.arange(n_region):
    obs_timeseries[:, iregion] = utils.calc_time_series(
        dsp.subset(obs_dataset_season, regional_bounds[iregion]))
    for imodel in np.arange(nmodel):
        model_timeseries[imodel, :, iregion] = utils.calc_time_series(
            dsp.subset(model_dataset_season[imodel], regional_bounds[iregion]))

year = np.arange(nyear)

regional_trends_obs = np.zeros(n_region)
regional_trends_obs_error = np.zeros(n_region)
regional_trends_model = np.zeros([nmodel, n_region])
regional_trends_model_error = np.zeros([nmodel, n_region])
regional_trends_ens = np.zeros(n_region)
regional_trends_ens_error = np.zeros(n_region)

for iregion in np.arange(n_region):
    regional_trends_obs[iregion], regional_trends_obs_error[
Exemplo n.º 3
0
    Bounds(-10.0, 10.0, 7.3, 15.0),
    Bounds(-10.9, 10.0, 5.0, 7.3),
    Bounds(33.9, 40.0,  6.9, 15.0),
    Bounds(10.0, 25.0,  0.0, 10.0),
    Bounds(10.0, 25.0, -10.0,  0.0),
    Bounds(30.0, 40.0, -15.0,  0.0),
    Bounds(33.0, 40.0, 25.0, 35.0)]

region_list = [["R" + str(i + 1)] for i in xrange(13)]

for regions in region_list:
    firstTime = True
    subset_name = regions[0] + "_CRU31"
    # labels.append(subset_name) #for legend, uncomment this line
    subset = dsp.subset(CRU31, list_of_regions[region_counter], subset_name)
    tSeries = utils.calc_time_series(subset)
    results.append(tSeries)
    tSeries = []
    firstTime = False
    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(target_datasets[member],
                            list_of_regions[region_counter],
                            subset_name)
        tSeries = utils.calc_time_series(subset)
        results.append(tSeries)
        tSeries = []

    plotter.draw_time_series(np.array(results), CRU31.times, labels, regions[
                             0], ptitle=regions[0], fmt='png')
Exemplo n.º 4
0
 def test_calc_time_series(self):
     expected_result = np.ones(12)
     np.testing.assert_array_equal(utils.calc_time_series(self.dataset), expected_result)
Exemplo n.º 5
0
 def test_calc_time_series(self):
     expected_result = np.ones(12)
     np.testing.assert_array_equal(
         utils.calc_time_series(self.dataset), expected_result)
Exemplo n.º 6
0
    Bounds(-10.9, 10.0, 5.0, 7.3),
    Bounds(33.9, 40.0, 6.9, 15.0),
    Bounds(10.0, 25.0, 0.0, 10.0),
    Bounds(10.0, 25.0, -10.0, 0.0),
    Bounds(30.0, 40.0, -15.0, 0.0),
    Bounds(33.0, 40.0, 25.0, 35.0)
]

region_list = [["R" + str(i + 1)] for i in xrange(13)]

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)
    tSeries = utils.calc_time_series(subset)
    results.append(tSeries)
    tSeries = []
    firstTime = False
    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)
        tSeries = utils.calc_time_series(subset)
        results.append(tSeries)
        tSeries = []

    plotter.draw_time_series(np.array(results),
                             CRU31.times,
                             labels,
Exemplo n.º 7
0
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', {}))
obs_dataset_season = dsp.temporal_subset(obs_dataset_subset, month_start, month_end,
                      average_each_year=True)

""" Temporal subset of model_dataset """
model_dataset_subset = [dsp.temporal_slice(dataset,start_time=start_date, end_time=end_date)
                        for dataset in model_dataset]
model_dataset_season = [dsp.temporal_subset(dataset, month_start, month_end,
                      average_each_year=True) for dataset in model_dataset_subset]


""" Spatial subset of obs_dataset and generate time series """
obs_timeseries = np.zeros([nyear, n_region])   # region index 0-6: NW, SW, NGP, SGP, MW, NE, SE
model_timeseries = np.zeros([nmodel, nyear, n_region])

for iregion in np.arange(n_region):
    obs_timeseries[:, iregion] = utils.calc_time_series(
                         dsp.subset(obs_dataset_season, regional_bounds[iregion]))
    for imodel in np.arange(nmodel):
        model_timeseries[imodel, :, iregion] = utils.calc_time_series(
                         dsp.subset(model_dataset_season[imodel], regional_bounds[iregion]))

year = np.arange(nyear)

regional_trends_obs = np.zeros(n_region)
regional_trends_obs_error = np.zeros(n_region)
regional_trends_model = np.zeros([nmodel, n_region])
regional_trends_model_error = np.zeros([nmodel, n_region])
regional_trends_ens = np.zeros(n_region)
regional_trends_ens_error = np.zeros(n_region)

for iregion in np.arange(n_region):
    regional_trends_obs[iregion], regional_trends_obs_error[iregion] = utils.calculate_temporal_trend_of_time_series(