unifhy.BritishNationalGrid.from_field
- classmethod BritishNationalGrid.from_field(field)
Instantiate a
BritishNationalGrid
from spatial dimension coordinates of acf.Field
.- Parameters
- field:
cf.Field
The field object that will be used to instantiate a
BritishNationalGrid
instance. This field must feature a ‘projection_y_coordinate’ and a ‘projection_x_coordinate’ dimension coordinates, and these must feature bounds. In addition, the coordination conversion ‘transverse_mercator’ must correspond to the parameters of the British National Grid (EPSG:27700).
- field:
- Returns
Examples
Instantiating from a 2D field:
>>> import cf >>> import numpy >>> f = cf.Field() >>> yc = f.set_construct( ... cf.DimensionCoordinate( ... properties={'standard_name': 'projection_y_coordinate', ... 'units': 'metres', ... 'axis': 'Y'}, ... data=cf.Data([12500, 13500, 14500]), ... bounds=cf.Bounds( ... data=cf.Data( ... numpy.column_stack( ... (numpy.arange(12000, 15000, 1000), ... numpy.arange(13000, 16000, 1000)) ... ) ... ) ... ) ... ), ... axes=f.set_construct(cf.DomainAxis(size=3)) ... ) >>> xc = f.set_construct( ... cf.DimensionCoordinate( ... properties={'standard_name': 'projection_x_coordinate', ... 'units': 'metres', ... 'axis': 'X'}, ... data=cf.Data([80500, 81500, 82500, 83500]), ... bounds=cf.Bounds( ... data=cf.Data( ... numpy.column_stack( ... (numpy.arange(80000, 84000, 1000), ... numpy.arange(81000, 85000, 1000)) ... ) ... ) ... ) ... ), ... axes=f.set_construct(cf.DomainAxis(size=4)) ... ) >>> crs = f.set_construct( ... cf.CoordinateReference( ... coordinate_conversion=cf.CoordinateConversion( ... parameters={'grid_mapping_name': 'transverse_mercator', ... 'projected_crs_name': 'OSGB 1936 / British National Grid', ... 'latitude_of_projection_origin': 49.0, ... 'longitude_of_central_meridian': -2.0, ... 'scale_factor_at_central_meridian': 0.9996012717, ... 'false_easting': 400000.0, ... 'false_northing': -100000.0, ... 'unit_conversion_factor': 0.0174532925199433} ... ), ... datum=cf.Datum( ... parameters={'geographic_crs_name': 'OSGB 1936', ... 'horizontal_datum_name': 'OSGB_1936', ... 'semi_major_axis': 6377563.396, ... 'inverse_flattening': 299.3249646, ... 'towgs84': [375., -111., 431., 0., 0., 0., 0.], ... 'longitude_of_prime_meridian': 0.0} ... ), ... coordinates=(yc, xc) ... ) ... ) >>> sd = BritishNationalGrid.from_field(f) >>> print(sd) BritishNationalGrid( shape {Y, X}: (3, 4) Y, projection_y_coordinate (3,): [12500, 13500, 14500] m X, projection_x_coordinate (4,): [80500, ..., 83500] m Y_bounds (3, 2): [[12000, ..., 15000]] m X_bounds (4, 2): [[80000, ..., 84000]] m )
Using the field interface back and forth:
>>> sd1 = BritishNationalGrid.from_extent_and_resolution( ... projection_y_coordinate_extent=(12000, 15000), ... projection_x_coordinate_extent=(80000, 84000), ... projection_y_coordinate_resolution=1000, ... projection_x_coordinate_resolution=1000, ... ) >>> sd2 = BritishNationalGrid.from_field(sd1.to_field()) >>> sd2 == sd1 True