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

Move plotting functions to separate modules #808

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
54ac6de
Move logo function to logo.py
willschlitzer Jan 28, 2021
7c90b77
Remove unused imports in logo.py
willschlitzer Jan 28, 2021
906edd1
Move coast function to coast.py
willschlitzer Jan 28, 2021
63d32b4
Run make format
willschlitzer Jan 28, 2021
0e67300
Move colorbar to colorbar.py
willschlitzer Jan 28, 2021
8a43456
Move grdcontour to grdcontour.py
willschlitzer Jan 28, 2021
5e2e98a
Remove unused import to grdcontour.py
willschlitzer Jan 28, 2021
3e2f32f
Fix doc string for grdcontour.py
willschlitzer Jan 28, 2021
291cef1
Move text function to text.py
willschlitzer Jan 28, 2021
e4d20c8
Move legend function to legend.py
willschlitzer Jan 28, 2021
fee00b7
Style checks
willschlitzer Jan 28, 2021
e409710
Move image function to image.py
willschlitzer Jan 28, 2021
955b894
Removed unused import
willschlitzer Jan 28, 2021
eed45d5
Move basemap function to basemap.py
willschlitzer Jan 28, 2021
3521be8
Move contour function to contour.py
willschlitzer Jan 28, 2021
137a03a
Move plot3d function to plot3d.py
willschlitzer Jan 28, 2021
13f0346
Move plot function to plot.py
willschlitzer Jan 28, 2021
c5f41ad
Move grdview function to grdview.py
willschlitzer Jan 28, 2021
f682831
Move grdimage function to grdimage.py
willschlitzer Jan 28, 2021
55f81f4
Style fix
willschlitzer Jan 28, 2021
a3a3e88
Style fix
willschlitzer Jan 28, 2021
2b58016
Remove unused imports from base_plotting.py
willschlitzer Jan 28, 2021
b0fc669
Update doc string
willschlitzer Jan 28, 2021
955f548
Merge branch 'master' into move-plotting-functions
willschlitzer Feb 5, 2021
cb4a193
Merge branch 'master' into move-plotting-functions
willschlitzer Feb 5, 2021
6e9633a
[format-command] fixes
actions-bot Feb 5, 2021
8f05c42
Merge branch 'master' into move-plotting-functions
weiji14 Feb 6, 2021
127b428
Simplify import of plotting modules from src
weiji14 Feb 6, 2021
d5f0fc7
Pylint disable protected-access on self._preprocess
weiji14 Feb 6, 2021
e1fc158
Merge branch 'master' into move-plotting-functions
willschlitzer Feb 6, 2021
ed7ef88
Apply suggestions from code review
willschlitzer Feb 6, 2021
5ac2e07
Delete base_plotting.py and move function imports to figure.py
willschlitzer Feb 6, 2021
175c9ba
Run make format
willschlitzer Feb 6, 2021
ddebe30
Merge branch 'master' into move-plotting-functions
willschlitzer Feb 7, 2021
bed53e7
Update pygmt/src/text.py
willschlitzer Feb 7, 2021
698b3d1
Add explanation for why the function is named "text_"
willschlitzer Feb 7, 2021
8973d83
Fix style issue
willschlitzer Feb 7, 2021
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
1,645 changes: 0 additions & 1,645 deletions pygmt/base_plotting.py

This file was deleted.

21 changes: 19 additions & 2 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
except ImportError:
Image = None

