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:

Tuple[float, float]

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:
  • cube_in_mask (Cube) – Land_sea mask information cube for input source grid (land=1) which should be in GeogCS’s lats/lons coordinate system.

  • classify_latlons (ndarray) – Latitude and longitude source grid points to classify (N x 2).

Return type:

ndarray

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.

Parameters:

cube_out_mask (Cube) – land_sea mask information cube for target grid (land=1)

Return type:

ndarray

Returns:

1D land-sea mask information for 1D-ordered target grid points

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.

Parameters:
  • cube_array (ndarray) – regridded value (multidimensional)

  • cube_in (Cube) – source cube (for value’s non-grid dimensions and attributes)

  • cube_out (Cube) – target cube (for target grid information)

Return type:

Cube

Returns:

Regridded result cube

ensure_ascending_coord(cube)[source]

Check if cube coordinates ascending. if not, make it ascending

Parameters:

cube (Cube) – Input source cube.

Return type:

Cube

Returns:

Cube with ascending coordinates

flatten_spatial_dimensions(cube)[source]

Reshape data cube from (….,lat,lon) into data (lat*lon,…).

Parameters:

cube (Cube) – Original data cube.

Return type:

Tuple[Union[ndarray, MaskedArray], int, int]

Returns:

  • Reshaped data array.

  • Index of latitude cube coords.

  • Index of longitude cube coords.

get_cube_coord_names(cube)[source]

Get all coordinate names from a cube.

Parameters:

cube (Cube) – Input cube.

Return type:

List[str]

Returns:

List of coordinate names.

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.

Parameters:
  • cube_in (Cube) – Source cube.

  • out_latlons (ndarray) – Target points’s latitude-longitudes.

Return type:

Tuple[ndarray, ndarray]

Returns:

  • Index array of target points outside input domain.

  • Index array of target points inside input domain.

latlon_from_cube(cube)[source]

Produce an array of latitude-longitude coordinates used by an Iris cube.

Parameters:

cube (Cube) – Cube with spatial coords.

Return type:

ndarray

Returns:

Latitude-longitude pairs (N x 2).

latlon_names(cube)[source]

Identify the names of the latitude and longitude dimensions of cube.

Parameters:

cube (Cube) – Input cube.

Return type:

Tuple[str, str]

Returns:

  • Name of latitude dimension of cube.

  • Name of longitude dimension of 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 points

  • outside_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:
  • in_is_land (ndarray) – Source point classifications (N).

  • out_is_land (ndarray) – Target point classifications (M).

  • nearest_in_indexes (ndarray) – Indexes of input points nearby output points (M x K).

Return type:

ndarray

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.

Parameters:
Return type:

Cube

Returns:

Data cube after slicing.

slice_mask_cube_by_domain(cube_in, cube_in_mask, output_domain)[source]

Extract cube domain to be consistent as cube_reference’s domain.

Parameters:
  • cube_in (Cube) – Input data cube to be sliced.

  • cube_in_mask (Cube) – Input mask cube to be sliced.

  • output_domain (Tuple[float, float, float, float]) – Lat_max, lon_max, lat_min, lon_min.

Return type:

Tuple[Cube, Cube]

Returns:

  • Data cube after slicing.

  • Mask cube after slicing.

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.