iconarray.core.crop.Crop#

class iconarray.core.crop.Crop(grid: xarray.Dataset, lon_bnds: list[float], lat_bnds: list[float], scale_factor=0.3)#

Cut the domain of an ICON grid and data to a region specified by a lat/lon retangle.

All cells whose center coordinates are not contained within the lat/lon region will be dropped. All neighbour edges and vertices of the selected cells will be included in the cropped domain. As a result, some edges and/or vertices, boundaries of an included triangle, might have coordinate that are not contained within the lat/lon region.

Parameters:
  • grid (xr.Dataset) – The input dataset representing an ICON grid. The dataset should contain at least:

    • cell,edge and vertex dimensions.

    • clon,clat,elon,elat,vlon,vlat coordinates

    • edge_of_cell, vertex_of_cell variables that provide the connectivity between edge and vertex locations to the cell

  • lon_bnds (list[float]) – [low,high] longitude bounds of the cropped domain

  • lat_bnds (list[float]) – [low,high] latitude bounds of the cropped domain

  • scale_factor (float) – factor of resolution between the icon grid and an auxiliary latlon grid needed by the cropping algorithm. We recommend using the default value and decrease it only if required.

Examples

load the grid dataset:

>>> in_grid = 'icon_grid_0001_R19B08.nc'
>>> grid = xr.open_dataset(in_grid)
>>> grid
... <xarray.Dataset>
... Dimensions:                        (cell: 1043968, vertex: 523485,
...                                     edge: 1567452, nv: 3, nc: 2, ne: 6, no: 4,
...                                     max_chdom: 1, cell_grf: 14, edge_grf: 24,
...                                     vert_grf: 13)
... Coordinates:
...     clon                           (cell) float64 0.2887 0.2889 ... 0.2423
...     clat                           (cell) float64 0.7384 0.7384 ... 0.7474
...     vlon                           (vertex) float64 ...
...     vlat                           (vertex) float64 ...
...     elon                           (edge) float64 ...
...     elat                           (edge) float64 ...
... Dimensions without coordinates: cell, vertex, edge, nv, nc, ne, no, max_chdom,
...                                 cell_grf, edge_grf, vert_grf
... Data variables: (12/51)
...     cartesian_x_vertices           (vertex) float64 ...
...     cartesian_y_vertices           (vertex) float64 ...
...     cartesian_z_vertices           (vertex) float64 ...
...     cell_area                      (cell) float64 ...
...     dual_area                      (vertex) float64 ...
...     lon_cell_centre                (cell) float64 ...
...     ...                             ...
...     end_idx_e                      (max_chdom, edge_grf) int32 ...
...     refin_v_ctrl                   (vertex) int32 ...
...     start_idx_v                    (max_chdom, vert_grf) int32 ...
...     end_idx_v                      (max_chdom, vert_grf) int32 ...
...     parent_edge_index              (edge) int32 ...
...     parent_vertex_index            (vertex) int32 ...
... Attributes: (12/18)
...     title:                ICON grid description
...     institution:          Max Planck Institute for Meteorology/Deutscher Wett...
...     source:               svn://rclh.dwd.de/for0adm/SVN_icontools/tags/iconto...
...     number_of_grid_used:  1
...     ICON_grid_file_uri:
...     centre:               215
...     ...                   ...
...     inverse_flattening:   0.0
...     grid_level:           8
...     grid_root:            19
...     uuidOfParHGrid:       e6ddd597-9c90-27b1-fbac-c40d47f72ba0
...     uuidOfHGrid:          5a0a863d-2523-9515-7789-4930e3452bc0
...     global_grid:          0

create a crop instance with the lat/lon coordinates for the region of interest

>>> crop = Crop(grid, [0.148, 0.155], [0.871, 0.877])
>>> crop.cropped_grid()
... Dimensions:                         (cell: 986, nv: 3, edge: 1530, nc: 2, no: 4,
...                                     vertex: 545, ne: 6)
... Coordinates:
...     clon                           (cell) float64 0.1544 0.1546 ... 0.1549
...     clat                           (cell) float64 0.8766 0.8768 ... 0.871 0.8711
...     elon                           (edge) float64 ...
...     elat                           (edge) float64 ...
...     vlon                           (vertex) float64 ...
...     vlat                           (vertex) float64 ...
... Dimensions without coordinates: cell, nv, edge, nc, no, vertex, ne
... Data variables: (12/45)
...     cell_area                      (cell) float64 ...
...     lon_cell_centre                (cell) float64 ...
...     lat_cell_centre                (cell) float64 ...
...     edge_of_cell                   (nv, cell) int64 1 2 766 766 ... 1528 205 205
...     vertex_of_cell                 (nv, cell) int64 1 137 341 138 ... 245 244 9
...     cell_area_p                    (cell) float64 ...
...     ...                             ...
...     dual_area_p                    (vertex) float64 ...
...     vlon_vertices                  (vertex, ne) float64 ...
...     vlat_vertices                  (vertex, ne) float64 ...
...     edge_orientation               (ne, vertex) int32 ...
...     refin_v_ctrl                   (vertex) int32 ...
...     parent_vertex_index            (vertex) int32 ...
... Attributes: (12/18)
...     title:                ICON grid description
...     institution:          Max Planck Institute for Meteorology/Deutscher Wett...
...     source:               svn://rclh.dwd.de/for0adm/SVN_icontools/tags/iconto...
...     number_of_grid_used:  1
...     ICON_grid_file_uri:
...     centre:               215
...     ...                   ...
...     inverse_flattening:   0.0
...     grid_level:           8
...     grid_root:            19
...     uuidOfParHGrid:       e6ddd597-9c90-27b1-fbac-c40d47f72ba0
...     uuidOfHGrid:          5a0a863d-2523-9515-7789-4930e3452bc0
...     global_grid:          0

