예제 #1
0
파일: simcyc.py 프로젝트: obienano/pycycdan
def simSuite(taus=[2.0],harms=[3],periods=[1.5e-3],snrs=[10],
             maxfun = 5):
  
    np.random.seed(42)  # seed the random number generator - Dan - 2012-11-18
    
    for tau in taus:
        for harm in harms:
            for period in periods:
                for snr in snrs:
                    prof = makeProfile(harm)
                    ht = makeht(tau, nlag=2048)
                    CS = initSim(ht,prof,ref_freq=1/period,bw=1.0,noise=snr,source = ('tau_%.1f_nharm_%d_period_%.2f_snr_%.3f' % (tau,harm,period*1000.,snr)))
                    CS.initProfile()
                    CS.pp_meas = CS.pp_ref.copy()
                    CS.pp_ref = prof
                    CS.ph_ref = pycyc.phase2harm(CS.pp_ref)
                    CS.ph_ref = pycyc.normalize_profile(CS.ph_ref)
                    CS.ph_ref[0] = 0
                    CS.s0 = CS.ph_ref.copy()

                    CS.plotdir = '.'
                    CS.pharm = harm
                    CS.tau = tau
                    CS.noise = snr
                    CS.loop(make_plots=False,maxfun=maxfun)
                    CS.noise = snr
                    CS.saveState(os.path.join(CS.plotdir,'cs_' + CS.source + '.pkl'))
                    pycyc.plotSimulation(CS)
예제 #2
0
def simSuite(taus=[2.0], harms=[3], periods=[1.5e-3], snrs=[10], maxfun=5):

    np.random.seed(42)  # seed the random number generator - Dan - 2012-11-18

    for tau in taus:
        for harm in harms:
            for period in periods:
                for snr in snrs:
                    prof = makeProfile(harm)
                    ht = makeht(tau, nlag=2048)
                    CS = initSim(
                        ht,
                        prof,
                        ref_freq=1 / period,
                        bw=1.0,
                        noise=snr,
                        source=('tau_%.1f_nharm_%d_period_%.2f_snr_%.3f' %
                                (tau, harm, period * 1000., snr)))
                    CS.initProfile()
                    CS.pp_meas = CS.pp_ref.copy()
                    CS.pp_ref = prof
                    CS.ph_ref = pycyc.phase2harm(CS.pp_ref)
                    CS.ph_ref = pycyc.normalize_profile(CS.ph_ref)
                    CS.ph_ref[0] = 0
                    CS.s0 = CS.ph_ref.copy()

                    CS.plotdir = '.'
                    CS.pharm = harm
                    CS.tau = tau
                    CS.noise = snr
                    CS.loop(make_plots=False, maxfun=maxfun)
                    CS.noise = snr
                    CS.saveState(
                        os.path.join(CS.plotdir, 'cs_' + CS.source + '.pkl'))
                    pycyc.plotSimulation(CS)
예제 #3
0
파일: simcyc.py 프로젝트: gitj/pycyc
def simSuite(taus=[2.0,10.0,100.0],harms=[3,10],periods=[1.5e-3,4e-3,10e-3],snrs=[10,100],
             maxfun = 100):
    for tau in taus:
        for harm in harms:
            for period in periods:
                for snr in snrs:
                    prof = makeProfile(harm)
                    ht = makeht(tau, nlag=2048)
                    CS = initSim(ht,prof,ref_freq=1/period,bw=1.0,noise=snr,source = ('tau_%.1f_nharm_%d_period_%.2f_snr_%.3f' % (tau,harm,period*1000.,snr)))
                    CS.initProfile()
                    CS.pp_meas = CS.pp_ref.copy()
                    CS.pp_ref = prof
                    CS.ph_ref = pycyc.phase2harm(CS.pp_ref)
                    CS.ph_ref = pycyc.normalize_profile(CS.ph_ref)
                    CS.ph_ref[0] = 0
                    CS.s0 = CS.ph_ref.copy()

                    CS.plotdir = '/home/gjones/workspace/pycyc/simsuite'
                    CS.pharm = harm
                    CS.tau = tau
                    CS.noise = snr
                    CS.loop(make_plots=False,maxfun=maxfun)
                    CS.noise = snr
                    CS.saveState(os.path.join(CS.plotdir,'cs_' + CS.source + '.pkl'))
                    pycyc.plotSimulation(CS)
