Example - Reproject Match

[1]:
import rioxarray # for the extension to load
import xarray

%matplotlib inline

Load in xarray datasets

[2]:
xds = xarray.open_dataarray("/mnt/c/Users/snowal/scripts/rioxarray/test/test_data/input/MODIS_ARRAY.nc")
xds_match = xarray.open_dataarray("/mnt/c/Users/snowal/scripts/rioxarray/test/test_data/input/MODIS_ARRAY_MATCH.nc")
[3]:
xds
[3]:
<xarray.DataArray (y: 200, x: 200)>
array([[ nan,  nan,  nan, ..., 656., 656., 554.],
       [ nan,  nan,  nan, ..., 694., 694., 642.],
       [ nan,  nan,  nan, ..., 456., 575., 642.],
       ...,
       [993., 817., 817., ..., 471., 479., 498.],
       [893., 893., 816., ..., 479., 479., 469.],
       [816., 816., 832., ..., 515., 469., 485.]], dtype=float32)
Coordinates:
  * y        (y) float64 5.05e+06 5.05e+06 5.05e+06 ... 5.004e+06 5.004e+06
  * x        (x) float64 -7.274e+06 -7.274e+06 ... -7.228e+06 -7.228e+06
Attributes:
    crs:        +a=6371007.181 +b=6371007.181 +lon_0=0 +no_defs +proj=sinu +u...
    res:        [231.65635826 231.65635826]
    is_tiled:   0
    nodata:     -28672.0
    transform:  [ 2.31656358e+02  0.00000000e+00 -7.27400965e+06  0.00000000e...
[4]:
xds.plot()
[4]:
<matplotlib.collections.QuadMesh at 0x7fd98d0a1c50>
../_images/examples_reproject_match_5_1.png
[5]:
xds_match
[5]:
<xarray.DataArray (y: 100, x: 150)>
array([[  nan,   nan,   nan, ...,   nan,   nan,   nan],
       [  nan,   nan,   nan, ...,   nan,   nan,   nan],
       [  nan,   nan,   nan, ...,   nan,   nan,   nan],
       ...,
       [  nan,   nan,   nan, ..., 1146.,  821.,  583.],
       [  nan,   nan,   nan, ..., 1146., 1262.,  735.],
       [  nan,   nan,   nan, ...,  912., 1024.,  853.]], dtype=float32)
Coordinates:
  * y            (y) float64 5.029e+06 5.029e+06 ... 4.991e+06 4.991e+06
  * x            (x) float64 4.853e+05 4.857e+05 ... 5.425e+05 5.429e+05
    spatial_ref  int64 ...
Attributes:
    crs:           +datum=WGS84 +no_defs +proj=utm +units=m +zone=15
    res:           [386.65122672 386.65122672]
    is_tiled:      0
    transform:     [ 3.86651227e+02  0.00000000e+00  4.85124883e+05  0.000000...
    grid_mapping:  spatial_ref
[6]:
xds_match.plot()
[6]:
<matplotlib.collections.QuadMesh at 0x7fd98d010630>
../_images/examples_reproject_match_7_1.png

Reproject Match

API Reference:

[7]:
xds_repr_match = xds.rio.reproject_match(xds_match)
[8]:
xds_repr_match
[8]:
<xarray.DataArray (y: 100, x: 150)>
array([[  nan,   nan,  581., ...,   nan,   nan,   nan],
       [  nan,   nan,   nan, ...,   nan,   nan,   nan],
       [  nan,   nan,  682., ...,   nan,   nan,   nan],
       ...,
       [  nan,   nan,   nan, ...,  821.,  821.,  583.],
       [  nan,   nan,   nan, ..., 1024.,  853.,  583.],
       [  nan,   nan,   nan, ...,  867.,  804.,  706.]], dtype=float32)
Coordinates:
  * x            (x) float64 4.853e+05 4.857e+05 ... 5.425e+05 5.429e+05
  * y            (y) float64 5.029e+06 5.029e+06 ... 4.991e+06 4.991e+06
    spatial_ref  int64 0
Attributes:
    transform:     (386.65122672362685, 0.0, 485124.8828918401, 0.0, -386.651...
    _FillValue:    -28672
    grid_mapping:  spatial_ref
[9]:
xds_repr_match.plot()
[9]:
<matplotlib.collections.QuadMesh at 0x7fd98c72c908>
../_images/examples_reproject_match_11_1.png