Beispiel #1
0
def drop_vs_dnu_nomu(fmax=61, fstep=0.1, drops=[0, 1, 2]):
    dnu = np.arange(1, fmax, fstep) * 1.e9
    fish = fisher.FisherEstimation()
    fish.set_signals(fncs=[
        sd.DeltaI_reltSZ_2param_yweight, sd.DeltaI_DeltaT, fg.thermal_dust_rad,
        fg.cib_rad, fg.jens_freefree_rad, fg.jens_synch_rad, fg.spinning_dust,
        fg.co_rad
    ])
    args = fish.args
    N = len(args)
    data = {}
    for drop in drops:
        print "on drop ", drop
        data[drop] = {}
        for arg in args:
            data[drop][arg] = []
        for k, nu in enumerate(dnu):
            if k % 100 == 0:
                print "on k ", k
            scale = 15.e9 / nu
            fish = fisher.FisherEstimation(fstep=nu, mult=scale, drop=drop)
            fish.set_signals(fncs=[
                sd.DeltaI_reltSZ_2param_yweight, sd.DeltaI_DeltaT,
                fg.thermal_dust_rad, fg.cib_rad, fg.jens_freefree_rad,
                fg.jens_synch_rad, fg.spinning_dust, fg.co_rad
            ])
            fish.run_fisher_calculation()
            for arg in args:
                data[drop][arg].append(fish.errors[arg])
    x = {}
    x['drops'] = drops
    x['dnu'] = dnu
    x['data'] = data
    np.save('fullcalc_10p_drop012_nomu', x)
    return
Beispiel #2
0
def drop_vs_dnu(fmax=61, fstep=0.1, drops=[0, 1, 2]):
    dnu = np.arange(1, fmax, fstep) * 1.e9
    fish = fisher.FisherEstimation()
    args = fish.args
    N = len(args)
    data = {}
    for drop in drops:
        print "on drop ", drop
        data[drop] = {}
        for arg in args:
            data[drop][arg] = []
        for k, nu in enumerate(dnu):
            if k % 100 == 0:
                print "on k ", k
            scale = 15.e9 / nu
            ps = {'As': 0.01, 'alps': 0.01}
            #ps = {'As':0.1, 'alps': 0.1}
            fish = fisher.FisherEstimation(fstep=nu,
                                           mult=scale,
                                           drop=drop,
                                           priors=ps)
            fish.run_fisher_calculation()
            for arg in args:
                data[drop][arg].append(fish.errors[arg])
    x = {}
    x['drops'] = drops
    x['dnu'] = dnu
    x['data'] = data
    np.save('fullcalc_1p_drop012_coarse', x)
    return
Beispiel #3
0
def sens_vs_nbins(sens=[1., 0.1, 0.01, 0.001]):
    nbins = np.arange(50, 601)[::-1]
    dnu = 3.e12 / nbins
    fish = fisher.FisherEstimation()
    args = fish.args
    N = len(args)
    data = {}
    for sen in sens:
        print "on sens ", sen
        data[sen] = {}
        for arg in args:
            data[sen][arg] = []
        for nu in dnu:
            scale = sen * (15.e9 / nu)
            #ps = {'As':0.1, 'alps': 0.1}
            #ps = {'As':0.01, 'alps': 0.01}
            ps = {}
            fish = fisher.FisherEstimation(fstep=nu, mult=scale, priors=ps)
            fish.run_fisher_calculation()
            for arg in args:
                data[sen][arg].append(fish.errors[arg])
    x = {}
    x['sens'] = sens
    x['dnu'] = dnu
    x['data'] = data
    np.save('senscalc_nbins_0p', x)
    return
Beispiel #4
0
def drop_vs_nbin(drops=[0, 1, 2]):
    nbins = np.arange(50, 601)[::-1]
    dnu = 3.e12 / nbins
    fish = fisher.FisherEstimation()
    args = fish.args
    N = len(args)
    data = {}
    for drop in drops:
        print "on drop ", drop
        data[drop] = {}
        for arg in args:
            data[drop][arg] = []
        for k, nu in enumerate(dnu):
            if k % 100 == 0:
                print "on k ", k
            scale = 15.e9 / nu
            #ps = {'As':0.01, 'alps': 0.01}
            ps = {'As': 0.1, 'alps': 0.1}
            fish = fisher.FisherEstimation(fstep=nu,
                                           mult=scale,
                                           drop=drop,
                                           priors=ps)
            fish.run_fisher_calculation()
            for arg in args:
                data[drop][arg].append(fish.errors[arg])
    x = {}
    x['drops'] = drops
    x['dnu'] = dnu
    x['data'] = data
    np.save('fullcalc_10p_drop012_nbins_onefifthsynch', x)
    return
