Skip to content

Commit 833e066

Browse files
committed
Simplify to avoid using instance variables
1 parent 9f69b2f commit 833e066

File tree

5 files changed

+281
-185
lines changed

5 files changed

+281
-185
lines changed

sbpy/surfaces/lambertian.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,46 @@
33
import numpy as np
44
import astropy.units as u
55

6-
from .surface import Surface
6+
from .surface import Surface, min_zero_cos
77
from ..units.typing import SpectralFluxDensityQuantity
88

99

1010
class LambertianSurface(Surface):
11-
"""Abstract base class for Lambertian surfaces."""
11+
"""Lambertian surface absorption, emission, and reflectance."""
1212

13+
@staticmethod
1314
@u.quantity_input
1415
def absorption(
15-
self,
1616
F_i: SpectralFluxDensityQuantity,
17+
epsilon: float,
1718
i: u.physical.angle,
1819
) -> u.Quantity:
19-
# use self._min_zero_cos(i) to ensure cos(>= 90 deg) = 0
20-
cos_i = self._min_zero_cos(i)
21-
return F_i * (1 - self.phys["albedo"]) * cos_i
20+
# use min_zero_cos(i) to ensure cos(>= 90 deg) = 0
21+
cos_i = min_zero_cos(i)
22+
return F_i * epsilon * cos_i
2223

24+
@staticmethod
2325
@u.quantity_input
2426
def emission(
25-
self,
2627
X_e: SpectralFluxDensityQuantity,
28+
epsilon: float,
2729
e: u.physical.angle,
2830
phi: u.physical.angle,
2931
) -> u.Quantity:
30-
# use self._min_zero_cos(e) to ensure cos(>= 90 deg) = 0
31-
cos_e = self._min_zero_cos(e)
32-
return X_e * cos_e / np.pi / u.sr
32+
# use min_zero_cos(e) to ensure cos(>= 90 deg) = 0
33+
cos_e = min_zero_cos(e)
34+
return X_e * epsilon * cos_e / np.pi / u.sr
3335

36+
@staticmethod
3437
@u.quantity_input
3538
def reflectance(
36-
self,
3739
F_i: SpectralFluxDensityQuantity,
40+
albedo: float,
3841
i: u.physical.angle,
3942
e: u.physical.angle,
4043
phi: u.physical.angle,
4144
) -> u.Quantity:
42-
# use self._min_zero_cos(theta) to ensure cos(>= 90 deg) = 0
43-
cos_i = self._min_zero_cos(i)
44-
cos_e = self._min_zero_cos(e)
45-
return F_i * self.phys["albedo"] * cos_i * cos_e / np.pi
45+
# use min_zero_cos(theta) to ensure cos(>= 90 deg) = 0
46+
cos_i = min_zero_cos(i)
47+
cos_e = min_zero_cos(e)
48+
return F_i * albedo * cos_i * cos_e / np.pi / u.sr

sbpy/surfaces/scattered.py

Lines changed: 165 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,199 @@
1-
# Licensed under a 3-clause BSD style license - see LICENSE.rst
1+
# # Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3-
import numpy as np
3+
# from abc import ABC, abstractmethod
44

5-
import astropy.units as u
5+
# import numpy as np
66

7-
from .surface import Surface
8-
from .lambertian import LambertianSurface
9-
from ..calib import Sun
10-
from ..units.typing import SpectralQuantity, SpectralFluxDensityQuantity, UnitLike
7+
# import astropy.units as u
118

9+
# from .surface import Surface
10+
# from .lambertian import LambertianSurface
11+
# from ..calib import Sun
12+
# from ..units.typing import SpectralQuantity, SpectralFluxDensityQuantity, UnitLike
1213

13-
class ScatteredSunlight(Surface):
14-
"""Abstract base class to observe sunlight scattered by a surface."""
1514

16-
@u.quantity_input
17-
def scattered_sunlight(
18-
self,
19-
wave_freq: SpectralQuantity,
20-
rh: u.physical.length,
21-
i: u.physical.angle,
22-
e: u.physical.angle,
23-
phi: u.physical.angle,
24-
unit: UnitLike = "W/(m2 sr um)",
25-
) -> u.Quantity:
26-
"""Radiance from sunlight scattered by a surface.
15+
# class ScatteredLight(ABC):
16+
# """Abstract base class to observe light scattered by a surface."""
2717

18+
# @u.quantity_input
19+
# def scattered_light(
20+
# self,
21+
# wave_freq: SpectralQuantity,
22+
# i: u.physical.angle,
23+
# e: u.physical.angle,
24+
# phi: u.physical.angle,
25+
# unit: UnitLike = "W/(m2 sr um)",
26+
# ) -> u.Quantity:
27+
# """Radiance from light scattered by a surface.
2828

