Skip to content
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

Fixes a cryptic error message when query points are out of bounds. #844

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion phoebe/atmospheres/passbands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,9 @@ def _log10_Inorm(self, query_pts, atm, intens_weighting='photon', atm_extrapolat
"""

log10_Inorm = self.ndp[atm].ndpolate(f'inorm@{intens_weighting}', query_pts, extrapolation_method=atm_extrapolation_method)
# log10_Inorm, nanmask = ndp.interp(req, raise_on_nans=raise_on_nans, return_nanmask=True, extrapolation_method=atm_extrapolation_method)
if raise_on_nans and np.any(np.isnan(log10_Inorm)):
raise ValueError(f'normal intensity interpolation failed: queried atmosphere values are out of bounds and atm_extrapolation_method={atm_extrapolation_method}.')

nanmask = np.zeros_like(log10_Inorm)
# nanmask is a mask of elements that were nans before extrapolation.

Expand Down Expand Up @@ -1847,6 +1849,9 @@ def _log10_Imu(self, atm, query_pts, intens_weighting='photon', atm_extrapolatio
"""

log10_Imu = self.ndp[atm].ndpolate(f'imu@{intens_weighting}', query_pts, extrapolation_method=atm_extrapolation_method)
if raise_on_nans and np.any(np.isnan(log10_Imu)):
raise ValueError(f'specific intensity interpolation failed: queried atmosphere values are out of bounds and atm_extrapolation_method={atm_extrapolation_method}.')

nanmask = np.zeros_like(log10_Imu)

if ~np.any(nanmask):
Expand Down
9 changes: 3 additions & 6 deletions phoebe/parameters/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11939,14 +11939,11 @@ def eq_needs_builtin(eq, include_math=True):
return False

def get_values(vars, safe_label=True, string_safe_arrays=False, use_distribution=None, needs_builtin=False):
# use np.float64 so that dividing by zero will result in a
# np.inf
def _single_value(quantity, string_safe_arrays=False):
if isinstance(quantity, u.Quantity):
if self.in_solar_units:
v = np.float64(u.to_solar(quantity).value)
else:
v = np.float64(quantity.si.value)
v = u.to_solar(quantity).value if self.in_solar_units else quantity.si.value
# cast to np.float64 so that dividing by zero will result in a np.inf
v = v.astype(np.float64) if isinstance(v, np.ndarray) else np.float64(v)

if isinstance(v, np.ndarray) and string_safe_arrays:
v = v.tolist()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_single/test_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_sun(plot=False):
assert b.get_value('distance', u.m) == 1.0*u.AU.to(u.m)

b.add_dataset('lc', pblum=1*u.solLum)
b.add_dataset('mesh', times=[0], columns=['teffs', 'areas', 'volume'], dataset='mesh01')
b.add_dataset('mesh', compute_times=[0], columns=['teffs', 'areas', 'volume'], dataset='mesh01')

b.run_compute(irrad_method='none', distortion_method='rotstar')

Expand Down