Exemple #1
0
    def chromred(self, option="vary"):
        """
    This is an generalization of DM noise, with the dependence of Fourier 
    amplitudes on radio frequency nu as ~ 1/nu^chi, where chi is a free
    parameter.

    Examples of chi:

    - Pulse scattering in the ISM: chi = 4 (Lyne A., Graham-Smith F., 2012,
      Pulsar astronomy)
    - Refractive propagation: chi = 6.4 (Shannon, R. M., and J. M. Cordes.
      MNRAS, 464.2 (2017): 2075-2089).
    """
        log10_A = parameter.Uniform(self.params.dmn_lgA[0],
                                    self.params.dmn_lgA[1])
        gamma = parameter.Uniform(self.params.dmn_gamma[0],
                                  self.params.dmn_gamma[1])
        pl = utils.powerlaw(log10_A=log10_A, gamma=gamma, \
                            components=self.params.red_general_nfouriercomp)
        nfreqs = self.determine_nfreqs(sel_func_name=None)

        if option == "vary":
            idx = parameter.Uniform(self.params.chrom_idx[0], \
                                    self.params.chrom_idx[1])
        else:
            idx = option

        chr_basis = gp_bases.createfourierdesignmatrix_chromatic(
            nmodes=nfreqs, Tspan=self.params.Tspan, idx=idx)

        chrn = gp_signals.BasisGP(pl, chr_basis, name='chromatic_gp')

        return chrn
Exemple #2
0
    def test_powerlaw_genmodes_prior(self):
        """Test that red noise signal returns correct values."""
        # set up signal parameter
        pr = gp_priors.powerlaw_genmodes(log10_A=parameter.Uniform(-18, -12),
                                         gamma=parameter.Uniform(1, 7))
        basis = gp_bases.createfourierdesignmatrix_chromatic(nmodes=30)
        rn = gp_signals.BasisGP(priorFunction=pr,
                                basisFunction=basis,
                                name="red_noise")
        rnm = rn(self.psr)

        # parameters
        log10_A, gamma = -14.5, 4.33
        params = {
            "B1855+09_red_noise_log10_A": log10_A,
            "B1855+09_red_noise_gamma": gamma
        }

        # basis matrix test
        F, f2 = gp_bases.createfourierdesignmatrix_chromatic(self.psr.toas,
                                                             self.psr.freqs,
                                                             nmodes=30)
        msg = "F matrix incorrect for turnover."
        assert np.allclose(F, rnm.get_basis(params)), msg

        # spectrum test
        phi = gp_priors.powerlaw_genmodes(f2, log10_A=log10_A, gamma=gamma)
        msg = "Spectrum incorrect for turnover."
        assert np.all(rnm.get_phi(params) == phi), msg

        # inverse spectrum test
        msg = "Spectrum inverse incorrect for turnover."
        assert np.all(rnm.get_phiinv(params) == 1 / phi), msg

        # test shape
        msg = "F matrix shape incorrect"
        assert rnm.get_basis(params).shape == F.shape, msg
Exemple #3
0
  def chromred(self,option="vary"):
    """
    This is an generalization of DM noise, with the dependence of Fourier
    amplitudes on radio frequency nu as ~ 1/nu^chi, where chi is a free
    parameter.

    Examples of chi:

    - Pulse scattering in the ISM: chi = 4 (Lyne A., Graham-Smith F., 2012,
      Pulsar astronomy)
    - Refractive propagation: chi = 6.4 (Shannon, R. M., and J. M. Cordes.
      MNRAS, 464.2 (2017): 2075-2089).
    """
    log10_A = parameter.Uniform(self.params.dmn_lgA[0],self.params.dmn_lgA[1])
    gamma = parameter.Uniform(self.params.dmn_gamma[0],self.params.dmn_gamma[1])
    option, nfreqs = self.option_nfreqs(option, sel_func_name=None)
    if type(option) is str and "turnover" in option:
      fc = parameter.Uniform(self.params.sn_fc[0],self.params.sn_fc[1])
      pl = powerlaw_bpl(log10_A=log10_A, gamma=gamma, fc=fc,
                        components=self.params.red_general_nfouriercomp)
      option_split = option.split("_")
      del option_split[option_split.index("turnover")]
      option = "_".join(option_split)
      if option.isdigit(): option = float(option)
    else:
      pl = utils.powerlaw(log10_A=log10_A, gamma=gamma, \
                          components=self.params.red_general_nfouriercomp)

    #idx_code = option.split"_").index("idx") + 1
    if option=="vary":
      idx = parameter.Uniform(self.params.chrom_idx[0], \
                              self.params.chrom_idx[1])
    else:
      idx = option

    chr_basis = gp_bases.createfourierdesignmatrix_chromatic(nmodes=nfreqs,
                                                   Tspan=self.params.Tspan,
                                                   idx=idx)

    chrn = gp_signals.BasisGP(pl, chr_basis, name='chromatic_gp')

    return chrn