예제 #4
0
파일: simcyc.py 프로젝트: obienano/pycycdan
def initSim(ht,prof,ref_freq,bw,rf = None,filename= None,source='fake',noise = None):
    if rf is None:
        rf = np.abs(bw)/2.0
    if ht.ndim == 1:
        ht = ht[None,:]
    CS = pycyc.CyclicSolver()
    CS.ht0 = ht
    if filename:
        CS.filename = filename
    else:
        CS.filename = 'sim%s_%.1fMHz_%.1fms' % (source,bw,1000.0/ref_freq)   
    CS.nchan = ht.shape[1]
    CS.nlag = CS.nchan
    CS.nphase = prof.shape[0]
    CS.nbin = CS.nphase
    CS.nharm = CS.nphase/2 + 1
    CS.source = source
    CS.nspec = ht.shape[0]
    CS.dynamic_spectrum = np.zeros((CS.nspec,CS.nchan))
    CS.optimized_filters = np.zeros((CS.nspec,CS.nchan),dtype='complex')
    CS.intrinsic_profiles = np.zeros((CS.nspec,CS.nbin))
    CS.nopt = 0
    CS.nloop = 0        

    CS.nopt = 0
    
    CS.ref_freq = ref_freq
    CS.bw = bw
    CS.ref_phase = 0
    CS.rf = rf
    
    CS.hf_prev = np.ones((CS.nchan,),dtype='complex')
    CS.pp_int = np.zeros((CS.nphase)) #intrinsic profile
    
    CS.pp_ref = prof.copy()
    
    CS.ph_ref = pycyc.phase2harm(CS.pp_ref)
    CS.ph_ref = pycyc.normalize_profile(CS.ph_ref)
    CS.ph_ref[0] = 0
    CS.s0 = CS.ph_ref.copy()
    
    CS.data = np.empty((CS.nspec,1,CS.nchan,CS.nphase), dtype='complex')
    for k in range(CS.nspec):
        CS.data[k,0,:,:] = pycyc.cs2ps(CS.modelCS(ht[k,:]))
    if noise is not None:
        signal = np.abs(CS.data).sum()
        CS.noise = noise
        rn = (np.random.randn(CS.data.shape[0],CS.data.shape[1],CS.data.shape[2],CS.data.shape[3]).astype('complex')
              +1j*np.random.randn(CS.data.shape[0],CS.data.shape[1],CS.data.shape[2],CS.data.shape[3]))
        rnpow = np.abs(rn).sum()
        fact = signal/rnpow
        CS.data = CS.data + rn*(fact/noise)
    return CS
예제 #5
0
파일: sim1643.py 프로젝트: gitj/pycyc
def initSim(ht,prof=std_prof,ref_freq=ref_freq,bw=bw,noise = None):
    CS = pycyc.CyclicSolver()
    CS.ht0 = ht
    CS.filename = 'sim1643'
    CS.nchan = ht.shape[0]
    CS.nlag = CS.nchan
    CS.nphase = prof.shape[0]
    CS.nharm = CS.nphase/2 + 1
    CS.source = 'J1643-1224sim'
    CS.nspec = 1
    CS.dynamic_spectrum = np.zeros((CS.nspec,CS.nchan))
    CS.optimized_filters = np.zeros((CS.nspec,CS.nchan),dtype='complex')
    CS.nopt = 0
    
    CS.ref_freq = ref_freq
    CS.bw = bw
    CS.ref_phase = 0
    CS.rf = rf
    
    CS.hf_prev = np.ones((CS.nchan,),dtype='complex')
    CS.pp_int = np.zeros((CS.nphase)) #intrinsic profile
    
    CS.pp_ref = prof.copy()
    
    CS.ph_ref = pycyc.phase2harm(CS.pp_ref)
    CS.ph_ref = pycyc.normalize_profile(CS.ph_ref)
    CS.ph_ref[0] = 0
    CS.s0 = CS.ph_ref.copy()
    
    csm = CS.modelCS(ht)
    CS.data = pycyc.cs2ps(csm)[None,None,:,:]
    CS.cs = csm.copy()
    if noise is not None:
        fact = CS.data.std()*noise
        CS.data += (np.random.randn(CS.data.shape[2],CS.data.shape[3]).astype('complex')+1j*np.random.randn(CS.data.shape[2],CS.data.shape[3]))*fact
    return CS
예제 #6
0
def initSim(ht,
            prof,
            ref_freq,
            bw,
            rf=None,
            filename=None,
            source='fake',
            noise=None):
    if rf is None:
        rf = np.abs(bw) / 2.0
    if ht.ndim == 1:
        ht = ht[None, :]
    CS = pycyc.CyclicSolver()
    CS.ht0 = ht
    if filename:
        CS.filename = filename
    else:
        CS.filename = 'sim%s_%.1fMHz_%.1fms' % (source, bw, 1000.0 / ref_freq)
    CS.nchan = ht.shape[1]
    CS.nlag = CS.nchan
    CS.nphase = prof.shape[0]
    CS.nbin = CS.nphase
    CS.nharm = CS.nphase / 2 + 1
    CS.source = source
    CS.nspec = ht.shape[0]
    CS.dynamic_spectrum = np.zeros((CS.nspec, CS.nchan))
    CS.optimized_filters = np.zeros((CS.nspec, CS.nchan), dtype='complex')
    CS.intrinsic_profiles = np.zeros((CS.nspec, CS.nbin))
    CS.nopt = 0
    CS.nloop = 0

    CS.nopt = 0

    CS.ref_freq = ref_freq
    CS.bw = bw
    CS.ref_phase = 0
    CS.rf = rf

    CS.hf_prev = np.ones((CS.nchan, ), dtype='complex')
    CS.pp_int = np.zeros((CS.nphase))  #intrinsic profile

    CS.pp_ref = prof.copy()

    CS.ph_ref = pycyc.phase2harm(CS.pp_ref)
    CS.ph_ref = pycyc.normalize_profile(CS.ph_ref)
    CS.ph_ref[0] = 0
    CS.s0 = CS.ph_ref.copy()

    CS.data = np.empty((CS.nspec, 1, CS.nchan, CS.nphase), dtype='complex')
    for k in range(CS.nspec):
        CS.data[k, 0, :, :] = pycyc.cs2ps(CS.modelCS(ht[k, :]))
    if noise is not None:
        signal = np.abs(CS.data).sum()
        CS.noise = noise
        rn = (np.random.randn(CS.data.shape[0], CS.data.shape[1],
                              CS.data.shape[2],
                              CS.data.shape[3]).astype('complex') +
              1j * np.random.randn(CS.data.shape[0], CS.data.shape[1],
                                   CS.data.shape[2], CS.data.shape[3]))
        rnpow = np.abs(rn).sum()
        fact = signal / rnpow
        CS.data = CS.data + rn * (fact / noise)
    return CS