Beispiel #1
0
 def setUp(self):
     self.mean_bias = metrics.TemporalMeanBias()
     # Initialize reference dataset
     self.reference_lat = np.array([10, 12, 14, 16, 18])
     self.reference_lon = np.array([100, 102, 104, 106, 108])
     self.reference_time = np.array(
         [dt.datetime(2000, x, 1) for x in range(1, 13)])
     flat_array = np.array(range(300))
     self.reference_value = flat_array.reshape(12, 5, 5)
     self.reference_variable = 'prec'
     self.reference_dataset = Dataset(self.reference_lat,
                                      self.reference_lon,
                                      self.reference_time,
                                      self.reference_value,
                                      self.reference_variable)
     # Initialize target dataset
     self.target_lat = np.array([1, 2, 4, 6, 8])
     self.target_lon = np.array([10, 12, 14, 16, 18])
     self.target_time = np.array(
         [dt.datetime(2001, x, 1) for x in range(1, 13)])
     flat_array = np.array(range(300, 600))
     self.target_value = flat_array.reshape(12, 5, 5)
     self.target_variable = 'tasmax'
     self.target_dataset = Dataset(self.target_lat,
                                   self.target_lon,
                                   self.target_time,
                                   self.target_value,
                                   self.target_variable)
def Map_plot_bias_of_multiyear_climatology(obs_dataset,
                                           obs_name,
                                           model_datasets,
                                           model_names,
                                           file_name,
                                           row,
                                           column,
                                           map_projection=None):
    '''Draw maps of observed multi-year climatology and biases of models"'''

    # calculate climatology of observation data
    obs_clim = utils.calc_temporal_mean(obs_dataset)
    # determine the metrics
    map_of_bias = metrics.TemporalMeanBias()

    # create the Evaluation object
    bias_evaluation = Evaluation(
        obs_dataset,  # Reference dataset for the evaluation
        model_datasets,  # list of target datasets for the evaluation
        [map_of_bias, map_of_bias])
    # run the evaluation (bias calculation)
    bias_evaluation.run()

    rcm_bias = bias_evaluation.results[0]

    fig = plt.figure()

    lat_min = obs_dataset.lats.min()
    lat_max = obs_dataset.lats.max()
    lon_min = obs_dataset.lons.min()
    lon_max = obs_dataset.lons.max()

    string_list = list(string.ascii_lowercase)
    ax = fig.add_subplot(row, column, 1)
    if map_projection == 'npstere':
        m = Basemap(ax=ax,
                    projection='npstere',
                    boundinglat=lat_min,
                    lon_0=0,
                    resolution='l',
                    fix_aspect=False)
    else:
        m = Basemap(ax=ax,
                    projection='cyl',
                    llcrnrlat=lat_min,
                    urcrnrlat=lat_max,
                    llcrnrlon=lon_min,
                    urcrnrlon=lon_max,
                    resolution='l',
                    fix_aspect=False)
    lons, lats = np.meshgrid(obs_dataset.lons, obs_dataset.lats)

    x, y = m(lons, lats)

    m.drawcoastlines(linewidth=1)
    m.drawcountries(linewidth=1)
    m.drawstates(linewidth=0.5, color='w')
    max = m.contourf(x,
                     y,
                     obs_clim,
                     levels=plotter._nice_intervals(obs_dataset.values, 10),
                     extend='both',
                     cmap='rainbow')
    ax.annotate('(a) \n' + obs_name, xy=(lon_min, lat_min))
    cax = fig.add_axes([0.02, 1. - float(1. / row), 0.01, 1. / row * 0.6])
    plt.colorbar(max, cax=cax)
    clevs = plotter._nice_intervals(rcm_bias, 11)
    for imodel in np.arange(len(model_datasets)):

        ax = fig.add_subplot(row, column, 2 + imodel)
        if map_projection == 'npstere':
            m = Basemap(ax=ax,
                        projection='npstere',
                        boundinglat=lat_min,
                        lon_0=0,
                        resolution='l',
                        fix_aspect=False)
        else:
            m = Basemap(ax=ax,
                        projection='cyl',
                        llcrnrlat=lat_min,
                        urcrnrlat=lat_max,
                        llcrnrlon=lon_min,
                        urcrnrlon=lon_max,
                        resolution='l',
                        fix_aspect=False)
        m.drawcoastlines(linewidth=1)
        m.drawcountries(linewidth=1)
        m.drawstates(linewidth=0.5, color='w')
        max = m.contourf(x,
                         y,
                         rcm_bias[imodel, :],
                         levels=clevs,
                         extend='both',
                         cmap='RdBu_r')
        ax.annotate('(' + string_list[imodel + 1] + ')  \n ' +
                    model_names[imodel],
                    xy=(lon_min, lat_min))

    cax = fig.add_axes([0.91, 0.1, 0.015, 0.8])
    plt.colorbar(max, cax=cax)

    plt.subplots_adjust(hspace=0.01, wspace=0.05)

    fig.savefig(file_name, dpi=600, bbox_inches='tight')