Skip to content
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

Default CPTs for GMT remote datasets #2325

Closed
seisman opened this issue Jan 15, 2023 · 7 comments · Fixed by #2728
Closed

Default CPTs for GMT remote datasets #2325

seisman opened this issue Jan 15, 2023 · 7 comments · Fixed by #2728
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@seisman
Copy link
Member

seisman commented Jan 15, 2023

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

map

In the following PyGMT script, a grid file name is directly passed to Figure.grdimage. This script produces the indentical image:

import pygmt
fig = pygmt.Figure()
fig.grdimage(grid="@earth_age_01d_g")
fig.colorbar(frame=True)
fig.savefig("map.png")

map

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).

import pygmt
from pygmt.datasets import load_earth_age

grid = load_earth_age()
fig = pygmt.Figure()
fig.grdimage(grid=grid)
fig.colorbar()
fig.savefig("map.png")

map

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.

@seisman seisman added the question Further information is requested label Jan 29, 2023
@michaelgrund
Copy link
Member

Agree, would be nice to have at least examples to show the most suitable CPT for each dataset.

@maxrjones
Copy link
Member

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.

@seisman seisman added enhancement Improving an existing feature and removed question Further information is requested labels Feb 12, 2023
@weiji14
Copy link
Member

weiji14 commented Jun 14, 2023

grid = load_earth_age()
fig = pygmt.Figure()
fig.grdimage(grid=grid)

Could we store the default cmap in an xarray accessor (#499) or attribute, and then let grdimage default to that cmap if cmap=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
Copy link
Member Author

seisman commented Jun 14, 2023

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.

@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Aug 15, 2023

@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:

import pygmt

# #############################################################################
# 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 turbo
fig.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 dataset
fig.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:
datasets_cpt_example_at

datasets_cpt_example_load


@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.
datasets_compare_cpts

@seisman
Copy link
Member Author

seisman commented Oct 7, 2023

Agree, would be nice to have at least examples to show the most suitable CPT for each dataset.

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:

  1. In the Remote Datasets site, each dataset already has an overview image. So we can just directly include these images on the API documentation page of the datasets. For examples, adding the following codes to https://www.pygmt.org/dev/api/generated/pygmt.datasets.load_earth_age.html
.. image:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_age.png
  1. 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.

@seisman seisman added this to the 0.11.0 milestone Oct 8, 2023
@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Oct 8, 2023

Agree, would be nice to have at least examples to show the most suitable CPT for each dataset.

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:

  1. In the Remote Datasets site, each dataset already has an overview image. So we can just directly include these images on the API documentation page of the datasets. For examples, adding the following codes to https://www.pygmt.org/dev/api/generated/pygmt.datasets.load_earth_age.html
.. image:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_age.png
  1. 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.

@seisman seisman added documentation Improvements or additions to documentation help wanted Helping hands are appreciated and removed enhancement Improving an existing feature labels Oct 9, 2023
@yvonnefroehlich yvonnefroehlich removed the help wanted Helping hands are appreciated label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
5 participants