Python API
xcube_resampling.spatial.resample_in_space(source_ds, target_gm=None, source_gm=None, variables=None, interp_methods=None, agg_methods=None, recover_nans=False, fill_values=None, tile_size=None)
Resample the spatial dimensions of a dataset to match a target grid mapping.
Depending on the regularity and compatibility of the source and target grid
mappings, this function will either rectify, reproject, or affine-transform the
spatial dimensions of source_ds
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_ds
|
Dataset
|
The input xarray.Dataset. Data variables must have dimensions in the following order: optional third dimension followed by the y-dimension (e.g., "y" or "lat") and the x-dimension (e.g., "x" or "lon"). |
required |
target_gm
|
GridMapping | None
|
The target GridMapping to which the dataset should be resampled.
Must be regular. If not provided, a default regular grid is derived
from |
None
|
source_gm
|
GridMapping | None
|
The GridMapping describing the source dataset's spatial layout.
If not provided, it is inferred from |
None
|
variables
|
str | Iterable[str] | None
|
A single variable name or iterable of variable names to be resampled. If None, all data variables will be processed. |
None
|
interp_methods
|
InterpMethods | None
|
Optional interpolation method to be used for upsampling spatial data variables. Can be a single interpolation method for all variables or a dictionary mapping variable names or dtypes to interpolation method. Supported methods include:
The default is |
None
|
agg_methods
|
AggMethods | None
|
Optional aggregation methods for downsampling spatial variables. Can be a single method for all variables or a dictionary mapping variable names or dtypes to methods. Supported methods include: "center", "count", "first", "last", "max", "mean", "median", "mode", "min", "prod", "std", "sum", and "var". Defaults to "center" for integer arrays, else "mean". |
None
|
recover_nans
|
RecoverNans
|
Optional boolean or mapping to enable NaN recovery during upsampling (only applies when interpolation method is not nearest). Can be a single boolean or a dictionary mapping variable names or dtypes to booleans. Defaults to False. |
False
|
fill_values
|
FillValues | None
|
Optional fill value(s) for areas outside input coverage. Can be a single value or dictionary by variable or type. If not provided, defaults based on data type are used:
|
None
|
tile_size
|
int | tuple[int, int] | None
|
Optional tile size used when generating a regular grid from
an irregular source grid mapping. Only used if |
None
|
Returns:
Type | Description |
---|---|
Dataset
|
A new dataset that has been spatially resampled to match the target grid mapping. |
Notes
- If
source_gm
is not provided, it is inferred fromsource_ds
. - If
target_gm
is not provided, and the source is irregular, it is derived fromsource_gm.to_regular(tile_size=tile_size)
. - If both grid mappings are regular and approximately equal, the original dataset is returned unchanged.
- If the transformation can be represented as an affine mapping, it is applied directly for performance.
- If the source is irregular, rectification is applied.
- Otherwise, a reprojection is performed.
- See the xcube-resampling documentation for more details.
Source code in xcube_resampling/spatial.py
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
xcube_resampling.affine.affine_transform_dataset(source_ds, target_gm, source_gm=None, variables=None, interp_methods=None, agg_methods=None, recover_nans=False, fill_values=None)
Apply an affine transformation to the spatial dimensions of a dataset, transforming it from the source grid mapping to the target grid mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_ds
|
Dataset
|
The input dataset to be transformed. |
required |
target_gm
|
GridMapping
|
The target grid mapping defining the spatial reference and output geometry. |
required |
source_gm
|
GridMapping | None
|
The grid mapping of the input dataset. If None, it is inferred from the dataset. |
None
|
variables
|
str | Iterable[str] | None
|
Optional variable(s) to transform. If None, all variables are used. |
None
|
interp_methods
|
InterpMethods | None
|
Optional interpolation method to be used for upsampling spatial data variables. Can be a single interpolation method for all variables or a dictionary mapping variable names or dtypes to interpolation method. Supported methods include:
The default is |
None
|
agg_methods
|
AggMethods | None
|
Optional aggregation methods for downsampling spatial variables. Can be a single method for all variables or a dictionary mapping variable names or dtypes to methods. Supported methods include: "center", "count", "first", "last", "max", "mean", "median", "mode", "min", "prod", "std", "sum", and "var". Defaults to "center" for integer arrays, else "mean". |
None
|
recover_nans
|
RecoverNans
|
Optional boolean or mapping to enable NaN recovery during upsampling (only applies when interpolation method is not nearest). Can be a single boolean or a dictionary mapping variable names or dtypes to booleans. Defaults to False. |
False
|
fill_values
|
FillValues | None
|
Optional fill value(s) for areas outside the input bounds. Can be a single value or a dictionary mapping variable names or dtypes to fill values. If not provided, defaults are:
|
None
|
Returns:
Type | Description |
---|---|
Dataset
|
A new dataset resampled and aligned to the target grid mapping. Data variables without spatial dimensions are copied to the output. Data variables with only one spatial dimension are ignored. |
Source code in xcube_resampling/affine.py
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 |
|
xcube_resampling.reproject.reproject_dataset(source_ds, target_gm, source_gm=None, variables=None, interp_methods=None, agg_methods=None, recover_nans=False, fill_values=None)
Reproject a dataset from one coordinate reference system (CRS) to another.
This function transforms a dataset’s 2D spatial variables to match a new CRS and
grid layout defined by target_gm
. It handles interpolation, optional
downsampling, and fill values for areas outside the input bounds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_ds
|
Dataset
|
The input dataset to be reprojected. |
required |
target_gm
|
GridMapping
|
The target grid mapping that defines the spatial reference and grid layout in the target CRS. |
required |
source_gm
|
GridMapping | None
|
Optional source grid mapping of the input dataset. If not provided, it is inferred from the dataset. |
None
|
variables
|
str | Iterable[str] | None
|
Optional variable name or list of variable names to reproject. If None, all suitable variables are processed. |
None
|
interp_methods
|
InterpMethods | None
|
Optional interpolation method to be used for upsampling spatial data variables. Can be a single interpolation method for all variables or a dictionary mapping variable names or dtypes to interpolation method. Supported methods include:
The default is |
None
|
agg_methods
|
AggMethods | None
|
Optional aggregation methods for downsampling spatial variables. Can be a single method for all variables or a dictionary mapping variable names or dtypes to methods. Supported methods include: "center", "count", "first", "last", "max", "mean", "median", "mode", "min", "prod", "std", "sum", and "var". Defaults to "center" for integer arrays, else "mean". |
None
|
recover_nans
|
RecoverNans
|
Optional boolean or mapping to enable NaN recovery during upsampling (only applies when interpolation method is not nearest). Can be a single boolean or a dictionary mapping variable names or dtypes to booleans. Defaults to False. |
False
|
fill_values
|
FillValues | None
|
Optional fill value(s) to assign outside source coverage. Can be a single value or dictionary by variable or type. If not set, defaults are:
|
None
|
Returns:
Type | Description |
---|---|
Dataset
|
A new dataset with variables reprojected to the target CRS and grid. Variables without 2D spatial dimensions are copied as-is. 1D spatial coordinate variables are ignored in the output. |
Source code in xcube_resampling/reproject.py
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 150 151 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 |
|
xcube_resampling.rectify.rectify_dataset(source_ds, target_gm=None, source_gm=None, variables=None, interp_methods=None, agg_methods=None, recover_nans=False, fill_values=None, tile_size=None)
Rectify a dataset with non-regular grid to a regular grid defined by a target grid mapping.
This function transforms spatial coordinates to a regular grid while preserving data values. It optionally downsamples high-resolution inputs prior to rectifying.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_ds
|
Dataset
|
The source dataset with 2D spatial coordinate variables. |
required |
target_gm
|
GridMapping | None
|
Optional target grid mapping defining the output regular grid. If not provided, one is derived from the source grid mapping. |
None
|
source_gm
|
GridMapping | None
|
Optional grid mapping of the source dataset. If not given, it is inferred from the dataset. |
None
|
variables
|
str | Iterable[str] | None
|
Optional variable(s) to rectify. If None, all eligible variables are processed. |
None
|
interp_methods
|
InterpMethods | None
|
Optional interpolation method to be used for upsampling spatial data variables. Can be a single interpolation method for all variables or a dictionary mapping variable names or dtypes to interpolation method. Supported methods include:
The default is |
None
|
agg_methods
|
AggMethods | None
|
Optional aggregation methods for downsampling spatial variables. Can be a single method for all variables or a dictionary mapping variable names or dtypes to methods. Supported methods include: "center", "count", "first", "last", "max", "mean", "median", "mode", "min", "prod", "std", "sum", and "var". Defaults to "center" for integer arrays, else "mean". |
None
|
recover_nans
|
RecoverNans
|
Optional boolean or mapping to enable NaN recovery during upsampling (only applies when interpolation method is not nearest). Can be a single boolean or a dictionary mapping variable names or dtypes to booleans. Defaults to False. |
False
|
fill_values
|
FillValues | None
|
Optional fill value(s) for areas outside input coverage. Can be a single value or dictionary by variable or type. If not provided, defaults based on data type are used:
|
None
|
tile_size
|
int | tuple[int, int] | None
|
Optional tile size for inferring a regular grid, if |
None
|
Returns:
Type | Description |
---|---|
Dataset
|
A new dataset with spatial variables rectified to a regular grid. Variables not having 2D spatial dimensions are copied as-is. 1D spatial coordinate variables are ignored in the output. |
Source code in xcube_resampling/rectify.py
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 150 151 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 |
|
xcube_resampling.gridmapping.GridMapping
Bases: ABC
An abstract base class for grid mappings that define an image grid and a transformation from image pixel coordinates to spatial Earth coordinates defined in a well-known coordinate reference system (CRS).
This class cannot be instantiated directly. Use one of its factory methods to create instances:
- :meth:
regular
- :meth:
from_dataset
- :meth:
from_coords
Some instance methods can be used to derive new instances:
- :meth:
derive
- :meth:
scale
- :meth:
transform
- :meth:
to_regular
This class is thread-safe.
Source code in xcube_resampling/gridmapping/base.py
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 150 151 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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 |
|
size
property
Image size (width, height) in pixels.
width
property
Image width in pixels.
height
property
Image height in pixels.
tile_size
property
Image tile size (width, height) in pixels.
is_tiled
property
Whether the image is tiled.
tile_width
property
Image tile width in pixels.
tile_height
property
Image tile height in pixels.
x_coords
property
The 1D or 2D x-coordinate array of shape (width,) or (height, width).
y_coords
property
The 1D or 2D y-coordinate array of shape (width,) or (height, width).
xy_coords
property
The x,y coordinates as data array of shape (2, height, width). Coordinates are given in units of the CRS.
xy_coords_chunks
property
Get the chunks for the xy_coords array.
xy_var_names
property
The variable names of the x,y coordinates as tuple (x_var_name, y_var_name).
xy_dim_names
property
The dimension names of the x,y coordinates as tuple (x_dim_name, y_dim_name).
xy_bbox
property
The image's bounding box in CRS coordinates.
x_min
property
Minimum x-coordinate in CRS units.
y_min
property
Minimum y-coordinate in CRS units.
x_max
property
Maximum x-coordinate in CRS units.
y_max
property
Maximum y-coordinate in CRS units.
xy_res
property
Pixel size in x and y direction.
x_res
property
Pixel size in CRS units per pixel in x-direction.
y_res
property
Pixel size in CRS units per pixel in y-direction.
crs
property
The coordinate reference system.
is_lon_360
property
Check whether x_max is greater than 180 degrees. Effectively tests whether the range x_min, x_max crosses the anti-meridian at 180 degrees. Works only for geographical coordinate reference systems.
is_regular
property
Do the x,y coordinates for a regular grid? A regular grid has a constant delta in both x- and y-directions of the x- and y-coordinates.
None, if this property cannot be determined,
Type | Description |
---|---|
bool | None
|
True or False otherwise. |
is_j_axis_up
property
Does the positive image j-axis point up? By default, the positive image j-axis points down.
None, if this property cannot be determined,
Type | Description |
---|---|
bool | None
|
True or False otherwise. |
ij_to_xy_transform
property
The affine transformation matrix from image to CRS coordinates. Defined only for grid mappings with rectified x,y coordinates.
xy_to_ij_transform
property
The affine transformation matrix from CRS to image coordinates. Defined only for grid mappings with rectified x,y coordinates.
ij_bbox
property
The image's bounding box in pixel coordinates.
ij_bboxes
property
The image tiles' bounding boxes in image pixel coordinates.
xy_bboxes
property
The image tiles' bounding boxes in CRS coordinates.
derive(xy_var_names=None, xy_dim_names=None, tile_size=None, is_j_axis_up=None)
Derive a new grid mapping from this one with some properties changed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xy_var_names
|
tuple[str, str]
|
The new x-, and y-variable names. |
None
|
xy_dim_names
|
tuple[str, str]
|
The new x-, and y-dimension names. |
None
|
tile_size
|
int | tuple[int, int]
|
The new tile size |
None
|
is_j_axis_up
|
bool
|
Whether j-axis points up. |
None
|
Returns:
Type | Description |
---|---|
GridMapping
|
A new, derived grid mapping. |
Source code in xcube_resampling/gridmapping/base.py
145 146 147 148 149 150 151 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 |
|
scale(xy_scale, tile_size=None)
Derive a scaled version of this regular grid mapping.
Scaling factors larger than one correspond to up-scaling (pixels sizes decrease, image size increases).
Scaling factors lower than one correspond to down-scaling. (pixels sizes increase, image size decreases).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xy_scale
|
FloatInt | tuple[FloatInt, FloatInt]
|
The x-, and y-scaling factors. May be a single number or tuple. |
required |
tile_size
|
int | tuple[int, int] | None
|
The new tile size |
None
|
Returns:
Type | Description |
---|---|
GridMapping
|
A new, scaled grid mapping. |
Source code in xcube_resampling/gridmapping/base.py
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 238 239 240 241 242 243 244 245 246 |
|
ij_transform_to(other)
Get the affine transformation matrix that transforms image coordinates of other into image coordinates of this image geometry.
Defined only for grid mappings with rectified x,y coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
GridMapping
|
The other image geometry |
required |
Returns:
Type | Description |
---|---|
AffineTransformMatrix
|
Affine transformation matrix |
Source code in xcube_resampling/gridmapping/base.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
|
ij_transform_from(other)
Get the affine transformation matrix that transforms image coordinates of this image geometry to image coordinates of other.
Defined only for grid mappings with rectified x,y coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
GridMapping
|
The other image geometry |
required |
Returns:
Type | Description |
---|---|
AffineTransformMatrix
|
Affine transformation matrix |
Source code in xcube_resampling/gridmapping/base.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
|
ij_bbox_from_xy_bbox(xy_bbox, xy_border=0.0, ij_border=0)
Compute bounding box in i,j pixel coordinates given a bounding box xy_bbox in x,y coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xy_bbox
|
tuple[float, float, float, float]
|
Box (x_min, y_min, x_max, y_max) given in the same CS as x and y. |
required |
xy_border
|
float
|
If non-zero, grows the bounding box xy_bbox before using it for comparisons. Defaults to 0. |
0.0
|
ij_border
|
int
|
If non-zero, grows the returned i,j bounding box and clips it to size. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
int
|
Bounding box in (i_min, j_min, i_max, j_max) in pixel |
int
|
coordinates. Returns |
int
|
intersecting any of the x,y coordinates. |
Source code in xcube_resampling/gridmapping/base.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
|
ij_bboxes_from_xy_bboxes(xy_bboxes, xy_border=0.0, ij_border=0, ij_bboxes=None)
Compute bounding boxes in pixel coordinates given bounding boxes xy_bboxes [[x_min, y_min, x_max, y_max], ...] in x,y coordinates.
The returned array in i,j pixel coordinates has the same shape as xy_bboxes. The value ranges in the returned array [[i_min, j_min, i_max, j_max], ..]] are:
- i_min from 0 to width-1, i_max from 1 to width;
- j_min from 0 to height-1, j_max from 1 to height;
so the i,j pixel coordinates can be used as array index slices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xy_bboxes
|
ndarray
|
Numpy array of x,y bounding boxes [[x_min, y_min, x_max, y_max], ...] given in the same CS as x and y. |
required |
xy_border
|
float
|
If non-zero, grows the bounding box xy_bbox before using it for comparisons. Defaults to 0. |
0.0
|
ij_border
|
int
|
If non-zero, grows the returned i,j bounding box and clips it to size. Defaults to 0. |
0
|
ij_bboxes
|
ndarray
|
Numpy array of pixel i,j bounding boxes [[x_min, y_min, x_max, y_max], ...]. If given, must have same shape as xy_bboxes. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
Bounding boxes in [[i_min, j_min, i_max, j_max], ..]] in |
ndarray
|
pixel coordinates. |
Source code in xcube_resampling/gridmapping/base.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
|
to_coords(xy_var_names=None, xy_dim_names=None, exclude_bounds=False, reuse_coords=False)
Get CF-compliant axis coordinate variables and cell boundary coordinate variables.
Defined only for grid mappings with regular x,y coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xy_var_names
|
tuple[str, str]
|
Optional coordinate variable names (x_var_name, y_var_name). |
None
|
xy_dim_names
|
tuple[str, str]
|
Optional coordinate dimensions names (x_dim_name, y_dim_name). |
None
|
exclude_bounds
|
bool
|
If True, do not create bounds coordinates. Defaults to False. |
False
|
reuse_coords
|
bool
|
Whether to either reuse target coordinate arrays from target_gm or to compute new ones. |
False
|
Returns:
Type | Description |
---|---|
Mapping[str, DataArray]
|
dictionary with coordinate variables |
Source code in xcube_resampling/gridmapping/base.py
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
|
transform(crs, *, xy_res=None, tile_size=None, xy_var_names=None, tolerance=DEFAULT_TOLERANCE)
Transform this grid mapping so it uses the given spatial coordinate reference system into another crs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
crs
|
str | CRS
|
The new spatial coordinate reference system. |
required |
xy_res
|
FloatInt | tuple[FloatInt, FloatInt]
|
Optional resolution in x- and y-directions. If given, speeds up the method by avoiding time-consuming spatial resolution estimation. |
None
|
tile_size
|
int | tuple[int, int]
|
Optional new tile size. |
None
|
xy_var_names
|
tuple[str, str]
|
Optional new coordinate names. |
None
|
tolerance
|
float
|
Absolute tolerance used when comparing coordinates with each other. Must be in the units of the crs and must be greater zero. |
DEFAULT_TOLERANCE
|
Returns:
Type | Description |
---|---|
GridMapping
|
A new grid mapping that uses crs. |
Source code in xcube_resampling/gridmapping/base.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
|
regular(size, xy_min, xy_res, crs, *, tile_size=None, is_j_axis_up=False)
classmethod
Create a new regular grid mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int | tuple[int, int]
|
Size in pixels. |
required |
xy_min
|
tuple[float, float]
|
Minimum x- and y-coordinates. |
required |
xy_res
|
float | tuple[float, float]
|
Resolution in x- and y-directions. |
required |
crs
|
str | CRS
|
Spatial coordinate reference system. |
required |
tile_size
|
int | tuple[int, int]
|
Optional tile size. |
None
|
is_j_axis_up
|
bool
|
Whether positive j-axis points up. Defaults to false. |
False
|
Returns:
Type | Description |
---|---|
GridMapping
|
A new regular grid mapping. |
Source code in xcube_resampling/gridmapping/base.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
|
to_regular(tile_size=None, is_j_axis_up=False)
Transform this grid mapping into one that is regular.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile_size
|
int | tuple[int, int] | None
|
Optional tile size. |
None
|
is_j_axis_up
|
bool
|
Whether positive j-axis points up. Defaults to false. |
False
|
Returns:
Type | Description |
---|---|
GridMapping
|
A new regular grid mapping or this grid mapping, if it is |
GridMapping
|
already regular. |
Source code in xcube_resampling/gridmapping/base.py
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
|
from_dataset(dataset, *, crs=None, tile_size=None, prefer_is_regular=True, prefer_crs=None, emit_warnings=False, tolerance=DEFAULT_TOLERANCE)
classmethod
Create a grid mapping for the given dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset
|
Dataset
|
The dataset. |
required |
crs
|
str | CRS | None
|
Optional spatial coordinate reference system. |
None
|
tile_size
|
int | tuple[int, int] | None
|
Optional tile size |
None
|
prefer_is_regular
|
bool
|
Whether to prefer a regular grid mapping if multiple found. Default is True. |
True
|
prefer_crs
|
str | CRS | None
|
The preferred CRS of a grid mapping if multiple found. |
None
|
emit_warnings
|
bool
|
Whether to emit warning for non-CF compliant datasets. |
False
|
tolerance
|
float
|
Absolute tolerance used when comparing coordinates with each other. Must be in the units of the crs and must be greater zero. |
DEFAULT_TOLERANCE
|
Returns:
Type | Description |
---|---|
GridMapping
|
a new grid mapping instance. |
Source code in xcube_resampling/gridmapping/base.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
|
from_coords(x_coords, y_coords, crs, *, tile_size=None, tolerance=DEFAULT_TOLERANCE)
classmethod
Create a grid mapping from given x- and y-coordinates x_coords, y_coords and spatial coordinate reference system crs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_coords
|
DataArray
|
The x-coordinates. |
required |
y_coords
|
DataArray
|
The y-coordinates. |
required |
crs
|
str | CRS
|
The spatial coordinate reference system. |
required |
tile_size
|
int | tuple[int, int] | None
|
Optional tile size. |
None
|
tolerance
|
float
|
Absolute tolerance used when comparing coordinates with each other. Must be in the units of the crs and must be greater zero. |
DEFAULT_TOLERANCE
|
Returns:
Type | Description |
---|---|
GridMapping
|
A new grid mapping. |
Source code in xcube_resampling/gridmapping/base.py
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 |
|
is_close(other, tolerance=DEFAULT_TOLERANCE)
Tests whether this grid mapping is close to other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
GridMapping
|
The other grid mapping. |
required |
tolerance
|
float
|
Absolute tolerance used when comparing coordinates with each other. Must be in the units of the crs and must be greater zero. |
DEFAULT_TOLERANCE
|
Returns:
Type | Description |
---|---|
bool
|
True, if so, False otherwise. |
Source code in xcube_resampling/gridmapping/base.py
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 |
|