Skip to content

Commit 31eef48

Browse files
committed
Update view extension apply method
- allow for optional arguments in apply - raise error if all arguments are None
1 parent 1174848 commit 31eef48

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

pystac/extensions/view.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def __init__(self, item):
2828
self.item = item
2929

3030
def apply(self,
31-
off_nadir=None,
32-
incidence_angle=None,
33-
azimuth=None,
34-
sun_azimuth=None,
35-
sun_elevation=None):
31+
off_nadir: Optional[float] = None,
32+
incidence_angle: Optional[float] = None,
33+
azimuth: Optional[float] = None,
34+
sun_azimuth: Optional[float] = None,
35+
sun_elevation: Optional[float] = None):
3636
"""Applies View Geometry extension properties to the extended Item.
3737
3838
Args:
@@ -49,11 +49,21 @@ def apply(self,
4949
sun_elevation (float): Sun elevation angle. The angle from the tangent of the scene
5050
center point to the sun. Measured from the horizon in degrees (0-90).
5151
"""
52-
self.off_nadir = off_nadir
53-
self.incidence_angle = incidence_angle
54-
self.azimuth = azimuth
55-
self.sun_azimuth = sun_azimuth
56-
self.sun_elevation = sun_elevation
52+
if (off_nadir is None and incidence_angle is None and azimuth is None
53+
and sun_azimuth is None and sun_elevation is None):
54+
raise pystac.STACError(
55+
'Must provide at least one of: off_nadir, incidence_angle, azimuth, sun_azimuth, sun_elevation' # noqa: E501
56+
)
57+
if off_nadir:
58+
self.off_nadir = off_nadir
59+
if incidence_angle:
60+
self.incidence_angle = incidence_angle
61+
if azimuth:
62+
self.azimuth = azimuth
63+
if sun_azimuth:
64+
self.sun_azimuth = sun_azimuth
65+
if sun_elevation:
66+
self.sun_elevation = sun_elevation
5767

5868
@property
5969
def off_nadir(self):

0 commit comments

Comments
 (0)