Skip to content

Commit

Permalink
resolving merge conflicts from parallax_refactor branch
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoleski committed Mar 8, 2022
2 parents 5d13302 + 752e777 commit 3b438a6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[**Detailed documentation: https://rpoleski.github.io/MulensModel/**](https://rpoleski.github.io/MulensModel/)

[Latest release: 2.6.6](https://github.com/rpoleski/MulensModel/releases/latest) and we're working on further developing the code.
[Latest release: 2.7.0](https://github.com/rpoleski/MulensModel/releases/latest) and we're working on further developing the code.

MulensModel can generate a microlensing light curve for a given set of microlensing parameters, fit that light curve to some data, and return a chi2 value. That chi2 can then be input into an arbitrary likelihood function to find the best-fit parameters.

Expand Down
30 changes: 5 additions & 25 deletions source/MulensModel/fitdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,31 +670,11 @@ def _get_d_u_d_params(self, parameters):

# Below we deal with parallax only.
if 'pi_E_N' in parameters or 'pi_E_E' in parameters:
warnings.warn(
"\n\nTests indicate that chi2 gradient for models with "
"parallax has BUGS!!!\n It's better not to use it or contact "
"code authors.\n")
# JCY Not happy about this as it requires importing from other
# modules. It is inelegant, which in my experience often means it
# needs to be refactored.
kwargs = dict()
if self.dataset.ephemerides_file is not None:
kwargs['satellite_skycoord'] = self.dataset.satellite_skycoord

parameters_no_piE = {**self.model.parameters.as_dict()}
parameters_no_piE.pop('pi_E_N')
parameters_no_piE.pop('pi_E_E')

trajectory_no_piE = Trajectory(
self.dataset.time, ModelParameters(parameters_no_piE),
**kwargs)
dx = trajectory.x - trajectory_no_piE.x
dy = trajectory.y - trajectory_no_piE.y
delta_E = dx * as_dict['pi_E_E'] + dy * as_dict['pi_E_N']
delta_N = dx * as_dict['pi_E_N'] - dy * as_dict['pi_E_E']
det = as_dict['pi_E_N']**2 + as_dict['pi_E_E']**2
gradient['pi_E_N'] = (d_u_d_x * delta_N + d_u_d_y * delta_E) / det
gradient['pi_E_E'] = (d_u_d_x * delta_E - d_u_d_y * delta_N) / det
delta_N = trajectory.delta_NE['N']
delta_E = trajectory.delta_NE['E']

gradient['pi_E_N'] = d_u_d_x * delta_N + d_u_d_y * delta_E
gradient['pi_E_E'] = d_u_d_x * delta_E - d_u_d_y * delta_N

return gradient

Expand Down
67 changes: 44 additions & 23 deletions source/MulensModel/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ def y(self):
"""
return self._y

@property
def parallax_delta_N_E(self):
"""
*dict*
Net North (key='N') and East (key='E') components of the parallax
offset calculated for each time stamp (so sum of the offsets from all
parallax types).
"""
return self._delta_N_E

def get_xy(self):
"""
For a given set of parameters
Expand All @@ -153,34 +164,18 @@ def get_xy(self):
raise ValueError("You're trying to calculate trajectory in " +
"a parallax model, but event sky " +
"coordinates were not provided.")

keys = ['earth_orbital', 'satellite', 'topocentric']
if set([self.parallax[k] for k in keys]) == set([False]):
raise ValueError(
'If pi_E value is provided then at least one value ' +
'of parallax dict has to be True ' +
'(earth_orbital, satellite, or topocentric)')

# Apply Earth Orbital parallax effect
if self.parallax['earth_orbital']:
[delta_tau, delta_u] = self._annual_parallax_trajectory()
vector_tau += delta_tau
vector_u += delta_u

# Apply satellite parallax effect
if (self.parallax['satellite'] and
self.satellite_skycoord is not None):
[delta_tau, delta_u] = self._satellite_parallax_trajectory()
vector_tau += delta_tau
vector_u += delta_u

# Apply topocentric parallax effect
if self.parallax['topocentric'] and self._earth_coords is not None:
# When you implement it, make sure the behavior
# depends on the access to the observatory location
# information as the satellite parallax depends on the
# access to satellite_skycoord.
raise NotImplementedError(
"The topocentric parallax effect not implemented yet")
self._calculate_delta_N_E()
[delta_tau, delta_u] = self._project_delta()
vector_tau += delta_tau
vector_u += delta_u

# If 2 lenses, rotate trajectory relative to binary lens axis
if self.parameters.n_lenses == 1:
Expand All @@ -203,14 +198,40 @@ def get_xy(self):
raise NotImplementedError(
"trajectory for more than 2 lenses not handled yet")

# Store trajectory
self._x = vector_x
self._y = vector_y

def _project_delta(self, delta):
def _calculate_delta_N_E(self):
"""
Calculate shifts caused by microlensing parallax effect.
"""
self._delta_N_E = {'N': 0., 'E': 0.}

if self.parallax['earth_orbital']:
delta_annual = self._get_delta_annual()
self._delta_N_E['N'] += delta_annual['N']
self._delta_N_E['E'] += delta_annual['E']

if (self.parallax['satellite'] and
self.satellite_skycoord is not None):
delta_satellite = self._get_delta_satellite()
self._delta_N_E['N'] += delta_satellite['N']
self._delta_N_E['E'] += delta_satellite['E']

if self.parallax['topocentric'] and self._earth_coords is not None:
# When you implement it, make sure the behavior depends on the
# access to the observatory location information as the satellite
# parallax depends on the access to satellite_skycoord.
raise NotImplementedError(
"The topocentric parallax effect not implemented yet")

def _project_delta(self, delta=None):
"""
Project N and E parallax offset vector onto the tau, beta plane.
"""
if delta is None:
delta = self.parallax_delta_N_E

delta_tau = (delta['N'] * self.parameters.pi_E_N +
delta['E'] * self.parameters.pi_E_E)
delta_beta = (-delta['N'] * self.parameters.pi_E_E +
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.6.6"
__version__ = "2.7.0"

0 comments on commit 3b438a6

Please sign in to comment.