reproject
canari_ml.preprocess.reproject
¶
canari_ml.preprocess.reproject.logger = logging.getLogger('rasterio')
module-attribute
¶
canari_ml.preprocess.reproject.ease2_reference_grid_setup(shape, target_crs)
¶
Sets up the EASE-Grid 2.0 CRS and creates a grid and binary mask.
This function defines the EASE-Grid 2.0 parameters based on the provided shape and target CRS. It creates a grid with projection coordinates and a binary mask that distinguishes the Northern Hemisphere (NH) from the Southern Hemisphere (SH).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
The shape of the grid (rows, columns). Supported shapes are (720, 720) for 25 km resolution and (500, 500) for 36 km resolution. |
required |
target_crs
|
str
|
The target coordinate reference system (CRS) in EPSG format (e.g., "EPSG:6931" for EASE-Grid 2.0 Northern Hemisphere). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[Cube, Cube]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided shape does not match the expected EASE-Grid 2.0 standard grid or if the target CRS is not supported. |
References
- https://nsidc.org/data/user-resources/help-center/guide-ease-grids#anchor-25-km-resolution-ease-grids
Source code in src/canari_ml/preprocess/reproject.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
canari_ml.preprocess.reproject.reproject_dataset(input_, grid, mask, target_crs='EPSG:6931')
¶
Reprojects a source dataset from EPSG:4326 (lat/lon) to a target CRS using Iris.
Based on code from Tony Phillips (BAS), sent via email on 04/03/25.This function takes an input dataset (xarray Dataset, DataArray, or file path),reprojects it to the specified target CRS, and applies a binary mask. The output is returned as an xarray Dataset or DataArray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_
|
str | Path | Dataset | DataArray
|
The input dataset to reproject. Can be a file path, an xarray Dataset, or an xarray DataArray. |
required |
grid
|
Cube
|
The target grid as an Iris cube. |
required |
mask
|
Cube
|
A binary mask cube with values 1 for the Northern Hemisphere and NaN for the Southern Hemisphere. |
required |
target_crs
|
optional
|
The target coordinate reference system (CRS) in EPSG format (e.g., "EPSG:6931"). Defaults to "EPSG:6931". |
'EPSG:6931'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
The reprojected dataset. If the input was an xarray DataArray, the output will also be a DataArray. Otherwise, it will be a Dataset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input type is not a string path, xarray Dataset, or array DataArray. |
References
- https://confluence.ecmwf.int/display/CKB/ERA5%3A+data+documentation#heading-SpatialreferencesystemsandEarthmodel
Source code in src/canari_ml/preprocess/reproject.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
canari_ml.preprocess.reproject.reproject_file(datafile, grid, mask, target_crs)
¶
Reprojects a single NetCDF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datafile
|
str
|
Path to the NetCDF file to reproject. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If an error occurs during reprojection. |
Source code in src/canari_ml/preprocess/reproject.py
canari_ml.preprocess.reproject.reproject_datasets_from_config(process_config, workers=1, **kwargs)
¶
Reprojects multiple datasets from input config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process_config
|
DatasetConfig
|
Configuration object containing dataset file paths. |
required |
workers
|
optional
|
Number of parallel workers to use. Defaults to 1. |
1
|
**kwargs
|
Unpack
|
Additional arguments to pass to |
{}
|