Skip to content

Commit

Permalink
ex16 correction by Raphael - better second Y scale
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoleski committed Nov 21, 2023
1 parent 106f682 commit a03cce4
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions examples/example_16/ulens_model_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
except Exception:
raise ImportError('\nYou have to install MulensModel first!\n')

__version__ = '0.34.0'
__version__ = '0.34.1'


class UlensModelFit(object):
Expand Down Expand Up @@ -3131,10 +3131,7 @@ def _second_Y_axis_get_fluxes(self, ylim):
flux_max = mm.Utils.get_flux_from_mag(ylim[1])
(source_flux, blend_flux) = self._event.get_ref_fluxes()

if self._model.n_sources == 1:
total_source_flux = source_flux
else:
total_source_flux = sum(source_flux)
total_source_flux = sum(source_flux)
A_min = (flux_min - blend_flux) / total_source_flux
A_max = (flux_max - blend_flux) / total_source_flux

Expand All @@ -3146,23 +3143,23 @@ def _second_Y_axis_optimal(self, ax2, A_min, A_max):
"""
ax2.set_ylim(A_min, A_max)
A_values = ax2.yaxis.get_ticklocs().round(7)
A_values = A_values[(A_values >= 1.) & (A_values < A_max)]
A_values = A_values[(A_values >= max(1, A_min)) & (A_values < A_max)]
is_integer = [mag.is_integer() for mag in A_values]
if all(is_integer):
labels = [f"{int(x):d}" for x in A_values]
return (A_values.tolist(), labels, False)
return (A_values, labels, False)

fnum = np.array([str(x)[::-1].find(".") for x in A_values])
labels = np.array([f"%0.{max(fnum)}f" % x for x in A_values])
if max(fnum) >= 4 and len(fnum[fnum < 4]) < 3:
msg = ("The computed magnifications for the second Y scale cover"
" a range too small to be shown: {:}")
warnings.warn(msg.format(A_values))
return (A_values.tolist(), labels.tolist(), True)
return (A_values, labels.tolist(), True)
if max(fnum) >= 4:
labels = np.array([f"{x:0.3f}" for x in A_values])

return (A_values[fnum < 4].tolist(), labels[fnum < 4].tolist(), False)
return (A_values[fnum < 4], labels[fnum < 4].tolist(), False)

def _second_Y_axis_warnings(self, flux, labels, A_values, A_min, A_max):
"""
Expand All @@ -3183,7 +3180,7 @@ def _second_Y_axis_warnings(self, flux, labels, A_values, A_min, A_max):
"side) Y-axis scale are from {:} to {:},\nbut the range "
"of plotted magnifications is from {:} to {:}, hence, "
"the second scale is not plotted")
args = [min(A_values), max(A_values), A_min[0], A_max[0]]
args = [np.min(A_values), np.max(A_values), A_min[0], A_max[0]]
warnings.warn(msg.format(*args))
return True

Expand Down

0 comments on commit a03cce4

Please sign in to comment.