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
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
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