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

Implement Projection classes to encapsulate arguments #379

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0c969bb
Initial commit for pygmt/projection.py; Contains a generic design/lay…
Nov 17, 2019
16819cc
Updated docstrings for class projection definitions.
Nov 18, 2019
979d057
Initial run of Black to reformat code.
Nov 18, 2019
c1161a3
Renamed lon0 to central_longitude and lat0 to central_latitude.
Nov 19, 2019
29e263d
Added the attribute to give meaning to the width argument (inches or…
Nov 19, 2019
129ae99
Updated example, and cleaned up docstring for unit description.
Nov 19, 2019
adef7ad
Removed center attribute from printed example.
Dec 7, 2019
97c836b
Specifying the projection code directly in the attrib creation, rathe…
Dec 7, 2019
a414f7e
Added the miscellaneous projections group; Mollweide, Sinusoidal, Eck…
Dec 7, 2019
c7ee1a2
Capitalised projection names where required, eg when named after the …
Dec 7, 2019
db7aca6
Added the Polyconic projection.
Dec 7, 2019
825cd66
Added the Miller and oblique 1, 2, 3 projections.
Dec 7, 2019
acaca7d
Added the Transverse Mercator and Universal Transverse Mercator Proje…
Dec 7, 2019
919102d
Added the equidistant cylindrical projection.
Dec 7, 2019
f5897a8
Fixed as per @leouieda suggestions.
Dec 7, 2019
7abe416
Missed one of the fixes as suggested by @leouieda
Dec 8, 2019
45abd59
Changed the default unit of inches to centimetres.
Dec 8, 2019
b9997c1
Removed superfluous comments regarding the private variables.
Dec 8, 2019
f92c7d1
Run Black formatting.
Dec 8, 2019
4161f9e
Update keyword args for the GeneralPerspective projection.
Jan 14, 2020
968b2cd
Initial unittests for the projection class configurations.
Jan 14, 2020
a77fd13
Added Polar and Linear projections. General cleanup.
Dec 18, 2022
d030593
Apply black formatting
Dec 18, 2022
cd38f61
Various reconfigs; some projs have updated, updated some that specifi…
Dec 19, 2022
4793155
Added a bunch more projections to the test suite.
Dec 19, 2022
0f24da2
Reworked the cylindrical projections to cater for the default and non…
Dec 20, 2022
a43d4c8
Added tests for the 3 oblique mercator projection options.
Dec 20, 2022
f39053a
Added tests for UTM, mercator, equidistant cylindrical. Minor additio…
Dec 21, 2022
f386b09
Applied black formatting.
Dec 21, 2022
8995715
Merge branch 'main' into proj-classes
Dec 23, 2022
20693e7
Caught test fails and updated.
Dec 23, 2022
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
Prev Previous commit
Next Next commit
Renamed lon0 to central_longitude and lat0 to central_latitude.
  • Loading branch information
Josh Sixsmith committed Dec 7, 2019
commit c1161a3c99610c174c52e75265b815c42115f7b4
96 changes: 48 additions & 48 deletions pygmt/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
to create a projection and output a valid GMT projection string.

>>> from pygmt import projection
>>> proj = projection.LambertAzimuthalEqualArea(lon0=30, lat0=-20, horizon=60, width="8i")
>>> proj = projection.LambertAzimuthalEqualArea(central_longitude=30, central_latitude=-20, horizon=60, width="8i")
>>> proj
LambertAzimuthalEqualArea(lon0=30, lat0=-20, horizon=60, width='8i')
LambertAzimuthalEqualArea(central_longitude=30, central_latitude=-20, horizon=60, width='8i')
>>> print(proj)
A30/-20/60/8i
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples are better placed in the tutorials, gallery, or class docstrings. This one will never be rendered in the documentation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove the module level example. I'll put some examples together in the tutorials section soon.

"""
Expand Down Expand Up @@ -81,24 +81,24 @@ class _Azimuthal(_Projection):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
horizon : float
The max distance to the projection centre in degrees. Default is 90.
width : str
The figure width. For example ``8i`` is 8 inches.
"""

lon0: float = attr.ib()
lat0: float = attr.ib()
central_longitude: float = attr.ib()
central_latitude: float = attr.ib()
horizon: float = attr.ib(default=90)
width: str = attr.ib()

# private; we don't want the user to care or know about
_fmt: str = attr.ib(
init=False, repr=False, default="{_code}{lon0}/{lat0}/{horizon}/{width}"
init=False, repr=False, default="{_code}{central_longitude}/{central_latitude}/{horizon}/{width}"
)
_code: str = attr.ib(init=False, repr=False, default=Supported.UNDEFINED.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is probably no need to define _code as "undefined" here. It's what has to be implemented by the base classes, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As _Projection, _Azimuthal, _Cylindrical are considered private, I wouldn't expect the user to call them directly. But they could and it would fail if _code is removed, as the _fmt attribute contains {_code}. It is just an empty string placeholder, as such in order to avoid failure from a user calling it explicitly, both the attribute _code and the portion of the str containing {_code} could be removed.
Any thoughts on that approach?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, scratch that, I can't modify the formatter string, as it used by most of the subclasses.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops again. I see what you mean. I'll remove it, and maybe I should get to bed ;)


Expand All @@ -119,20 +119,20 @@ class _Cylindrical(_Projection):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
width : str
The figure width. For example ``8i`` is 8 inches.
"""

lon0: float = attr.ib()
lat0: float = attr.ib()
central_longitude: float = attr.ib()
central_latitude: float = attr.ib()
width: str = attr.ib()

# private; we don't want the user to care or know about
_fmt: str = attr.ib(init=False, repr=False, default="{_code}{lon0}/{lat0}/{wdith}")
_fmt: str = attr.ib(init=False, repr=False, default="{_code}{central_longitude}/{central_latitude}/{wdith}")
_code: str = attr.ib(init=False, repr=False, default=Supported.UNDEFINED.value)


Expand All @@ -144,9 +144,9 @@ class _Conic:

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
lat1 : float
The first standard parallel.
Expand All @@ -156,15 +156,15 @@ class _Conic:
The figure width. For example ``8i`` is 8 inches.
"""

lon0: float = attr.ib()
lat0: float = attr.ib()
central_longitude: float = attr.ib()
central_latitude: float = attr.ib()
lat1: float = attr.ib()
lat2: float = attr.ib()
width: float = attr.ib()

# private; we don't want the user to care or know about
_fmt: str = attr.ib(
init=False, repr=False, default="{_code}{lon0}/{lat0}/{lat1}/{lat2}/{width}"
init=False, repr=False, default="{_code}{central_longitude}/{central_latitude}/{lat1}/{lat2}/{width}"
)


Expand All @@ -176,9 +176,9 @@ class LambertAzimuthalEqualArea(_Azimuthal):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
horizon : float
The max distance to the projection centre in degrees. Default is 90.
Expand All @@ -200,9 +200,9 @@ class AzimuthalEquidistant(_Azimuthal):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
horizon : float
The max distance to the projection centre in degrees. Default is 180.
Expand All @@ -226,9 +226,9 @@ class AzimuthalGnomic(_Azimuthal):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
horizon : float
The max distance to the projection centre in degrees. Default is 60.
Expand Down Expand Up @@ -260,9 +260,9 @@ class AzimuthalOrthographic(_Azimuthal):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
horizon : float
The max distance to the projection centre in degrees. Default is 90.
Expand Down Expand Up @@ -294,9 +294,9 @@ class GeneralPerspective(_Projection):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre (in degrees).
lat0 : float
central_latitude : float
The latitude of the projection centre (in degrees).
altitude : float
The height in km of the viewpoint above local sea level.
Expand All @@ -314,8 +314,8 @@ class GeneralPerspective(_Projection):
The figure width. For example ``8i`` is 8 inches.
"""

lon0: float = attr.ib()
lat0: float = attr.ib()
central_longitude: float = attr.ib()
central_latitude: float = attr.ib()
altitude: float = attr.ib()
azimuth: float = attr.ib()
tilt: float = attr.ib()
Expand All @@ -328,7 +328,7 @@ class GeneralPerspective(_Projection):
_fmt: str = attr.ib(
init=False,
repr=False,
default="{_code}{lon0}/{lat0}/{altitude}/{azimuth}/{tilt}/{twist}/{viewport_width}/{viewport_height}/{width}",
default="{_code}{central_longitude}/{central_latitude}/{altitude}/{azimuth}/{tilt}/{twist}/{viewport_width}/{viewport_height}/{width}",
)
_code: str = attr.ib(
init=False, repr=False, default=Supported.GENERAL_PERSPECTIVE.value
Expand All @@ -343,9 +343,9 @@ class GeneralSterographic(_Azimuthal):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
horizon : float
The max distance to the projection centre in degrees. Default is 90.
Expand Down Expand Up @@ -377,9 +377,9 @@ class AlbersConicEqualArea(_Conic):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
lat1 : float
The first standard parallel.
Expand All @@ -403,9 +403,9 @@ class EquidistantConic(_Conic):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
lat1 : float
The first standard parallel.
Expand All @@ -427,9 +427,9 @@ class CassiniCylindrical(_Cylindrical):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
width : str
The figure width. For example ``8i`` is 8 inches.
Expand All @@ -449,16 +449,16 @@ class MercatorCylindrical(_Cylindrical):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre. Default is 180.
lat0 : float
central_latitude : float
The latitude of the projection centre. Default is 0.
width : str
The figure width. For example ``8i`` is 8 inches.
"""

lon0: float = attr.ib(default=180, kw_only=True)
lat0: float = attr.ib(default=0, kw_only=True)
central_longitude: float = attr.ib(default=180, kw_only=True)
central_latitude: float = attr.ib(default=0, kw_only=True)

# private; we don't want the user to care or know about
_code: str = attr.ib(
Expand All @@ -474,16 +474,16 @@ class CylindricalStereographic(_Cylindrical):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre. Default is 180.
lat0 : float
central_latitude : float
The latitude of the projection centre. Default is 0.
width : str
The figure width. For example ``8i`` is 8 inches.
"""

lon0: float = attr.ib(default=180, kw_only=True)
lat0: float = attr.ib(default=0, kw_only=True)
central_longitude: float = attr.ib(default=180, kw_only=True)
central_latitude: float = attr.ib(default=0, kw_only=True)

# private; we don't want the user to care or know about
_code: str = attr.ib(
Expand All @@ -499,9 +499,9 @@ class CylindricalEqualArea(_Cylindrical):

Parameters
----------
lon0 : float
central_longitude : float
The longitude of the projection centre.
lat0 : float
central_latitude : float
The latitude of the projection centre.
width : str
The figure width. For example ``8i`` is 8 inches.
Expand Down