Beispiel #1
0
 def inverse_jacobian(self, maps):
     """Returns the Jacobian for the transforming mass1 and mass2 to
     mchirp and q.
     """
     m1 = conversions.primary_mass(maps['mass1'], maps['mass2'])
     m2 = conversions.secondary_mass(maps['mass1'], maps['mass2'])
     return conversions.mchirp_from_mass1_mass2(m1, m2) / m2**2.
Beispiel #2
0
    def rvs(self, size=1, param=None):
        """Gives a set of random values drawn from this distribution.

        In the returned set, mass2 <= mass1.

        Parameters
        ----------
        size : int
            The number of values to generate; default is 1.
        param : str, optional
            If provided, will just return values for the given parameter.

        Returns
        -------
        structured array
            The random values in a numpy structured array.
        """
        arr = super(UniformComponentMasses, self).rvs(size=size)
        # enforce m1 > m2
        m1 = conversions.primary_mass(arr['mass1'], arr['mass2'])
        m2 = conversions.secondary_mass(arr['mass1'], arr['mass2'])
        arr['mass1'][:] = m1
        arr['mass2'][:] = m2
        if param is not None:
            arr = arr[param]
        return arr
Beispiel #3
0
    def inverse_transform(self, maps):
        """This function transforms from component masses to chirp mass and
        mass ratio.

        Parameters
        ----------
        maps : a mapping object

        Examples
        --------
        Convert a dict of numpy.array:

        >>> import numpy
        >>> from pycbc import transforms
        >>> t = transforms.MchirpQToMass1Mass2()
        >>> t.inverse_transform({'mass1': numpy.array([16.4]), 'mass2': numpy.array([8.2])})
            {'mass1': array([ 16.4]), 'mass2': array([ 8.2]),
             'mchirp': array([ 9.97717521]), 'q': 2.0}

        Returns
        -------
        out : dict
            A dict with key as parameter name and value as numpy.array or float
            of transformed values.
        """
        out = {}
        out[parameters.mchirp] = \
                 conversions.mchirp_from_mass1_mass2(maps[parameters.mass1],
                                                     maps[parameters.mass2])
        m_p = conversions.primary_mass(maps[parameters.mass1],
                                       maps[parameters.mass2])
        m_s = conversions.secondary_mass(maps[parameters.mass1],
                                         maps[parameters.mass2])
        out[parameters.q] = m_p / m_s
        return self.format_output(maps, out)
Beispiel #4
0
 def inverse_jacobian(self, maps):
     """Returns the Jacobian for the transforming mass1 and mass2 to
     mchirp and q.
     """
     m1 = conversions.primary_mass(maps['mass1'], maps['mass2'])
     m2 = conversions.secondary_mass(maps['mass1'], maps['mass2'])
     return conversions.mchirp_from_mass1_mass2(m1, m2)/m2**2.
Beispiel #5
0
    def inverse_transform(self, maps):
        """This function transforms from component masses to chirp mass and
        mass ratio.

        Parameters
        ----------
        maps : a mapping object

        Examples
        --------
        Convert a dict of numpy.array:

        >>> import numpy
        >>> from pycbc import transforms
        >>> t = transforms.MchirpQToMass1Mass2()
        >>> t.inverse_transform({'mass1': numpy.array([16.4]), 'mass2': numpy.array([8.2])})
            {'mass1': array([ 16.4]), 'mass2': array([ 8.2]),
             'mchirp': array([ 9.97717521]), 'q': 2.0}

        Returns
        -------
        out : dict
            A dict with key as parameter name and value as numpy.array or float
            of transformed values.
        """
        out = {}
        out[parameters.mchirp] = \
                 conversions.mchirp_from_mass1_mass2(maps[parameters.mass1],
                                                     maps[parameters.mass2])
        m_p = conversions.primary_mass(maps[parameters.mass1],
                                       maps[parameters.mass2])
        m_s = conversions.secondary_mass(maps[parameters.mass1],
                                         maps[parameters.mass2])
        out[parameters.q] = m_p / m_s
        return self.format_output(maps, out)
