From c746d46c09b6bc4e97efbb6a65ceaed42fe03c11 Mon Sep 17 00:00:00 2001 From: mjmroz Date: Wed, 13 Nov 2024 21:15:56 +0100 Subject: [PATCH 01/26] added interactive best model plot --- examples/example_16/ob03235_2_full.yaml | 3 +- .../example_16/ob08092-o4_minimal_plot.yaml | 1 + examples/example_16/ulens_model_fit.py | 559 +++++++++++++++++- 3 files changed, 561 insertions(+), 2 deletions(-) diff --git a/examples/example_16/ob03235_2_full.yaml b/examples/example_16/ob03235_2_full.yaml index 23780c8e1..4cb7eb305 100644 --- a/examples/example_16/ob03235_2_full.yaml +++ b/examples/example_16/ob03235_2_full.yaml @@ -1,6 +1,6 @@ photometry_files: - {file_name: data/OB03235/OB03235_OGLE.txt, bandpass: I, plot_properties: {zorder: 10., color: red, label: "OGLE I-band"}, scale_errorbars: {factor: 1.5, minimum: 0.001}} - - {file_name: data/OB03235/OB03235_MOA.txt, phot_fmt: flux} + - {file_name: data/OB03235/OB03235_MOA.txt, phot_fmt: flux, scale_errorbars: {factor: 1., minimum: 0.}} # To add satellite ephemeris: # - {file_name: some_K2_data.txt, phot_fmt: flux, bandpass: 'Kp', ephemerides_file: K2_ephemeris_01.dat} # For files with time starting with 245...: @@ -120,6 +120,7 @@ plots: best model: # You can skip the line below - the light curve will be plotted on screen. file: ob03235_2_model.png + interactive : ob03235_2_model.html time range: 2452820 2452855 magnitude range: 19.3 16.9 rcParams: diff --git a/examples/example_16/ob08092-o4_minimal_plot.yaml b/examples/example_16/ob08092-o4_minimal_plot.yaml index 8b7978e14..0761140cb 100644 --- a/examples/example_16/ob08092-o4_minimal_plot.yaml +++ b/examples/example_16/ob08092-o4_minimal_plot.yaml @@ -20,3 +20,4 @@ fitting_parameters: plots: best model: file: ob08092-o4_minimal_plot.png + interactive: ob08092-o4_minimal_plot.html diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 5bdfe6d28..0a960d071 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -14,6 +14,8 @@ from matplotlib import pyplot as plt from matplotlib import gridspec, rcParams, rcParamsDefault # from matplotlib.backends.backend_pdf import PdfPages +import plotly.graph_objects as go +from MulensModel.utils import PlotUtils import_failed = set() try: @@ -351,6 +353,7 @@ class UlensModelFit(object): 'time range': 2456050. 2456300. 'best model': 'file': 'my_fit_best.png' + 'interactive' : 'my_fit_best.html' 'time range': 2456000. 2456300. 'magnitude range': 15.123 13.012 'legend': @@ -792,7 +795,7 @@ def _check_plots_parameters_best_model(self): Check if parameters of best model make sense """ allowed = set(['file', 'time range', 'magnitude range', 'legend', - 'rcParams', 'second Y scale']) + 'rcParams', 'second Y scale', 'interactive']) unknown = set(self._plots['best model'].keys()) - allowed if len(unknown) > 0: raise ValueError( @@ -823,6 +826,9 @@ def _check_plots_parameters_best_model(self): args = [key, type(self._plots['best model'][key])] raise TypeError(msg.format(*args)) + if 'interactive' in self._plots['best model']: + self._check_plots_parameters_best_model_interactive() + if 'second Y scale' in self._plots['best model']: self._check_plots_parameters_best_model_Y_scale() @@ -846,6 +852,17 @@ def _set_time_range_for_plot(self, plot_type): "plot:\n" + text[0] + " " + text[1]) self._plots[plot_type]['time range'] = [t_0, t_1] + def _check_plots_parameters_best_model_interactive(self): + """ + Check if there is no problem with interactive best plot + """ + if 'file' not in self._plots['best model']: + raise ValueError( + "When choosing to create an interactive plot of the best model," + + " a regular plot must also be generated. " + + + "Please specify the 'best model' 'file' in YAML input.") + def _check_plots_parameters_best_model_Y_scale(self): """ Check if parameters for second Y scale make sense. @@ -3335,6 +3352,8 @@ def _make_plots(self): self._trace_plot() if 'best model' in self._plots: self._best_model_plot() + if 'interactive' in self._plots['best model']: + self._make_interactive_plot() if 'trajectory' in self._plots: self._make_trajectory_plot() @@ -3795,6 +3814,544 @@ def _make_trajectory_plot(self): self._save_figure(self._plots['trajectory'].get('file'), dpi=dpi) + def _get_kwargs_for_plotly_plot(self, scale): + """_ + setting kwargs for interactive plot + """ + sizes = np.array([ + 10., # markers data points + 4., # model line + 4., # residuals error thickens + 4., # residuals error width + 56., # font label + 3., # zero-line width in residuals + 8., # markers residuals + 4., # axes and legend border width + 15., # ticks len + 30., # font lagend + ]) + sizes = sizes*scale + + kwargs_interactive = dict( + sizes=sizes, + colors=['black', # axes + 'black', # font + '#b9b9b9' # legend border + ], + opacity=0.7, + width=1920*scale, + height=1440*scale, + font='Old Standard TT, serif', + paper_bgcolor='white', + ) + + return kwargs_interactive + + def _make_interactive_layout( + self, + ylim, + ylim_residuals, + height_ratios, + hspace, + sizes, + colors, + opacity, + width, + height, + font, + paper_bgcolor, + t_start, + t_stop, + subtract_2450000=None, + subtract_2460000=None, + **kwargs): + """ + Creates plotly.graph_objects.Layout object analogues to best model plot + """ + hsplit = height_ratios[1] / height_ratios[0] + subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + + xtitle = 'Time' + if subtract > 0.: + xtitle = xtitle+' - {:d}'.format(int(subtract)) + + t_start = t_start - subtract + t_stop = t_stop - subtract + + layout = go.Layout( + autosize=True, + width=width, + height=height, + showlegend=True, + legend=dict( + x=1.02, + y=.98, + bgcolor=paper_bgcolor, + bordercolor=colors[2], + borderwidth=sizes[7], + font=dict( + family=font, + size=sizes[9]) + ), + paper_bgcolor=paper_bgcolor, + plot_bgcolor=paper_bgcolor, + font=dict( + family=font, + size=sizes[4], + color=colors[1] + ), + yaxis=dict( + title_text='Magnitude', + domain=[hsplit+(hspace/2), 1], + # anchor="y", + showgrid=False, + mirror='all', + ticks='inside', + showline=True, + ticklen=sizes[8], + tickwidth=sizes[7], + linewidth=sizes[7], + linecolor=colors[0], + range=ylim, + tickfont=dict( + family=font, + size=sizes[4], + color=colors[1] + ), + ), + yaxis2=dict( + title_text='Residuals', + domain=[0, hsplit-(hspace/2)], + anchor="x", + showgrid=False, + mirror='all', + ticks='inside', + ticklen=sizes[8], + linewidth=sizes[7], + tickwidth=sizes[7], + showline=True, + linecolor=colors[0], + range=ylim_residuals, + tickfont=dict( + family=font, + size=sizes[4], + color=colors[1] + ), + ), + xaxis=dict( + anchor="y", + showgrid=False, + mirror='ticks', + side='top', + ticks='inside', + scaleanchor='x2', + matches='x2', + showline=True, + ticklen=sizes[8], + linecolor=colors[0], + linewidth=sizes[7], + tickwidth=sizes[7], + showticklabels=False, + range=[t_start, t_stop], + tickfont=dict( + family=font, + size=sizes[4], + color=colors[1] + ), + ), + xaxis2=dict( + title_text=xtitle, + anchor="y2", + showgrid=False, + mirror='all', + ticks='inside', + scaleanchor='x', + matches='x', + showline=True, + ticklen=sizes[8], + linecolor=colors[0], + tickwidth=sizes[7], + linewidth=sizes[7], + range=[t_start, t_stop], + tickfont=dict( + family=font, + size=sizes[4], + color=colors[1] + ), + ), + ) + return layout + + def _make_interactive_lc_traces( + self, + f_source_0, f_blend_0, + sizes, + colors, + opacity, + width, + height, + font, + paper_bgcolor, + t_start, + t_stop, + name=None, + dash='solid', + subtract_2450000=None, + subtract_2460000=None, + gamma=None, + bandpass=None, + **kwargs): + """ + Creates plotly.graph_objects.Scatter object with model light-curve + """ + traces_lc = [] + times = np.linspace(t_start, t_stop, num=20000) + subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + + if isinstance(name, type(None)): + showlegend = False + else: + showlegend = True + + for dataset in self._datasets: + if dataset.ephemerides_file is None: + lc = self._model.get_lc( + times=times, source_flux=f_source_0, blend_flux=f_blend_0, + gamma=gamma, bandpass=bandpass) + times = times - subtract + traces_lc.append(go.Scatter(x=times, + y=lc, + name=name, + showlegend=showlegend, + mode='lines', + line=dict( + color=colors[1], + width=sizes[1], + dash=dash, + ), + xaxis="x", + yaxis="y", + )) + return traces_lc + + for (i, model) in enumerate(self._models_satellite): + name = self._event.datasets[i].plot_properties['label'] + model.parameters.parameters = {**self._model.parameters.parameters} + lc = self._model.get_lc(times=times, source_flux=f_source_0, + blend_flux=f_blend_0, + gamma=gamma, bandpass=bandpass) + times = times - subtract + traces_lc.append(go.Scatter(x=times, + y=lc, + name=name, + mode='lines', + showlegend=True, + line=dict( + color=colors[1], + width=sizes[1], + dash=dash, + ), + xaxis="x", + yaxis="y", + )) + + return traces_lc + + def _make_one_interactive_data_trace( + self, + dataset_index, + times, + y_value, + y_err, + xaxis, + yaxis, + showlegend, + colors, + sizes, + opacity, + show_errorbars=None, + show_bad=None, + **kwargs): + """ + Creates plotly.graph_objects.Scatter object with + data points form a given data set + """ + trace_data = [] + dataset = self._event.datasets[dataset_index] + + if show_errorbars is None: + show_errorbars = dataset.plot_properties.get( + 'show_errorbars', True) + + if show_bad is None: + show_bad = dataset.plot_properties.get('show_bad', False) + + times_good = times[dataset.good] + times_bad = times[dataset.bad] + y_good = y_value[dataset.good] + y_bad = y_value[dataset.bad] + y_err_good = y_err[dataset.good] + y_err_bad = y_err[dataset.bad] + + trace_data_good = go.Scatter( + x=times_good, + y=y_good, + opacity=opacity, + name=dataset.plot_properties['label'], + + mode='markers', + showlegend=showlegend, + error_y=dict( + type='data', + array=y_err_good, + visible=show_errorbars, + thickness=sizes[2], + width=sizes[3]), + marker=dict( + color=dataset.plot_properties['color'], + size=sizes[0], + line=dict( + color=dataset.plot_properties['color'], + width=1, + ), + ), + xaxis=xaxis, + yaxis=yaxis, + ) + trace_data.append(trace_data_good) + if show_bad: + trace_data_bad = go.Scatter( + x=times_bad, + y=y_bad, + opacity=opacity, + name=dataset.plot_properties['label'], + legendgroup=str(dataset_index), + mode='markers', + showlegend=showlegend, + error_y=dict( + type='data', + array=y_err_bad, + visible=False, + thickness=sizes[2], + width=sizes[3]), + marker=dict( + color='black', + size=sizes[0]*0.8, + line=dict( + color='black', + width=1, + ), + ), + xaxis=xaxis, + yaxis=yaxis, + ) + + trace_data.append(trace_data_bad) + + return trace_data + + def _make_interactive_data_traces( + self, + kwargs_interactive, + phot_fmt='mag', + data_ref=None, + show_errorbars=False, + show_bad=None, + subtract_2450000=False, + subtract_2460000=False, + **kwargs, + ): + """ + Creates plotly.graph_objects.Scatter object for observation points + per each data set. + """ + traces_data = [] + self._event._set_default_colors() # For each dataset + if self._event.fits is None: + self._event.get_chi2() + + if data_ref is None: + data_ref = self._event.data_ref + + subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + + # Get fluxes for the reference dataset + (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) + for (dataset_index, data) in enumerate(self._datasets): + # Scale the data flux + (flux, err_flux) = self._event.fits[dataset_index].scale_fluxes( + f_source_0, f_blend_0) + (y_value, y_err) = PlotUtils.get_y_value_y_err( + phot_fmt, flux, err_flux) + times = data.time-subtract + trace_data = self._make_one_interactive_data_trace( + dataset_index, + times, + y_value, + y_err, + xaxis='x', + yaxis='y', + showlegend=True, + show_errorbars=show_errorbars, + show_bad=show_bad, + **kwargs_interactive, + ) + traces_data.extend(trace_data) + return traces_data + + def _make_interactive_residuals_traces( + self, + kwargs_interactive, + phot_fmt='mag', + data_ref=None, + show_errorbars=True, + show_bad=None, + subtract_2450000=False, + subtract_2460000=False, + **kwargs,): + """ + Creates plotly.graph_objects.Scatter object for residuals points + per each data set. + """ + traces_residuals = [] + self._event._set_default_colors() # For each dataset + if self._event.fits is None: + self._event.get_chi2() + + if data_ref is None: + data_ref = self._event.data_ref + + subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + + # Get fluxes for the reference dataset + (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) + kwargs_residuals = {'phot_fmt': 'scaled', 'bad': False, + 'source_flux': f_source_0, 'blend_flux': f_blend_0} + if show_bad: + kwargs_residuals['bad'] = True + + for (dataset_index, data) in enumerate(self._datasets): + # Scale the data flux + (y_value, y_err) = self._event.fits[dataset_index].get_residuals( + **kwargs_residuals) + times = data.time-subtract + trace_residuals = self._make_one_interactive_data_trace( + dataset_index, + times, + y_value, + y_err, + xaxis='x2', + yaxis='y2', + showlegend=False, + show_errorbars=show_errorbars, + show_bad=show_bad, + **kwargs_interactive, + ) + traces_residuals.extend(trace_residuals) + + return traces_residuals + + def _make_interactive_zero_trace( + self, t_start, t_stop, colors, sizes, + subtract_2450000=False, subtract_2460000=False, + **kwargs): + """ + Creates plotly.graph_objects.Scatter object for line y=0 in + residuals plot + """ + subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + times = np.linspace(t_start, t_stop, num=2000) + line = np.zeros(len(times)) + trace_0 = go.Scatter( + x=times-subtract, + y=line, + mode='lines', + line=dict( + color=colors[0], + width=sizes[1], + dash='dash', + ), + xaxis="x2", + yaxis="y2", + showlegend=False, + ) + return trace_0 + + def _save_interactive_fig(self): + """ + Saving interactive figure + """ + file = self._plots['best model']['interactive'] + if path.exists(file): + if path.isfile(file): + msg = "Existing file " + file + " will be overwritten" + warnings.warn(msg) + self._interactive_fig.write_html(file, full_html=True) + + def _get_time_span_data(self): + """ + Returning time span of datasets + + """ + t_min = np.zeros(len(self._datasets)) + t_max = np.zeros(len(self._datasets)) + for (i, data) in enumerate(self._datasets): + t_min[i] = min(data.time) + t_max[i] = max(data.time) + + return (min(t_min), max(t_max)) + + def _make_interactive_plot(self): + """ + plot best model and residuals interactively + """ + scale = 0.5 # original size=(1920:1440) + + self._ln_like(self._best_model_theta) # Sets all parameters to + # the best model. + + self._reset_rcParams() + if 'rcParams' in self._plots['best model']: + for (key, value) in self._plots['best model']['rcParams'].items(): + rcParams[key] = value + + kwargs_all = self._get_kwargs_for_best_model_plot() + (kwargs_grid, kwargs_model, kwargs, xlim, t_1, t_2) = kwargs_all[:6] + (kwargs_axes_1, kwargs_axes_2) = kwargs_all[6:] + (ylim, ylim_residuals) = self._get_ylim_for_best_model_plot(t_1, t_2) + kwargs_interactive = self._get_kwargs_for_plotly_plot(scale) + layout = self._make_interactive_layout(ylim, ylim_residuals, + **kwargs_grid, + **kwargs_model, + **kwargs_interactive) + t_data_start, t_data_stop = self._get_time_span_data() + kwargs_model['t_start'] = t_data_start + kwargs_model['t_stop'] = t_data_stop + data_ref = self._event.data_ref + (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) + traces_lc = self._make_interactive_lc_traces(f_source_0, f_blend_0, + **kwargs_model, + **kwargs_interactive,) + self._interactive_fig = go.Figure(data=traces_lc, layout=layout) + + trace_0 = (self._make_interactive_zero_trace( + **kwargs_model, **kwargs_interactive)) + self._interactive_fig.add_trace(trace_0) + + traces_data = self._make_interactive_data_traces( + kwargs_interactive, + **kwargs) + for trace in traces_data: + self._interactive_fig.add_trace(trace) + + traces_residuals = self._make_interactive_residuals_traces( + kwargs_interactive, + **kwargs_model) + for trace in traces_residuals: + self._interactive_fig.add_trace(trace) + + self._save_interactive_fig() + if __name__ == '__main__': if len(sys.argv) != 2: From 463dc6ed71344a4a1c5122dffede396118868ce5 Mon Sep 17 00:00:00 2001 From: mjmroz <92979576+mjmroz@users.noreply.github.com> Date: Wed, 13 Nov 2024 21:22:56 +0100 Subject: [PATCH 02/26] minor update --- examples/example_16/ob03235_2_full.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_16/ob03235_2_full.yaml b/examples/example_16/ob03235_2_full.yaml index 4cb7eb305..233a25629 100644 --- a/examples/example_16/ob03235_2_full.yaml +++ b/examples/example_16/ob03235_2_full.yaml @@ -1,6 +1,6 @@ photometry_files: - {file_name: data/OB03235/OB03235_OGLE.txt, bandpass: I, plot_properties: {zorder: 10., color: red, label: "OGLE I-band"}, scale_errorbars: {factor: 1.5, minimum: 0.001}} - - {file_name: data/OB03235/OB03235_MOA.txt, phot_fmt: flux, scale_errorbars: {factor: 1., minimum: 0.}} + - {file_name: data/OB03235/OB03235_MOA.txt, phot_fmt: flux} # To add satellite ephemeris: # - {file_name: some_K2_data.txt, phot_fmt: flux, bandpass: 'Kp', ephemerides_file: K2_ephemeris_01.dat} # For files with time starting with 245...: From 1572393df49ef0f37584b9a469a94336b53a6179 Mon Sep 17 00:00:00 2001 From: mjmroz Date: Wed, 13 Nov 2024 21:59:41 +0100 Subject: [PATCH 03/26] minor update --- examples/example_16/ulens_model_fit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 0a960d071..04c45164d 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -331,8 +331,8 @@ class UlensModelFit(object): ``trajectory``, and ``best model``. The values are also dicts and currently accepted keys are: 1) for ``best model``: - ``'file'``, ``'time range'``, ``'magnitude range'``, ``'legend'``, - and ``'rcParams'``, + ``'file'``,``'interactive' ``'time range'``, ``'magnitude range'``, + ``'legend'``,`and ``'rcParams'``, 2) for ``triangle`` and ``trace``: ``'file'`` and ``'shift t_0'`` (*bool*, *True* is default) 3) for ``trajectory``: @@ -858,8 +858,8 @@ def _check_plots_parameters_best_model_interactive(self): """ if 'file' not in self._plots['best model']: raise ValueError( - "When choosing to create an interactive plot of the best model," + - " a regular plot must also be generated. " + + "When choosing to create an interactive plot of the best" + + " model, a regular plot must also be generated. " + "Please specify the 'best model' 'file' in YAML input.") From 4829d1235378aaef27fc557c77eda074a54b9ffe Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sat, 16 Nov 2024 08:23:24 +0100 Subject: [PATCH 04/26] ex16: turning on errorbars in interactive mode --- examples/example_16/ulens_model_fit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 04c45164d..413ab826c 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -4155,7 +4155,7 @@ def _make_interactive_data_traces( kwargs_interactive, phot_fmt='mag', data_ref=None, - show_errorbars=False, + show_errorbars=True, show_bad=None, subtract_2450000=False, subtract_2460000=False, From 4f3cab113db81336d8a0f6321f6b03f8c32394d7 Mon Sep 17 00:00:00 2001 From: mjmroz Date: Sun, 17 Nov 2024 15:14:46 +0100 Subject: [PATCH 05/26] Splitting functions into shorter ones, moved plotly import, enabled only interactive plots. --- .../ob08092-o4_minimal_interactive_plot.yaml | 21 ++ .../example_16/ob08092-o4_minimal_plot.yaml | 5 +- examples/example_16/ulens_model_fit.py | 325 ++++++++++-------- 3 files changed, 199 insertions(+), 152 deletions(-) create mode 100644 examples/example_16/ob08092-o4_minimal_interactive_plot.yaml diff --git a/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml b/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml new file mode 100644 index 000000000..33464da3c --- /dev/null +++ b/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml @@ -0,0 +1,21 @@ +photometry_files: data/OB08092/phot_ob08092_O4.dat +# Define model to be plotted: +model: + parameters: t_0 u_0 t_E + values: 2455379.5716130617 0.5236953977433282 17.926270401551196 +# Three sections below will be ignored by the plotting script: +starting_parameters: + t_0: gauss 2455380. 0.1 + u_0: uniform 0.001 1. + t_E: gauss 20. 5. +min_values: + u_0: 0. + t_E: 0. +fitting_parameters: + n_walkers: 10 + n_steps: 1000 + n_burn: 500 +# Now set the file where you want the light curve to be plotted: +plots: + best model: + interactive: ob08092-o4_minimal_plot.html diff --git a/examples/example_16/ob08092-o4_minimal_plot.yaml b/examples/example_16/ob08092-o4_minimal_plot.yaml index 0761140cb..64d9321d5 100644 --- a/examples/example_16/ob08092-o4_minimal_plot.yaml +++ b/examples/example_16/ob08092-o4_minimal_plot.yaml @@ -18,6 +18,5 @@ fitting_parameters: n_burn: 500 # Now set the file where you want the light curve to be plotted: plots: - best model: - file: ob08092-o4_minimal_plot.png - interactive: ob08092-o4_minimal_plot.html + best model: + file: ob08092-o4_minimal_plot.png diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 413ab826c..81db7cf45 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -14,7 +14,6 @@ from matplotlib import pyplot as plt from matplotlib import gridspec, rcParams, rcParamsDefault # from matplotlib.backends.backend_pdf import PdfPages -import plotly.graph_objects as go from MulensModel.utils import PlotUtils import_failed = set() @@ -39,7 +38,10 @@ import ultranest except Exception: import_failed.add("ultranest") - +try: + import plotly.graph_objects as go +except Exception: + import_failed.add("plotly") try: import MulensModel as mm except Exception: @@ -779,7 +781,8 @@ def _check_plots_parameters(self): if 'trace' in self._plots: self._check_plots_parameters_trace() - names = {key: value['file'] for (key, value) in self._plots.items()} + names = {key: value.get('file', None) + for (key, value) in self._plots.items()} done = {} for (plot_type, name) in names.items(): if name is None: @@ -856,12 +859,10 @@ def _check_plots_parameters_best_model_interactive(self): """ Check if there is no problem with interactive best plot """ - if 'file' not in self._plots['best model']: - raise ValueError( - "When choosing to create an interactive plot of the best" + - " model, a regular plot must also be generated. " + - - "Please specify the 'best model' 'file' in YAML input.") + if "second Y scale" in self._plots['best model']: + msg = "Interactive plot will not have a" + \ + "second Y scale. This feature is not implemented." + warnings.warn(msg) def _check_plots_parameters_best_model_Y_scale(self): """ @@ -1731,7 +1732,7 @@ def _parse_fit_constraints_soft_blending(self, key, value): sigma = float(value.split()[0]) sets = list(map(self._get_no_of_dataset, - shlex.split(value, posix=False)[1:])) + shlex.split(value, posix=False)[1:])) if len(sets) > len(self._datasets): raise ValueError( "dataset number specified in" + @@ -3506,8 +3507,8 @@ def _best_model_plot(self): plt.xlim(*xlim) plt.ylim(*ylim_residuals) axes.tick_params(**kwargs_axes_2) - - self._save_figure(self._plots['best model'].get('file'), dpi=dpi) + if self._plots['best model'].get('file') is not None: + self._save_figure(self._plots['best model'].get('file'), dpi=dpi) def _get_kwargs_for_best_model_plot(self): """ @@ -3814,6 +3815,63 @@ def _make_trajectory_plot(self): self._save_figure(self._plots['trajectory'].get('file'), dpi=dpi) + def _make_interactive_plot(self): + """ + plot best model and residuals interactively + """ + scale = 0.5 # original size=(1920:1440) + + self._ln_like(self._best_model_theta) # Sets all parameters to + # the best model. + + self._reset_rcParams() + if 'rcParams' in self._plots['best model']: + for (key, value) in self._plots['best model']['rcParams'].items(): + rcParams[key] = value + + kwargs_all = self._get_kwargs_for_best_model_plot() + (ylim, ylim_residuals) = self._get_ylim_for_best_model_plot( + *kwargs_all[4:6]) + layout, kwargs_model, kwargs_interactive, kwargs = \ + self._prepare_interactive_layout( + scale, kwargs_all, ylim, ylim_residuals) + + t_data_start, t_data_stop = self._get_time_span_data() + kwargs_model['t_start'] = t_data_start + kwargs_model['t_stop'] = t_data_stop + data_ref = self._event.data_ref + (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) + traces_lc = self._make_interactive_lc_traces(f_source_0, f_blend_0, + **kwargs_model, + **kwargs_interactive,) + self._interactive_fig = go.Figure(data=traces_lc, layout=layout) + + self._add_interactive_zero_trace( + **kwargs_model, **kwargs_interactive) + self._add_interactive_data_traces( + kwargs_interactive, + **kwargs) + self._add_interactive_residuals_traces( + kwargs_interactive, + **kwargs_model) + + self._save_interactive_fig() + + def _prepare_interactive_layout( + self, scale, kwargs_all, ylim, ylim_residuals): + """Prepares the layout for the interactive plot.""" + kwargs_grid, kwargs_model, kwargs, xlim, t_1, t_2 = kwargs_all[:6] + kwargs_axes_1, kwargs_axes_2 = kwargs_all[6:] + kwargs_interactive = self._get_kwargs_for_plotly_plot(scale) + + layout = self._make_interactive_layout( + ylim, ylim_residuals, + **kwargs_grid, + **kwargs_model, + **kwargs_interactive + ) + return layout, kwargs_model, kwargs_interactive, kwargs + def _get_kwargs_for_plotly_plot(self, scale): """_ setting kwargs for interactive plot @@ -4002,7 +4060,7 @@ def _make_interactive_lc_traces( bandpass=None, **kwargs): """ - Creates plotly.graph_objects.Scatter object with model light-curve + Creates plotly.graph_objects.Scatter objects with model light curve """ traces_lc = [] times = np.linspace(t_start, t_stop, num=20000) @@ -4019,43 +4077,52 @@ def _make_interactive_lc_traces( times=times, source_flux=f_source_0, blend_flux=f_blend_0, gamma=gamma, bandpass=bandpass) times = times - subtract - traces_lc.append(go.Scatter(x=times, - y=lc, - name=name, - showlegend=showlegend, - mode='lines', - line=dict( - color=colors[1], - width=sizes[1], - dash=dash, - ), - xaxis="x", - yaxis="y", - )) - return traces_lc - - for (i, model) in enumerate(self._models_satellite): + traces_lc.append(self._make_interactive_scatter_lc( + times, lc, name, showlegend, colors[1], sizes[1], dash)) + return traces_lc + + traces_lc.extend(self._generate_traces_for_models( + traces_lc, times, f_source_0, f_blend_0, gamma, bandpass, + colors, sizes, dash, subtract, showlegend)) + return traces_lc + + def _make_interactive_scatter_lc_satellite( + self, traces, times, f_source_0, f_blend_0, gamma, + bandpass, colors, sizes, dash, subtract, showlegend): + """Generates Plotly Scatter traces for + the light-curve satellite models.""" + + for i, model in enumerate(self._models_satellite): name = self._event.datasets[i].plot_properties['label'] model.parameters.parameters = {**self._model.parameters.parameters} lc = self._model.get_lc(times=times, source_flux=f_source_0, blend_flux=f_blend_0, gamma=gamma, bandpass=bandpass) times = times - subtract - traces_lc.append(go.Scatter(x=times, - y=lc, - name=name, - mode='lines', - showlegend=True, - line=dict( - color=colors[1], - width=sizes[1], - dash=dash, - ), - xaxis="x", - yaxis="y", - )) - - return traces_lc + trace = self._make_interactive_scatter_lc( + times, lc, name, showlegend, colors[1], sizes[1], dash) + traces.append(trace) + return traces + + def _make_interactive_scatter_lc( + self, times, lc, name, + showlegend, color, size, dash): + """Creates a Plotly Scatter trace for the light curve.""" + + return go.Scatter( + x=times, + y=lc, + name=name, + showlegend=showlegend, + mode='lines', + line=dict( + color=color, + width=size, + dash=dash, + ), + xaxis="x", + yaxis="y" + ) def _make_one_interactive_data_trace( self, @@ -4077,80 +4144,90 @@ def _make_one_interactive_data_trace( data points form a given data set """ trace_data = [] - dataset = self._event.datasets[dataset_index] + dataset, show_errorbars, show_bad = self._get_interactive_dataset( + dataset_index) - if show_errorbars is None: - show_errorbars = dataset.plot_properties.get( - 'show_errorbars', True) + trace_data_good = self._make_interactive_good_data_trace( + dataset, times, y_value, y_err, opacity, + sizes, xaxis, yaxis, showlegend, show_errorbars) + trace_data.append(trace_data_good) - if show_bad is None: - show_bad = dataset.plot_properties.get('show_bad', False) + if show_bad: + trace_data_bad = self._make_interactive_bad_data_trace( + dataset, times, y_value, y_err, opacity, + sizes, xaxis, yaxis, showlegend) + trace_data.append(trace_data_bad) + return trace_data + def _get_interactive_dataset(self, dataset_index): + """Get dataset properties for interactive plot settings.""" + dataset = self._event.datasets[dataset_index] + show_errorbars = dataset.plot_properties.get('show_errorbars', True) + show_bad = dataset.plot_properties.get('show_bad', False) + return dataset, show_errorbars, show_bad + + def _make_interactive_good_data_trace( + self, dataset, times, y_value, y_err, opacity, + sizes, xaxis, yaxis, showlegend, show_errorbars): + """Creates a single plotly.graph_objects.Scatter + object for the good data points.""" times_good = times[dataset.good] - times_bad = times[dataset.bad] y_good = y_value[dataset.good] - y_bad = y_value[dataset.bad] y_err_good = y_err[dataset.good] + return self._make_interactive_data_trace( + times_good, y_good, y_err_good, dataset, + opacity, sizes, xaxis, yaxis, showlegend, show_errorbars) + + def _make_interactive_bad_data_trace( + self, dataset, times, y_value, y_err, opacity, + sizes, xaxis, yaxis, showlegend): + """Creates a single plotly.graph_objects.Scatter + object for the bad data points.""" + times_bad = times[dataset.bad] + y_bad = y_value[dataset.bad] y_err_bad = y_err[dataset.bad] + return self._make_interactive_data_trace( + times_bad, y_bad, y_err_bad, dataset, + opacity, sizes, xaxis, yaxis, showlegend, + show_errorbars=False, + color_override='black', + error_visible=False + ) - trace_data_good = go.Scatter( - x=times_good, - y=y_good, + def _make_interactive_data_trace( + self, x, y, y_err, dataset, opacity, sizes, xaxis, yaxis, + showlegend, show_errorbars, + color_override=None, error_visible=True): + """Creates single plotly.graph_objects.Scatter + object for good or bad data.""" + color = color_override if color_override \ + else dataset.plot_properties['color'] + return go.Scatter( + x=x, + y=y, opacity=opacity, name=dataset.plot_properties['label'], - mode='markers', showlegend=showlegend, error_y=dict( type='data', - array=y_err_good, - visible=show_errorbars, + array=y_err, + visible=error_visible, thickness=sizes[2], width=sizes[3]), marker=dict( - color=dataset.plot_properties['color'], + color=color, size=sizes[0], line=dict( - color=dataset.plot_properties['color'], + color=color, width=1, ), ), xaxis=xaxis, yaxis=yaxis, ) - trace_data.append(trace_data_good) - if show_bad: - trace_data_bad = go.Scatter( - x=times_bad, - y=y_bad, - opacity=opacity, - name=dataset.plot_properties['label'], - legendgroup=str(dataset_index), - mode='markers', - showlegend=showlegend, - error_y=dict( - type='data', - array=y_err_bad, - visible=False, - thickness=sizes[2], - width=sizes[3]), - marker=dict( - color='black', - size=sizes[0]*0.8, - line=dict( - color='black', - width=1, - ), - ), - xaxis=xaxis, - yaxis=yaxis, - ) - - trace_data.append(trace_data_bad) - - return trace_data - def _make_interactive_data_traces( + def _add_interactive_data_traces( self, kwargs_interactive, phot_fmt='mag', @@ -4197,9 +4274,10 @@ def _make_interactive_data_traces( **kwargs_interactive, ) traces_data.extend(trace_data) - return traces_data + for trace in traces_data: + self._interactive_fig.add_trace(trace) - def _make_interactive_residuals_traces( + def _add_interactive_residuals_traces( self, kwargs_interactive, phot_fmt='mag', @@ -4248,10 +4326,10 @@ def _make_interactive_residuals_traces( **kwargs_interactive, ) traces_residuals.extend(trace_residuals) + for trace in traces_residuals: + self._interactive_fig.add_trace(trace) - return traces_residuals - - def _make_interactive_zero_trace( + def _add_interactive_zero_trace( self, t_start, t_stop, colors, sizes, subtract_2450000=False, subtract_2460000=False, **kwargs): @@ -4275,7 +4353,7 @@ def _make_interactive_zero_trace( yaxis="y2", showlegend=False, ) - return trace_0 + self._interactive_fig.add_trace(trace_0) def _save_interactive_fig(self): """ @@ -4301,57 +4379,6 @@ def _get_time_span_data(self): return (min(t_min), max(t_max)) - def _make_interactive_plot(self): - """ - plot best model and residuals interactively - """ - scale = 0.5 # original size=(1920:1440) - - self._ln_like(self._best_model_theta) # Sets all parameters to - # the best model. - - self._reset_rcParams() - if 'rcParams' in self._plots['best model']: - for (key, value) in self._plots['best model']['rcParams'].items(): - rcParams[key] = value - - kwargs_all = self._get_kwargs_for_best_model_plot() - (kwargs_grid, kwargs_model, kwargs, xlim, t_1, t_2) = kwargs_all[:6] - (kwargs_axes_1, kwargs_axes_2) = kwargs_all[6:] - (ylim, ylim_residuals) = self._get_ylim_for_best_model_plot(t_1, t_2) - kwargs_interactive = self._get_kwargs_for_plotly_plot(scale) - layout = self._make_interactive_layout(ylim, ylim_residuals, - **kwargs_grid, - **kwargs_model, - **kwargs_interactive) - t_data_start, t_data_stop = self._get_time_span_data() - kwargs_model['t_start'] = t_data_start - kwargs_model['t_stop'] = t_data_stop - data_ref = self._event.data_ref - (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) - traces_lc = self._make_interactive_lc_traces(f_source_0, f_blend_0, - **kwargs_model, - **kwargs_interactive,) - self._interactive_fig = go.Figure(data=traces_lc, layout=layout) - - trace_0 = (self._make_interactive_zero_trace( - **kwargs_model, **kwargs_interactive)) - self._interactive_fig.add_trace(trace_0) - - traces_data = self._make_interactive_data_traces( - kwargs_interactive, - **kwargs) - for trace in traces_data: - self._interactive_fig.add_trace(trace) - - traces_residuals = self._make_interactive_residuals_traces( - kwargs_interactive, - **kwargs_model) - for trace in traces_residuals: - self._interactive_fig.add_trace(trace) - - self._save_interactive_fig() - if __name__ == '__main__': if len(sys.argv) != 2: From 6e436d396b244e64c9d88627f837fd013aa6e2f3 Mon Sep 17 00:00:00 2001 From: mjmroz Date: Sun, 17 Nov 2024 15:26:00 +0100 Subject: [PATCH 06/26] small correction --- examples/example_16/ulens_model_fit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 81db7cf45..fcbcac71d 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3507,8 +3507,8 @@ def _best_model_plot(self): plt.xlim(*xlim) plt.ylim(*ylim_residuals) axes.tick_params(**kwargs_axes_2) - if self._plots['best model'].get('file') is not None: - self._save_figure(self._plots['best model'].get('file'), dpi=dpi) + + self._save_figure(self._plots['best model'].get('file'), dpi=dpi) def _get_kwargs_for_best_model_plot(self): """ From 54a4c06021ad0cb3de1338ebcbadf4c9e6ef393d Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 17 Nov 2024 20:56:29 +0100 Subject: [PATCH 07/26] ex16 - shortening example yaml and reverting to 4 spaces --- .../ob08092-o4_minimal_interactive_plot.yaml | 20 ++++--------------- .../example_16/ob08092-o4_minimal_plot.yaml | 4 ++-- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml b/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml index 33464da3c..0abd14db0 100644 --- a/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml +++ b/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml @@ -1,21 +1,9 @@ photometry_files: data/OB08092/phot_ob08092_O4.dat # Define model to be plotted: model: - parameters: t_0 u_0 t_E - values: 2455379.5716130617 0.5236953977433282 17.926270401551196 -# Three sections below will be ignored by the plotting script: -starting_parameters: - t_0: gauss 2455380. 0.1 - u_0: uniform 0.001 1. - t_E: gauss 20. 5. -min_values: - u_0: 0. - t_E: 0. -fitting_parameters: - n_walkers: 10 - n_steps: 1000 - n_burn: 500 + parameters: t_0 u_0 t_E + values: 2455379.5716130617 0.5236953977433282 17.926270401551196 # Now set the file where you want the light curve to be plotted: plots: - best model: - interactive: ob08092-o4_minimal_plot.html + best model: + interactive: ob08092-o4_minimal_plot.html diff --git a/examples/example_16/ob08092-o4_minimal_plot.yaml b/examples/example_16/ob08092-o4_minimal_plot.yaml index 64d9321d5..53bce3fed 100644 --- a/examples/example_16/ob08092-o4_minimal_plot.yaml +++ b/examples/example_16/ob08092-o4_minimal_plot.yaml @@ -18,5 +18,5 @@ fitting_parameters: n_burn: 500 # Now set the file where you want the light curve to be plotted: plots: - best model: - file: ob08092-o4_minimal_plot.png + best model: + file: ob08092-o4_minimal_plot.png From 8b3a717204772981a650772fcecc09f151047ced Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 17 Nov 2024 21:01:47 +0100 Subject: [PATCH 08/26] ex16: correcting imports, flake8 --- examples/example_16/ulens_model_fit.py | 36 ++++++++++++-------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index fcbcac71d..d0891ebfc 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -14,7 +14,6 @@ from matplotlib import pyplot as plt from matplotlib import gridspec, rcParams, rcParamsDefault # from matplotlib.backends.backend_pdf import PdfPages -from MulensModel.utils import PlotUtils import_failed = set() try: @@ -39,7 +38,7 @@ except Exception: import_failed.add("ultranest") try: - import plotly.graph_objects as go + from plotly import graph_objects except Exception: import_failed.add("plotly") try: @@ -3830,13 +3829,11 @@ def _make_interactive_plot(self): rcParams[key] = value kwargs_all = self._get_kwargs_for_best_model_plot() - (ylim, ylim_residuals) = self._get_ylim_for_best_model_plot( - *kwargs_all[4:6]) - layout, kwargs_model, kwargs_interactive, kwargs = \ - self._prepare_interactive_layout( - scale, kwargs_all, ylim, ylim_residuals) + (ylim, ylim_residuals) = self._get_ylim_for_best_model_plot(*kwargs_all[4:6]) + (layout, kwargs_model, kwargs_interactive, kwargs) = \ + self._prepare_interactive_layout(scale, kwargs_all, ylim, ylim_residuals) - t_data_start, t_data_stop = self._get_time_span_data() + (t_data_start, t_data_stop) = self._get_time_span_data() kwargs_model['t_start'] = t_data_start kwargs_model['t_stop'] = t_data_stop data_ref = self._event.data_ref @@ -3844,7 +3841,7 @@ def _make_interactive_plot(self): traces_lc = self._make_interactive_lc_traces(f_source_0, f_blend_0, **kwargs_model, **kwargs_interactive,) - self._interactive_fig = go.Figure(data=traces_lc, layout=layout) + self._interactive_fig = graph_objects.Figure(data=traces_lc, layout=layout) self._add_interactive_zero_trace( **kwargs_model, **kwargs_interactive) @@ -3927,7 +3924,7 @@ def _make_interactive_layout( Creates plotly.graph_objects.Layout object analogues to best model plot """ hsplit = height_ratios[1] / height_ratios[0] - subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) xtitle = 'Time' if subtract > 0.: @@ -3936,7 +3933,7 @@ def _make_interactive_layout( t_start = t_start - subtract t_stop = t_stop - subtract - layout = go.Layout( + layout = graph_objects.Layout( autosize=True, width=width, height=height, @@ -4064,7 +4061,7 @@ def _make_interactive_lc_traces( """ traces_lc = [] times = np.linspace(t_start, t_stop, num=20000) - subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) if isinstance(name, type(None)): showlegend = False @@ -4109,7 +4106,7 @@ def _make_interactive_scatter_lc( showlegend, color, size, dash): """Creates a Plotly Scatter trace for the light curve.""" - return go.Scatter( + return graph_objects.Scatter( x=times, y=lc, name=name, @@ -4202,7 +4199,7 @@ def _make_interactive_data_trace( object for good or bad data.""" color = color_override if color_override \ else dataset.plot_properties['color'] - return go.Scatter( + return graph_objects.Scatter( x=x, y=y, opacity=opacity, @@ -4250,7 +4247,7 @@ def _add_interactive_data_traces( if data_ref is None: data_ref = self._event.data_ref - subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) # Get fluxes for the reference dataset (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) @@ -4258,8 +4255,7 @@ def _add_interactive_data_traces( # Scale the data flux (flux, err_flux) = self._event.fits[dataset_index].scale_fluxes( f_source_0, f_blend_0) - (y_value, y_err) = PlotUtils.get_y_value_y_err( - phot_fmt, flux, err_flux) + (y_value, y_err) = mm.utils.PlotUtils.get_y_value_y_err(phot_fmt, flux, err_flux) times = data.time-subtract trace_data = self._make_one_interactive_data_trace( dataset_index, @@ -4299,7 +4295,7 @@ def _add_interactive_residuals_traces( if data_ref is None: data_ref = self._event.data_ref - subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) # Get fluxes for the reference dataset (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) @@ -4337,10 +4333,10 @@ def _add_interactive_zero_trace( Creates plotly.graph_objects.Scatter object for line y=0 in residuals plot """ - subtract = PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) times = np.linspace(t_start, t_stop, num=2000) line = np.zeros(len(times)) - trace_0 = go.Scatter( + trace_0 = graph_objects.Scatter( x=times-subtract, y=line, mode='lines', From 21357f09851f654c264b0f55809458945f7c9629 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 17 Nov 2024 21:03:02 +0100 Subject: [PATCH 09/26] ex16 minor --- examples/example_16/ulens_model_fit.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index d0891ebfc..5a1473966 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -4086,10 +4086,9 @@ def _make_interactive_lc_traces( def _make_interactive_scatter_lc_satellite( self, traces, times, f_source_0, f_blend_0, gamma, bandpass, colors, sizes, dash, subtract, showlegend): - """Generates Plotly Scatter traces for - the light-curve satellite models.""" + """Generates Plotly Scatter traces for the light-curve satellite models.""" - for i, model in enumerate(self._models_satellite): + for (i, model) in enumerate(self._models_satellite): name = self._event.datasets[i].plot_properties['label'] model.parameters.parameters = {**self._model.parameters.parameters} lc = self._model.get_lc(times=times, source_flux=f_source_0, From 7d465f3f12f7b6715b73de37998fd51cb56aa85f Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 17 Nov 2024 21:28:39 +0100 Subject: [PATCH 10/26] ex16 - only changing order of functions --- examples/example_16/ulens_model_fit.py | 206 ++++++++++++------------- 1 file changed, 103 insertions(+), 103 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 5a1473966..a3c5d08c8 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -4037,6 +4037,19 @@ def _make_interactive_layout( ) return layout + def _get_time_span_data(self): + """ + Returning time span of datasets + + """ + t_min = np.zeros(len(self._datasets)) + t_max = np.zeros(len(self._datasets)) + for (i, data) in enumerate(self._datasets): + t_min[i] = min(data.time) + t_max[i] = max(data.time) + + return (min(t_min), max(t_max)) + def _make_interactive_lc_traces( self, f_source_0, f_blend_0, @@ -4120,6 +4133,81 @@ def _make_interactive_scatter_lc( yaxis="y" ) + def _add_interactive_zero_trace( + self, t_start, t_stop, colors, sizes, + subtract_2450000=False, subtract_2460000=False, + **kwargs): + """ + Creates plotly.graph_objects.Scatter object for line y=0 in + residuals plot + """ + subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + times = np.linspace(t_start, t_stop, num=2000) + line = np.zeros(len(times)) + trace_0 = graph_objects.Scatter( + x=times-subtract, + y=line, + mode='lines', + line=dict( + color=colors[0], + width=sizes[1], + dash='dash', + ), + xaxis="x2", + yaxis="y2", + showlegend=False, + ) + self._interactive_fig.add_trace(trace_0) + + def _add_interactive_data_traces( + self, + kwargs_interactive, + phot_fmt='mag', + data_ref=None, + show_errorbars=True, + show_bad=None, + subtract_2450000=False, + subtract_2460000=False, + **kwargs, + ): + """ + Creates plotly.graph_objects.Scatter object for observation points + per each data set. + """ + traces_data = [] + self._event._set_default_colors() # For each dataset + if self._event.fits is None: + self._event.get_chi2() + + if data_ref is None: + data_ref = self._event.data_ref + + subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + + # Get fluxes for the reference dataset + (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) + for (dataset_index, data) in enumerate(self._datasets): + # Scale the data flux + (flux, err_flux) = self._event.fits[dataset_index].scale_fluxes( + f_source_0, f_blend_0) + (y_value, y_err) = mm.utils.PlotUtils.get_y_value_y_err(phot_fmt, flux, err_flux) + times = data.time-subtract + trace_data = self._make_one_interactive_data_trace( + dataset_index, + times, + y_value, + y_err, + xaxis='x', + yaxis='y', + showlegend=True, + show_errorbars=show_errorbars, + show_bad=show_bad, + **kwargs_interactive, + ) + traces_data.extend(trace_data) + for trace in traces_data: + self._interactive_fig.add_trace(trace) + def _make_one_interactive_data_trace( self, dataset_index, @@ -4174,22 +4262,6 @@ def _make_interactive_good_data_trace( times_good, y_good, y_err_good, dataset, opacity, sizes, xaxis, yaxis, showlegend, show_errorbars) - def _make_interactive_bad_data_trace( - self, dataset, times, y_value, y_err, opacity, - sizes, xaxis, yaxis, showlegend): - """Creates a single plotly.graph_objects.Scatter - object for the bad data points.""" - times_bad = times[dataset.bad] - y_bad = y_value[dataset.bad] - y_err_bad = y_err[dataset.bad] - return self._make_interactive_data_trace( - times_bad, y_bad, y_err_bad, dataset, - opacity, sizes, xaxis, yaxis, showlegend, - show_errorbars=False, - color_override='black', - error_visible=False - ) - def _make_interactive_data_trace( self, x, y, y_err, dataset, opacity, sizes, xaxis, yaxis, showlegend, show_errorbars, @@ -4223,54 +4295,21 @@ def _make_interactive_data_trace( yaxis=yaxis, ) - def _add_interactive_data_traces( - self, - kwargs_interactive, - phot_fmt='mag', - data_ref=None, - show_errorbars=True, - show_bad=None, - subtract_2450000=False, - subtract_2460000=False, - **kwargs, - ): - """ - Creates plotly.graph_objects.Scatter object for observation points - per each data set. - """ - traces_data = [] - self._event._set_default_colors() # For each dataset - if self._event.fits is None: - self._event.get_chi2() - - if data_ref is None: - data_ref = self._event.data_ref - - subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) - - # Get fluxes for the reference dataset - (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) - for (dataset_index, data) in enumerate(self._datasets): - # Scale the data flux - (flux, err_flux) = self._event.fits[dataset_index].scale_fluxes( - f_source_0, f_blend_0) - (y_value, y_err) = mm.utils.PlotUtils.get_y_value_y_err(phot_fmt, flux, err_flux) - times = data.time-subtract - trace_data = self._make_one_interactive_data_trace( - dataset_index, - times, - y_value, - y_err, - xaxis='x', - yaxis='y', - showlegend=True, - show_errorbars=show_errorbars, - show_bad=show_bad, - **kwargs_interactive, - ) - traces_data.extend(trace_data) - for trace in traces_data: - self._interactive_fig.add_trace(trace) + def _make_interactive_bad_data_trace( + self, dataset, times, y_value, y_err, opacity, + sizes, xaxis, yaxis, showlegend): + """Creates a single plotly.graph_objects.Scatter + object for the bad data points.""" + times_bad = times[dataset.bad] + y_bad = y_value[dataset.bad] + y_err_bad = y_err[dataset.bad] + return self._make_interactive_data_trace( + times_bad, y_bad, y_err_bad, dataset, + opacity, sizes, xaxis, yaxis, showlegend, + show_errorbars=False, + color_override='black', + error_visible=False + ) def _add_interactive_residuals_traces( self, @@ -4324,32 +4363,6 @@ def _add_interactive_residuals_traces( for trace in traces_residuals: self._interactive_fig.add_trace(trace) - def _add_interactive_zero_trace( - self, t_start, t_stop, colors, sizes, - subtract_2450000=False, subtract_2460000=False, - **kwargs): - """ - Creates plotly.graph_objects.Scatter object for line y=0 in - residuals plot - """ - subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) - times = np.linspace(t_start, t_stop, num=2000) - line = np.zeros(len(times)) - trace_0 = graph_objects.Scatter( - x=times-subtract, - y=line, - mode='lines', - line=dict( - color=colors[0], - width=sizes[1], - dash='dash', - ), - xaxis="x2", - yaxis="y2", - showlegend=False, - ) - self._interactive_fig.add_trace(trace_0) - def _save_interactive_fig(self): """ Saving interactive figure @@ -4361,19 +4374,6 @@ def _save_interactive_fig(self): warnings.warn(msg) self._interactive_fig.write_html(file, full_html=True) - def _get_time_span_data(self): - """ - Returning time span of datasets - - """ - t_min = np.zeros(len(self._datasets)) - t_max = np.zeros(len(self._datasets)) - for (i, data) in enumerate(self._datasets): - t_min[i] = min(data.time) - t_max[i] = max(data.time) - - return (min(t_min), max(t_max)) - if __name__ == '__main__': if len(sys.argv) != 2: From 24ebe95618f7ecb39cd364e4dc6ff757b63d0ccf Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 17 Nov 2024 21:50:24 +0100 Subject: [PATCH 11/26] ex16 highlighting off --- examples/example_16/ulens_model_fit.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index a3c5d08c8..c14d09b2d 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -4367,12 +4367,12 @@ def _save_interactive_fig(self): """ Saving interactive figure """ - file = self._plots['best model']['interactive'] - if path.exists(file): - if path.isfile(file): - msg = "Existing file " + file + " will be overwritten" + file_ = self._plots['best model']['interactive'] + if path.exists(file_): + if path.isfile(file_): + msg = "Existing file " + file_ + " will be overwritten" warnings.warn(msg) - self._interactive_fig.write_html(file, full_html=True) + self._interactive_fig.write_html(file_, full_html=True) if __name__ == '__main__': From a1ac34528431bf8237575280bb89fa182d83e813 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 17 Nov 2024 21:53:51 +0100 Subject: [PATCH 12/26] ex16 - shortening _make_interactive_plot() --- examples/example_16/ulens_model_fit.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index c14d09b2d..9d7ac224c 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3820,8 +3820,7 @@ def _make_interactive_plot(self): """ scale = 0.5 # original size=(1920:1440) - self._ln_like(self._best_model_theta) # Sets all parameters to - # the best model. + self._ln_like(self._best_model_theta) # Sets all parameters to the best model. self._reset_rcParams() if 'rcParams' in self._plots['best model']: @@ -3838,19 +3837,12 @@ def _make_interactive_plot(self): kwargs_model['t_stop'] = t_data_stop data_ref = self._event.data_ref (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) - traces_lc = self._make_interactive_lc_traces(f_source_0, f_blend_0, - **kwargs_model, - **kwargs_interactive,) + traces_lc = self._make_interactive_lc_traces(f_source_0, f_blend_0, **kwargs_model, **kwargs_interactive) self._interactive_fig = graph_objects.Figure(data=traces_lc, layout=layout) - self._add_interactive_zero_trace( - **kwargs_model, **kwargs_interactive) - self._add_interactive_data_traces( - kwargs_interactive, - **kwargs) - self._add_interactive_residuals_traces( - kwargs_interactive, - **kwargs_model) + self._add_interactive_zero_trace(**kwargs_model, **kwargs_interactive) + self._add_interactive_data_traces(kwargs_interactive, **kwargs) + self._add_interactive_residuals_traces(kwargs_interactive, **kwargs_model) self._save_interactive_fig() From e0cd286b520441bcdf1f63f8c784d4c4b962d659 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 17 Nov 2024 22:00:08 +0100 Subject: [PATCH 13/26] ex16 - shortening code --- examples/example_16/ulens_model_fit.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 9d7ac224c..a7138e541 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3878,20 +3878,10 @@ def _get_kwargs_for_plotly_plot(self, scale): 30., # font lagend ]) sizes = sizes*scale + colors = ['black', 'black', '#b9b9b9'] # This are: axes, font, and legend border. - kwargs_interactive = dict( - sizes=sizes, - colors=['black', # axes - 'black', # font - '#b9b9b9' # legend border - ], - opacity=0.7, - width=1920*scale, - height=1440*scale, - font='Old Standard TT, serif', - paper_bgcolor='white', - ) - + kwargs_interactive = dict(sizes=sizes, colors=colors, opacity=0.7, width=1920*scale, + height=1440*scale, font='Old Standard TT, serif', paper_bgcolor='white') return kwargs_interactive def _make_interactive_layout( From 3277ed256c0fe046dfc53e0bd3e3265f438e6545 Mon Sep 17 00:00:00 2001 From: mjmroz Date: Sun, 17 Nov 2024 22:42:49 +0100 Subject: [PATCH 14/26] repaired _make_interactive_scatter_lc_satellite() --- examples/example_16/ulens_model_fit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index a7138e541..ed8da35e9 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -4073,7 +4073,7 @@ def _make_interactive_lc_traces( times, lc, name, showlegend, colors[1], sizes[1], dash)) return traces_lc - traces_lc.extend(self._generate_traces_for_models( + traces_lc.extend(self._make_interactive_scatter_lc_satellite( traces_lc, times, f_source_0, f_blend_0, gamma, bandpass, colors, sizes, dash, subtract, showlegend)) return traces_lc From f37097b85c00b6a27634a3eea73a98beec6c777d Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 17 Nov 2024 23:33:46 +0100 Subject: [PATCH 15/26] ex16 - simplifying code --- examples/example_16/ulens_model_fit.py | 70 ++++---------------------- 1 file changed, 10 insertions(+), 60 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index ed8da35e9..c0d7a269d 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3915,6 +3915,9 @@ def _make_interactive_layout( t_start = t_start - subtract t_stop = t_stop - subtract + font_1 = dict(family=font, size=sizes[4], color=colors[1]) + kwargs_y = dict(mirror='all', showgrid=False, ticks='inside', showline=True, + ticklen=sizes[8], tickwidth=sizes[7], linewidth=sizes[7], linecolor=colors[0], tickfont=font_1) layout = graph_objects.Layout( autosize=True, width=width, @@ -3926,55 +3929,12 @@ def _make_interactive_layout( bgcolor=paper_bgcolor, bordercolor=colors[2], borderwidth=sizes[7], - font=dict( - family=font, - size=sizes[9]) - ), + font=dict(family=font, size=sizes[9])), paper_bgcolor=paper_bgcolor, plot_bgcolor=paper_bgcolor, - font=dict( - family=font, - size=sizes[4], - color=colors[1] - ), - yaxis=dict( - title_text='Magnitude', - domain=[hsplit+(hspace/2), 1], - # anchor="y", - showgrid=False, - mirror='all', - ticks='inside', - showline=True, - ticklen=sizes[8], - tickwidth=sizes[7], - linewidth=sizes[7], - linecolor=colors[0], - range=ylim, - tickfont=dict( - family=font, - size=sizes[4], - color=colors[1] - ), - ), - yaxis2=dict( - title_text='Residuals', - domain=[0, hsplit-(hspace/2)], - anchor="x", - showgrid=False, - mirror='all', - ticks='inside', - ticklen=sizes[8], - linewidth=sizes[7], - tickwidth=sizes[7], - showline=True, - linecolor=colors[0], - range=ylim_residuals, - tickfont=dict( - family=font, - size=sizes[4], - color=colors[1] - ), - ), + font=font_1, + yaxis=dict(title_text='Magnitude', domain=[hsplit+(hspace/2), 1], range=ylim, **kwargs_y), + yaxis2=dict(title_text='Residuals', domain=[0, hsplit-(hspace/2)], anchor="x", range=ylim_residuals, **kwargs_y), xaxis=dict( anchor="y", showgrid=False, @@ -3990,12 +3950,7 @@ def _make_interactive_layout( tickwidth=sizes[7], showticklabels=False, range=[t_start, t_stop], - tickfont=dict( - family=font, - size=sizes[4], - color=colors[1] - ), - ), + tickfont=font_1), xaxis2=dict( title_text=xtitle, anchor="y2", @@ -4010,13 +3965,8 @@ def _make_interactive_layout( tickwidth=sizes[7], linewidth=sizes[7], range=[t_start, t_stop], - tickfont=dict( - family=font, - size=sizes[4], - color=colors[1] - ), - ), - ) + tickfont=font_1) + ) return layout def _get_time_span_data(self): From bc3f3ca98d675e29b61a19be20be369d44aeb6f7 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Mon, 18 Nov 2024 07:03:08 +0100 Subject: [PATCH 16/26] ex16 graph_objects -> go --- examples/example_16/ulens_model_fit.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index c0d7a269d..68c8c4bce 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -38,7 +38,7 @@ except Exception: import_failed.add("ultranest") try: - from plotly import graph_objects + import plotly.graph_objects as go except Exception: import_failed.add("plotly") try: @@ -3838,7 +3838,7 @@ def _make_interactive_plot(self): data_ref = self._event.data_ref (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) traces_lc = self._make_interactive_lc_traces(f_source_0, f_blend_0, **kwargs_model, **kwargs_interactive) - self._interactive_fig = graph_objects.Figure(data=traces_lc, layout=layout) + self._interactive_fig = go.Figure(data=traces_lc, layout=layout) self._add_interactive_zero_trace(**kwargs_model, **kwargs_interactive) self._add_interactive_data_traces(kwargs_interactive, **kwargs) @@ -3918,7 +3918,7 @@ def _make_interactive_layout( font_1 = dict(family=font, size=sizes[4], color=colors[1]) kwargs_y = dict(mirror='all', showgrid=False, ticks='inside', showline=True, ticklen=sizes[8], tickwidth=sizes[7], linewidth=sizes[7], linecolor=colors[0], tickfont=font_1) - layout = graph_objects.Layout( + layout = go.Layout( autosize=True, width=width, height=height, @@ -4050,7 +4050,7 @@ def _make_interactive_scatter_lc( showlegend, color, size, dash): """Creates a Plotly Scatter trace for the light curve.""" - return graph_objects.Scatter( + return go.Scatter( x=times, y=lc, name=name, @@ -4076,7 +4076,7 @@ def _add_interactive_zero_trace( subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) times = np.linspace(t_start, t_stop, num=2000) line = np.zeros(len(times)) - trace_0 = graph_objects.Scatter( + trace_0 = go.Scatter( x=times-subtract, y=line, mode='lines', @@ -4202,7 +4202,7 @@ def _make_interactive_data_trace( object for good or bad data.""" color = color_override if color_override \ else dataset.plot_properties['color'] - return graph_objects.Scatter( + return go.Scatter( x=x, y=y, opacity=opacity, From ffee7bf12acaef42376afdc642c078fb6fd066f5 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Mon, 18 Nov 2024 07:04:43 +0100 Subject: [PATCH 17/26] ex16 warning -> error --- examples/example_16/ulens_model_fit.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 68c8c4bce..436c970f3 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -859,9 +859,8 @@ def _check_plots_parameters_best_model_interactive(self): Check if there is no problem with interactive best plot """ if "second Y scale" in self._plots['best model']: - msg = "Interactive plot will not have a" + \ - "second Y scale. This feature is not implemented." - warnings.warn(msg) + msg = "Interactive plot will not have a second Y scale. This feature is not yet implemented." + raise NotImplementedError(msg) def _check_plots_parameters_best_model_Y_scale(self): """ From ba75bcd8cdfbd1b40667a69059cb563b2ba05c22 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Mon, 18 Nov 2024 07:24:32 +0100 Subject: [PATCH 18/26] ex16 - simplifying and shortening code --- examples/example_16/ulens_model_fit.py | 94 ++++++-------------------- 1 file changed, 20 insertions(+), 74 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 436c970f3..06e4d11a6 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3637,15 +3637,12 @@ def _plot_models_for_best_model_plot(self, fluxes, kwargs_model): """ for dataset in self._datasets: if dataset.ephemerides_file is None: - self._model.plot_lc( - source_flux=fluxes[0], blend_flux=fluxes[1], - **kwargs_model) + self._model.plot_lc(source_flux=fluxes[0], blend_flux=fluxes[1], **kwargs_model) break for model in self._models_satellite: model.parameters.parameters = {**self._model.parameters.parameters} - model.plot_lc(source_flux=fluxes[0], blend_flux=fluxes[1], - **kwargs_model) + model.plot_lc(source_flux=fluxes[0], blend_flux=fluxes[1], **kwargs_model) def _plot_legend_for_best_model_plot(self): """ @@ -3883,24 +3880,9 @@ def _get_kwargs_for_plotly_plot(self, scale): height=1440*scale, font='Old Standard TT, serif', paper_bgcolor='white') return kwargs_interactive - def _make_interactive_layout( - self, - ylim, - ylim_residuals, - height_ratios, - hspace, - sizes, - colors, - opacity, - width, - height, - font, - paper_bgcolor, - t_start, - t_stop, - subtract_2450000=None, - subtract_2460000=None, - **kwargs): + def _make_interactive_layout(self, ylim, ylim_residuals, height_ratios, hspace, sizes, colors, opacity, width, + height, font, paper_bgcolor, t_start, t_stop, + subtract_2450000=None, subtract_2460000=None, **kwargs): """ Creates plotly.graph_objects.Layout object analogues to best model plot """ @@ -3915,63 +3897,28 @@ def _make_interactive_layout( t_stop = t_stop - subtract font_1 = dict(family=font, size=sizes[4], color=colors[1]) - kwargs_y = dict(mirror='all', showgrid=False, ticks='inside', showline=True, - ticklen=sizes[8], tickwidth=sizes[7], linewidth=sizes[7], linecolor=colors[0], tickfont=font_1) + font_2 = dict(family=font, size=sizes[9]) + kwargs_ = dict(showgrid=False, ticks='inside', showline=True, ticklen=sizes[8], + tickwidth=sizes[7], linewidth=sizes[7], linecolor=colors[0], tickfont=font_1) + kwargs_y = {'mirror': 'all', **kwargs_} + kwargs_x = {'range': [t_start, t_stop], **kwargs_} layout = go.Layout( - autosize=True, - width=width, - height=height, - showlegend=True, - legend=dict( - x=1.02, - y=.98, - bgcolor=paper_bgcolor, - bordercolor=colors[2], - borderwidth=sizes[7], - font=dict(family=font, size=sizes[9])), - paper_bgcolor=paper_bgcolor, - plot_bgcolor=paper_bgcolor, - font=font_1, + autosize=True, width=width, height=height, showlegend=True, + legend=dict(x=1.02, y=.98, bgcolor=paper_bgcolor, bordercolor=colors[2], borderwidth=sizes[7], + font=dict(family=font, size=sizes[9])), + paper_bgcolor=paper_bgcolor, plot_bgcolor=paper_bgcolor, font=font_1, yaxis=dict(title_text='Magnitude', domain=[hsplit+(hspace/2), 1], range=ylim, **kwargs_y), - yaxis2=dict(title_text='Residuals', domain=[0, hsplit-(hspace/2)], anchor="x", range=ylim_residuals, **kwargs_y), - xaxis=dict( - anchor="y", - showgrid=False, - mirror='ticks', - side='top', - ticks='inside', - scaleanchor='x2', - matches='x2', - showline=True, - ticklen=sizes[8], - linecolor=colors[0], - linewidth=sizes[7], - tickwidth=sizes[7], - showticklabels=False, - range=[t_start, t_stop], - tickfont=font_1), - xaxis2=dict( - title_text=xtitle, - anchor="y2", - showgrid=False, - mirror='all', - ticks='inside', - scaleanchor='x', - matches='x', - showline=True, - ticklen=sizes[8], - linecolor=colors[0], - tickwidth=sizes[7], - linewidth=sizes[7], - range=[t_start, t_stop], - tickfont=font_1) + yaxis2=dict(title_text='Residuals', domain=[0, hsplit-(hspace/2)], anchor="x", range=ylim_residuals, + **kwargs_y), + xaxis=dict(anchor="y", mirror='ticks', side='top', scaleanchor='x2', matches='x2', showticklabels=False, + **kwargs_x), + xaxis2=dict(title_text=xtitle, anchor="y2", mirror='all', scaleanchor='x', matches='x', **kwargs_x) ) return layout def _get_time_span_data(self): """ Returning time span of datasets - """ t_min = np.zeros(len(self._datasets)) t_max = np.zeros(len(self._datasets)) @@ -4015,8 +3962,7 @@ def _make_interactive_lc_traces( for dataset in self._datasets: if dataset.ephemerides_file is None: lc = self._model.get_lc( - times=times, source_flux=f_source_0, blend_flux=f_blend_0, - gamma=gamma, bandpass=bandpass) + times=times, source_flux=f_source_0, blend_flux=f_blend_0, gamma=gamma, bandpass=bandpass) times = times - subtract traces_lc.append(self._make_interactive_scatter_lc( times, lc, name, showlegend, colors[1], sizes[1], dash)) From 4af57e453b7d6baf9b51746eaee5ce00d26ec031 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Thu, 21 Nov 2024 01:08:12 +0100 Subject: [PATCH 19/26] ex16 - MM conventions, shorter code --- examples/example_16/ulens_model_fit.py | 139 ++++++------------------- 1 file changed, 34 insertions(+), 105 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 06e4d11a6..e3991778e 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3904,8 +3904,8 @@ def _make_interactive_layout(self, ylim, ylim_residuals, height_ratios, hspace, kwargs_x = {'range': [t_start, t_stop], **kwargs_} layout = go.Layout( autosize=True, width=width, height=height, showlegend=True, - legend=dict(x=1.02, y=.98, bgcolor=paper_bgcolor, bordercolor=colors[2], borderwidth=sizes[7], - font=dict(family=font, size=sizes[9])), + legend=dict( + x=1.02, y=.98, bgcolor=paper_bgcolor, bordercolor=colors[2], borderwidth=sizes[7], font=font_2), paper_bgcolor=paper_bgcolor, plot_bgcolor=paper_bgcolor, font=font_1, yaxis=dict(title_text='Magnitude', domain=[hsplit+(hspace/2), 1], range=ylim, **kwargs_y), yaxis2=dict(title_text='Residuals', domain=[0, hsplit-(hspace/2)], anchor="x", range=ylim_residuals, @@ -4036,23 +4036,13 @@ def _add_interactive_zero_trace( ) self._interactive_fig.add_trace(trace_0) - def _add_interactive_data_traces( - self, - kwargs_interactive, - phot_fmt='mag', - data_ref=None, - show_errorbars=True, - show_bad=None, - subtract_2450000=False, - subtract_2460000=False, - **kwargs, - ): + def _add_interactive_data_traces(self, kwargs_interactive, phot_fmt='mag', data_ref=None, show_errorbars=True, + show_bad=None, subtract_2450000=False, subtract_2460000=False, **kwargs): """ Creates plotly.graph_objects.Scatter object for observation points per each data set. """ - traces_data = [] - self._event._set_default_colors() # For each dataset + self._event._set_default_colors() if self._event.fits is None: self._event.get_chi2() @@ -4060,64 +4050,39 @@ def _add_interactive_data_traces( data_ref = self._event.data_ref subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) - - # Get fluxes for the reference dataset (f_source_0, f_blend_0) = self._event.get_flux_for_dataset(data_ref) + + traces_data = [] for (dataset_index, data) in enumerate(self._datasets): # Scale the data flux - (flux, err_flux) = self._event.fits[dataset_index].scale_fluxes( - f_source_0, f_blend_0) + (flux, err_flux) = self._event.fits[dataset_index].scale_fluxes(f_source_0, f_blend_0) (y_value, y_err) = mm.utils.PlotUtils.get_y_value_y_err(phot_fmt, flux, err_flux) times = data.time-subtract trace_data = self._make_one_interactive_data_trace( - dataset_index, - times, - y_value, - y_err, - xaxis='x', - yaxis='y', - showlegend=True, - show_errorbars=show_errorbars, - show_bad=show_bad, - **kwargs_interactive, - ) + dataset_index, times, y_value, y_err, xaxis='x', yaxis='y', showlegend=True, + show_errorbars=show_errorbars, show_bad=show_bad, **kwargs_interactive) traces_data.extend(trace_data) + for trace in traces_data: self._interactive_fig.add_trace(trace) - def _make_one_interactive_data_trace( - self, - dataset_index, - times, - y_value, - y_err, - xaxis, - yaxis, - showlegend, - colors, - sizes, - opacity, - show_errorbars=None, - show_bad=None, - **kwargs): + def _make_one_interactive_data_trace(self, dataset_index, times, y_value, y_err, xaxis, yaxis, showlegend, + colors, sizes, opacity, show_errorbars=None, show_bad=None, **kwargs): """ - Creates plotly.graph_objects.Scatter object with - data points form a given data set + Creates plotly.graph_objects.Scatter object with data points form a given data set. """ trace_data = [] - dataset, show_errorbars, show_bad = self._get_interactive_dataset( - dataset_index) + dataset, show_errorbars, show_bad = self._get_interactive_dataset(dataset_index) trace_data_good = self._make_interactive_good_data_trace( - dataset, times, y_value, y_err, opacity, - sizes, xaxis, yaxis, showlegend, show_errorbars) + dataset, times, y_value, y_err, opacity, sizes, xaxis, yaxis, showlegend, show_errorbars) trace_data.append(trace_data_good) if show_bad: - trace_data_bad = self._make_interactive_bad_data_trace( - dataset, times, y_value, y_err, opacity, - sizes, xaxis, yaxis, showlegend) + trace_data_bad = self._make_interactive_bad_data_trace(dataset, times, y_value, y_err, opacity, + sizes, xaxis, yaxis, showlegend) trace_data.append(trace_data_bad) + return trace_data def _get_interactive_dataset(self, dataset_index): @@ -4125,13 +4090,12 @@ def _get_interactive_dataset(self, dataset_index): dataset = self._event.datasets[dataset_index] show_errorbars = dataset.plot_properties.get('show_errorbars', True) show_bad = dataset.plot_properties.get('show_bad', False) - return dataset, show_errorbars, show_bad + return (dataset, show_errorbars, show_bad) def _make_interactive_good_data_trace( self, dataset, times, y_value, y_err, opacity, sizes, xaxis, yaxis, showlegend, show_errorbars): - """Creates a single plotly.graph_objects.Scatter - object for the good data points.""" + """Creates a single plotly.graph_objects.Scatter object for the good data points.""" times_good = times[dataset.good] y_good = y_value[dataset.good] y_err_good = y_err[dataset.good] @@ -4139,44 +4103,19 @@ def _make_interactive_good_data_trace( times_good, y_good, y_err_good, dataset, opacity, sizes, xaxis, yaxis, showlegend, show_errorbars) - def _make_interactive_data_trace( - self, x, y, y_err, dataset, opacity, sizes, xaxis, yaxis, - showlegend, show_errorbars, - color_override=None, error_visible=True): - """Creates single plotly.graph_objects.Scatter - object for good or bad data.""" - color = color_override if color_override \ - else dataset.plot_properties['color'] - return go.Scatter( - x=x, - y=y, - opacity=opacity, - name=dataset.plot_properties['label'], - mode='markers', - showlegend=showlegend, - error_y=dict( - type='data', - array=y_err, - visible=error_visible, - thickness=sizes[2], - width=sizes[3]), - marker=dict( - color=color, - size=sizes[0], - line=dict( - color=color, - width=1, - ), - ), - xaxis=xaxis, - yaxis=yaxis, - ) + def _make_interactive_data_trace(self, x, y, y_err, dataset, opacity, sizes, xaxis, yaxis, + showlegend, show_errorbars, color_override=None, error_visible=True): + """Creates single plotly.graph_objects.Scatter object for good or bad data.""" + color = color_override if color_override else dataset.plot_properties['color'] + error_y = dict(type='data', array=y_err, visible=error_visible, thickness=sizes[2], width=sizes[3]) + marker = dict(color=color, size=sizes[0], line=dict(color=color, width=1)) + return go.Scatter(x=x, y=y, opacity=opacity, name=dataset.plot_properties['label'], mode='markers', + showlegend=showlegend, error_y=error_y, marker=marker, xaxis=xaxis, yaxis=yaxis) def _make_interactive_bad_data_trace( self, dataset, times, y_value, y_err, opacity, sizes, xaxis, yaxis, showlegend): - """Creates a single plotly.graph_objects.Scatter - object for the bad data points.""" + """Creates a single plotly.graph_objects.Scatter object for the bad data points.""" times_bad = times[dataset.bad] y_bad = y_value[dataset.bad] y_err_bad = y_err[dataset.bad] @@ -4220,23 +4159,13 @@ def _add_interactive_residuals_traces( kwargs_residuals['bad'] = True for (dataset_index, data) in enumerate(self._datasets): - # Scale the data flux - (y_value, y_err) = self._event.fits[dataset_index].get_residuals( - **kwargs_residuals) + (y_value, y_err) = self._event.fits[dataset_index].get_residuals(**kwargs_residuals) times = data.time-subtract trace_residuals = self._make_one_interactive_data_trace( - dataset_index, - times, - y_value, - y_err, - xaxis='x2', - yaxis='y2', - showlegend=False, - show_errorbars=show_errorbars, - show_bad=show_bad, - **kwargs_interactive, - ) + dataset_index, times, y_value, y_err, xaxis='x2', yaxis='y2', + showlegend=False, show_errorbars=show_errorbars, show_bad=show_bad, **kwargs_interactive) traces_residuals.extend(trace_residuals) + for trace in traces_residuals: self._interactive_fig.add_trace(trace) From 5f6615ba1a0950f79ceddf5f7426bff415d18ae6 Mon Sep 17 00:00:00 2001 From: mjmroz Date: Wed, 27 Nov 2024 18:32:39 +0100 Subject: [PATCH 20/26] Shortened, removed not used 'sizes' entry --- examples/example_16/ulens_model_fit.py | 105 +++++++------------------ 1 file changed, 27 insertions(+), 78 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 8e216e138..042164e8d 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3868,8 +3868,7 @@ def _make_interactive_plot(self): self._save_interactive_fig() - def _prepare_interactive_layout( - self, scale, kwargs_all, ylim, ylim_residuals): + def _prepare_interactive_layout(self, scale, kwargs_all, ylim, ylim_residuals): """Prepares the layout for the interactive plot.""" kwargs_grid, kwargs_model, kwargs, xlim, t_1, t_2 = kwargs_all[:6] kwargs_axes_1, kwargs_axes_2 = kwargs_all[6:] @@ -3893,8 +3892,7 @@ def _get_kwargs_for_plotly_plot(self, scale): 4., # residuals error thickens 4., # residuals error width 56., # font label - 3., # zero-line width in residuals - 8., # markers residuals + 4., # zero-line width in residuals 4., # axes and legend border width 15., # ticks len 30., # font lagend @@ -3922,17 +3920,17 @@ def _make_interactive_layout(self, ylim, ylim_residuals, height_ratios, hspace, t_start = t_start - subtract t_stop = t_stop - subtract - font_1 = dict(family=font, size=sizes[4], color=colors[1]) - font_2 = dict(family=font, size=sizes[9]) - kwargs_ = dict(showgrid=False, ticks='inside', showline=True, ticklen=sizes[8], - tickwidth=sizes[7], linewidth=sizes[7], linecolor=colors[0], tickfont=font_1) + font_base = dict(family=font, size=sizes[4], color=colors[1]) + font_legend = dict(family=font, size=sizes[8]) + kwargs_ = dict(showgrid=False, ticks='inside', showline=True, ticklen=sizes[7], + tickwidth=sizes[6], linewidth=sizes[6], linecolor=colors[0], tickfont=font_base) kwargs_y = {'mirror': 'all', **kwargs_} kwargs_x = {'range': [t_start, t_stop], **kwargs_} layout = go.Layout( autosize=True, width=width, height=height, showlegend=True, legend=dict( - x=1.02, y=.98, bgcolor=paper_bgcolor, bordercolor=colors[2], borderwidth=sizes[7], font=font_2), - paper_bgcolor=paper_bgcolor, plot_bgcolor=paper_bgcolor, font=font_1, + x=1.02, y=.98, bgcolor=paper_bgcolor, bordercolor=colors[2], borderwidth=sizes[6], font=font_legend), + paper_bgcolor=paper_bgcolor, plot_bgcolor=paper_bgcolor, font=font_base, yaxis=dict(title_text='Magnitude', domain=[hsplit+(hspace/2), 1], range=ylim, **kwargs_y), yaxis2=dict(title_text='Residuals', domain=[0, hsplit-(hspace/2)], anchor="x", range=ylim_residuals, **kwargs_y), @@ -3954,25 +3952,9 @@ def _get_time_span_data(self): return (min(t_min), max(t_max)) - def _make_interactive_lc_traces( - self, - f_source_0, f_blend_0, - sizes, - colors, - opacity, - width, - height, - font, - paper_bgcolor, - t_start, - t_stop, - name=None, - dash='solid', - subtract_2450000=None, - subtract_2460000=None, - gamma=None, - bandpass=None, - **kwargs): + def _make_interactive_lc_traces(self, f_source_0, f_blend_0, sizes, colors, opacity, width, height, font, + paper_bgcolor, t_start, t_stop, name=None, dash='solid', subtract_2450000=None, + subtract_2460000=None, gamma=None, bandpass=None, **kwargs): """ Creates plotly.graph_objects.Scatter objects with model light curve """ @@ -3992,7 +3974,7 @@ def _make_interactive_lc_traces( times = times - subtract traces_lc.append(self._make_interactive_scatter_lc( times, lc, name, showlegend, colors[1], sizes[1], dash)) - return traces_lc + break traces_lc.extend(self._make_interactive_scatter_lc_satellite( traces_lc, times, f_source_0, f_blend_0, gamma, bandpass, @@ -4007,8 +3989,7 @@ def _make_interactive_scatter_lc_satellite( for (i, model) in enumerate(self._models_satellite): name = self._event.datasets[i].plot_properties['label'] model.parameters.parameters = {**self._model.parameters.parameters} - lc = self._model.get_lc(times=times, source_flux=f_source_0, - blend_flux=f_blend_0, + lc = self._model.get_lc(times=times, source_flux=f_source_0,blend_flux=f_blend_0, gamma=gamma, bandpass=bandpass) times = times - subtract trace = self._make_interactive_scatter_lc( @@ -4021,25 +4002,12 @@ def _make_interactive_scatter_lc( showlegend, color, size, dash): """Creates a Plotly Scatter trace for the light curve.""" - return go.Scatter( - x=times, - y=lc, - name=name, - showlegend=showlegend, - mode='lines', - line=dict( - color=color, - width=size, - dash=dash, - ), - xaxis="x", - yaxis="y" - ) + return go.Scatter(x=times, y=lc, name=name, showlegend=showlegend, mode='lines', + line=dict(color=color, width=size, dash=dash), + xaxis="x", yaxis="y") - def _add_interactive_zero_trace( - self, t_start, t_stop, colors, sizes, - subtract_2450000=False, subtract_2460000=False, - **kwargs): + def _add_interactive_zero_trace(self, t_start, t_stop, colors, sizes, + subtract_2450000=False, subtract_2460000=False, **kwargs): """ Creates plotly.graph_objects.Scatter object for line y=0 in residuals plot @@ -4047,19 +4015,9 @@ def _add_interactive_zero_trace( subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) times = np.linspace(t_start, t_stop, num=2000) line = np.zeros(len(times)) - trace_0 = go.Scatter( - x=times-subtract, - y=line, - mode='lines', - line=dict( - color=colors[0], - width=sizes[1], - dash='dash', - ), - xaxis="x2", - yaxis="y2", - showlegend=False, - ) + trace_0 = go.Scatter(x=times-subtract, y=line, mode='lines', + line=dict(color=colors[0], width=sizes[5], dash='dash'), + xaxis="x2", yaxis="y2", showlegend=False,) self._interactive_fig.add_trace(trace_0) def _add_interactive_data_traces(self, kwargs_interactive, phot_fmt='mag', data_ref=None, show_errorbars=True, @@ -4105,8 +4063,8 @@ def _make_one_interactive_data_trace(self, dataset_index, times, y_value, y_err, trace_data.append(trace_data_good) if show_bad: - trace_data_bad = self._make_interactive_bad_data_trace(dataset, times, y_value, y_err, opacity, - sizes, xaxis, yaxis, showlegend) + trace_data_bad = self._make_interactive_bad_data_trace( + dataset, times, y_value, y_err, opacity, sizes, xaxis, yaxis, showlegend) trace_data.append(trace_data_bad) return trace_data @@ -4138,9 +4096,8 @@ def _make_interactive_data_trace(self, x, y, y_err, dataset, opacity, sizes, xax return go.Scatter(x=x, y=y, opacity=opacity, name=dataset.plot_properties['label'], mode='markers', showlegend=showlegend, error_y=error_y, marker=marker, xaxis=xaxis, yaxis=yaxis) - def _make_interactive_bad_data_trace( - self, dataset, times, y_value, y_err, opacity, - sizes, xaxis, yaxis, showlegend): + def _make_interactive_bad_data_trace(self, dataset, times, y_value, y_err, opacity, sizes, + xaxis, yaxis, showlegend): """Creates a single plotly.graph_objects.Scatter object for the bad data points.""" times_bad = times[dataset.bad] y_bad = y_value[dataset.bad] @@ -4153,16 +4110,8 @@ def _make_interactive_bad_data_trace( error_visible=False ) - def _add_interactive_residuals_traces( - self, - kwargs_interactive, - phot_fmt='mag', - data_ref=None, - show_errorbars=True, - show_bad=None, - subtract_2450000=False, - subtract_2460000=False, - **kwargs,): + def _add_interactive_residuals_traces(self, kwargs_interactive, phot_fmt='mag', data_ref=None, show_errorbars=True, + show_bad=None, subtract_2450000=False, subtract_2460000=False, **kwargs,): """ Creates plotly.graph_objects.Scatter object for residuals points per each data set. From bba0625400dd8897c6e3d87b5e634fbdbc5a8c09 Mon Sep 17 00:00:00 2001 From: mjmroz Date: Wed, 27 Nov 2024 22:22:05 +0100 Subject: [PATCH 21/26] added ploly to requirements --- examples/example_16/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/example_16/requirements.txt b/examples/example_16/requirements.txt index a56b342ac..be35a5ef4 100644 --- a/examples/example_16/requirements.txt +++ b/examples/example_16/requirements.txt @@ -1,6 +1,7 @@ numpy scipy>=0.18.0 matplotlib +plotly yaml emcee corner From 2a1878e0b77b441371b7ad8240789a63fd54295f Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Thu, 28 Nov 2024 05:16:02 +0100 Subject: [PATCH 22/26] ex16: flake8 compliance --- examples/example_16/ob08092-o4_minimal_interactive_plot.yaml | 2 +- examples/example_16/ob08092-o4_minimal_plot.yaml | 2 +- examples/example_16/ulens_model_fit.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml b/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml index 0abd14db0..cacb34a6b 100644 --- a/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml +++ b/examples/example_16/ob08092-o4_minimal_interactive_plot.yaml @@ -6,4 +6,4 @@ model: # Now set the file where you want the light curve to be plotted: plots: best model: - interactive: ob08092-o4_minimal_plot.html + interactive: ob08092-o4_minimal_plot.html diff --git a/examples/example_16/ob08092-o4_minimal_plot.yaml b/examples/example_16/ob08092-o4_minimal_plot.yaml index 53bce3fed..08e31d227 100644 --- a/examples/example_16/ob08092-o4_minimal_plot.yaml +++ b/examples/example_16/ob08092-o4_minimal_plot.yaml @@ -19,4 +19,4 @@ fitting_parameters: # Now set the file where you want the light curve to be plotted: plots: best model: - file: ob08092-o4_minimal_plot.png + file: ob08092-o4_minimal_plot.png diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 042164e8d..0992f917b 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3989,7 +3989,7 @@ def _make_interactive_scatter_lc_satellite( for (i, model) in enumerate(self._models_satellite): name = self._event.datasets[i].plot_properties['label'] model.parameters.parameters = {**self._model.parameters.parameters} - lc = self._model.get_lc(times=times, source_flux=f_source_0,blend_flux=f_blend_0, + lc = self._model.get_lc(times=times, source_flux=f_source_0, blend_flux=f_blend_0, gamma=gamma, bandpass=bandpass) times = times - subtract trace = self._make_interactive_scatter_lc( @@ -4041,7 +4041,7 @@ def _add_interactive_data_traces(self, kwargs_interactive, phot_fmt='mag', data_ # Scale the data flux (flux, err_flux) = self._event.fits[dataset_index].scale_fluxes(f_source_0, f_blend_0) (y_value, y_err) = mm.utils.PlotUtils.get_y_value_y_err(phot_fmt, flux, err_flux) - times = data.time-subtract + times = data.time - subtract trace_data = self._make_one_interactive_data_trace( dataset_index, times, y_value, y_err, xaxis='x', yaxis='y', showlegend=True, show_errorbars=show_errorbars, show_bad=show_bad, **kwargs_interactive) From 97e9b665da190008d9f1556792760a8568b2a9b9 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Thu, 28 Nov 2024 05:25:19 +0100 Subject: [PATCH 23/26] ex16 reducing to 5000 epochs in model LC --- examples/example_16/ulens_model_fit.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 0992f917b..864bd90f6 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3959,8 +3959,8 @@ def _make_interactive_lc_traces(self, f_source_0, f_blend_0, sizes, colors, opac Creates plotly.graph_objects.Scatter objects with model light curve """ traces_lc = [] - times = np.linspace(t_start, t_stop, num=20000) subtract = mm.utils.PlotUtils.find_subtract(subtract_2450000, subtract_2460000) + times = np.linspace(t_start, t_stop, num=5000) - subtract if isinstance(name, type(None)): showlegend = False @@ -3971,14 +3971,12 @@ def _make_interactive_lc_traces(self, f_source_0, f_blend_0, sizes, colors, opac if dataset.ephemerides_file is None: lc = self._model.get_lc( times=times, source_flux=f_source_0, blend_flux=f_blend_0, gamma=gamma, bandpass=bandpass) - times = times - subtract traces_lc.append(self._make_interactive_scatter_lc( times, lc, name, showlegend, colors[1], sizes[1], dash)) break traces_lc.extend(self._make_interactive_scatter_lc_satellite( - traces_lc, times, f_source_0, f_blend_0, gamma, bandpass, - colors, sizes, dash, subtract, showlegend)) + traces_lc, times, f_source_0, f_blend_0, gamma, bandpass, colors, sizes, dash, subtract, showlegend)) return traces_lc def _make_interactive_scatter_lc_satellite( From 920554fc8e73e9d3aedc2e4412423e7064477a5f Mon Sep 17 00:00:00 2001 From: mjmroz Date: Thu, 28 Nov 2024 23:11:24 +0100 Subject: [PATCH 24/26] version and check_import update --- examples/example_16/ulens_model_fit.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 864bd90f6..9f753e52c 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -694,6 +694,9 @@ def _check_imports(self): if self._plots is not None and 'triangle' in self._plots: required_packages.add('corner') + if self._plots['best model'] and 'interactive' in self._plots['best model']: + required_packages.add('plotly') + failed = import_failed.intersection(required_packages) if len(failed) > 0: @@ -705,6 +708,8 @@ def _check_imports(self): "\nFor corner package it's enough that you run:\nwget " + "https://raw.githubusercontent.com/dfm/corner.py/" + "v2.0.0/corner/corner.py") + if "plotly" in failed: + message += ("\nThe plotly package is required for creating interactive best model plots.") raise ImportError(message) From b151093988d998633222c1ccf2d2323b9e26fe16 Mon Sep 17 00:00:00 2001 From: mjmroz Date: Thu, 28 Nov 2024 23:14:39 +0100 Subject: [PATCH 25/26] version update --- examples/example_16/ulens_model_fit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 9f753e52c..199db349c 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -47,7 +47,7 @@ raise ImportError('\nYou have to install MulensModel first!\n') -__version__ = '0.40.1' +__version__ = '0.40.2' class UlensModelFit(object): From 8ee1b30955878294faae49c0ed645cf39c2355f5 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Fri, 29 Nov 2024 07:03:21 +0100 Subject: [PATCH 26/26] ex16 - version update before merge --- examples/example_16/ulens_model_fit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 199db349c..85af3521d 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -47,7 +47,7 @@ raise ImportError('\nYou have to install MulensModel first!\n') -__version__ = '0.40.2' +__version__ = '0.41.0' class UlensModelFit(object):