LALSimulation  5.4.0.1-ec27e42
nrfits.py
Go to the documentation of this file.
1 """
2 Base class for Numerical Relativity fits such as remnant BH mass, spin, etc.
3 
4 Vijay Varma, 2019.
5 """
6 
7 #=============================================================================
8 class NRFits(object):
9  """
10  Base class to evaluate NR fits.
11 
12  For each new fit, you need to do the following:
13  1. Add a new derived class for this class in a separate file and add the
14  new class to fits_collection in eval_fits.py.
15  2. override _get_fit_params() and _eval_fit() in the new derived class.
16  3. Add the new filename to Makefile.am
17 
18  See NRSur7dq4Remnant.py for an example.
19  """
20 
21  # ------------------------------------------------------------------------
22  def _get_fit_params(self, m1, m2, chiA_vec, chiB_vec, f_ref,
23  extra_params_dict):
24  """ Not all fits will require all of these parameters, this function
25  should be used to get the required params, and if necessary, process
26  them to get the parameters that are used to evaluate the actual fits.
27 
28  For example: chiA_vec/chiB_vec are defined at f_ref, this function
29  could take these initial spins and evolve them to get the spins at
30  ISCO, which are then used to evaluate the fits.
31 
32  See eval_fits.eval_nrfit() for the definitions of the arguments of
33  this function.
34  """
35  raise NotImplementedError("Please override me.")
36  return fit_params
37 
38  # ------------------------------------------------------------------------
39  def _eval_fit(self, fit_params, fit_type, extra_params_dict):
40  """ Evaluates a particular fit for a given model using the fit_params
41  returned by _get_fit_params().
42  """
43  raise NotImplementedError("Please override me.")
44 
45  # ------------------------------------------------------------------------
46  def __call__(self, m1, m2, chiA_vec, chiB_vec, f_ref, fit_types_list,
47  extra_params_dict):
48  """ Evaluates all fits given in fit_types_list and returns them as
49  a dictionary.
50 
51  See eval_fits.eval_nrfit() for the definitions of the arguments of
52  this function.
53  """
54 
55  # Get the parameters used to evaluate the fits. This includes any
56  # spin evolution that may be required
57  fit_params = self._get_fit_params_get_fit_params(m1, m2, chiA_vec, chiB_vec,
58  f_ref, extra_params_dict)
59 
60  # Add more if needed and update the fit_types_list documentation in
61  # eval_fits.py
62  allowed_fit_types = [
63  "FinalMass",
64  "FinalSpin",
65  "RecoilKick",
66  "PeakLuminosity",
67  ]
68 
69  # Loop over fit_types_list and return a dictionary of values
70  return_dict = {}
71  for fit_type in fit_types_list:
72  if fit_type not in allowed_fit_types:
73  raise ValueError("Invalid fit_type=%s. "%fit_type \
74  + "Should be one of ["+ ", ".join(allowed_fit_types) + "].")
75  return_dict[fit_type] = self._eval_fit_eval_fit(fit_params, fit_type,
76  extra_params_dict)
77 
78  return return_dict
79 
80 
Base class for Numerical Relativity fits such as remnant BH mass, spin, etc.
Definition: nrfits.py:19
def _eval_fit(self, fit_params, fit_type, extra_params_dict)
Definition: nrfits.py:42
def _get_fit_params(self, m1, m2, chiA_vec, chiB_vec, f_ref, extra_params_dict)
Definition: nrfits.py:34
def __call__(self, m1, m2, chiA_vec, chiB_vec, f_ref, fit_types_list, extra_params_dict)
Evaluates all fits given in fit_types_list and returns them as a dictionary.
Definition: nrfits.py:53