Beispiel #6
0
    def setUp(self, *args):
        self.numtests = 1000
        self.precision = 1e-8
        self.f_lower = 10.
        # create some component masses to work with
        self.m1 = numpy.random.uniform(1., 100., size=self.numtests)
        self.m2 = numpy.random.uniform(1., 100., size=self.numtests)
        # create some spins to work with
        spin_angledist = distributions.UniformSolidAngle()
        rvals = spin_angledist.rvs(size=self.numtests)
        self.spin1_polar = rvals['theta']
        self.spin1_az = rvals['phi']
        self.spin1_amp = numpy.random.uniform(0., 1., size=self.numtests)
        rvals = spin_angledist.rvs(size=self.numtests)
        self.spin2_polar = rvals['theta']
        self.spin2_az = rvals['phi']
        self.spin2_amp = numpy.random.uniform(0., 1., size=self.numtests)

        # calculate derived parameters from each
        self.mp = conversions.primary_mass(self.m1, self.m2)
        self.ms = conversions.secondary_mass(self.m1, self.m2)
        self.mtotal = conversions.mtotal_from_mass1_mass2(self.m1, self.m2)
        self.q = conversions.q_from_mass1_mass2(self.m1, self.m2)
        self.invq = conversions.invq_from_mass1_mass2(self.m1, self.m2)
        self.mchirp = conversions.mchirp_from_mass1_mass2(self.m1, self.m2)
        self.eta = conversions.eta_from_mass1_mass2(self.m1, self.m2)
        self.tau0 = conversions.tau0_from_mtotal_eta(self.mtotal, self.eta,
                                                     self.f_lower)
        self.tau3 = conversions.tau3_from_mtotal_eta(self.mtotal, self.eta,
                                                     self.f_lower)
        self.spin1x, self.spin1y, self.spin1z = \
            coordinates.spherical_to_cartesian(self.spin1_amp, self.spin1_az,
                                self.spin1_polar)
        self.spin2x, self.spin2y, self.spin2z = \
            coordinates.spherical_to_cartesian(self.spin2_amp, self.spin2_az,
                                self.spin2_polar)
        self.effective_spin = conversions.chi_eff(self.m1, self.m2,
                                self.spin1z, self.spin2z)
        self.chi_p = conversions.chi_p(self.m1, self.m2, self.spin1x,
            self.spin1y, self.spin2x, self.spin2y)
        self.primary_spinx = conversions.primary_spin(self.m1, self.m2,
                                self.spin1x, self.spin2x)
        self.primary_spiny = conversions.primary_spin(self.m1, self.m2,
                                self.spin1y, self.spin2y)
        self.primary_spinz = conversions.primary_spin(self.m1, self.m2,
                                self.spin1z, self.spin2z)
        self.secondary_spinx = conversions.secondary_spin(self.m1, self.m2,
                                    self.spin1x, self.spin2x)
        self.secondary_spiny = conversions.secondary_spin(self.m1, self.m2,
                                    self.spin1y, self.spin2y)
        self.secondary_spinz = conversions.secondary_spin(self.m1, self.m2,
                                    self.spin1z, self.spin2z)
    def setUp(self, *args):
        self.numtests = 1000
        self.precision = 1e-8
        self.f_lower = 10.
        # create some component masses to work with
        self.m1 = numpy.random.uniform(1., 100., size=self.numtests)
        self.m2 = numpy.random.uniform(1., 100., size=self.numtests)
        # create some spins to work with
        spin_angledist = distributions.UniformSolidAngle()
        rvals = spin_angledist.rvs(size=self.numtests)
        self.spin1_polar = rvals['theta']
        self.spin1_az = rvals['phi']
        self.spin1_amp = numpy.random.uniform(0., 1., size=self.numtests)
        rvals = spin_angledist.rvs(size=self.numtests)
        self.spin2_polar = rvals['theta']
        self.spin2_az = rvals['phi']
        self.spin2_amp = numpy.random.uniform(0., 1., size=self.numtests)

        # calculate derived parameters from each
        self.mp = conversions.primary_mass(self.m1, self.m2)
        self.ms = conversions.secondary_mass(self.m1, self.m2)
        self.mtotal = conversions.mtotal_from_mass1_mass2(self.m1, self.m2)
        self.q = conversions.q_from_mass1_mass2(self.m1, self.m2)
        self.invq = conversions.invq_from_mass1_mass2(self.m1, self.m2)
        self.mchirp = conversions.mchirp_from_mass1_mass2(self.m1, self.m2)
        self.eta = conversions.eta_from_mass1_mass2(self.m1, self.m2)
        self.tau0 = conversions.tau0_from_mtotal_eta(self.mtotal, self.eta,
                                                     self.f_lower)
        self.tau3 = conversions.tau3_from_mtotal_eta(self.mtotal, self.eta,
                                                     self.f_lower)
        self.spin1x, self.spin1y, self.spin1z = \
            coordinates.spherical_to_cartesian(self.spin1_amp, self.spin1_az,
                                self.spin1_polar)
        self.spin2x, self.spin2y, self.spin2z = \
            coordinates.spherical_to_cartesian(self.spin2_amp, self.spin2_az,
                                self.spin2_polar)
        self.effective_spin = conversions.chi_eff(self.m1, self.m2,
                                self.spin1z, self.spin2z)
        self.primary_spinx = conversions.primary_spin(self.m1, self.m2,
                                self.spin1x, self.spin2x)
        self.primary_spiny = conversions.primary_spin(self.m1, self.m2,
                                self.spin1y, self.spin2y)
        self.primary_spinz = conversions.primary_spin(self.m1, self.m2,
                                self.spin1z, self.spin2z)
        self.secondary_spinx = conversions.secondary_spin(self.m1, self.m2,
                                    self.spin1x, self.spin2x)
        self.secondary_spiny = conversions.secondary_spin(self.m1, self.m2,
                                    self.spin1y, self.spin2y)
        self.secondary_spinz = conversions.secondary_spin(self.m1, self.m2,
                                    self.spin1z, self.spin2z)
