-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomPulse.py
72 lines (55 loc) · 2.57 KB
/
CustomPulse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from __future__ import print_function, division
import numpy as np
import math
import xpsi
from xpsi.likelihoods.default_background_marginalisation import eval_loglike_phaseIntervals_maximise as eval_loglike_maximise
from xpsi.likelihoods.default_background_marginalisation import precomputation
from xpsi.tools import phase_interpolator
from xpsi.tools.phase_integrator import phase_integrator
from xpsi.tools.synthesise import synthesise
from xpsi.global_imports import _kpc
class CustomPulse(xpsi.Pulse):
""" A custom calculation of the logarithm of the likelihood.
We extend the :class:`xpsi.Pulse.Pulse` class to make it callable.
We overwrite the body of the __call__ method. The docstring for the
abstract method is copied.
"""
def __init__(self, workspace_intervals = 1000, epsabs = 0, epsrel = 1.0e-8,
epsilon = 1.0e-3, sigmas = 10.0, **kwargs):
""" Perform precomputation. """
super(CustomPulse, self).__init__(**kwargs)
try:
self._precomp = precomputation(self._data.counts.astype(np.int32))
except AttributeError:
print('No data... can synthesise data but cannot evaluate a '
'likelihood function.')
else:
self._workspace_intervals = workspace_intervals
self._epsabs = epsabs
self._epsrel = epsrel
self._epsilon = epsilon
self._sigmas = sigmas
def __call__(self, p, *args, **kwargs):
"""
Parameter vector:
* p[0] = phase shift primary (alias for initial azimuth/phase of photosphere)
* p[1] = phase shift secondary
"""
self.shift = np.array(p)
self.loglikelihood, self.expected_counts, self.background_signal = \
eval_loglike_maximise(self._data.exposure_time,
self._data.phases,
self._data.counts,
self._pulse,
self._phases,
self._shift,
self._precomp,
self._workspace_intervals,
self._epsabs,
self._epsrel,
self._epsilon,
self._sigmas,
kwargs.get('llzero'))
__call__.__doc__ = xpsi.Pulse.__call__.__doc__ + __call__.__doc__
def synthesise(self):
""" Overwrite. """