I have a DataArray object named rio.
In [59]: rio
Out[59]:
<xarray.DataArray (band: 1, y: 106, x: 193)>
array([[[0, 0, ..., 0, 0],
[0, 0, ..., 0, 0],
...,
[0, 0, ..., 0, 0],
[0, 0, ..., 0, 0]]], dtype=uint8)
Coordinates:
* band (band) int32 1
* y (y) float64 -33.9 -33.95 -34.0 -34.05 ... -39.05 -39.1 -39.15 -39.2
* x (x) float64 140.8 140.8 140.9 140.9 ... 149.9 149.9 150.0 150.0
Attributes:
transform: (0.04791259799999997, 0.0, 140.776046753, 0.0, -0.0504760740...
crs: +init=epsg:4326
res: (0.04791259799999997, 0.05047607400000004)
is_tiled: 1
nodatavals: (255.0,)
I would like to rename y to latitude and x to longitude. So the resulted rio object will be:
In [59]: rio
Out[59]:
<xarray.DataArray (band: 1, latitude: 106, longitude: 193)>
array([[[0, 0, ..., 0, 0],
[0, 0, ..., 0, 0],
...,
[0, 0, ..., 0, 0],
[0, 0, ..., 0, 0]]], dtype=uint8)
Coordinates:
* band (band) int32 1
* latitude (latitude) float64 -33.9 -33.95 -34.0 -34.05 ... -39.05 -39.1 -39.15 -39.2
* longitude (longitude) float64 140.8 140.8 140.9 140.9 ... 149.9 149.9 150.0 150.0
Attributes:
transform: (0.04791259799999997, 0.0, 140.776046753, 0.0, -0.0504760740...
crs: +init=epsg:4326
res: (0.04791259799999997, 0.05047607400000004)
is_tiled: 1
nodatavals: (255.0,)
I need help on what methods I should use on the DataArray class?
I figured it out:
rio.rename({'x': 'longitude','y': 'latitude'})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With