From af5c4144d2e896871983d98b823c0b452ac46fc6 Mon Sep 17 00:00:00 2001 From: jenniferyee Date: Thu, 7 Dec 2023 10:33:10 -0500 Subject: [PATCH] Updated warning and behavior for negative errorbars in plotting. (moved from PlotUtils to private function in MulensData) --- source/MulensModel/mulensdata.py | 21 +++++++++++++++------ source/MulensModel/utils.py | 13 ++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source/MulensModel/mulensdata.py b/source/MulensModel/mulensdata.py index db6a79fdf..e5de250a1 100644 --- a/source/MulensModel/mulensdata.py +++ b/source/MulensModel/mulensdata.py @@ -450,17 +450,26 @@ def _plot_datapoints( if show_errorbars: if np.any(y_err[self.good] < 0.): - warnings.warn("Cannot plot errorbars with negative values. " - "Skipping dataset: " + self._get_name()) - return + ind_neg_err = np.where((y_err < 0.) & self.good) + warnings.warn( + "Some points have errorbars with negative values. " + + "Setting to zero. \n" + + "Dataset: " + self._get_name() + + "\nEpochs: {0}".format(self.time[ind_neg_err])) + y_err[ind_neg_err] = 0. + container = self._plt_errorbar(time_good, y_good, y_err[self.good], properties) if show_bad: if np.any(y_err[self.bad] < 0.): + ind_neg_err = np.where((y_err < 0.) & self.bad) warnings.warn( - "Cannot plot errorbars with negative values (bad " - "data). Skipping dataset: " + self._get_name()) - return + "Some (bad data) points have errorbars with " + + "negative values. Setting to zero. \n" + + "Dataset: " + self._get_name() + + "\nEpochs: {0}".format(self.time[ind_neg_err])) + y_err[ind_neg_err] = 0. + if not ('color' in properties_bad or 'c' in properties_bad): properties_bad['color'] = container[0].get_color() diff --git a/source/MulensModel/utils.py b/source/MulensModel/utils.py index 7e78f8876..3361fce94 100644 --- a/source/MulensModel/utils.py +++ b/source/MulensModel/utils.py @@ -371,23 +371,14 @@ def get_y_value_y_err(phot_fmt, flux, flux_err): """ if phot_fmt == 'mag': - (y_value, y_err) = Utils.get_mag_and_err_from_flux(flux, flux_err) + return Utils.get_mag_and_err_from_flux(flux, flux_err) elif phot_fmt == 'flux': - (y_value, y_err) = (flux, flux_err) + return (flux, flux_err) else: raise ValueError( 'Unrecognized photometry format: {:}, '.format(phot_fmt) + 'allowed values are "mag" and "flux"') - index = (y_err < 0) - if np.sum(index) > 0: - if not isinstance(y_err, np.ndarray): - y_err = np.array(y_err) - - y_err[index] = 0 - - return (y_value, y_err) - get_y_value_y_err = staticmethod(get_y_value_y_err) def find_subtract(subtract_2450000=False, subtract_2460000=False):