Skip to content

Commit

Permalink
improve robustness against input parameter type or dtype (scalar/arra…
Browse files Browse the repository at this point in the history
…y, dtype)
  • Loading branch information
ghislainp committed Aug 23, 2019
1 parent a4c2ac9 commit bcffc5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions smrt/core/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __init__(self, frequency=None, theta_inc_deg=None, theta_deg=None, phi_deg=N

if theta_deg is None:
raise SMRTError("Sensor requires the argument 'theta_deg' to be set")
self.theta_deg = np.atleast_1d(theta_deg).flatten()
self.theta_deg = np.atleast_1d(theta_deg).flatten().astype(dtype=float)

if len(np.unique(self.theta_deg)) != len(self.theta_deg):
raise SMRTError("Zenith angle theta has duplicated values which is invalid.")
Expand All @@ -158,7 +158,7 @@ def __init__(self, frequency=None, theta_inc_deg=None, theta_deg=None, phi_deg=N
self.mu_s = np.cos(self.theta)

if phi_deg is not None:
self.phi_deg = np.atleast_1d(phi_deg).flatten()
self.phi_deg = np.atleast_1d(phi_deg).flatten().astype(dtype=float)
self.phi = np.radians(self.phi_deg)
else:
self.phi = 0.0
Expand All @@ -167,7 +167,7 @@ def __init__(self, frequency=None, theta_inc_deg=None, theta_deg=None, phi_deg=N
self.theta_inc_deg = None
self.theta_inc = None
else:
self.theta_inc_deg = np.atleast_1d(theta_inc_deg).flatten()
self.theta_inc_deg = np.atleast_1d(theta_inc_deg).flatten().astype(dtype=float)

if len(np.unique(self.theta_inc_deg)) != len(self.theta_inc_deg):
raise SMRTError("Zenith angle theta_inc has duplicated values which is invalid.")
Expand Down
4 changes: 2 additions & 2 deletions smrt/emmodel/iba.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ..core.error import SMRTError
from ..core.globalconstants import C_SPEED
from .effective_permittivity import depolarization_factors, polder_van_santen
from ..core.lib import smrt_matrix, generic_ft_even_matrix
from ..core.lib import smrt_matrix, generic_ft_even_matrix, len_atleast_1d

#
# For developers: all emmodel must implement the `effective_permittivity`, `ke` and `phase` functions with the same arguments as here
Expand Down Expand Up @@ -357,7 +357,7 @@ def ke(self, mu):
streams, which is set by the radiative transfer solver.
"""
return np.full(len(mu), self.ks + self.ka)
return np.full(len_atleast_1d(mu), self.ks + self.ka)

def effective_permittivity(self):
""" Calculation of complex effective permittivity of the medium.
Expand Down

0 comments on commit bcffc5b

Please sign in to comment.