示例#1
0
def regrid(data, from_lat, from_lon, to_resolution):
    lat_min, lon_min = np.nanmin(from_lat), np.nanmin(from_lon)
    lat_max, lon_max = np.nanmax(from_lat), np.nanmax(from_lon)
    to_lat = np.arange(lat_min, lat_max, to_resolution)
    to_lon = np.arange(lon_min, lon_max, to_resolution)

    latitude = DimCoord(from_lat, standard_name='latitude', units='degrees')
    longitude = DimCoord(from_lon, standard_name='longitude', units='degrees')
    num_months = data.shape[2]
    time = DimCoord(np.linspace(1, num_months, num_months),
                    standard_name='time',
                    units='month')
    cube1 = Cube(data,
                 dim_coords_and_dims=[(time, 2), (latitude, 0),
                                      (longitude, 1)])
    regridded_data = cube1.interpolate([('latitude', to_lat),
                                        ('longitude', to_lon)],
                                       iris.analysis.Linear())
    reshaped_data = np.transpose(regridded_data.data[:], (2, 0, 1))
    return reshaped_data, regridded_data.coord(
        'latitude').points[:], regridded_data.coord('longitude').points[:]
lat01 = np.arange(lat_min, lat_max, 0.1)
lon01 = np.arange(lon_min, lon_max, 0.1)

latitude = DimCoord(lat, standard_name='latitude', units='degrees')
longitude = DimCoord(lon, standard_name='longitude', units='degrees')
time = DimCoord(np.linspace(1, 12, 12), standard_name='time', units='month')
#print (time)

cube1 = Cube(GC_column_mon_mean,
             dim_coords_and_dims=[(latitude, 1), (longitude, 2), (time, 0)])

cube2 = Cube(data_emission1,
             dim_coords_and_dims=[(latitude, 1), (longitude, 2), (time, 0)])

regridded_data_GC_column = cube1.interpolate([('latitude', lat01),
                                              ('longitude', lon01)],
                                             iris.analysis.Linear())
print(regridded_data_GC_column.shape, 'regrid_GC_column_shape')

regridded_data_emission = cube2.interpolate([('latitude', lat01),
                                             ('longitude', lon01)],
                                            iris.analysis.Linear())
print(regridded_data_emission, 'regrid_emission_shape')

lat_n = regridded_data_emission.coord('latitude')
lat_n = lat_n.points[:]
lon_n = regridded_data_emission.coord('longitude')
lon_n = lon_n.points[:]

lat_n_min, lon_n_min = np.nanmin(lat_n), np.nanmin(lon_n)
lat_n_max, lon_n_max = np.nanmax(lat_n), np.nanmax(lon_n)