diff --git a/README.md b/README.md index 6f3651cb..c533ad5c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [**Detailed documentation: https://rpoleski.github.io/MulensModel/**](https://rpoleski.github.io/MulensModel/) -[Latest release: 2.19.0](https://github.com/rpoleski/MulensModel/releases/latest) and we're working on further developing the code. +[Latest release: 2.19.2](https://github.com/rpoleski/MulensModel/releases/latest) and we're working on further developing the code. MulensModel can generate a microlensing light curve for a given set of microlensing parameters, fit that light curve to some data, and return a chi2 value. That chi2 (and its gradient in some cases) can then be input into an arbitrary likelihood function to find the best-fit parameters. diff --git a/source/MulensModel/mulensdata.py b/source/MulensModel/mulensdata.py index e687c4aa..63d0e8d0 100644 --- a/source/MulensModel/mulensdata.py +++ b/source/MulensModel/mulensdata.py @@ -451,26 +451,11 @@ def _plot_datapoints( y_bad = y_value[self.bad] if show_errorbars: - if np.any(y_err[self.good] < 0.): - 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. - + self._mask_negative_errorbars(y_err, kind='good') 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( - "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. + self._mask_negative_errorbars(y_err, kind='bad') if not ('color' in properties_bad or 'c' in properties_bad): properties_bad['color'] = container[0].get_color() @@ -549,6 +534,28 @@ def _set_plot_properties(self, show_errorbars=True, bad=False, **kwargs): return properties + def _mask_negative_errorbars(self, y_err, kind): + """ + Change negative uncertainties to 0. + Parameters kind should be 'good' or 'bad'. + """ + if kind == 'good': + mask = self.good + elif kind == 'bad': + mask = self.bad + else: + raise ValueError('internal error: {:}'.format(kind)) + + if not np.any(y_err[mask] < 0.): + return + + indexes = ((y_err < 0.) & mask) + msg = ("Some {:} data points have scaled errorbars with negative " + "values. Setting them to zero for plotting.\nDataset: {:}\n" + "Epochs: {:}") + warnings.warn(msg.format(kind, self._get_name(), self.time[indexes])) + y_err[indexes] = 0. + def _plt_errorbar(self, time, y, yerr, kwargs): """ save run of matplotlib.pyplot.errorbar(); returns ErrorbarContainer diff --git a/source/MulensModel/version.py b/source/MulensModel/version.py index 4c813929..6e9a2492 100644 --- a/source/MulensModel/version.py +++ b/source/MulensModel/version.py @@ -1 +1 @@ -__version__ = "2.19.1" +__version__ = "2.19.2"