Thanks for trying this in Julia @Joaquim!
Hm, seems like I have to look at this in more detail. At least it’s working now.
However, the Gallery example RGB Image — PyGMT works without any conversion. There the tif file is loaded via rioxarray.open_rasterio
into a xarray.DataArray
. This is what I did analoagous for the “LC2013.tif” file:
import pygmt
import rioxarray
# Load tif file
with rioxarray.open_rasterio(filename="LC2013.tif") as img:
image = img.rio.clip_box(minx=99.5, maxx=101.1, miny=38.4, maxy=40)
image = img.load()
I think after this step it’s no longer a picture:
image
Out[1]:
<xarray.DataArray (band: 1, y: 4530, x: 4530)>
array([[[0, 0, 0, ..., 0, 0, 0],
[0, 7, 7, ..., 7, 7, 7],
[0, 7, 7, ..., 7, 7, 7],
...,
[0, 4, 4, ..., 4, 4, 4],
[0, 4, 4, ..., 4, 4, 4],
[0, 4, 4, ..., 4, 4, 4]]])
Coordinates:
* band (band) int32 1
* x (x) float64 99.41 99.41 99.41 99.41 ... 101.1 101.1 101.1 101.1
* y (y) float64 40.0 40.0 40.0 40.0 ... 38.34 38.34 38.34 38.34
spatial_ref int32 0
Attributes:
AREA_OR_POINT: Area
TIFFTAG_XRESOLUTION: 1
TIFFTAG_YRESOLUTION: 1
_FillValue: 0
scale_factor: 1.0
add_offset: 0.0
Interestenting not only image.data = image.data.astype("float")
but also image.data = image.data.astype("int")
lead to a correct color-coding.
image.data
Out[2]:
array([[[0, 0, 0, ..., 0, 0, 0],
[0, 7, 7, ..., 7, 7, 7],
[0, 7, 7, ..., 7, 7, 7],
...,
[0, 4, 4, ..., 4, 4, 4],
[0, 4, 4, ..., 4, 4, 4],
[0, 4, 4, ..., 4, 4, 4]]], dtype=uint8)
image.data = image.data.astype("float")
image.data
Out[3]:
array([[[0., 0., 0., ..., 0., 0., 0.],
[0., 7., 7., ..., 7., 7., 7.],
[0., 7., 7., ..., 7., 7., 7.],
...,
[0., 4., 4., ..., 4., 4., 4.],
[0., 4., 4., ..., 4., 4., 4.],
[0., 4., 4., ..., 4., 4., 4.]]])
image.data = image.data.astype("int")
image.data
Out[4]:
array([[[0, 0, 0, ..., 0, 0, 0],
[0, 7, 7, ..., 7, 7, 7],
[0, 7, 7, ..., 7, 7, 7],
...,
[0, 4, 4, ..., 4, 4, 4],
[0, 4, 4, ..., 4, 4, 4],
[0, 4, 4, ..., 4, 4, 4]]])