open a dataset with data:

>>> ds_cell = xr.open_dataset("lfff00010000_cell.nc")
>>> ds_cell
... Dimensions:                  (generalVerticalLayer: 80, time: 1, cell: 1043968,
...                               vertices: 3)
... Coordinates:
...     number                   int64 1
...     forecast_reference_time  datetime64[ns] 2022-02-16
...     step                     timedelta64[ns] 01:00:00
...   * generalVerticalLayer     (generalVerticalLayer) float64 1.0 2.0 ... 80.0
...   * time                     (time) datetime64[ns] 2022-02-16T01:00:00
...     clon                     (cell) float32 0.2887 0.2889 ... 0.2422 0.2423
...     clat                     (cell) float32 0.7384 0.7384 ... 0.7472 0.7474
...     clat_bnds                (cell, vertices) float32 0.7385 0.7384 ... 0.7475
...     clon_bnds                (cell, vertices) float32 0.2888 0.2886 ... 0.2423
... Dimensions without coordinates: cell, vertices
... Data variables:
...     unknown                  (time, generalVerticalLayer, cell) float32 0.0 ....
...     pres                     (time, generalVerticalLayer, cell) float32 4.675...
...     t                        (time, generalVerticalLayer, cell) float32 213.0...
...     u                        (time, generalVerticalLayer, cell) float32 0.0 ....
...     v                        (time, generalVerticalLayer, cell) float32 -9.53...
...     q                        (time, generalVerticalLayer, cell) float32 3.067...
...     clwmr                    (time, generalVerticalLayer, cell) float32 0.0 ....
... Attributes:
...     GRIB_edition:            2
...     GRIB_centre:             lssw
...     GRIB_centreDescription:  Zurich
...     GRIB_subCentre:          255
...     Conventions:             CF-1.7
...     institution:             Zurich

crop the dataset that contains all cell variables:

>>> cell_rds = crop(ds_cell)
>>> cell_rds
... Dimensions:                  (generalVerticalLayer: 80, time: 1, cell: 986,
...                             vertices: 3)
... Coordinates:
...     number                   int64 1
...     forecast_reference_time  datetime64[ns] 2022-02-16
...     step                     timedelta64[ns] 01:00:00
... * generalVerticalLayer     (generalVerticalLayer) float64 1.0 2.0 ... 80.0
... * time                     (time) datetime64[ns] 2022-02-16T01:00:00
...     clon                     (cell) float32 0.1544 0.1546 ... 0.1547 0.1549
...     clat                     (cell) float32 0.8766 0.8768 ... 0.871 0.8711
...     clat_bnds                (cell, vertices) float32 0.8765 0.8767 ... 0.8712
...     clon_bnds                (cell, vertices) float32 0.1544 0.1546 ... 0.1547
... Dimensions without coordinates: cell, vertices
... Data variables:
...     unknown                  (time, generalVerticalLayer, cell) float32 0.0 ....
...     pres                     (time, generalVerticalLayer, cell) float32 4.596...
...     t                        (time, generalVerticalLayer, cell) float32 213.2...
...     u                        (time, generalVerticalLayer, cell) float32 21.96...
...     v                        (time, generalVerticalLayer, cell) float32 -11.1...
...     q                        (time, generalVerticalLayer, cell) float32 3.034...
...     clwmr                    (time, generalVerticalLayer, cell) float32 0.0 ....
... Attributes:
...     GRIB_edition:            2
...     GRIB_centre:             lssw
...     GRIB_centreDescription:  Zurich
...     GRIB_subCentre:          255
...     Conventions:             CF-1.7
...     institution:             Zurich
__init__(grid: xarray.Dataset, lon_bnds: list[float], lat_bnds: list[float], scale_factor=0.3)#

Methods

__init__(grid, lon_bnds, lat_bnds[, ...])

crop_fields()

Crop all variables of the grid.

crop_grid()

Crop the coordinates for cells, edges and vertices.

cropped_grid()

Return a dataset of a grid cropped to the lat/lon area specified.