You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most GMT remote datasets have a default CPT. When plotting a dataset without specifying a CPT, the default CPT will be used. For example, the default CPT for earth_age dataset is @earth_age.cpt.
The following command plots the earth_age_01d_g.nc grid using the default @earth_age.cpt file.
gmt grdimage @earth_age_01d_g -png map
In the following PyGMT script, a grid file name is directly passed to Figure.grdimage. This script produces the indentical image:
However, if we load the dataset into a xarray.DataArray and pass it to Figure.grdimage, the default CPT changes to "turbo" (GMT's default CPT for any grid data).
It would be good if PyGMT can use the specific CPT when a CPT is not specified, although it's technically difficult. At least we should document the default CPT for each dataset and add an example showing how to use the default dataset CPT.
This mechanism was discussed a bit in GenericMappingTools/gmt#6178 (comment). I think it would take detecting whether the user has set the current CPT and evaluating the grid for a cpt attr, then setting an argument to -C if only the latter is true. It would be worth evaluating the overhead for those checks. At least, documenting GMT's defaults seems useful.
Could we store the default cmap in an xarray accessor (#499) or attribute,
We can, but xarray accessor or attribute have known limitations (#2375). The saved CPT information will be lost after some grid operations.
and then let grdimage default to that cmap if cmap=None?
The default value of cmap is always None, and cmap=None means that GMT will use the default CPT (turbo) or the current hidden CPT, depending on if a current hidden CPT exists. So we can't let grdimage default to that cmap if cmap=None.
@seisman: [...] add an example showing how to use the default dataset CPT.
Should such a gallery example focus on one remote dataset? E.g. earth_age: Code example:
importpygmt# ############################################################################## Use "@earth_age_01d_g" to download the remote dataset `earth_age_01d_g`# directly within the method pygmt.Figure.grdimage.fig=pygmt.Figure()
fig.grdimage(grid="@earth_age_01d_g", frame=True)
fig.colorbar(frame="+lage / Myr")
fig.show()
# fig.savefig("datasets_cpt_example_at.png")# ############################################################################## Use `pygmt.datasets.load_earth_age()` to download the remote dataset # `earth_age` into a `xarray.DataArray`.grid_earth_age=pygmt.datasets.load_earth_age()
fig=pygmt.Figure()
# Left: Use GMT's overall default colormap turbofig.grdimage(grid=grid_earth_age, frame=["af", "WSne"])
fig.colorbar(frame="+lage / Myr")
fig.shift_origin(xshift="16c")
# Right: Use GMT's default colormap for the earth_age remote datasetfig.grdimage(grid=grid_earth_age, cmap="@earth_age.cpt", frame=["af", "wSne"])
fig.colorbar(frame="+lage / Myr")
fig.show()
# fig.savefig("datasets_cpt_example_load.png")
Output figues:
@michaelgrund: Agree, would be nice to have at least examples to show the most suitable CPT for each dataset.
Or do we want any kind of overview, which shows / compares the colormaps for all remote datasets?
Regarding the unexpected display of the remote dataset earth_mask see issue #2629, please. Edit 2023/08/16: Corrected figure based on the fix in PR #2632.
Just like the Projections gallery, we can create a gallery for all available datasets.
I prefer to option 1, because it's much simpler, and we don't have to add so many scripts for these datasets, which also slowdown the documentation building. The Remote Datasets site should be the central place to show all the available datasets.
Just like the Projections gallery, we can create a gallery for all available datasets.
I prefer to option 1, because it's much simpler, and we don't have to add so many scripts for these datasets, which also slowdown the documentation building. The Remote Datasets site should be the central place to show all the available datasets.
I also prefer option 1. Having a gallery for all available datasets separately from the API reference would probably lead to reduant parts.
Activity
michaelgrund commentedon Jan 31, 2023
Agree, would be nice to have at least examples to show the most suitable CPT for each dataset.
maxrjones commentedon Feb 4, 2023
This mechanism was discussed a bit in GenericMappingTools/gmt#6178 (comment). I think it would take detecting whether the user has set the current CPT and evaluating the grid for a cpt attr, then setting an argument to -C if only the latter is true. It would be worth evaluating the overhead for those checks. At least, documenting GMT's defaults seems useful.
weiji14 commentedon Jun 14, 2023
Could we store the default cmap in an xarray accessor (#499) or attribute, and then let
grdimagedefault to that cmap ifcmap=None?Or, if we don't want to add the extra logic to
grdimage, we could attempt to add it in the.gmt.imshow()function at #2372.seisman commentedon Jun 14, 2023
We can, but xarray accessor or attribute have known limitations (#2375). The saved CPT information will be lost after some grid operations.
The default value of
cmapis alwaysNone, andcmap=Nonemeans that GMT will use the default CPT (turbo) or the current hidden CPT, depending on if a current hidden CPT exists. So we can't letgrdimagedefault to that cmap ifcmap=None.yvonnefroehlich commentedon Aug 15, 2023
Should such a gallery example focus on one remote dataset? E.g.
earth_age:Code example:
Output figues:

Or do we want any kind of overview, which shows / compares the colormaps for all remote datasets?

Regarding the unexpected display of the remote dataset
earth_masksee issue #2629, please.Edit 2023/08/16: Corrected figure based on the fix in PR #2632.
seisman commentedon Oct 7, 2023
Here are my thoughts. Instead of creating a huge image with too many datasets as done in #2325 (comment), I think we have two options:
I prefer to option 1, because it's much simpler, and we don't have to add so many scripts for these datasets, which also slowdown the documentation building. The Remote Datasets site should be the central place to show all the available datasets.
yvonnefroehlich commentedon Oct 8, 2023
I also prefer option 1. Having a gallery for all available datasets separately from the API reference would probably lead to reduant parts.