Exemple #4
0
def chromatic_noise_block(gp_kernel='nondiag',
                          psd='powerlaw',
                          nondiag_kernel='periodic',
                          prior='log-uniform',
                          dt=15,
                          df=200,
                          idx=4,
                          include_quadratic=False,
                          Tspan=None,
                          name='chrom',
                          components=30,
                          coefficients=False):
    """
    Returns GP chromatic noise model :

        1. Chromatic modeled with user defined PSD with
        30 sampling frequencies. Available PSDs are
        ['powerlaw', 'turnover' 'spectrum']

    :param gp_kernel:
        Whether to use a diagonal kernel for the GP. ['diag','nondiag']
    :param nondiag_kernel:
        Which nondiagonal kernel to use for the GP.
        ['periodic','sq_exp','periodic_rfband','sq_exp_rfband']
    :param psd:
        PSD to use for common red noise signal. Available options
        are ['powerlaw', 'turnover' 'spectrum']
    :param prior:
        What type of prior to use for amplitudes. ['log-uniform','uniform']
    :param dt:
        time-scale for linear interpolation basis (days)
    :param df:
        frequency-scale for linear interpolation basis (MHz)
    :param idx:
        Index of radio frequency dependence (i.e. DM is 2). Any float will work.
    :param include_quadratic:
        Whether to include a quadratic fit.
    :param name: Name of signal
    :param Tspan:
        Tspan from which to calculate frequencies for PSD-based GPs.
    :param components:
        Number of frequencies to use in 'diag' GPs.
    :param coefficients:
        Whether to keep coefficients of the GP.

    """
    if gp_kernel == 'diag':
        chm_basis = gpb.createfourierdesignmatrix_chromatic(nmodes=components,
                                                            Tspan=Tspan)
        if psd in ['powerlaw', 'turnover']:
            if prior == 'uniform':
                log10_A = parameter.LinearExp(-18, -11)
            elif prior == 'log-uniform':
                log10_A = parameter.Uniform(-18, -11)
            gamma = parameter.Uniform(0, 7)

            # PSD
            if psd == 'powerlaw':
                chm_prior = utils.powerlaw(log10_A=log10_A, gamma=gamma)
            elif psd == 'turnover':
                kappa = parameter.Uniform(0, 7)
                lf0 = parameter.Uniform(-9, -7)
                chm_prior = utils.turnover(log10_A=log10_A,
                                           gamma=gamma,
                                           lf0=lf0,
                                           kappa=kappa)

        if psd == 'spectrum':
            if prior == 'uniform':
                log10_rho = parameter.LinearExp(-10, -4, size=components)
            elif prior == 'log-uniform':
                log10_rho = parameter.Uniform(-10, -4, size=components)
            chm_prior = gpp.free_spectrum(log10_rho=log10_rho)

    elif gp_kernel == 'nondiag':
        if nondiag_kernel == 'periodic':
            # Periodic GP kernel for DM
            log10_sigma = parameter.Uniform(-10, -4)
            log10_ell = parameter.Uniform(1, 4)
            log10_p = parameter.Uniform(-4, 1)
            log10_gam_p = parameter.Uniform(-3, 2)

            chm_basis = gpk.linear_interp_basis_chromatic(dt=dt * const.day)
            chm_prior = gpk.periodic_kernel(log10_sigma=log10_sigma,
                                            log10_ell=log10_ell,
                                            log10_gam_p=log10_gam_p,
                                            log10_p=log10_p)

        elif nondiag_kernel == 'periodic_rfband':
            # Periodic GP kernel for DM with RQ radio-frequency dependence
            log10_sigma = parameter.Uniform(-10, -4)
            log10_ell = parameter.Uniform(1, 4)
            log10_ell2 = parameter.Uniform(2, 7)
            log10_alpha_wgt = parameter.Uniform(-4, 1)
            log10_p = parameter.Uniform(-4, 1)
            log10_gam_p = parameter.Uniform(-3, 2)

            chm_basis = gpk.get_tf_quantization_matrix(df=df,
                                                       dt=dt * const.day,
                                                       dm=True,
                                                       idx=idx)
            chm_prior = gpk.tf_kernel(log10_sigma=log10_sigma,
                                      log10_ell=log10_ell,
                                      log10_gam_p=log10_gam_p,
                                      log10_p=log10_p,
                                      log10_alpha_wgt=log10_alpha_wgt,
                                      log10_ell2=log10_ell2)

        elif nondiag_kernel == 'sq_exp':
            # squared-exponential kernel for DM
            log10_sigma = parameter.Uniform(-10, -4)
            log10_ell = parameter.Uniform(1, 4)

            chm_basis = gpk.linear_interp_basis_chromatic(dt=dt * const.day,
                                                          idx=idx)
            chm_prior = gpk.se_dm_kernel(log10_sigma=log10_sigma,
                                         log10_ell=log10_ell)
        elif nondiag_kernel == 'sq_exp_rfband':
            # Sq-Exp GP kernel for Chrom with RQ radio-frequency dependence
            log10_sigma = parameter.Uniform(-10, -4)
            log10_ell = parameter.Uniform(1, 4)
            log10_ell2 = parameter.Uniform(2, 7)
            log10_alpha_wgt = parameter.Uniform(-4, 1)

            dm_basis = gpk.get_tf_quantization_matrix(df=df,
                                                      dt=dt * const.day,
                                                      dm=True,
                                                      idx=idx)
            dm_prior = gpk.sf_kernel(log10_sigma=log10_sigma,
                                     log10_ell=log10_ell,
                                     log10_alpha_wgt=log10_alpha_wgt,
                                     log10_ell2=log10_ell2)

    cgp = gp_signals.BasisGP(chm_prior,
                             chm_basis,
                             name=name + '_gp',
                             coefficients=coefficients)

    if include_quadratic:
        # quadratic piece
        basis_quad = chrom.chromatic_quad_basis(idx=idx)
        prior_quad = chrom.chromatic_quad_prior()
        cquad = gp_signals.BasisGP(prior_quad, basis_quad, name=name + '_quad')
        cgp += cquad

    return cgp