-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate with rioxarray and implement GMT_IMAGE to read RGB GeoTIFFs #1555
Comments
Side note: Both A & B require |
Thanks for chiming in @snowman2! I see you've opened an issue with making
I stand corrected, it's only the |
@joa-quim how do you link the data to the |
I don't use |
That makes sense, thanks for the explanation and sharing the link to the code. |
Description of the desired feature
This is a parallel issue to #578 and #1442. While researching how to read GeoTIFFs into an
xarray.DataArray
, specifically GeoTIFFs with RGB bands stored in a single band but with a color lookup table, I discovered that there wasn't really a straightforward solution 😅 So this issue is mainly to jot down some notes.1) Reading GeoTiff into
xarray.DataArray
Method A:
rioxarray.open_rasterio
Pros: Reads in data with proper dtype (e.g. uint8) and proper spatial_ref
Cons:
rioxarray
is a bit of a heavy dependency as it requiresscipy
(edit: may be resolved with corteva/rioxarray#413, edit2:rioxarray=0.8.0
has madescipy
optional!)gives
Method B:
xr.open_dataarray(..., engine="rasterio")
Pros:
Requires onlyEasier to put intorasterio
(a Pythonic GDAL wrapper) to be installed, which keeps things lightweightpygmt.load_dataarray
as it only requires the 'engine' argumentCons: Seems to read in data as float32 by default
Note: There was an
xr.open_rasterio
function in xarray v0.19.0, but it is pending deprecation, see pydata/xarray#4697, and removal PR at pydata/xarray#5808.produces
TLDR My preference is to use (A)
rioxarray.open_rasterio
because it reads in data properly as uint8, with a fallback to (B)xr.open_dataarray(..., engine=rasterio)
if onlyrasterio
is installed.2) Reading RGB colors from a GeoTIFF
Here's where things get a bit tricky. Neither
rioxarray.open_rasterio
norxarray.open_dataarray
reads in GeoTIFFs with color interpretation, i.e. RGB colors stored in a GeoTIFF will be read as a single band rather than 3 separate bands! This includes the@earth_day_01d
and@earth_night_01d
imagery. To be clear, non-color GeoTIFFs (e.g. DEMs, single band Landsat/Sentinel-2 images) are fine.Good news is that the color interpretation mechanism is present in
rasterio
see https://github.com/mapbox/rasterio/blob/1.2.8/docs/topics/color.rst and rasterio/rasterio#100. This is wrapping around the GDAL Color Table stuff (https://gdal.org/user/raster_data_model.html#color-table)Bad news is that we'll need to have that mechanism in
rioxarray
orxarray
in order to use it (unless we want to go with a purerasterio
route). There is an issue open though at corteva/rioxarray#191, so it might be a matter of helping to open a Pull Request in those libraries to implement the feature.3) Implementing GMT_IMAGE in PyGMT
So once we've solved (1) and (2) above, the next step would be, how to pass that 3-band RGB color
xarray.DataArray
into GMT? Max mentioned at #578 (comment) that we might need to use theGMT_IMAGE
resource, but that hasn't been added into pygmt.clib as of PyGMT v0.4.1.Probably need something like a
virtualfile_from_image
function, similar tovirtualfile_from_grid
(done in #159) at https://github.com/GenericMappingTools/pygmt/blame/v0.4.1/pygmt/clib/session.py#L1278Are you willing to help implement and maintain this feature? Something to do for PyGMT v0.6.0 I think.
The steps I think would be to:
rioxarray
and/orrasterio
as an optional dependency for PyGMT (added in Add Figure.tilemap to plot XYZ tile maps #2394)rioxarray
to get the color interpretation working (Read colormap and colorinterp from GeoTIFF as an attribute corteva/rioxarray#414)pygmt.load_dataarray
function to handle reading in RGB GeoTIFFsGMT_IMAGE
in PyGMT (Wrap GMT's standard data type GMT_IMAGE for images #3338, GMT_IMAGE: Implement the GMT_IMAGE.to_dataarray method for 3-band images #3128)References:
The text was updated successfully, but these errors were encountered: