-
Notifications
You must be signed in to change notification settings - Fork 224
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
Add gallery example for plotting an RGB image from an xarray.DataArray #2641
Changes from 1 commit
9d38316
60d1be3
b516c19
e7b66e6
9085f65
4fd90be
7586ef7
3c0712d
00b427b
2553cce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
RGB Image | ||
--------- | ||
The :meth:`pygmt.Figure.grdimage` method can be used to plot Red, Green, Blue | ||
(RGB) images, or any 3-band false color combination. Here, we'll use | ||
:meth:`rioxarray.open_rasterio` to read a GeoTIFF file into an | ||
:class:`xarray.DataArray` format, and plot it on a map. | ||
|
||
The example below shows a Worldview 2 satellite image over | ||
`Lāhainā, Hawai'i during the August 2023 wildfires | ||
<https://en.wikipedia.org/wiki/2023_Hawaii_wildfires#L%C4%81hain%C4%81>`_. | ||
Data is sourced from a Cloud-Optimized GeoTIFF file hosted on | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`OpenAerialMap <https://map.openaerialmap.org>`_ under a | ||
`CC BY-NC 4.0 <https://creativecommons.org/licenses/by-nc/4.0/>`_ license. | ||
""" | ||
import pygmt | ||
import rioxarray | ||
|
||
############################################################################### | ||
# Read 3-band data from GeoTIFF into an xarray.DataArray object | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
image = rioxarray.open_rasterio( | ||
filename="https://oin-hotosm.s3.us-east-1.amazonaws.com/64d6a49a19cb3a000147a65b/0/64d6a49a19cb3a000147a65c.tif", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This GeoTiff file is almost 1 GB, which is too big to download. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The next line |
||
overview_level=5, | ||
) | ||
# Subset to area of Lāhainā in EPSG:32604 coordinates | ||
image = image.rio.clip_box(minx=738000, maxx=755000, miny=2300000, maxy=2318000) | ||
image | ||
|
||
############################################################################### | ||
# Plot the RGB imagery | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig = pygmt.Figure() | ||
fig.grdimage( | ||
grid=image, | ||
projection="x1:100000", | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
frame=[r"WSne+tL@!a\225hain@!a\225, Hawai\047i on 9 Aug 2023", "af"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to use the composite character There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's fine. Maybe it's possible to avoid that the letters are too close to each other by using another font style? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with @michaelgrund, these unequally spaced letters are a bit strange. Looking at the example at https://docs.generic-mapping-tools.org/6.4/tutorial/session-2.html#gmt-tut-10, using the font Times-Roman does not lead to unequally spaced letters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree that the spacing looks weird. I've changed the font to Times-Roman at b516c19 and it looks a bit better now: |
||
) | ||
fig.show() |
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.
Is it possible to make this work as a link to https://corteva.github.io/rioxarray/stable/rioxarray.html#rioxarray.open_rasterio?
If this is not easy to do, then we leave it as is. At least in the code example below, the link works.
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.
Ah yes, good catch. I used the wrong intersphinx directive, should be
:py:func:
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.
Ah, great. Thanks!