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
Updated docstrings for class projection definitions.
  • Loading branch information
Josh Sixsmith committed Nov 18, 2019
commit 16819cce8440483204a5f175b34f59734995ccff
213 changes: 200 additions & 13 deletions pygmt/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ class _Azimuthal(_Projection):

"""
Base class for azimuthal projections.

Parameters
----------
lon0 : float
The longitude of the projection centre.
lat0 : 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()
Expand Down Expand Up @@ -106,6 +117,15 @@ class _Cylindrical(_Projection):

"""
Base class for cylindrical projections.

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

lon0: float = attr.ib()
Expand All @@ -118,11 +138,25 @@ class _Cylindrical(_Projection):
_code: str = attr.ib(init=False, repr=False,
default=Supported.UNDEFINED.value)


@attr.s(kw_only=True)
class _Conic:

"""
Base class for conic projections.

Parameters
----------
lon0 : float
The longitude of the projection centre.
lat0 : float
The latitude of the projection centre.
lat1 : float
The first standard parallel.
lat2 : float
The second standard parallel.
width : str
The figure width. For example ``8i`` is 8 inches.
"""

lon0: float = attr.ib()
Expand All @@ -140,7 +174,18 @@ class _Conic:
class LambertAzimuthalEqualArea(_Azimuthal):

"""
Definition for the lambert azimuthal equal area projection.
Class definition for the lambert azimuthal equal area projection.

Parameters
----------
lon0 : float
The longitude of the projection centre.
lat0 : 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.
"""

# private; we don't want the user to care or know about
Expand All @@ -152,7 +197,18 @@ class LambertAzimuthalEqualArea(_Azimuthal):
class AzimuthalEquidistant(_Azimuthal):

"""
Definition for the azimuthal equidistant projection.
Class definition for the azimuthal equidistant projection.

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

horizon: float = attr.ib(default=180, kw_only=True)
Expand All @@ -166,14 +222,25 @@ class AzimuthalEquidistant(_Azimuthal):
class AzimuthalGnomic(_Azimuthal):

"""
Definition for the azimuthal gnomic projection.
Class definition for the azimuthal gnomic projection.

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

horizon: float = attr.ib(default=60, kw_only=True)

# private; we don't want the user to care or know about
_code: str = attr.ib(init=False, repr=False,
default=Supported.AZIMUTHAL_EQUIDISTANT.value)
default=Supported.AZIMUTHAL_GNOMIC.value)

@horizon.validator
def check_horizon(self, attribute, value):
Expand All @@ -188,14 +255,25 @@ def check_horizon(self, attribute, value):
class AzimuthalOrthographic(_Azimuthal):

"""
Definition for the azimuthal orthographic projection.
Class definition for the azimuthal orthographic projection.

Parameters
----------
lon0 : float
The longitude of the projection centre.
lat0 : 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.
"""

horizon: float = attr.ib(default=60, kw_only=True)
horizon: float = attr.ib(default=90)

# private; we don't want the user to care or know about
_code: str = attr.ib(init=False, repr=False,
default=Supported.AZIMUTHAL_EQUIDISTANT.value)
default=Supported.AZIMUTHAL_ORTHOGRAPHIC.value)

@horizon.validator
def check_horizon(self, attribute, value):
Expand All @@ -210,7 +288,28 @@ def check_horizon(self, attribute, value):
class GeneralPerspective(_Projection):

"""
Definition for the azimuthal general perspective projection.
Class definition for the azimuthal general perspective projection.

Parameters
----------
lon0 : float
The longitude of the projection centre (in degrees).
lat0 : float
The latitude of the projection centre (in degrees).
altitude : float
The height in km of the viewpoint above local sea level.
azimuth : float
The direction (in degrees) in which you are looking is specified, measured clockwise from north.
tilt : float
The viewing angle relative to zenith (in degrees).
twist : float
The clockwise rotation of the image (in degrees).
viewport_width : float
The width of the viewing angle (in degrees).
viewport_height : float
The height of the viewing angle (in degrees).
width : str
The figure width. For example ``8i`` is 8 inches.
"""

