-
Notifications
You must be signed in to change notification settings - Fork 230
WIP: Add Figure.directional_rose to plot a directional rose on map #4025
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
Draft
seisman
wants to merge
19
commits into
main
Choose a base branch
from
feature/direction_rose
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
59f2b18
Add Figure.directional_rose to plot a directional rose on map
seisman 07fc243
Add to API doc
seisman 29c28bc
Add more docstrings
seisman 33398b5
Fix typos
seisman f325296
Improve docstrings
seisman aac91ad
Improve docstring [skip ci]
seisman 2fdca74
Merge branch 'main' into feature/direction_rose
seisman 607f4db
Better arguments for position_type
seisman a36b8af
Add more parameters
seisman 6c890cf
Add more type hints
seisman 64bf23a
Update to the new position type
seisman 8ba0992
Merge branch 'main' into feature/direction_rose
seisman 50476ea
Updates
seisman 8696c72
Merge branch 'main' into feature/direction_rose
seisman e4e1759
updates
seisman 8c46b9a
Add tests
seisman 6f9153c
Updates
seisman f8d2837
Merge branch 'main' into feature/direction_rose
seisman cee6028
Add verbose and transparency
seisman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
""" | ||
directional_rose - Add a map directional rose. | ||
""" | ||
|
||
from collections.abc import Sequence | ||
from typing import Literal | ||
|
||
from pygmt._typing import AnchorCode | ||
from pygmt.alias import Alias, AliasSystem | ||
from pygmt.clib import Session | ||
from pygmt.helpers import build_arg_list | ||
|
||
|
||
def directional_rose( | ||
self, | ||
position, | ||
position_type: Literal["user", "justify", "mirror", "normalize", "plot"] = "user", | ||
width: float | str | None = None, | ||
justify: AnchorCode | None = None, | ||
offset: Sequence[float | str] | None = None, | ||
label: Sequence[str] | bool = False, | ||
fancy: Literal[1, 2, 3] | bool = False, | ||
): | ||
r""" | ||
Add a directional rose to the map. | ||
|
||
Parameters | ||
---------- | ||
position/position_type | ||
Location of the rose. The actual meaning of this parameter depends on the | ||
``position_type`` parameter. | ||
|
||
- ``position_type="user"``: *position* is given as (x, y) in user coordinates. | ||
- ``position_type="normalize"``: *position* is given as (nx, ny) in normalized | ||
coordinates, where (0, 0) is the lower-left corner and (1, 1) is the | ||
upper-right corner of the map. | ||
- ``position_type="plot"``: *position* is given as (x, y) in plot coordinates. | ||
- ``position_type="justify"``: *position* is given as a two-character | ||
justification code, meaning the anchor point of the rose is inside the map | ||
bounding box. | ||
- ``position_type="mirror"``: *position* is given as a two-character | ||
justification code, but the rose is outside the map bounding box. | ||
width | ||
Width of the rose in plot coordinates (append **i** (inch), | ||
**cm** (centimeters), or **p** (points)), or append % for a size in percentage | ||
of map width [default is 10%]. | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
label | ||
A sequence of four strings to label the cardinal points W,E,S,N. Use an empty | ||
string to skip a specific label. If set to ``True``, use the default labels | ||
``["W", "E", "S", "N"]``. | ||
fancy | ||
Get a fancy rose. The fanciness level can be set to 1, 2, or 3: | ||
|
||
- Level 1 draws the two principal E-W, N-S orientations | ||
- Level 2 adds the two intermediate NW-SE and NE-SW orientations | ||
- Level 3 adds the four minor orientations WNW-ESE, NNW-SSE, NNE-SSW, and | ||
ENE-WSW | ||
|
||
If set to ``True``, it defaults to level 1. | ||
offset | ||
*offset* or (*offset_x*, *offset_y*). | ||
Offset the anchor point by *offset_x* and *offset_y*. If a single value *offset* | ||
is given, *offset_y* = *offset_x* = *offset*. | ||
justify | ||
Set the anchor point. Specify a two-character (order independent) code. Choose | ||
from vertical **T**\(op), **M**\(iddle), or **B**\(ottom) and horizontal | ||
**L**\(eft), **C**\(entre), or **R**\(ight). | ||
|
||
Examples | ||
-------- | ||
>>> import pygmt | ||
>>> fig = pygmt.Figure() | ||
>>> fig.basemap(region=[0, 80, -30, 30], projection="M10c", frame=True) | ||
>>> fig.directional_rose(position=(10, 10), position_type="user") | ||
>>> fig.show() | ||
""" | ||
self._activate_figure() | ||
|
||
aliasdict = AliasSystem( | ||
Td=[ | ||
Alias( | ||
position_type, | ||
name="position_type", | ||
mapping={ | ||
"user": "g", | ||
"justify": "j", | ||
"mirror": "J", | ||
"normalize": "n", | ||
"plot": "x", | ||
}, | ||
), | ||
Alias(position, name="position", separator="/"), | ||
Alias(width, name="width", prefix="+w"), | ||
Alias(fancy, name="fancy", prefix="+f"), | ||
Alias(justify, name="justify", prefix="+j"), | ||
Alias(label, name="label", prefix="+l", separator=",", size=4), | ||
Alias(offset, name="offset", prefix="+o", separator="/", size=[1, 2]), | ||
] | ||
) | ||
|
||
with Session() as lib: | ||
lib.call_module(module="basemap", args=build_arg_list(aliasdict)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 am not sure if "justify" and "mirror" are suitable / understandable terms here, especially "mirror" appears a bit strange for me. Is this orientated on some other implementaiton or documentation?
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.
GMT uses long names like
mapcoords
,inside
,outside
,boxcoords
,plotcoords
https://github.com/GenericMappingTools/gmt/blob/98a9b39c1a94ff23dba8dd89fca9fae367432303/src/longopt/psbasemap_inc.h#L30
but
gmtlogo
usesuser|map
,justify
,mirror
,normalize
,plot
https://github.com/GenericMappingTools/gmt/blob/98a9b39c1a94ff23dba8dd89fca9fae367432303/src/longopt/gmtlogo_inc.h#L29
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.
All the parameters/arguments need more discussions.