unifhy.RotatedLatLonGrid.from_field
- classmethod RotatedLatLonGrid.from_field(field)
Instantiate a
RotatedLatLonGrid
from spatial dimension coordinates of acf.Field
.- Parameters
- field:
cf.Field
The field object that will be used to instantiate a
RotatedLatLonGrid
instance. This field must feature a ‘grid_latitude’ and a ‘grid_longitude’ dimension coordinates, and these must feature bounds. In addition, the parameters required for the conversion of the grid to a true latitude-longitude reference system must be set (i.e. grid_north_pole_latitude, grid_north_pole_longitude, and optional north_pole_grid_longitude).
- field:
- Returns
Examples
Instantiating from a 2D field:
>>> import cf >>> f = cf.Field() >>> lat = f.set_construct( ... cf.DimensionCoordinate( ... properties={'standard_name': 'grid_latitude', ... 'units': 'degrees', ... 'axis': 'Y'}, ... data=cf.Data([-0.88, -0.44, 0., 0.44, 0.88]), ... bounds=cf.Bounds(data=cf.Data([[-1.1, -0.66], [-0.66, -0.22], ... [-0.22, 0.22], [0.22, 0.66], ... [0.66, 1.1]])) ... ), ... axes=f.set_construct(cf.DomainAxis(size=5)) ... ) >>> lon = f.set_construct( ... cf.DimensionCoordinate( ... properties={'standard_name': 'grid_longitude', ... 'units': 'degrees', ... 'axis': 'X'}, ... data=cf.Data([-2.5, -2.06, -1.62, -1.18]), ... bounds=cf.Bounds(data=cf.Data([[-2.72, -2.28], [-2.28, -1.84], ... [-1.84, -1.4], [-1.4, -0.96]])) ... ), ... axes=f.set_construct(cf.DomainAxis(size=4)) ... ) >>> crs = f.set_construct( ... cf.CoordinateReference( ... coordinate_conversion=cf.CoordinateConversion( ... parameters={'grid_mapping_name': 'rotated_latitude_longitude', ... 'grid_north_pole_latitude': 38.0, ... 'grid_north_pole_longitude': 190.0}), ... coordinates=(lat, lon) ... ) ... ) >>> sd = RotatedLatLonGrid.from_field(f) >>> print(sd) RotatedLatLonGrid( shape {Y, X}: (5, 4) Y, grid_latitude (5,): [-0.88, ..., 0.88] degrees X, grid_longitude (4,): [-2.5, ..., -1.18] degrees Y_bounds (5, 2): [[-1.1, ..., 1.1]] degrees X_bounds (4, 2): [[-2.72, ..., -0.96]] degrees )
Using the field interface back and forth:
>>> sd1 = RotatedLatLonGrid.from_extent_and_resolution( ... grid_latitude_extent=(-1.1, 1.1), ... grid_longitude_extent=(-2.72, -0.96), ... grid_latitude_resolution=0.44, ... grid_longitude_resolution=0.44, ... grid_north_pole_latitude=38.0, ... grid_north_pole_longitude=190.0 ... ) >>> sd2 = RotatedLatLonGrid.from_field(sd1.to_field()) >>> sd2 == sd1 True