lon0: float = attr.ib()
Expand All @@ -225,8 +324,7 @@ class GeneralPerspective(_Projection):

# private; we don't want the user to care or know about
_fmt: str = attr.ib(init=False, repr=False,
default=("{_code}{lon0}/{lat0}/{altitude}/{azimuth}/"
"{tilt}/{twist}/{Width}/{Height}/{width}"))
default="{_code}{lon0}/{lat0}/{altitude}/{azimuth}/{tilt}/{twist}/{viewport_width}/{viewport_height}/{width}")
_code: str = attr.ib(init=False, repr=False,
default=Supported.GENERAL_PERSPECTIVE.value)

Expand All @@ -235,7 +333,18 @@ class GeneralPerspective(_Projection):
class GeneralSterographic(_Azimuthal):

"""
Definition for the azimuthal general sterographic projection.
Class definition for the azimuthal general sterographic projection.

Parameters
----------
lon0 : float
The longitude of the projection centre.
lat0 : 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.
"""

horizon: float = attr.ib(default=90, kw_only=True)
Expand All @@ -257,7 +366,20 @@ def check_horizon(self, attribute, value):
class AlbersConicEqualArea(_Conic):

"""
Definition for the albers conic equal area projection.
Class definition for the albers conic equal area projection.

Parameters
----------
lon0 : float
The longitude of the projection centre.
lat0 : float
The latitude of the projection centre.
lat1 : float
The first standard parallel.
lat2 : float
The second standard parallel.
width : str
The figure width. For example ``8i`` is 8 inches.
"""

# private; we don't want the user to care or know about
Expand All @@ -269,7 +391,20 @@ class AlbersConicEqualArea(_Conic):
class EquidistantConic(_Conic):

"""
Definition for the equidistant conic projection.
Class definition for the equidistant conic projection.

Parameters
----------
lon0 : float
The longitude of the projection centre.
lat0 : float
The latitude of the projection centre.
lat1 : float
The first standard parallel.
lat2 : float
The second standard parallel.
width : str
The figure width. For example ``8i`` is 8 inches.
"""

# private; we don't want the user to care or know about
Expand All @@ -280,6 +415,19 @@ class EquidistantConic(_Conic):
@attr.s(frozen=True)
class CassiniCylindrical(_Cylindrical):

"""
Class definition for the cassini cylindrical projection.

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

# private; we don't want the user to care or know about
_code: str = attr.ib(init=False, repr=False,
default=Supported.CASSINI_CYLINDRICAL.value)
Expand All @@ -288,6 +436,19 @@ class CassiniCylindrical(_Cylindrical):
@attr.s(frozen=True)
class MercatorCylindrical(_Cylindrical):

"""
Class definition for the cassini cylindrical projection.

Parameters
----------
lon0 : float
The longitude of the projection centre. Default is 180.
lat0 : 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)

Expand All @@ -299,6 +460,19 @@ class MercatorCylindrical(_Cylindrical):
@attr.s(frozen=True)
class CylindricalStereographic(_Cylindrical):

"""
Class definition for the cassini cylindrical projection.

Parameters
----------
lon0 : float
The longitude of the projection centre. Default is 180.
lat0 : 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)

Expand All @@ -310,6 +484,19 @@ class CylindricalStereographic(_Cylindrical):
@attr.s(frozen=True)
class CylindricalEqualArea(_Cylindrical):

"""
Class definition for the cassini cylindrical projection.

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

# private; we don't want the user to care or know about
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# private; we don't want the user to care or know about

No need to repeat the same comment everywhere. In fact, _ is commonly used in Python to indicate "private" so there is no need for this comment at all. In general, our rule is that it's better to have code that doesn't need comments.

Copy link
Author

Choose a reason for hiding this comment

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

Fair comment. I'll remove them.

_code: str = attr.ib(init=False, repr=False,
default=Supported.CYLINDRICAL_EQUAL_AREA.value)