29-
Parameters
30-
----------
31-
wave_freq : `astropy.units.Quantity`
32-
Wavelength or frequency at which to evaluate the Sun. Arrays are
33-
evaluated with `sbpy.calib.core.Sun.observe()`.
3429

35-
rh : `~astropy.units.Quantity`
36-
Heliocentric distance.
30+
# Parameters
31+
# ----------
3732

38-
i : `~astropy.units.Quantity`
39-
Angle from normal of incident light.
33+
# wave_freq : `astropy.units.Quantity`
34+
# Wavelength or frequency at which to evaluate the light source.
4035

41-
e : `~astropy.units.Quantity`
42-
Angle from normal of emitted light.
36+
# i : `~astropy.units.Quantity`
37+
# Angle from normal of incident light.
4338

44-
phi : `~astropy.units.Quantity`
45-
Source-target-observer (phase) angle.
39+
# e : `~astropy.units.Quantity`
40+
# Angle from normal of emitted light.
4641

47-
unit : `~astropy.units.Unit`, optional
48-
Unit of the return value.
42+
# phi : `~astropy.units.Quantity`
43+
# Source-target-observer (phase) angle.
4944

45+
# unit : `~astropy.units.Unit`, optional
46+
# Unit of the return value.
5047

51-
Returns
52-
-------
53-
radiance : `~astropy.units.Quantity`
54-
Observed radiance.
5548

56-
"""
49+
# Returns
50+
# -------
5751

58-
sun = Sun.from_default()
59-
flux_density_unit = u.Unit(unit) * u.sr
60-
if wave_freq.size == 1:
61-
F_i = sun(wave_freq, unit=flux_density_unit)
62-
else:
63-
F_i = sun.observe(wave_freq, unit=flux_density_unit)
52+
# radiance : `~astropy.units.Quantity`
53+
# Observed radiance.
6454

65-
F_i /= rh.to_value("au") ** 2
66-
return self.reflectance(F_i, i, e, phi).to(unit)
55+
# """
6756

68-
@u.quantity_input
69-
def scattered_sunlight_from_vectors(
70-
self,
71-
wave_freq: SpectralQuantity,
72-
n: np.ndarray,
73-
rs: u.physical.length,
74-
ro: u.physical.length,
75-
unit: UnitLike = "W/(m2 sr um)",
76-
) -> u.Quantity:
77-
"""Observed sunlight reflected from a surface.
57+
# @u.quantity_input
58+
# def scattered_light_from_vectors(
59+
# self,
60+
# wave_freq: SpectralQuantity,
61+
# n: np.ndarray,
62+
# rs: u.physical.length,
63+
# ro: u.physical.length,
64+
# unit: UnitLike = "W/(m2 sr um)",
65+
# ) -> u.Quantity:
66+
# """Observed light reflected from a surface.
7867

7968

80-
Parameters
81-
----------
82-
wave_freq : `astropy.units.Quantity`
83-
Wavelength or frequency at which to evaluate the Sun. Arrays are
84-
evaluated with `sbpy.calib.core.Sun.observe()`.
69+
# Parameters
70+
# ----------
8571

86-
n : `numpy.ndarray`
87-
Surface normal vector.
72+
# wave_freq : `astropy.units.Quantity`
73+
# Wavelength or frequency at which to evaluate the light source.
8874

89-
rs : `~astropy.units.Quantity`
90-
Radial vector from the surface to the light source.
75+
# n : `numpy.ndarray`
76+
# Surface normal vector.
9177

92-
ro : `~astropy.units.Quantity`
93-
Radial vector from the surface to the observer.
78+
# rs : `~astropy.units.Quantity`
79+
# Radial vector from the surface to the light source.
9480

95-
unit : `~astropy.units.Unit`, optional
96-
Unit of the return value.
81+
# ro : `~astropy.units.Quantity`
82+
# Radial vector from the surface to the observer.
9783

84+
# unit : `~astropy.units.Unit`, optional
85+
# Unit of the return value.
9886

99-
Returns
100-
-------
101-
radiance : `~astropy.units.Quantity`
102-
Observed radiance.
10387

104-
"""
105-
rh = np.linalg.norm(rs).to("au")
106-
i, e, phi = self._vectors_to_angles(n, rs, ro)
107-
return self.scattered_sunlight(wave_freq, rh, i, e, phi, unit=unit)
88+
# Returns
89+
# -------
10890

109-
__doc__ += Surface.__doc__[Surface.__doc__.index("\n") + 1 :] # noqa: E203
91+
# radiance : `~astropy.units.Quantity`
92+
# Observed radiance.
11093

94+
# """
11195

112-
class LambertianSurfaceScatteredSunlight(LambertianSurface, ScatteredSunlight):
113-
"""Sunlight scattered from a Lambertian surface.
11496

115-
The surface is assumed to be illuminated by the Sun.
97+
# class ScatteredSunlight(ScatteredLight):
98+
# """Observe sunlight scattered by a surface."""
11699

117-
"""
100+
# @u.quantity_input
101+
# def scattered_light(
102+
# self,
103+
# wave_freq: SpectralQuantity,
104+
# i: u.physical.angle,
105+
# e: u.physical.angle,
106+
# phi: u.physical.angle,
107+
# rh: u.physical.length = 1 * u.au,
108+
# unit: UnitLike = "W/(m2 sr um)",
109+
# ) -> u.Quantity:
110+
# """Radiance from sunlight scattered by a surface.
118111

119-
__doc__ += Surface.__doc__[Surface.__doc__.index("\n") :] # noqa: E203
112+
113+
# Parameters
114+
# ----------
115+
116+
# wave_freq : `astropy.units.Quantity`
117+
# Wavelength or frequency at which to evaluate the Sun. Arrays are
118+
# evaluated with `sbpy.calib.core.Sun.observe()`.
119+
120+
# i : `~astropy.units.Quantity`
121+
# Angle from normal of incident light.
122+
123+
# e : `~astropy.units.Quantity`
124+
# Angle from normal of emitted light.
125+
126+
# phi : `~astropy.units.Quantity`
127+
# Source-target-observer (phase) angle.
128+
129+
# rh : `~astropy.units.Quantity`
130+
# Heliocentric distance, default = 1 au.
131+
132+
# unit : `~astropy.units.Unit`, optional
133+
# Unit of the return value.
134+
135+
136+
# Returns
137+
# -------
138+
# radiance : `~astropy.units.Quantity`
139+
# Observed radiance.
140+
141+
# """
142+
143+
# sun = Sun.from_default()
144+
# flux_density_unit = u.Unit(unit) * u.sr
145+
# if wave_freq.size == 1:
146+
# F_i = sun(wave_freq, unit=flux_density_unit)
147+
# else:
148+
# F_i = sun.observe(wave_freq, unit=flux_density_unit)
149+
150+
# F_i /= rh.to_value("au") ** 2
151+
# return self.reflectance(F_i, i, e, phi).to(unit)
152+
153+
# @u.quantity_input
154+
# def scattered_light_from_vectors(
155+
# self,
156+
# wave_freq: SpectralQuantity,
157+
# n: np.ndarray,
158+
# rs: u.physical.length,
159+
# ro: u.physical.length,
160+
# unit: UnitLike = "W/(m2 sr um)",
161+
# ) -> u.Quantity:
162+
# """Observed sunlight reflected from a surface.
163+
164+
165+
# Parameters
166+
# ----------
167+
168+
# wave_freq : `astropy.units.Quantity`
169+
# Wavelength or frequency at which to evaluate the Sun. Arrays are
170+
# evaluated with `sbpy.calib.core.Sun.observe()`.
171+
172+
# n : `numpy.ndarray`
173+
# Surface normal vector.
174+
175+
# rs : `~astropy.units.Quantity`
176+
# Radial vector from the surface to the light source.
177+
178+
# ro : `~astropy.units.Quantity`
179+
# Radial vector from the surface to the observer.
180+
181+
# unit : `~astropy.units.Unit`, optional
182+
# Unit of the return value.
183+
184+
185+
# Returns
186+
# -------
187+
188+
# radiance : `~astropy.units.Quantity`
189+
# Observed radiance.
190+
191+
# """
192+
193+
# rh = np.linalg.norm(rs).to("au")
194+
# i, e, phi = self._vectors_to_angles(n, rs, ro)
195+
# return self.scattered_sunlight(wave_freq, i, e, phi, rh=rh, unit=unit)
196+
197+
198+
# class LambertianSurfaceScatteredSunlight(LambertianSurface, ScatteredSunlight):
199+
# """Sunlight scattered from a Lambertian surface."""

0 commit comments

Comments
 (0)