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

000_general: Add first version of colorwheel #23

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1a99475
Add first version of colorwheel
yvonnefroehlich May 20, 2024
d767762
Update image for 000_general README
yvonnefroehlich May 20, 2024
d15c988
Simplify windturbine example
yvonnefroehlich May 20, 2024
f15cbb4
Add documentation for paramters
yvonnefroehlich May 20, 2024
403baa0
Improve docs
yvonnefroehlich May 20, 2024
290da99
Adjust code regarding config
yvonnefroehlich May 20, 2024
eb984a1
Fix typo
yvonnefroehlich May 20, 2024
be4fd64
Merge remote-tracking branch 'origin/main' into add-colorwheel
May 22, 2024
2e9ef1c
Specify GMT version
yvonnefroehlich May 22, 2024
0682e8d
Merge remote-tracking branch 'origin/main' into add-colorwheel
yvonnefroehlich May 22, 2024
a04995f
Merge remote-tracking branch 'origin/main' into add-colorwheel
yvonnefroehlich Jul 21, 2024
2caefee
Merge remote-tracking branch 'origin/main' into add-colorwheel
yvonnefroehlich Jul 29, 2024
a78bdf3
Merge remote-tracking branch 'origin/main' into add-colorwheel
yvonnefroehlich Jul 30, 2024
fc0930e
Merge remote-tracking branch 'origin/main' into add-colorwheel
yvonnefroehlich Aug 31, 2024
8684eb1
Merge remote-tracking branch 'origin/main' into add-colorwheel
yvonnefroehlich Sep 8, 2024
589b290
Merge remote-tracking branch 'origin/main' into add-colorwheel
yvonnefroehlich Oct 3, 2024
4a6f359
Merge remote-tracking branch 'origin/main' into add-colorwheel
yvonnefroehlich Oct 4, 2024
7c4e989
Merge remote-tracking branch 'origin/main' into add-colorwheel
yvonnefroehlich Nov 26, 2024
004033a
Update READMEs
yvonnefroehlich Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions 000_general_stuff/02_colorwheel/colorwheel_pygmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# #############################################################################
# Colorwheel for cyclic colormaps created with PyGMT
# Scientific colourmaps by Fabio Crameri: romaO, bamO, brocO, corkO, vikO
# cmocean colormaps by Kristen M. Thyng: phase
# -----------------------------------------------------------------------------
# Created: 2024/05/20
# Author: Yvonne Fröhlich
# ORCID: https://orcid.org/0000-0002-8566-0619
# GitHub: https://github.com/yvonnefroehlich/gmt-pygmt-plotting
# -----------------------------------------------------------------------------
# - Created: 2024/05/15
# PyGMT v0.12.0 -> https://www.pygmt.org/v0.12.0/ | https://www.pygmt.org/
# GMT 6.5.0 -> https://www.generic-mapping-tools.org/
# #############################################################################


import numpy as np
import pygmt


def colorwheel(cmap, perspective, rho_min=1, rho_max=2.5, fig_instance=None):
"""
-------------------------------------------------------------------------
Parameters
-------------------------------------------------------------------------
Required
- cmap : str | name of a cyclic colormap
- perspective : list of two floats | azimuth, elevation
Optional
- rho_min : float | inner radius of colorwheel | Default 1
- rho_max : float | outer radius of colorwheel | Default 2.5
- fig_instance : Provide a PyGMT figure instance | Default a new one is set up
"""

# -------------------------------------------------------------------------
# Set up rotated rectangle or bar data
# -------------------------------------------------------------------------
# [[lon, lat, direction, width, height]]
# In polar coordinates lon refers to the angle and lat to the radius (rho)
# Location applies to the center of the bar -> shift by length/2
# Add quantity for fill color as second column (zero-based indexing)
# Direction of bar (j) is from North but still counter-clockwise -> negative sign
data_bars = np.zeros([360, 6])
for i_ang in range(0, 360, 1): # min, max], step
data_bars_temp = np.array([
i_ang, rho_min+rho_max/2, i_ang, -i_ang, 0.05, rho_max-rho_min,
])
data_bars[i_ang,:] = data_bars_temp

# -------------------------------------------------------------------------
# Create colorwheel plot
# -------------------------------------------------------------------------
if fig_instance != None:
fig = fig_instance
else:
fig = pygmt.Figure()

