From 182afdcb4af47dce35fdca57cffb8beea2b0d1df Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Tue, 23 Apr 2024 15:05:16 +0200 Subject: [PATCH 1/4] First changes to add plotting model in fluxes, issue #129 --- source/MulensModel/model.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/source/MulensModel/model.py b/source/MulensModel/model.py index 02eda247..f3d845a0 100644 --- a/source/MulensModel/model.py +++ b/source/MulensModel/model.py @@ -301,7 +301,7 @@ def _parse_fluxes_for_get_lc(self, source_flux, source_flux_ratio, return (source_flux, source_flux_ratio, blend_flux) def _get_lc(self, times, t_range, t_start, t_stop, dt, n_epochs, gamma, - source_flux, blend_flux, return_times=False): + source_flux, blend_flux, phot_fmt='mag', return_times=False): """ calculate magnitudes without making checks on input parameters @@ -329,17 +329,25 @@ def _get_lc(self, times, t_range, t_start, t_stop, dt, n_epochs, gamma, flux += blend_flux - magnitudes = Utils.get_mag_from_flux(flux) + if phot_fmt == 'mag': + mag_or_flux = Utils.get_mag_from_flux(flux) + elif phot_fmt == 'flux': + mag_or_flux = flux + else: + raise ValueError( + 'phot_fmt must be one of "mag", "flux", or "scaled". Your ' + + 'value: {0}'.format(phot_fmt)) if return_times: - return (times, magnitudes) + return (times, mag_or_flux) else: - return magnitudes + return mag_or_flux def plot_lc( self, times=None, t_range=None, t_start=None, t_stop=None, dt=None, n_epochs=None, source_flux=None, blend_flux=None, source_flux_ratio=None, gamma=None, bandpass=None, + phot_fmt='mag', subtract_2450000=False, subtract_2460000=False, data_ref=None, flux_ratio_constraint=None, fit_blending=None, f_source=None, f_blend=None, @@ -416,16 +424,19 @@ def plot_lc( gamma = self._get_limb_coeff_gamma(bandpass, gamma) self._check_gamma_for_2_sources(gamma) - (times, magnitudes) = self._get_lc( + (times, mag_or_flux) = self._get_lc( times=times, t_range=t_range, t_start=t_start, t_stop=t_stop, dt=dt, n_epochs=n_epochs, gamma=gamma, source_flux=source_flux, - blend_flux=blend_flux, return_times=True) + blend_flux=blend_flux, phot_fmt=phot_fmt, return_times=True) subtract = PlotUtils.find_subtract(subtract_2450000=subtract_2450000, subtract_2460000=subtract_2460000) - self._plt_plot(times-subtract, magnitudes, kwargs) - plt.ylabel('Magnitude') + self._plt_plot(times-subtract, mag_or_flux, kwargs) + if phot_fmt == 'mag': + plt.ylabel('Magnitude') + elif phot_fmt == 'flux': + plt.ylabel('Flux') plt.xlabel( PlotUtils.find_subtract_xlabel( subtract_2450000=subtract_2450000, From a5941fa36536fb0bcc5e78f139c13187c148223e Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Wed, 24 Apr 2024 18:01:25 +0200 Subject: [PATCH 2/4] Arranged phot_fmt keyword, examples are ok, issue #129 --- source/MulensModel/model.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/MulensModel/model.py b/source/MulensModel/model.py index f3d845a0..fdc1575d 100644 --- a/source/MulensModel/model.py +++ b/source/MulensModel/model.py @@ -301,7 +301,7 @@ def _parse_fluxes_for_get_lc(self, source_flux, source_flux_ratio, return (source_flux, source_flux_ratio, blend_flux) def _get_lc(self, times, t_range, t_start, t_stop, dt, n_epochs, gamma, - source_flux, blend_flux, phot_fmt='mag', return_times=False): + source_flux, blend_flux, return_times=False, phot_fmt="mag"): """ calculate magnitudes without making checks on input parameters @@ -347,10 +347,9 @@ def plot_lc( self, times=None, t_range=None, t_start=None, t_stop=None, dt=None, n_epochs=None, source_flux=None, blend_flux=None, source_flux_ratio=None, gamma=None, bandpass=None, - phot_fmt='mag', subtract_2450000=False, subtract_2460000=False, data_ref=None, flux_ratio_constraint=None, - fit_blending=None, f_source=None, f_blend=None, + fit_blending=None, f_source=None, f_blend=None, phot_fmt="mag", **kwargs): """ Plot the model light curve in magnitudes. @@ -387,6 +386,10 @@ def plot_lc( f_source, f_blend: DEPRECATED use *source_flux* or *blend_flux* instead. + phot_fmt: *str* + Specifies whether the photometry is provided in magnitude or + flux space. Accepts either 'mag' or 'flux'. Default = 'mag'. + ``**kwargs``: any arguments accepted by :py:func:`matplotlib.pyplot.plot()`. """ @@ -427,7 +430,7 @@ def plot_lc( (times, mag_or_flux) = self._get_lc( times=times, t_range=t_range, t_start=t_start, t_stop=t_stop, dt=dt, n_epochs=n_epochs, gamma=gamma, source_flux=source_flux, - blend_flux=blend_flux, phot_fmt=phot_fmt, return_times=True) + blend_flux=blend_flux, return_times=True, phot_fmt=phot_fmt) subtract = PlotUtils.find_subtract(subtract_2450000=subtract_2450000, subtract_2460000=subtract_2460000) @@ -443,7 +446,7 @@ def plot_lc( subtract_2460000=subtract_2460000)) (ymin, ymax) = plt.gca().get_ylim() - if ymax > ymin: + if ymax > ymin and phot_fmt == 'mag': plt.gca().invert_yaxis() def _plt_plot(self, x, y, kwargs): From ca9b04dc0461438222020223d07d309394471ad7 Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Thu, 25 Apr 2024 12:55:54 +0200 Subject: [PATCH 3/4] Small changes and two functions shortened, issue #129 --- source/MulensModel/model.py | 39 ++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/source/MulensModel/model.py b/source/MulensModel/model.py index fdc1575d..dca6a535 100644 --- a/source/MulensModel/model.py +++ b/source/MulensModel/model.py @@ -303,7 +303,7 @@ def _parse_fluxes_for_get_lc(self, source_flux, source_flux_ratio, def _get_lc(self, times, t_range, t_start, t_stop, dt, n_epochs, gamma, source_flux, blend_flux, return_times=False, phot_fmt="mag"): """ - calculate magnitudes without making checks on input parameters + calculate magnitude or flux without making checks on input parameters source_flux is a *float* (for single source model) or an iterable (for multiple sources) @@ -329,6 +329,13 @@ def _get_lc(self, times, t_range, t_start, t_stop, dt, n_epochs, gamma, flux += blend_flux + return self._return_mag_or_flux(times, flux, return_times, phot_fmt) + + def _return_mag_or_flux(self, times, flux, return_times, phot_fmt): + """ + Obtain what is returned in function _get_lc, where phot_fmt and + return_times are explicitly given + """ if phot_fmt == 'mag': mag_or_flux = Utils.get_mag_from_flux(flux) elif phot_fmt == 'flux': @@ -387,7 +394,7 @@ def plot_lc( use *source_flux* or *blend_flux* instead. phot_fmt: *str* - Specifies whether the photometry is provided in magnitude or + Specifies whether the photometry is plotted in magnitude or flux space. Accepts either 'mag' or 'flux'. Default = 'mag'. ``**kwargs``: @@ -436,6 +443,23 @@ def plot_lc( subtract_2460000=subtract_2460000) self._plt_plot(times-subtract, mag_or_flux, kwargs) + self._plt_settings(phot_fmt, subtract_2450000, subtract_2460000) + + def _plt_plot(self, x, y, kwargs): + """ + safe run of matplotlib.pyplot.plot() + """ + try: + plt.plot(x, y, **kwargs) + except Exception: + print("kwargs passed to plt.plot():") + print(kwargs) + raise + + def _plt_settings(self, phot_fmt, subtract_2450000, subtract_2460000): + """ + Arrange the plot settings, regarding axes labels and ranges + """ if phot_fmt == 'mag': plt.ylabel('Magnitude') elif phot_fmt == 'flux': @@ -449,17 +473,6 @@ def plot_lc( if ymax > ymin and phot_fmt == 'mag': plt.gca().invert_yaxis() - def _plt_plot(self, x, y, kwargs): - """ - safe run of matplotlib.pyplot.plot() - """ - try: - plt.plot(x, y, **kwargs) - except Exception: - print("kwargs passed to plt.plot():") - print(kwargs) - raise - def plot_caustics(self, n_points=5000, epoch=None, **kwargs): """ Plot the caustic structure. See From b485b167495040787d18188691a5ae693cb5b516 Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Fri, 26 Apr 2024 10:42:35 +0200 Subject: [PATCH 4/4] Updated version number and changed names --- source/MulensModel/model.py | 6 +++--- source/MulensModel/version.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/MulensModel/model.py b/source/MulensModel/model.py index dca6a535..1c57ea56 100644 --- a/source/MulensModel/model.py +++ b/source/MulensModel/model.py @@ -443,7 +443,7 @@ def plot_lc( subtract_2460000=subtract_2460000) self._plt_plot(times-subtract, mag_or_flux, kwargs) - self._plt_settings(phot_fmt, subtract_2450000, subtract_2460000) + self._plot_axes(phot_fmt, subtract_2450000, subtract_2460000) def _plt_plot(self, x, y, kwargs): """ @@ -456,9 +456,9 @@ def _plt_plot(self, x, y, kwargs): print(kwargs) raise - def _plt_settings(self, phot_fmt, subtract_2450000, subtract_2460000): + def _plot_axes(self, phot_fmt, subtract_2450000, subtract_2460000): """ - Arrange the plot settings, regarding axes labels and ranges + Adjust axes labels and ranges, given the inputs phot_fmt and subtract """ if phot_fmt == 'mag': plt.ylabel('Magnitude') diff --git a/source/MulensModel/version.py b/source/MulensModel/version.py index 73636577..0ca05961 100644 --- a/source/MulensModel/version.py +++ b/source/MulensModel/version.py @@ -1 +1 @@ -__version__ = "2.21.4" +__version__ = "2.22.0"