Skip to content

Commit

Permalink
better warning for missing FS magnification method
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoleski committed Oct 5, 2023
1 parent dd54d4e commit e3a45e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
37 changes: 19 additions & 18 deletions source/MulensModel/magnificationcurve.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import math
import warnings

from os.path import join
import numpy as np

from MulensModel.binarylens import BinaryLens
from MulensModel.binarylenswithshear import BinaryLensWithShear
from MulensModel.modelparameters import ModelParameters
from MulensModel.pointlens import PointLens, get_pspl_magnification
from MulensModel.pointlenswithshear import PointLensWithShear
from MulensModel.trajectory import Trajectory
import MulensModel as mm


class MagnificationCurve(object):
Expand Down Expand Up @@ -54,15 +49,15 @@ def __init__(self, times, parameters, parallax=None,
self.times = np.atleast_1d(times)

# Check for ModelParameters and set.
if isinstance(parameters, ModelParameters):
if isinstance(parameters, mm.ModelParameters):
self.parameters = parameters
else:
raise TypeError(
'parameters is a required keyword and must be a ' +
'ModelParameters object')

# Calculate the source trajectory (i.e. u(t))
self.trajectory = Trajectory(
self.trajectory = mm.Trajectory(
self.times, parameters=parameters, parallax=parallax,
coords=coords, satellite_skycoord=satellite_skycoord)

Expand Down Expand Up @@ -177,7 +172,13 @@ def _check_for_finite_source_method(self):
methods = self._methods_names + [self._default_method]
set_ = set(['point_source', 'point_source_point_lens', None])
if len(set(methods)-set_) == 0:
warnings.warn('no finite-source method is set', UserWarning)
path = join(
mm.MODULE_PATH, "documents", "magnification_methods.pdf")
msg = ("No finite-source method is set.\n"
"For possible magnification methods see\n" + path + "or\n"
"https://github.com/rpoleski/MulensModel/blob/master/"
"documents/magnification_methods.pdf")
warnings.warn(msg, UserWarning)
return

def get_point_lens_magnification(self):
Expand Down Expand Up @@ -256,12 +257,12 @@ def get_point_lens_magnification(self):
" lenses")

if self.parameters.is_external_mass_sheet:
point_lens = PointLensWithShear(self.parameters)
point_lens = mm.PointLensWithShear(self.parameters)
magnification = point_lens.get_point_source_magnification(
self.trajectory)
else:
point_lens = PointLens(self.parameters)
magnification = get_pspl_magnification(self.trajectory)
point_lens = mm.PointLens(self.parameters)
magnification = mm.get_pspl_magnification(self.trajectory)

methods = self._methods_for_epochs()
if len(set(methods)-set([None, 'point_source'])) == 0:
Expand Down Expand Up @@ -389,10 +390,10 @@ def get_binary_lens_magnification(self):
" lenses")

if not self.parameters.is_external_mass_sheet:
binary_lens_class = BinaryLens
binary_lens_class = mm.BinaryLens
kwargs = dict()
else:
binary_lens_class = BinaryLensWithShear
binary_lens_class = mm.BinaryLensWithShear
K = self.parameters.parameters.get('convergence_K', 0)
G = self.parameters.parameters.get('shear_G', complex(0, 0))
kwargs = {'convergence_K': K, 'shear_G': G}
Expand Down Expand Up @@ -460,20 +461,20 @@ def _get_binary_lens_magnification(self, binary_lens_class,
m = binary_lens.hexadecapole_magnification(
x, y, rho=self.parameters.rho, gamma=self._gamma)
elif method == 'vbbl':
if isinstance(binary_lens, BinaryLensWithShear):
if isinstance(binary_lens, mm.BinaryLensWithShear):
raise ValueError("Finite source VBBL is not available "
"for BinaryLensWithShear")
m = binary_lens.vbbl_magnification(
x, y, rho=self.parameters.rho, gamma=self._gamma, **kwargs)
elif method == 'adaptive_contouring':
if isinstance(binary_lens, BinaryLensWithShear):
if isinstance(binary_lens, mm.BinaryLensWithShear):
raise ValueError("Adaptive contouring is not available "
"for BinaryLensWithShear")
m = binary_lens.adaptive_contouring_magnification(
x, y, rho=self.parameters.rho, gamma=self._gamma, **kwargs)
elif method == 'point_source_point_lens':
u = math.sqrt(x**2 + y**2)
m = get_pspl_magnification(u)
m = mm.get_pspl_magnification(u)
else:
msg = 'Unknown method specified for binary lens: {:}'
raise ValueError(msg.format(method))
Expand Down
2 changes: 1 addition & 1 deletion source/MulensModel/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.18.2"
__version__ = "2.18.3"

0 comments on commit e3a45e7

Please sign in to comment.