Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed deprecated stuff in Version3_1 branch #126

Merged
merged 14 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/example_08_planet_grid_fitting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
"point_lens_event.plot_data(show_bad=True)\n",
"pl.show()\n",
"print(point_lens_event.get_ref_fluxes())\n",
"print(point_lens_event.model.magnification(t_0))\n",
"print(point_lens_event.model.get_magnification(t_0))\n",
"\n",
"point_lens_event.plot_model(subtract_2460000=True, color='black', zorder=10)\n",
"point_lens_event.plot_data(show_bad=True, subtract_2460000=True)\n",
Expand Down Expand Up @@ -629,7 +629,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion examples/example_13_caustic_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def generate_random_parameters(parameters, starting, n, s=None, q=None):
if 'methods' in model_settings:
my_model.set_magnification_methods(model_settings['methods'])
if 'default_method' in model_settings:
my_model.set_default_magnification_method(model_settings['default_method'])
my_model.default_magnification_method = model_settings['default_method']
my_event = mm.Event(datasets=datasets, model=my_model)

# Prepare sampler.
Expand Down
2 changes: 1 addition & 1 deletion examples/example_15_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def generate_random_parameters(parameters, starting, n):
if 'methods' in model_settings:
my_model.set_magnification_methods(model_settings['methods'])
if 'default_method' in model_settings:
my_model.set_default_magnification_method(model_settings['default_method'])
my_model.default_magnification_method = model_settings['default_method']
my_event = mm.Event(datasets=datasets, model=my_model)

# Prepare sampler.
Expand Down
4 changes: 2 additions & 2 deletions examples/example_16/ulens_model_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,8 +1640,8 @@ def _make_model_and_event(self):
for (band, u_value) in self._model_parameters[key].items():
model.set_limb_coeff_u(band, u_value)
if 'default method' in self._model_parameters:
model.set_default_magnification_method(
self._model_parameters['default method'])
model.default_magnification_method = \
self._model_parameters['default method']
if 'methods' in self._model_parameters:
model.set_magnification_methods(
self._model_parameters['methods'])
Expand Down
107 changes: 6 additions & 101 deletions source/MulensModel/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class Event(object):
:py:class:`~MulensModel.mulensdata.MulensData` object is specified,
it will take precedence over a band.

fit: DEPRECATED

data_ref: *int* or :py:class:`~MulensModel.mulensdata.MulensData`
Reference dataset. If *int* then gives index of reference dataset
in :py:attr:`~datasets`. Default is the first dataset.
Expand Down Expand Up @@ -433,10 +431,6 @@ def plot_trajectory(self, **kwargs):
Plot the trajectory of the source. See
:py:func:`MulensModel.model.Model.plot_trajectory()` for details.
"""
if 'show_data' in kwargs:
raise AttributeError('Parameter show_data is deprecated. Use '
'plot_source_for_datasets() instead.')

self.model.plot_trajectory(**kwargs)

def plot_source_for_datasets(self, **kwargs):
Expand Down Expand Up @@ -541,38 +535,25 @@ def get_flux_for_dataset(self, dataset):

return (source_flux, blend_flux)

def get_ref_fluxes(self, data_ref=None, fit_blending=None):
def get_ref_fluxes(self):
"""
Get source and blending fluxes for the reference dataset. See
:py:func:`~get_flux_for_dataset()`. If the reference dataset is not
set, uses the first dataset as default. See :py:obj:`~data_ref`.
"""
if data_ref is not None:
warnings.warn(
'data_ref will be deprecated. It is redundant for getting ' +
'the flux of the reference dataset. For the flux of an ' +
'arbitrary dataset, use get_flux_for_dataset')

if fit_blending is not None:
self._apply_fit_blending(fit_blending)

return self.get_flux_for_dataset(self.data_ref)

def get_chi2(self, fit_blending=None):
def get_chi2(self):
"""
Calculates chi^2 of current model by fitting for source and
blending fluxes.

Parameters :
fit_blending: DEPRECATED. use :py:attr:`~fix_blend_flux` instead.

Returns :
chi2: *float*
Chi^2 value

"""
if fit_blending is not None:
self._apply_fit_blending(fit_blending)

self.fit_fluxes()
chi2 = []
Expand All @@ -584,36 +565,29 @@ def get_chi2(self, fit_blending=None):

return self.chi2

def get_chi2_for_dataset(self, index_dataset, fit_blending=None):
def get_chi2_for_dataset(self, index_dataset):
"""
Calculates chi^2 for a single dataset

Parameters :
index_dataset: *int*
index that specifies for which dataset the chi^2 is requested

fit_blending: DEPRECATED. use :py:attr:`~fix_blending` instead.

Returns :
chi2: *float*
chi2 for dataset[index_dataset].

"""
if fit_blending is not None:
self._apply_fit_blending(fit_blending)

self.fit_fluxes()

return self.fits[index_dataset].chi2

def get_chi2_per_point(self, fit_blending=None, bad=False):
def get_chi2_per_point(self, bad=False):
"""
Calculates chi^2 for each data point of the current model by
fitting for source and blending fluxes.

Parameters :
fit_blending: DEPRECATED. use :py:attr:`~fix_blending` instead.

bad: *bool*
Should chi2 be also caclulated for points marked as bad in
MulensData? If `False` (default), then bad epochs have chi2 of
Expand All @@ -635,9 +609,6 @@ def get_chi2_per_point(self, fit_blending=None, bad=False):
print(chi2[0][10])

