improver.regrid.grid module#
Grid handling for regridding
- calculate_input_grid_spacing(cube_in)[source]#
Calculate grid spacing in latitude and logitude. Check if input source grid is on even-spacing and ascending lat/lon system.
- Parameters:
cube_in (
Cube) – Input source cube.- Return type:
- Returns:
Grid spacing in latitude, in degree.
Grid spacing in logitude, in degree.
- Raises:
ValueError – If input grid is not on a latitude/longitude system or input grid coordinates are not ascending.
- classify_input_surface_type(cube_in_mask, classify_latlons)[source]#
Classify surface types of source grid points based on a binary True/False land mask cube_in_mask’s grid could be different from input source grid of NWP results.
- Parameters:
- Return type:
- Returns:
Classifications (N) for 1D-ordered source grid points.
- classify_output_surface_type(cube_out_mask)[source]#
Classify surface types of target grid points based on a binary True/False land mask.
- create_regrid_cube(cube_array, cube_in, cube_out)[source]#
Create a regridded cube from regridded value(numpy array). Source cube_in must be in regular latitude/longitude coordinates. Target cube_out can be either regular latitude/longitude grid or equal area.
- ensure_ascending_coord(cube)[source]#
Check if cube coordinates ascending. if not, make it ascending
- flatten_spatial_dimensions(cube)[source]#
Reshape data cube from (….,lat,lon) into data (lat*lon,…).
- group_target_points_with_source_domain(cube_in, out_latlons)[source]#
Group cube_out’s grid points into outside or inside cube_in’s domain.
- latlon_from_cube(cube)[source]#
Produce an array of latitude-longitude coordinates used by an Iris cube.
- mask_target_points_outside_source_domain(total_out_point_num, outside_input_domain_index, inside_input_domain_index, regrid_result)[source]#
Mask target points outside cube_in’s domain.
- Parameters:
total_out_point_num (
int) – Total number of target pointsoutside_input_domain_index (
ndarray) – Index array of target points outside input domain.inside_input_domain_index (
ndarray) – Index array of target points inside input domain.regrid_result (
Union[ndarray,MaskedArray]) – Array of regridded result in (lat*lon,….) or (projy*projx,…).
- Return type:
Union[ndarray,MaskedArray]- Returns:
Array of regridded result in (lat*lon,….) or (projy*projx,…).
- similar_surface_classify(in_is_land, out_is_land, nearest_in_indexes)[source]#
Classify surface types as matched (True) or unmatched(False) between target points and their source point.
- Parameters:
- Return type:
- Returns:
Boolean true if input surface type matches output or no matches (M x K).
- slice_cube_by_domain(cube_in, output_domain)[source]#
Extract cube domain to be consistent as cube_reference’s domain.
- slice_mask_cube_by_domain(cube_in, cube_in_mask, output_domain)[source]#
Extract cube domain to be consistent as cube_reference’s domain.
- unflatten_spatial_dimensions(regrid_result, cube_out_mask, in_values, lats_index, lons_index)[source]#
Reshape numpy array regrid_result from (lat*lon,…) to (….,lat,lon) or from (projy*projx,…) to (…,projy,projx).
- Parameters:
regrid_result (
ndarray) – Array of regridded result in (lat*lon,….) or (projy*projx,…).cube_out_mask (
Cube) – Target grid cube (for getting grid dimension here).in_values (
ndarray) – Reshaped source data (in _reshape_data_cube).lats_index (
int) – Index of lats or projy coord in reshaped array.lons_index (
int) – Index of lons or projx coord in reshaped array.
- Return type:
Union[ndarray,MaskedArray]- Returns:
Reshaped data array.