From 3a72ef0ea7142a4653315f00acce76481a28c35e Mon Sep 17 00:00:00 2001 From: Andrej Prsa Date: Wed, 10 Apr 2024 11:41:17 -0400 Subject: [PATCH 1/2] Fixes a cryptic error message when query points are out of bounds. Closes #843. --- phoebe/atmospheres/passbands.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phoebe/atmospheres/passbands.py b/phoebe/atmospheres/passbands.py index d7774f865..fae030baf 100644 --- a/phoebe/atmospheres/passbands.py +++ b/phoebe/atmospheres/passbands.py @@ -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: + 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. @@ -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: + 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): From b5160211fce0667bc6f0447c354857209a7f951f Mon Sep 17 00:00:00 2001 From: Andrej Prsa Date: Wed, 10 Apr 2024 15:12:37 -0400 Subject: [PATCH 2/2] Numpy 1.26+ compatibility fix, passband raise_on_nans fix * In parameters.py, the cast to float64() on arrays is deprecated; fixed. * In the PR change in passbands.py, the 'if' statement was missing an actual test for nans; fixed. * In test_single.py, `times` was passed instead of `compute_times`; fixed. --- phoebe/atmospheres/passbands.py | 4 ++-- phoebe/parameters/parameters.py | 9 +++------ tests/tests/test_single/test_single.py | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/phoebe/atmospheres/passbands.py b/phoebe/atmospheres/passbands.py index fae030baf..6588b0515 100644 --- a/phoebe/atmospheres/passbands.py +++ b/phoebe/atmospheres/passbands.py @@ -1620,7 +1620,7 @@ 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) - if raise_on_nans: + 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) @@ -1849,7 +1849,7 @@ 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: + 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) diff --git a/phoebe/parameters/parameters.py b/phoebe/parameters/parameters.py index 4896e34f6..9d967c8ed 100644 --- a/phoebe/parameters/parameters.py +++ b/phoebe/parameters/parameters.py @@ -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() diff --git a/tests/tests/test_single/test_single.py b/tests/tests/test_single/test_single.py index 3eedd3a89..ab10c3ee1 100644 --- a/tests/tests/test_single/test_single.py +++ b/tests/tests/test_single/test_single.py @@ -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')