processing.select#
Functions
|
Convert the geographic coordinates to Lambert Conformal Coordinates. |
|
Converts a geographic (longitude, latitude) point to a rotated pole (rlon, rlat) point. |
|
Generates a mask from a shapefile to apply to an xarray Dataset. |
|
Select a point from the dataset based on the provided geographic coordinates. |
|
Selects a specific geographical region from an xarray Dataset based on given region bounds. |
- convert_geo_to_LCC(coord: tuple, ds: Dataset)[source]#
Convert the geographic coordinates to Lambert Conformal Coordinates.
- Parameters:
coord (tuple) – Geographic coordinates as a (longitude, latitude) pair in degrees.
ds (xarray.Dataset) – The input dataset containing the Lambert Conformal Conic grid information.
- Returns:
The corresponding Lambert Conformal Coordinates as (x, y) in meters.
- Return type:
tuple
- convert_geo_to_rot(coord: tuple, ds: Dataset)[source]#
Converts a geographic (longitude, latitude) point to a rotated pole (rlon, rlat) point.
- Parameters:
coord (list or tuple) – Geographic coordinates as a (longitude, latitude) pair in degrees.
ds (xarray.Dataset) – The input dataset containing the rotated pole grid information (e.g., from a COSMO-CLM file).
- Returns:
The corresponding rotated pole coordinates as [rlon, rlat] in degrees.
- Return type:
list
- get_shapefile_mask(ds: Dataset, shapefile_path: Path)[source]#
Generates a mask from a shapefile to apply to an xarray Dataset.
This function reads a shapefile using Geopandas, converts it to the WGS84 coordinate reference system (CRS), and creates a mask that can be applied to the input xarray Dataset. The mask identifies the grid cells that fall within the shapefile’s region.
- Parameters:
ds (xr.Dataset) – Input xarray Dataset containing longitude and latitude coordinates.
shapefile_path (Path) – Path to the shapefile to be used for masking.
- Returns:
mask_shp – A boolean mask array where grid cells within the shapefile region are marked as True, and those outside are marked as False.
- Return type:
xr.Dataset
Notes
The shapefile is converted to the WGS84 CRS (EPSG:4326) before creating the mask.
The function uses the regionmask library to generate the mask.
Examples
>>> import xarray as xr >>> from pathlib import Path >>> ds = xr.open_dataset('path_to_your_dataset.nc') >>> shapefile = Path('path_to_your_shapefile.shp') >>> mask = get_shapefile_mask(ds, shapefile)
- select_point(ds: Dataset, lat_point: float, lon_point: float, projection: str = None)[source]#
Select a point from the dataset based on the provided geographic coordinates.
- Parameters:
ds (xarray.Dataset) – The input dataset from which to select the point.
lon_point (float) – Geographic longitude coordinate
lat_point (float) – Geographic latitude coordinate
projection (str, optional) – The projection of the dataset. The point will be projected to the dataset’s coordinate system before selection. Currently supported projections are ‘rotated_pole’ and ‘lcc’ (Lambert Conformal Coordinates).
- Returns:
The dataset subset at the nearest point to the specified coordinates.
- Return type:
- select_region(ds: Dataset, region: str)[source]#
Selects a specific geographical region from an xarray Dataset based on given region bounds.
- Parameters:
ds (xr.Dataset) – The input xarray Dataset from which to select the region.
region (str) – The name of the region to select. This should correspond to a key in the region_bounds dictionary, which defines the latitude and longitude bounds
- Returns:
A new xarray Dataset containing only the data within the specified region.
- Return type:
xr.Dataset
Examples
>>> ds_region = select_region(ds, 'europe')