Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience function for making a regridding target Cube of specified shape #5770

Open
trexfeathers opened this issue Feb 22, 2024 · 0 comments

Comments

@trexfeathers
Copy link
Contributor

✨ Feature Request

  • As a: user of Iris regridding
  • I want: an easier way to create a target Cube from scratch, with a specified shape
  • So that: I can easily regrid my source data even when I do not have a target that includes data

A function in iris.util that returns a Cube would seem like the simplest implementation, with various config for coordinate lengths, coordinate units, etcetera. Ideally we could not only create standard rectilinear space (1-dimensional coordinates) but also curvilinear (2-dimensional coordinates) and mesh (using MeshCoords).

To advertise this more strongly we could consider allowing regridders to accept a 'cube shape specification' as the target, in addition to accepting an actual Cube. Perhaps by introducing a CubeShape class somewhere?

Motivation

Currently regridding without a loaded target Cube requires creating a Cube from scratch, with all the necessary Coords attached. Many users are unaware this is possible, and many more find it difficult. More significant: it is not obvious to a non-developer that Iris regridding will work fine with a Cube that has blank data.

Additional context

Mentioned in #4447. Any convenience should be revisited if we ever get the ability to create a data-less Cube.

A private testing convenience exists for this in esmf-regrid.tests.unit.schemes.test__cube_to_GridInfo._grid_cube()

Expand for some typical code that users currently need for this case:
min_x = -20
max_x = 20
min_y = 40
max_y = 60

points_x = np.linspace(min_x, max_x, 100)
points_y = np.linspace(min_y, max_y, 100)

my_cs = GeogCS(DEFAULT_SPHERICAL_EARTH_RADIUS)

coord_x = DimCoord(points_x, standard_name="longitude", units="degrees", coord_system=my_cs)
coord_y = DimCoord(points_y, standard_name="latitude", units="degrees", coord_system=my_cs)
target_cube = Cube(np.zeros((100, 100)), dim_coords_and_dims=[(coord_x, 0), (coord_y, 1)])

regridded_cube = my_cube.regrid(target_cube, Nearest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant