Skip to content

Commit

Permalink
rename private method X._func to public method X.phase_function
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelquast committed Feb 6, 2024
1 parent 3ec9eac commit 64c1943
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
10 changes: 7 additions & 3 deletions src/rt1_model/_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,11 @@ def calc(self, **params):
{
*self._all_param_symbs,
*map(
str, [*self.V._func.free_symbols, *self.SRF._func.free_symbols]
str,
[
*self.V.phase_function.free_symbols,
*self.SRF.phase_function.free_symbols,
],
),
}
- {"phi_0", "phi_ex", "theta_0", "theta_ex"}
Expand Down Expand Up @@ -1415,7 +1419,7 @@ def _d_volume_dummy_lambda(self, key):

return _lambdify(
args,
sp.diff(self.V._func, sp.Symbol(key)),
sp.diff(self.V.phase_function, sp.Symbol(key)),
)

def _d_surface_ddummy(self, key):
Expand Down Expand Up @@ -1486,7 +1490,7 @@ def _d_surface_dummy_lambda(self, key):

return _lambdify(
args,
sp.diff(self.SRF._func, sp.Symbol(key)),
sp.diff(self.SRF.phase_function, sp.Symbol(key)),
)

def jacobian(self, param_list=["omega", "tau", "NormBRDF"], format="list"):
Expand Down
18 changes: 9 additions & 9 deletions src/rt1_model/_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ def _lambda_func(self, *args):

# replace arguments and evaluate expression
args = (theta_0, theta_ex, phi_0, phi_ex) + tuple(args)
pfunc = _lambdify(args, self._func)
pfunc = _lambdify(args, self.phase_function)

# TODO check requirement for this!
# if _func is a constant, lambdify will create a function that returns a scalar
# if phase_function is a constant, lambdify will create a function that returns a scalar
# which is not suitable for further processing. in that case, vectorize the
# obtained function

# TODO maybe find a better check for this
# if self._func.is_constant(): # this is too slow!
# if len(self._func.free_symbols) == 0:
# if self.phase_function.is_constant(): # this is too slow!
# if len(self.phase_function.free_symbols) == 0:
# pfunc = np.vectorize(pfunc)

return pfunc
Expand Down Expand Up @@ -246,13 +246,13 @@ def __init__(self, choices=None, **kwargs):
super().__init__(**kwargs)

@property
def _func(self):
"""Phase function as sympy object for later evaluation."""
_func = 0
def phase_function(self):
"""Phase function as sympy expression for later evaluation."""
func = 0
for c, o in zip(self._weights, self._objs):
_func += c * o._func
func += c * o.phase_function

return _func
return func

@property
def ncoefs(self):
Expand Down
6 changes: 4 additions & 2 deletions src/rt1_model/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def polarplot(
param_dict = [param_dict]

# Check if all required parameters have been provided in the param_dict
required_symbs = set(map(str, V_SRF._func.free_symbols)) - {
required_symbs = set(map(str, V_SRF.phase_function.free_symbols)) - {
"phi_0",
"phi_ex",
"theta_0",
Expand Down Expand Up @@ -397,7 +397,9 @@ def _check_params(R, param_dict, additional_params=[]):
# check if all required parameters for the analyzers have been defined
symbs = {
*R._all_param_symbs,
*map(str, [*R.V._func.free_symbols, *R.SRF._func.free_symbols]),
*map(
str, [*R.V.phase_function.free_symbols, *R.SRF.phase_function.free_symbols]
),
} - {"phi_0", "phi_ex", "theta_0", "theta_ex"}
for p in additional_params:
symbs.add(p)
Expand Down
10 changes: 5 additions & 5 deletions src/rt1_model/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def legendre_coefficients(self):
...

@abstractmethod
def _func(self):
def phase_function(self):
"""Phase function as sympy object."""
...

Expand Down Expand Up @@ -93,7 +93,7 @@ def legendre_coefficients(self):
return (1.0 / sp.pi) * sp.KroneckerDelta(0, n)

@property
def _func(self):
def phase_function(self):
"""Phase function as sympy object."""
return 1.0 / sp.pi

Expand Down Expand Up @@ -141,7 +141,7 @@ def legendre_coefficients(self):
)

@property
def _func(self):
def phase_function(self):
"""Phase function as sympy object."""
return (
1.0
Expand Down Expand Up @@ -178,7 +178,7 @@ def __init__(self, t=None, **kwargs):
self.t = _parse_sympy_param(t)

@property
def _func(self):
def phase_function(self):
"""Phase function as sympy object."""

return (
Expand Down Expand Up @@ -221,7 +221,7 @@ def __init__(self, t=None, **kwargs):
self.t = _parse_sympy_param(t)

@property
def _func(self):
def phase_function(self):
"""Define Phase function as sympy object."""

nadir_hemreflect = 4 * (
Expand Down
20 changes: 10 additions & 10 deletions src/rt1_model/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def legendre_coefficients(self):
...

@abstractmethod
def _func(self):
"""Phase function as sympy object."""
def phase_function(self):
"""Phase function as sympy expression."""
...


Expand Down Expand Up @@ -92,8 +92,8 @@ def legendre_coefficients(self):
return (1.0 / (4.0 * sp.pi)) * sp.KroneckerDelta(0, n)

@property
def _func(self):
"""Phase function as sympy object."""
def phase_function(self):
"""Phase function as sympy expression."""
return 1.0 / (4.0 * sp.pi)


Expand All @@ -118,8 +118,8 @@ def ncoefs(self):
return 3

@property
def _func(self):
"""Phase function as sympy object."""
def phase_function(self):
"""Phase function as sympy expression."""
return 3.0 / (16.0 * sp.pi) * (1.0 + self.scat_angle_symbolic**2.0)

@property
Expand Down Expand Up @@ -160,8 +160,8 @@ def __init__(self, t=None, **kwargs):
self.t = _parse_sympy_param(t)

@property
def _func(self):
"""Phase function as sympy object."""
def phase_function(self):
"""Phase function as sympy expression."""
func = (1.0 - self.t**2.0) / (
(4.0 * sp.pi)
* (1.0 + self.t**2.0 - 2.0 * self.t * self.scat_angle_symbolic) ** 1.5
Expand Down Expand Up @@ -201,8 +201,8 @@ def __init__(self, t=None, **kwargs):
self.t = _parse_sympy_param(t)

@property
def _func(self):
"""Phase function as sympy object."""
def phase_function(self):
"""Phase function as sympy expression."""
return (
3.0
/ (8.0 * sp.pi)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_volume_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_surface_init(backend):

SRF.calc(0.1, 0.2, 0.3, 0.4)
SRF.legendre_expansion(0.1, 0.2, 0.3, 0.4)
SRF._func
SRF.phase_function


@pytest.mark.parametrize("backend", ["sympy", "symengine"])
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_volume_init(backend):
# evaluate function numerical
V.calc(0.1, 0.2, 0.3, 0.4)
V.legendre_expansion(0.1, 0.2, 0.3, 0.4)
V._func
V.phase_function


@pytest.mark.parametrize("backend", ["sympy", "symengine"])
Expand All @@ -110,7 +110,7 @@ def test_linear_combinations_SRF(backend):

SRF.calc(0.1, 0.2, 0.3, 0.4)
SRF.legendre_expansion(0.1, 0.2, 0.3, 0.4)
SRF._func
SRF.phase_function


@pytest.mark.parametrize("backend", ["sympy", "symengine"])
Expand All @@ -135,4 +135,4 @@ def test_linear_combinations_V(backend):

V.calc(0.1, 0.2, 0.3, 0.4)
V.legendre_expansion(0.1, 0.2, 0.3, 0.4)
V._func
V.phase_function

0 comments on commit 64c1943

Please sign in to comment.