Skip to content

Commit

Permalink
Updated warning and behavior for negative errorbars in plotting. (mov…
Browse files Browse the repository at this point in the history
…ed from PlotUtils to private function in MulensData)
  • Loading branch information
jenniferyee committed Dec 7, 2023
1 parent de817cc commit af5c414
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
21 changes: 15 additions & 6 deletions source/MulensModel/mulensdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
13 changes: 2 additions & 11 deletions source/MulensModel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit af5c414

Please sign in to comment.