-
Notifications
You must be signed in to change notification settings - Fork 213
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
0c969bb
16819cc
979d057
c1161a3
29e263d
129ae99
adef7ad
97c836b
a414f7e
c7ee1a2
db7aca6
825cd66
acaca7d
919102d
f5897a8
7abe416
45abd59
b9997c1
f92c7d1
4161f9e
968b2cd
a77fd13
d030593
cd38f61
4793155
0f24da2
a43d4c8
f39053a
f386b09
8995715
20693e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -65,8 +65,7 @@ class _Projection: | |||
|
||||
# private; we don't want the user to care or know about | ||||
_fmt: str = attr.ib(init=False, repr=False, default="{_code}") | ||||
_code: str = attr.ib(init=False, repr=False, | ||||
default=Supported.UNDEFINED.value) | ||||
_code: str = attr.ib(init=False, repr=False, default=Supported.UNDEFINED.value) | ||||
|
||||
def __str__(self): | ||||
maxrjones marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
exclude = attr.fields(self.__class__)._fmt | ||||
|
@@ -98,10 +97,10 @@ class _Azimuthal(_Projection): | |||
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}") | ||||
_code: str = attr.ib(init=False, repr=False, | ||||
default=Supported.UNDEFINED.value) | ||||
_fmt: str = attr.ib( | ||||
init=False, repr=False, default="{_code}{lon0}/{lat0}/{horizon}/{width}" | ||||
) | ||||
_code: str = attr.ib(init=False, repr=False, default=Supported.UNDEFINED.value) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is probably no need to define There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ;) |
||||
|
||||
@horizon.validator | ||||
def check_horizon(self, attribute, value): | ||||
|
@@ -133,10 +132,8 @@ class _Cylindrical(_Projection): | |||
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}") | ||||
_code: str = attr.ib(init=False, repr=False, | ||||
default=Supported.UNDEFINED.value) | ||||
_fmt: str = attr.ib(init=False, repr=False, default="{_code}{lon0}/{lat0}/{wdith}") | ||||
_code: str = attr.ib(init=False, repr=False, default=Supported.UNDEFINED.value) | ||||
|
||||
|
||||
@attr.s(kw_only=True) | ||||
|
@@ -166,8 +163,9 @@ class _Conic: | |||
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}") | ||||
_fmt: str = attr.ib( | ||||
init=False, repr=False, default="{_code}{lon0}/{lat0}/{lat1}/{lat2}/{width}" | ||||
) | ||||
|
||||
|
||||
@attr.s(frozen=True) | ||||
|
@@ -189,8 +187,9 @@ class LambertAzimuthalEqualArea(_Azimuthal): | |||
""" | ||||
|
||||
# private; we don't want the user to care or know about | ||||
_code: str = attr.ib(init=False, repr=False, | ||||
default=Supported.LAMBERT_AZIMUTH_EQUAL_AREA.value) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.LAMBERT_AZIMUTH_EQUAL_AREA.value | ||||
) | ||||
|
||||
|
||||
@attr.s(frozen=True) | ||||
|
@@ -214,8 +213,9 @@ class AzimuthalEquidistant(_Azimuthal): | |||
horizon: float = attr.ib(default=180, 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) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.AZIMUTHAL_EQUIDISTANT.value | ||||
) | ||||
|
||||
|
||||
@attr.s(frozen=True) | ||||
|
@@ -239,8 +239,9 @@ class AzimuthalGnomic(_Azimuthal): | |||
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_GNOMIC.value) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.AZIMUTHAL_GNOMIC.value | ||||
) | ||||
|
||||
@horizon.validator | ||||
def check_horizon(self, attribute, value): | ||||
|
@@ -272,8 +273,9 @@ class AzimuthalOrthographic(_Azimuthal): | |||
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_ORTHOGRAPHIC.value) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.AZIMUTHAL_ORTHOGRAPHIC.value | ||||
) | ||||
|
||||
@horizon.validator | ||||
def check_horizon(self, attribute, value): | ||||
|
@@ -323,10 +325,14 @@ class GeneralPerspective(_Projection): | |||
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}/{altitude}/{azimuth}/{tilt}/{twist}/{viewport_width}/{viewport_height}/{width}") | ||||
_code: str = attr.ib(init=False, repr=False, | ||||
default=Supported.GENERAL_PERSPECTIVE.value) | ||||
_fmt: str = attr.ib( | ||||
init=False, | ||||
repr=False, | ||||
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 | ||||
) | ||||
|
||||
|
||||
@attr.s(frozen=True) | ||||
|
@@ -350,8 +356,9 @@ class GeneralSterographic(_Azimuthal): | |||
horizon: float = attr.ib(default=90, 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.GENERAL_STEREOGRAPHIC.value) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.GENERAL_STEREOGRAPHIC.value | ||||
) | ||||
|
||||
@horizon.validator | ||||
def check_horizon(self, attribute, value): | ||||
|
@@ -383,8 +390,9 @@ class AlbersConicEqualArea(_Conic): | |||
""" | ||||
|
||||
# private; we don't want the user to care or know about | ||||
_code: str = attr.ib(init=False, repr=False, | ||||
default=Supported.ALBERS_CONIC_EQUAL_AREA.value) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.ALBERS_CONIC_EQUAL_AREA.value | ||||
) | ||||
|
||||
|
||||
@attr.s(frozen=True, kw_only=True) | ||||
|
@@ -408,8 +416,7 @@ class EquidistantConic(_Conic): | |||
""" | ||||
|
||||
# private; we don't want the user to care or know about | ||||
_code: str = attr.ib(init=False, repr=False, | ||||
default=Supported.EQUIDISTANT_CONIC) | ||||
_code: str = attr.ib(init=False, repr=False, default=Supported.EQUIDISTANT_CONIC) | ||||
|
||||
|
||||
@attr.s(frozen=True) | ||||
|
@@ -429,8 +436,9 @@ class CassiniCylindrical(_Cylindrical): | |||
""" | ||||
|
||||
# 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) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.CASSINI_CYLINDRICAL.value | ||||
) | ||||
|
||||
|
||||
@attr.s(frozen=True) | ||||
|
@@ -453,8 +461,9 @@ class MercatorCylindrical(_Cylindrical): | |||
lat0: float = attr.ib(default=0, 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.MERCATOR_CYLINDRICAL.value) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.MERCATOR_CYLINDRICAL.value | ||||
) | ||||
|
||||
|
||||
@attr.s(frozen=True) | ||||
|
@@ -477,8 +486,9 @@ class CylindricalStereographic(_Cylindrical): | |||
lat0: float = attr.ib(default=0, 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.CYLINDRICAL_STEROGRAPHIC.value) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.CYLINDRICAL_STEROGRAPHIC.value | ||||
) | ||||
|
||||
|
||||
@attr.s(frozen=True) | ||||
|
@@ -498,5 +508,6 @@ class CylindricalEqualArea(_Cylindrical): | |||
""" | ||||
|
||||
# private; we don't want the user to care or know about | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No need to repeat the same comment everywhere. In fact, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||
_code: str = attr.ib( | ||||
init=False, repr=False, default=Supported.CYLINDRICAL_EQUAL_AREA.value | ||||
) |
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.
_code
and_fmt
are the main things that child classes need to specify, right? If so, they should abstract in the base class. To do that, the_Projection
and_Azimuthal
et al should probably be abstract base classes.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.
I'm not sure how well an
ABC
will work with a child class being defined viaattrs
. From the docs,attrs
trawls the class hierarchy and collects all attributes, and then writes its' own methods to access the required attributes.So setting an attribute on a child class on a property defined via an
ABC
fails.eg:
Calling:
A way around this would be to create a different attribute and define a property that returns it, but I think it then adds additional complexity to the class definition when you need to define the attribute.
eg
Was this along the lines of what you meant when defining the base classes to be an abstract base class?
I'll admit I haven't done much with them since making the move to attrs.