Beispiel #8
0
    def transform(self, maps):
        """ This function transforms from mass-weighted spins to caretsian spins
        in the x-y plane.

        Parameters
        ----------
        maps : a mapping object

        Returns
        -------
        out : dict
            A dict with key as parameter name and value as numpy.array or float
            of transformed values.
        """

        # find primary and secondary masses
        # since functions in conversions.py map to primary/secondary masses
        m_p = conversions.primary_mass(maps["mass1"], maps["mass2"])
        m_s = conversions.secondary_mass(maps["mass1"], maps["mass2"])

        # find primary and secondary xi
        # can re-purpose spin functions for just a generic variable
        xi_p = conversions.primary_spin(maps["mass1"], maps["mass2"],
                                        maps["xi1"], maps["xi2"])
        xi_s = conversions.secondary_spin(maps["mass1"], maps["mass2"],
                                          maps["xi1"], maps["xi2"])

        # convert using convention of conversions.py that is mass1 > mass2
        spinx_p = conversions.spin1x_from_xi1_phi_a_phi_s(
            xi_p, maps["phi_a"], maps["phi_s"])
        spiny_p = conversions.spin1y_from_xi1_phi_a_phi_s(
            xi_p, maps["phi_a"], maps["phi_s"])
        spinx_s = conversions.spin2x_from_mass1_mass2_xi2_phi_a_phi_s(
            m_p, m_s, xi_s, maps["phi_a"], maps["phi_s"])
        spiny_s = conversions.spin2y_from_mass1_mass2_xi2_phi_a_phi_s(
            m_p, m_s, xi_s, maps["phi_a"], maps["phi_s"])

        # map parameters from primary/secondary to indices
        out = {}
        if isinstance(m_p, numpy.ndarray):
            mass1, mass2 = map(numpy.array, [maps["mass1"], maps["mass2"]])
            mask_mass1_gte_mass2 = mass1 >= mass2
            mask_mass1_lt_mass2 = mass1 < mass2
            out[parameters.spin1x] = numpy.concatenate(
                spinx_p[mask_mass1_gte_mass2], spinx_s[mask_mass1_lt_mass2])
            out[parameters.spin1y] = numpy.concatenate(
                spiny_p[mask_mass1_gte_mass2], spiny_s[mask_mass1_lt_mass2])
            out[parameters.spin2x] = numpy.concatenate(
                spinx_p[mask_mass1_lt_mass2], spinx_s[mask_mass1_gte_mass2])
            out[parameters.spin2y] = numpy.concatenate(
                spinx_p[mask_mass1_lt_mass2], spinx_s[mask_mass1_gte_mass2])
        elif maps["mass1"] > maps["mass2"]:
            out[parameters.spin1x] = spinx_p
            out[parameters.spin1y] = spiny_p
            out[parameters.spin2x] = spinx_s
            out[parameters.spin2y] = spiny_s
        else:
            out[parameters.spin1x] = spinx_s
            out[parameters.spin1y] = spiny_s
            out[parameters.spin2x] = spinx_p
            out[parameters.spin2y] = spiny_p

        return self.format_output(maps, out)