"""
if fit_blending is not None:
self._apply_fit_blending(fit_blending)

self.fit_fluxes(bad=bad)

# Calculate chi^2 given the fit
Expand All @@ -650,7 +621,7 @@ def get_chi2_per_point(self, fit_blending=None, bad=False):

return chi2_per_point

def get_chi2_gradient(self, parameters, fit_blending=None):
def get_chi2_gradient(self, parameters):
"""
Fit for fluxes and calculate chi^2 gradient (also called Jacobian),
i.e., :math:`d chi^2/d parameter`.
Expand All @@ -662,18 +633,14 @@ def get_chi2_gradient(self, parameters, fit_blending=None):
``t_E``, ``pi_E_N``, and ``pi_E_E``. The parameters for
which you request gradient must be defined in py:attr:`~model`.

fit_blending: DEPRECATED. use :py:attr:`~fix_blending` instead.

Returns :
gradient: *float* or *np.ndarray*
chi^2 gradient

"""
if fit_blending is not None:
self._apply_fit_blending(fit_blending)

self.fit_fluxes()
self.calculate_chi2_gradient(parameters)

return self.chi2_gradient

def calculate_chi2_gradient(self, parameters):
Expand Down Expand Up @@ -778,14 +745,6 @@ def _update_coords(self, coords=None):
if self._model is not None:
self._model.coords = self._coords

# We run the command below with try, because _update_coords() is called
# by _set_datasets before self._datasets is set.
try:
for dataset in self._datasets:
dataset.coords = self._coords
except Exception:
pass

@property
def model(self):
"""an instance of :py:class:`~MulensModel.model.Model`"""
Expand Down Expand Up @@ -822,15 +781,7 @@ def _set_datasets(self, new_value):
can be called by __init__ or @datasets.setter
passes datasets to property self._model
"""
if isinstance(new_value, list):
for dataset in new_value:
if dataset.coords is not None:
self._update_coords(coords=dataset.coords)

if isinstance(new_value, MulensData):
if new_value.coords is not None:
self._update_coords(coords=new_value.coords)

new_value = [new_value]

if new_value is None:
Expand Down Expand Up @@ -1000,49 +951,3 @@ def sum_function(self):
@sum_function.setter
def sum_function(self, new_value):
self._sum_function = new_value

# ----Stuff that Doesn't Work (or is Deprecated)---- #
def reset_best_chi2(self):
"""
DEPRECATED

Reset :py:attr:`~best_chi2` attribute and its parameters
(:py:attr:`~best_chi2_parameters`).
"""
raise AttributeError(
'reset_best_chi2 (and best_chi2) has been deprecated.')

@property
def best_chi2(self):
"""
DEPRECATED

*float*

The smallest value returned by :py:func:`get_chi2()`.
"""
raise AttributeError('best_chi2 has been deprecated.')

@property
def best_chi2_parameters(self):
"""
DEPRECATED

*dict*

Parameters that gave the smallest chi2.
"""
raise AttributeError(
'best_chi2_parameters (and best_chi2) has been deprecated.')

def _apply_fit_blending(self, fit_blending):
warnings.warn(
'fit_blending option will be deprecated in future.' +
'To fix the blending, set Event.fix_blend_flux instead.',
FutureWarning)
self._fits = None
if fit_blending is True:
self.fix_blend_flux = {}
else:
for dataset in self.datasets:
self.fix_blend_flux[dataset] = 0.
29 changes: 9 additions & 20 deletions source/MulensModel/fitdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,8 @@ def scale_fluxes(self, source_flux, blend_flux):

return (flux, err_flux)

def get_residuals(
self, phot_fmt=None, source_flux=None, blend_flux=None, bad=False,
type=None):
def get_residuals(self, phot_fmt=None, source_flux=None, blend_flux=None,
bad=False):
"""
Calculate the residuals for each datapoint relative to the model.

Expand All @@ -492,9 +491,6 @@ def get_residuals(
magnification for each point to ensure that there are values
even for bad datapoints.

type:
DEPRECATED, see "phot_fmt" above.

Returns :
residuals: *np.ndarray*
the residuals for the corresponding dataset.
Expand All @@ -503,20 +499,13 @@ def get_residuals(
the scaled errorbars for each point. For plotting
errorbars for the residuals.
"""
if type is not None:
if type == 'mag':
warnings.warn(
'"mag" returns residuals in the original data flux' +
'system. To scale the residuals, use "scaled".')
warnings.warn(
'type keyword will be deprecated. Use "phot_fmt" instead.',
FutureWarning)
phot_fmt = type

if bad:
self._calculate_magnifications(bad=True)

if phot_fmt == 'mag':
warnings.warn(
'"mag" returns residuals in the original data flux system.' +
' To scale the residuals, use "scaled".')
residuals = self._dataset.mag - self.get_model_magnitudes()
errorbars = self._dataset.err_mag
elif phot_fmt == 'flux':
Expand Down Expand Up @@ -894,7 +883,7 @@ def gamma(self):
class FSPL_Derivatives(object):

def __init__(self, fit):
raise NotImplementedError(
'The FSPL_Derivatives class was deprecated in Version 3. ' +
'Its various functions were incorporated into the new ' +
'PointLens classes.')
raise NotImplementedError(
'The FSPL_Derivatives class was deprecated in Version 3. ' +
'Its various functions were incorporated into the new ' +
'PointLens classes.')
Loading