-
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
Allow passing in Red, Green, Blue grids into grdimage #370
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation here only allows for file inputs at the moment. Wondering if there's a demand out there from our users to pass in xarray.DataArray
RGB grids as well? It'll be a lot more work to implement (and might actually fit in a separate Pull Request), but just throwing the bone out there.
Edit: Updated implementation to work with list of xarray.DataArray grids as well.
def test_grdimage_rgb_files(): | ||
"Plot an image using Red, Green, and Blue file inputs" | ||
fig = Figure() | ||
fig.grdimage(grid=["@earth_relief_60m", "@earth_relief_60m", "@earth_relief_60m"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite like this unit test example, since they're clearly not RGB grids. Does anyone have a better sample dataset recommendation? Preferably a small one that has a fairly stable URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I can only think of raw data at the moment. What format do you need as input (I'm not super familiar with the limitations of gmt)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GeoTiffs would be nice. Or anything GDAL can read I think. I quite like the zenodo idea, something with a persistent doi. But happy with any other good public domain ones too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There has to be some landsat data or something. @snowman2 does a lot with rioxarray and may have an idea of a persistent/versioned RGB geotiff. I'll ask the Pytroll core developers too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand what you are asking, there is an RGB tif in the example here: https://corteva.github.io/rioxarray/html/examples/COG.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did look at the rioxarray example a while ago actually, but the test here requires tiffs of individual bands, e.g r.tif, g.tif, b.tif. Landsat on AWS does provide individual bands but they're quite big...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh if you need the bands to be in separate tif files then that is going to be harder to track down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just take a regular RGB file and write each band to its own tif file.
import rioxarray
rds = rioxarray,open_rasterio(....)
rdssub = rds.sel(band=1)
rdssub.rio.to_raster(....)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought I might need to create some dummy test files. @seisman just mentioned a similar idea with splitting a raster into R,G,B bands. Just seems like quite a bit of work for a unit test (requires set-up and tear down). What about daily/weather satellites e.g. MODIS/Himawari with a coarse resolution, anyone know where to get a sample?
Using the sequence_space converter to allow for multiple grid inputs into `grdimage`. Useful when users want to make an RGB image plot e.g. from Landsat images (Bands 4,3,2).
Extends `grdimage` to accept a list of individual red, green and blue xarray.DataArrays for plotting. Had to revert using the 'sequence_space' decorator as it would not work nicely for multiple grids... Implementation uses the contextlib.ExitStack method to create multiple virtual grid files and enter multiple contexts (similar to 3448972). Also added one test case with dummy data, but could do with more to capture edge cases.
6b61b93
to
201664b
Compare
FYI, there was a module grd2rgb in GMT5, but was removed from GMT6. Not sure if it helps with this issue. @PaulWessel Is there an equivalent module or command in GMT6, which can convert a grid/image to rgb? |
FYI, it seems GMT will "disable" the feature to pass R, G, B grids into grdimage and grdview. Instead, users should use grdmix to convert RGB grids to a single image, and then pass it to grdimage/grdview. See related discussions at GenericMappingTools/gmt#4044 (comment), GenericMappingTools/gmt#4044 (comment), GenericMappingTools/gmt#4163. |
Ok, I'll will put this on hold first until GMT 6.2.0. Probably should just close this, but I'll leave it open so that we can cherry-pick the tests from this branch into the |
@weiji14 Do you think we should close this PR? |
Since GMT doesn't support Red, Green and Blue grids separately into For those following, I've started a new implementation at #2590 to allow |
Hi @weiji14 and @seisman and @maxrjones: Could you please send me a list of major activities for the pyGMT team since last July? I am writing the annual NSF report and would at least like to mention any workshops or presentations you may have had. Given time-zones, please send me something this morning (if you can). |
@maxrjones gave a SciPy Talk on July, 13, 2022. The related material is available at https://github.com/maxrjones/scipy2022. |
Hmm, don't think we had any workshops for PyGMT since Jul 2022, the last one was the EGU 2022 workshop in May 2022. And yes, Max's SciPy talk is at https://www.youtube.com/watch?v=nCktihu9bWg |
Great, thanks! |
Description of proposed changes
Allow for multiple grid inputs into
grdimage
via a Python list.Using the sequence_space converter (created in #325) to do that.Edit: Using if-then parsing instead to handle a list of xarray.DataArray grids better. Useful when users want to make an RGB image plot e.g. from Landsat images (Bands 4,3,2).Below is a bit of a convoluted example based on this tutorial (in Chinese) which has preprocessed grd files scaled to 0-255 range, all courtesy of @whyjz (Hi 👋!).
Fixes #
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.