Beispiel #9
0
    def transform(self, maps):
        """ This function transforms from mass-weighted spins to caretsian spins
        in the x-y plane.

        Parameters
        ----------
        maps : a mapping object

        Returns
        -------
        out : dict
            A dict with key as parameter name and value as numpy.array or float
            of transformed values.
        """

        # find primary and secondary masses
        # since functions in conversions.py map to primary/secondary masses
        m_p = conversions.primary_mass(maps["mass1"], maps["mass2"])
        m_s = conversions.secondary_mass(maps["mass1"], maps["mass2"])

        # find primary and secondary xi
        # can re-purpose spin functions for just a generic variable
        xi_p = conversions.primary_spin(maps["mass1"], maps["mass2"],
                                        maps["xi1"], maps["xi2"])
        xi_s = conversions.secondary_spin(maps["mass1"], maps["mass2"],
                                          maps["xi1"], maps["xi2"])

        # convert using convention of conversions.py that is mass1 > mass2
        spinx_p = conversions.spin1x_from_xi1_phi_a_phi_s(
                           xi_p, maps["phi_a"], maps["phi_s"])
        spiny_p = conversions.spin1y_from_xi1_phi_a_phi_s(
                           xi_p, maps["phi_a"], maps["phi_s"])
        spinx_s = conversions.spin2x_from_mass1_mass2_xi2_phi_a_phi_s(
                           m_p, m_s, xi_s, maps["phi_a"], maps["phi_s"])
        spiny_s = conversions.spin2y_from_mass1_mass2_xi2_phi_a_phi_s(
                           m_p, m_s, xi_s, maps["phi_a"], maps["phi_s"])

        # map parameters from primary/secondary to indices
        out = {}
        if isinstance(m_p, numpy.ndarray):
            mass1, mass2 = map(numpy.array, [maps["mass1"], maps["mass2"]])
            mask_mass1_gte_mass2 = mass1 >= mass2
            mask_mass1_lt_mass2 = mass1 < mass2
            out[parameters.spin1x] = numpy.concatenate((
                                        spinx_p[mask_mass1_gte_mass2],
                                        spinx_s[mask_mass1_lt_mass2]))
            out[parameters.spin1y] = numpy.concatenate((
                                        spiny_p[mask_mass1_gte_mass2],
                                        spiny_s[mask_mass1_lt_mass2]))
            out[parameters.spin2x] = numpy.concatenate((
                                        spinx_p[mask_mass1_lt_mass2],
                                        spinx_s[mask_mass1_gte_mass2]))
            out[parameters.spin2y] = numpy.concatenate((
                                        spinx_p[mask_mass1_lt_mass2],
                                        spinx_s[mask_mass1_gte_mass2]))
        elif maps["mass1"] > maps["mass2"]:
            out[parameters.spin1x] = spinx_p
            out[parameters.spin1y] = spiny_p
            out[parameters.spin2x] = spinx_s
            out[parameters.spin2y] = spiny_s
        else:
            out[parameters.spin1x] = spinx_s
            out[parameters.spin1y] = spiny_s
            out[parameters.spin2x] = spinx_p
            out[parameters.spin2y] = spiny_p

        return self.format_output(maps, out)