print cube
sea_water_potential_temperature (time: 60; depth: 50; cell index along second dimension: 300; cell index along first dimension: 360)
Dimension coordinates:
time x - - -
depth - x - -
cell index along second dimension - - x -
cell index along first dimension - - - x
Auxiliary coordinates:
latitude - - x x
longitude - - x x
import iris, numpy
from iris.experimental.regrid import regrid_weighted_curvilinear_to_rectilinear
def make_grid(lat_values, lon_values):
"""Make a dummy cube with desired grid."""
latitude = iris.coords.DimCoord(lat_values,
standard_name='latitude',
units='degrees_north',
coord_system=None)
longitude = iris.coords.DimCoord(lon_values,
standard_name='longitude',
units='degrees_east',
coord_system=None)
dummy_data = numpy.zeros((len(lat_values), len(lon_values)))
new_cube = iris.cube.Cube(dummy_data, dim_coords_and_dims=[(latitude, 0), (longitude, 1)])
return new_cube
src_cube = cube[0, 0]
weights = numpy.ones(src_cube.shape)
lats = numpy.arange(-90, 91, 1)
lons = numpy.arange(0, 360, 1)
target_grid_cube = make_grid(lats, lons)
target_grid_cube.coord('longitude').guess_bounds()
target_grid_cube.coord('latitude').guess_bounds()
regridded_cube = regrid_weighted_curvilinear_to_rectilinear(src_cube, weights, target_grid_cube)
regrid_weighted_curvilinear_to_rectilinear only handles 2D fields, I'd then have to iterate over each ['time', 'depth'] slice to regrid the entire cube.Not actually answering your question, but on a related note:
I'm currently trying to regrid Arctic System Reanalysis from North Polar Stereographic coordinates to a regular lat/lon grid.
The subset of original data looks like this:
Temperature / (K) (Time: 128; pressure: 10; y_coordinate: 180; x_coordinate: 200)
Dimension coordinates:
Time x - - -
pressure - x - -
y_coordinate - - x -
x_coordinate - - - x
Auxiliary coordinates:
latitude - - x x
longitude - - x xSince the coordinate system is not recognised automatically, I define it as following:
asr_coord_system = iris.coord_systems.Stereographic(90, -175)Then, I'm using almost the same approach to interpolate the data to rectilinear grid:
def make_grid(lat_values, lon_values):
"""Make a dummy cube with desired grid."""
geogcs = iris.coord_systems.GeogCS(iris.fileformats.pp.EARTH_RADIUS)
latitude = iris.coords.DimCoord(lat_values,
standard_name='latitude',
units='degrees_north',
coord_system=geogcs)
longitude = iris.coords.DimCoord(lon_values,
standard_name='longitude',
units='degrees_east',
coord_system=geogcs)
dummy_data = np.zeros((len(lat_values), len(lon_values)))
new_cube = iris.cube.Cube(dummy_data, dim_coords_and_dims=[(latitude, 0), (longitude, 1)])
return new_cube
src_cube = cube[0, 0]
weights = np.ones(src_cube.shape)
lats = np.arange(65, 91, 1)
lons = np.arange(-20, 25, 1)
target_grid_cube = make_grid(lats, lons)
target_grid_cube.coord('longitude').guess_bounds()
target_grid_cube.coord('latitude').guess_bounds()
regridded_cube = regrid_weighted_curvilinear_to_rectilinear(src_cube, weights, target_grid_cube)However, I get strange results with only one row of data, while the rest of the array is masked.
Does anyone know what I am doing wrong? Can it be done in iris at all?
Cheers,
Denis
Hi,