Beispiel #5
0
def run():
    pool = mp.Pool()

    nargs = ['mu', 'y', 'kT', 'DeltaT']
    fish = fisher.FisherEstimation(duration=12., bandpass=False)
    fncs = [sd.DeltaI_mu, sd.DeltaI_reltSZ_2param_yweight, sd.DeltaI_DeltaT]
    fish.set_signals(fncs)
    x = fish.center_frequencies
    noise = fish.noise / 1000.
    y = sd.DeltaI_mu(x) + sd.DeltaI_reltSZ_2param_yweight(
        x) + sd.DeltaI_DeltaT(x)
    yerr = noise * np.random.randn(len(x))
    y += yerr
    ndim, nwalkers = 4, 32
    pos = [
        fish.p0 * (1. + 1.e-1 * np.random.randn(ndim)) for i in range(nwalkers)
    ]

    sampler = emcee.EnsembleSampler(nwalkers,
                                    ndim,
                                    lnprob,
                                    args=(x, y, noise),
                                    pool=pool)
    sampler.run_mcmc(pos, 2000)
    pool.close()

    samples = sampler.chain[:, 500:, :].reshape((-1, ndim))
    p_mc = map(lambda v: (v[1], v[2] - v[1], v[1] - v[0]),
               zip(*np.percentile(samples, [16, 50, 84], axis=0)))
    for k in range(4):
        print nargs[k], (p_mc[k][1] + p_mc[k][2]) / 2.
    return
Beispiel #6
0
 def __init__(fncs=None, duration=86.4, nwalkers=0, gf=1.e-3, threads=16):    
     if fncs is None:
         print "need funcs" 
         return
     fish = fisher.FisherEstimation(duration=duration, bandpass=False)
     self.freqs = fish.center_frequencies
     self.noise = fish.noise
     self.fncs = fncs
     self.setup_fncs()
     self.generate_data()
     self.setup_mcmc(nwalkers, gf, threads)
def lnlike(theta):
    fs, ns = theta[:200], theta[200:]

    fish = fisher.FisherEstimation(bandpass=False, priors={})
    fish.set_signals([sd.DeltaI_mu, sd.DeltaI_reltSZ_2param_yweight, sd.DeltaI_DeltaT, \
                      fg.thermal_dust_rad, fg.cib_rad, fg.jens_freefree_rad, fg.jens_synch_rad])
    fish.center_frequencies = fs
    fish.noise = ns
    fish.run_fisher_calculation()
    if np.isnan(fish.errors['mu_amp']):
        return -np.inf
    return -(fish.errors['mu_amp'] / 2.e-8 - 1. / 3.)**2
Beispiel #8
0
def sens_vs_dnu(fmax=61, fstep=0.1, sens=[1., 0.1, 0.01, 0.001]):
    dnu = np.arange(1, fmax, fstep) * 1.e9
    fish = fisher.FisherEstimation()
    args = fish.args
    N = len(args)
    data = {}
    for sen in sens:
        print "on sens ", sen
        data[sen] = {}
        for arg in args:
            data[sen][arg] = []
        for nu in dnu:
            scale = sen * (15.e9 / nu)
            fish = fisher.FisherEstimation(fstep=nu, mult=scale)
            fish.run_fisher_calculation()
            for arg in args:
                data[sen][arg].append(fish.errors[arg])
    x = {}
    x['sens'] = sens
    x['dnu'] = dnu
    x['data'] = data
    np.save('datatest', x)
    return
        return np.inf
    if np.any(fs > 3.01e12):
        return np.inf
    if np.any(np.diff(fs) < 1e9):
        return np.inf
    if np.any(ns < 1.e-2):
        return np.inf
    if np.any(ns > 1.e2):
        return np.inf
    return 0.


def lnprob(theta):
    lp = lnprior(theta)
    if not np.isfinite(lp):
        return -np.inf
    return lp + lnlike(theta)


fish = fisher.FisherEstimation(bandpass=False, priors={})
fish.set_signals([sd.DeltaI_mu, sd.DeltaI_reltSZ_2param_yweight, sd.DeltaI_DeltaT, \
                  fg.thermal_dust_rad, fg.cib_rad, fg.jens_freefree_rad, fg.jens_synch_rad])
fs0 = fish.center_frequencies
noise0 = fish.noise / 10.
p0 = np.concatenate([fs0, noise0])
ndim, nwalkers = 400, 1024
pos = [p0 + 1.e-3 * np.random.randn(ndim) for i in range(nwalkers)]
sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob)
sampler.run_mcmc(pos, 64)
np.savez('optimize1', sampler)
Beispiel #10
0
import fisher 
import foregrounds as fg
import spectral_distortions as sd

# PIXIE with all signals is the default. 
fish = fisher.FisherEstimation()
# args are stored in fish.args, values are stored in dictionary fish.argvals, 
# and fisher uncertainties are in fish.errors
fish.run_fisher_calculation()
# print the errors in sigma
fish.print_errors()

# To set the signals by hand, just modify the fncs arg here:
fish = fisher.FisherEstimation()
fish.set_signals(fncs=[sd.DeltaI_reltSZ_2param_yweight, sd.DeltaI_DeltaT, sd.DeltaI_mu,
                       fg.thermal_dust_rad, fg.cib_rad, fg.jens_freefree_rad,
                       fg.jens_synch_rad, fg.spinning_dust, fg.co_rad])
fish.run_fisher_calculation()
fish.print_errors()


# To change the frequencies (Hz), duration (months), or scale the noise by mult, 
# turn off the step function bandpass or change fsky, 
# edit any of the following
fish = fisher.FisherEstimation(fmin=5.e9, fmax=1.e12, fstep=5.e9, duration=60, mult=0.1, bandpass=False, fsky=0.5)


# Lastly to put priors (in fractions of the parameter value), drop the first n bins or mask out Galactic CO lines do:
fish = fisher.FisherEstimation(priors={'Td':0.1, 'Asd':0.01}, drop=2, doCO=True)