from pygmt.base_plotting import BasePlotting
from pygmt.clib import Session
from pygmt.exceptions import GMTError, GMTInvalidInput
from pygmt.helpers import (
Expand All @@ -27,7 +26,7 @@
SHOWED_FIGURES = []


class Figure(BasePlotting):
class Figure:
"""
A GMT figure to handle all plotting.

Expand Down Expand Up @@ -372,3 +371,21 @@ def _repr_html_(self):
base64_png = base64.encodebytes(raw_png)
html = '<img src="data:image/png;base64,{image}" width="{width}px">'
return html.format(image=base64_png.decode("utf-8"), width=500)

from pygmt.src import ( # pylint: disable=import-outside-toplevel
basemap,
coast,
colorbar,
contour,
grdcontour,
grdimage,
grdview,
image,
inset,
legend,
logo,
meca,
plot,
plot3d,
text,
)
13 changes: 13 additions & 0 deletions pygmt/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
Source code for PyGMT modules.
"""
# pylint: disable=import-outside-toplevel
from pygmt.src.basemap import basemap
from pygmt.src.blockmedian import blockmedian
from pygmt.src.coast import coast
from pygmt.src.colorbar import colorbar
from pygmt.src.contour import contour
from pygmt.src.grdcontour import grdcontour
from pygmt.src.grdcut import grdcut
from pygmt.src.grdfilter import grdfilter
from pygmt.src.grdimage import grdimage
from pygmt.src.grdtrack import grdtrack
from pygmt.src.grdview import grdview
from pygmt.src.image import image
from pygmt.src.info import info
from pygmt.src.inset import inset
from pygmt.src.legend import legend
from pygmt.src.logo import logo
from pygmt.src.makecpt import makecpt
from pygmt.src.meca import meca
from pygmt.src.plot import plot
from pygmt.src.plot3d import plot3d
from pygmt.src.surface import surface
from pygmt.src.text import text_ as text # "text" is an argument within "text_"
from pygmt.src.which import which
78 changes: 78 additions & 0 deletions pygmt/src/basemap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
basemap - Plot base maps and frames for the figure.
"""

from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import (
args_in_kwargs,
build_arg_string,
fmt_docstring,
kwargs_to_strings,
use_alias,
)


@fmt_docstring
@use_alias(
R="region",
J="projection",
Jz="zscale",
JZ="zsize",
B="frame",
L="map_scale",
Td="rose",
Tm="compass",
U="timestamp",
V="verbose",
X="xshift",
Y="yshift",
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", p="sequence")
def basemap(self, **kwargs):
"""
Plot base maps and frames for the figure.

Creates a basic or fancy basemap with axes, fill, and titles. Several
map projections are available, and the user may specify separate
tick-mark intervals for boundary annotation, ticking, and [optionally]
gridlines. A simple map scale or directional rose may also be plotted.

At least one of the options *frame*, *map_scale*, *rose* or *compass*
must be specified.

Full option list at :gmt-docs:`basemap.html`

{aliases}

Parameters
----------
{J}
zscale/zsize : float or str
Set z-axis scaling or z-axis size.
{R}
{B}
map_scale : str
``'[g|j|J|n|x]refpoint'``
Draws a simple map scale centered on the reference point specified.
rose : str
Draws a map directional rose on the map at the location defined by
the reference and anchor points.
compass : str
Draws a map magnetic rose on the map at the location defined by the
reference and anchor points
{U}
{V}
{XY}
{p}
{t}
"""
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
if not args_in_kwargs(args=["B", "L", "Td", "Tm"], kwargs=kwargs):
raise GMTInvalidInput(
"At least one of frame, map_scale, compass, or rose must be specified."
)
with Session() as lib:
lib.call_module("basemap", build_arg_string(kwargs))
196 changes: 196 additions & 0 deletions pygmt/src/coast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
"""
coast - Plot land and water.
"""

from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import (
args_in_kwargs,
build_arg_string,
fmt_docstring,
kwargs_to_strings,
use_alias,
)


@fmt_docstring
@use_alias(
R="region",
J="projection",
A="area_thresh",
C="lakes",
B="frame",
D="resolution",
E="dcw",
I="rivers",
L="map_scale",
N="borders",
W="shorelines",
G="land",
S="water",
U="timestamp",
V="verbose",
X="xshift",
Y="yshift",
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", p="sequence")
def coast(self, **kwargs):
r"""
Plot continents, shorelines, rivers, and borders on maps

Plots grayshaded, colored, or textured land-masses [or water-masses] on
maps and [optionally] draws coastlines, rivers, and political
boundaries. Alternatively, it can (1) issue clip paths that will
contain all land or all water areas, or (2) dump the data to an ASCII
table. The data files come in 5 different resolutions: (**f**)ull,
(**h**)igh, (**i**)ntermediate, (**l**)ow, and (**c**)rude. The full
resolution files amount to more than 55 Mb of data and provide great
detail; for maps of larger geographical extent it is more economical to
use one of the other resolutions. If the user selects to paint the
land-areas and does not specify fill of water-areas then the latter
will be transparent (i.e., earlier graphics drawn in those areas will
not be overwritten). Likewise, if the water-areas are painted and no
land fill is set then the land-areas will be transparent.

A map projection must be supplied.

Full option list at :gmt-docs:`coast.html`

{aliases}

Parameters
----------
{J}
{R}
area_thresh : int, float, or str
*min_area*\ [/*min_level*/*max_level*][**+ag**\|\ **i**\
\|\ **s**\|\ **S**][**+r**\|\ **l**][**+p**\
*percent*].
Features with an area smaller than min_area in km^2 or of
hierarchical level that is lower than min_level or higher than
max_level will not be plotted.
{B}
lakes : str or list
*fill*\ [**+l**\|\ **+r**].
Set the shade, color, or pattern for lakes and river-lakes. The
default is the fill chosen for wet areas set by the ``water``
argument. Optionally, specify separate fills by appending
**+l** for lakes or **+r** for river-lakes, and passing multiple
strings in a list.
resolution : str
**f**\|\ **h**\|\ **i**\|\ **l**\|\ **c**.
Selects the resolution of the data set to: (**f**\ )ull,
(**h**\ )igh, (**i**\ )ntermediate, (**l**\ )ow,
and (**c**\ )rude.
land : str
Select filling or clipping of “dry” areas.
rivers : int or str or list
*river*\ [/*pen*].
Draw rivers. Specify the type of rivers and [optionally] append
pen attributes [Default pen: width = default, color = black,
style = solid].

Choose from the list of river types below; pass a list to
``rivers`` to use multiple arguments.

0 = Double-lined rivers (river-lakes)

1 = Permanent major rivers

2 = Additional major rivers

3 = Additional rivers

4 = Minor rivers

5 = Intermittent rivers - major

6 = Intermittent rivers - additional

7 = Intermittent rivers - minor

8 = Major canals

9 = Minor canals

10 = Irrigation canals

You can also choose from several preconfigured river groups:

a = All rivers and canals (0-10)

A = All rivers and canals except river-lakes (1-10)

r = All permanent rivers (0-4)

R = All permanent rivers except river-lakes (1-4)

i = All intermittent rivers (5-7)

c = All canals (8-10)
map_scale : str
[**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*.
Draws a simple map scale centered on the reference point specified.
borders : int or str or list
*border*\ [/*pen*].
Draw political boundaries. Specify the type of boundary and
[optionally] append pen attributes [Default pen: width = default,
color = black, style = solid].

Choose from the list of boundaries below. Pass a list to
``borders`` to use multiple arguments.

1 = National boundaries

2 = State boundaries within the Americas

3 = Marine boundaries

a = All boundaries (1-3)
water : str
Select filling or clipping of “wet” areas.
{U}
shorelines : int or str or list
[*level*\ /]\ *pen*.
Draw shorelines [Default is no shorelines]. Append pen attributes
[Defaults: width = default, color = black, style = solid] which
apply to all four levels. To set the pen for a single level,
pass a string with *level*\ /*pen*\ , where level is
1-4 and represent coastline, lakeshore, island-in-lake shore, and
lake-in-island-in-lake shore. Pass a list of *level*\ /*pen*
strings to ``shorelines`` to set multiple levels. When specific
level pens are set, those not listed will not be drawn.
dcw : str or list
*code1,code2,…*\ [**+l**\|\ **L**\ ][**+g**\ *fill*\ ]
[**+p**\ *pen*\ ][**+z**].
Select painting or dumping country polygons from the
`Digital Chart of the World
<https://en.wikipedia.org/wiki/Digital_Chart_of_the_World>`__.
Append one or more comma-separated countries using the 2-character
`ISO 3166-1 alpha-2 convention
<https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>`__.
To select a state of a country (if available), append
.\ *state*, (e.g, US.TX for Texas). To specify a whole continent,
prepend **=** to any of the continent codes (e.g. =EU for Europe).
Append **+p**\ *pen* to draw polygon outlines
(default is no outline) and **+g**\ *fill* to fill them
(default is no fill). Append **+l**\|\ **+L** to *=continent* to
only list countries in that continent; repeat if more than one
continent is requested. Append **+z** to place the country code in
the segment headers via **-Z**\ *code* settings.To apply different
settings to different countries, pass a list of string arguments.
{XY}
{p}
{t}
{V}
"""
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
if not args_in_kwargs(args=["C", "G", "S", "I", "N", "Q", "W"], kwargs=kwargs):
raise GMTInvalidInput(
"""At least one of the following arguments must be specified:
lakes, land, water, rivers, borders, Q, or shorelines"""
)
with Session() as lib:
lib.call_module("coast", build_arg_string(kwargs))
Loading