with pygmt.config(
PS_PAGE_COLOR="white@1", # Make area outside of plot transparent
MAP_FRAME_PEN="white", # Make frame outline white
):
fig.basemap(
region=[0, 360, 0, rho_max],
# Use geographic azimuth instead of standard angle -> backazimuth
# Go clockwise from North instead of counter-clockwise from East
projection=f"P{rho_max * 2}c+a",
frame="rltb",
)

# Create colormap for direction (backazimuth)
pygmt.makecpt(cmap=cmap, cyclic=True, series=[0, 360, 1])

# Plot rotated rectangles with color-coding
# Set perspective as [azimuth, elevation]
fig.plot(data=data_bars, style="j", cmap=True, perspective=perspective)

# Show and save
fig_name = f"colorwheel_N_cw_pygmt_bar_{cmap}"
if fig_instance == None:
fig.show()
for ext in ["png"]: #, "pdf", "eps"]:
fig.savefig(fname=f"{fig_name}.{ext}", dpi=720)
print(fig_name)


# %%
# -----------------------------------------------------------------------------
# Examples
# -----------------------------------------------------------------------------
fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -2, 2], projection="X10c/4c", frame=0)

fig.shift_origin(xshift="0.6c", yshift="2c")
for cmap in ["romaO", "bamO", "brocO", "corkO", "vikO", "phase"]:

colorwheel(
cmap=cmap,
perspective=[90, -90], # anti-clockwise from horizontal
rho_min=0.2,
rho_max=0.6,
fig_instance=fig,
)
fig.shift_origin(yshift="-1.4c")
colorwheel(
cmap=cmap,
perspective=[180, 90], # clockwise from vertical (-> backazimuth)
rho_min=0.2,
rho_max=0.6,
fig_instance=fig,
)
fig.text(x=1, y=2.4, text=cmap, no_clip=True)
pygmt.makecpt(cmap=cmap, series=[0, 360], cyclic=True)
fig.colorbar(cmap=True, position="jBC+o0c/-0.5c+w1.1c/0.25c+h", frame=0)
fig.shift_origin(xshift="1.5c", yshift="1.4c")

fig.show()
fig.savefig(fname="colorwheel_all_cmaps.png")
1 change: 1 addition & 0 deletions 000_general_stuff/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
_Recommended versions_: PyGMT v0.11.0 / v0.12.0 / v0.13.0, GMT 6.4.0 / 6.5.0

- **[01_custom_symbols](https://github.com/yvonnefroehlich/gmt-pygmt-plotting/tree/main/000_general_stuff/01_custom_symbols)**
- **[02_colorwheel](https://github.com/yvonnefroehlich/gmt-pygmt-plotting/tree/main/000_general_stuff/02_colorwheel)**
- **[03_cb_font_scaling](https://github.com/yvonnefroehlich/gmt-pygmt-plotting/tree/main/000_general_stuff/03_cb_font_scaling)**

![](https://github.com/yvonnefroehlich/gmt-pygmt-plotting/raw/main/_images/github_maps_readme_000general.png)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If you make use of this material, please acknowledge the relating publications i

## Content

- **[000_general_stuff](https://github.com/yvonnefroehlich/gmt-pygmt-plotting/tree/main/000_general_stuff)**: Custom symbols
- **[000_general_stuff](https://github.com/yvonnefroehlich/gmt-pygmt-plotting/tree/main/000_general_stuff)**: Custom symbols, colorwheel
- **[001_paper_RFSG_2022](https://github.com/yvonnefroehlich/gmt-pygmt-plotting/tree/main/001_paper_RFSG_2022)**: Maps of [**_Ritter et al. (2022)_**](https://doi.org/10.1007/s10950-022-10112-w)
- **[002_paper_FGR_2024](https://github.com/yvonnefroehlich/gmt-pygmt-plotting/tree/main/002_paper_FGR_2024)**: Maps of [**_Fröhlich et al. (2024)_**](https://doi.org/10.1093/gji/ggae245)
- **[003_taup](https://github.com/yvonnefroehlich/gmt-pygmt-plotting/tree/main/003_taup)**: Travel paths of seismological phases through the Earth interior; related to [**_Fröhlich et al. (2024)_**](https://doi.org/10.1093/gji/ggae245)
Expand Down
Binary file modified _images/github_maps_readme_000general.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.