def simulate_AETnoise_from_arbitrary_SpH(duration, stime, t0, GWSpectralSlope, H0, Ppath, lmax, seed, N_previous_draws, Nvar, compute_ORF_SpHs, *orfpaths): """ Simulates noise(s) in the freq-domain from SpHs of ORF and SkyMap. Partly hardwired to simulate for A,E and T. tdiORF_SpHs' IJs are set from AET explicitly, so they can be used for analysis too. INPUT: duration -- duration of the time-series stime -- sampling time t0 --- initial time GWSpectralSlope --- GW background spectral slope H0 --- normalisation constant for H(f) Ppath --- file path to SkyMap of P_{lm}s lmax --- maximum degree l in SpH considered seed --- seed for the random number generator: 'random' or a positive integer N_previous_draws --- numuber of random number draws to discard first Nvar --- number of random variables (or time-series) compute_ORF_SpHs --- True (to compute tdiORF_SpHs) or False (to load from disk) *orfpaths --- file paths to save or to look for tdiORF_SpHs OUTPUT: t --- time labels of the time-series (N x 1 numpy array) n --- time-series (Nvar x N numpy array) """ Nvar = 3 #3 variables: A, E and T IJs = [ 'AA', 'AE', 'AT', 'EE', 'ET', 'TT' ] #Explicitly label tdiORF_SpHs (Not really needed here, but this way they can be used for the analysis pipeline.) freqdict = mufls.get_freqs_from_duration_and_stime(stime, duration) if compute_ORF_SpHs: Nindies = int(Nvar * (Nvar + 1) / 2) if len(orfpaths) < Nindies: raise InputError, 'You must enter at least %d orfpaths!' % Nindies [ make_arbitrary_tdiORF_SpHs(orfpaths[k], freqdict['f'], IJ=IJs[k], lmax=lmax) for k in range(Nindies) ] f, comatrix = mufls.get_CovarMatrix(Nvar, Ppath, GWSpectralSlope, H0, *orfpaths) else: f, comatrix = mufls.get_CovarMatrix(Nvar, Ppath, GWSpectralSlope, H0, *orfpaths) if not np.allclose(f, freqdict['f']): raise InputError, 'Frequencies of loaded covariance matrix do not match those of the fft. Try computing the tdiORF_SpHs first with compute_ORF_SpHs=True' t, n = mufls.get_noise_freq_domain_CovarMatrix( comatrix, freqdict['df'], t0, freqdict['parityN'], seed=seed, N_previous_draws=N_previous_draws) return t, n
def simulate_AETnoise_from_arbitrary_SpH( duration , stime , t0 , GWSpectralSlope, H0, Ppath , lmax , seed , N_previous_draws , Nvar , compute_ORF_SpHs , *orfpaths ) : """ Simulates noise(s) in the freq-domain from SpHs of ORF and SkyMap. Partly hardwired to simulate for A,E and T. tdiORF_SpHs' IJs are set from AET explicitly, so they can be used for analysis too. INPUT: duration -- duration of the time-series stime -- sampling time t0 --- initial time GWSpectralSlope --- GW background spectral slope H0 --- normalisation constant for H(f) Ppath --- file path to SkyMap of P_{lm}s lmax --- maximum degree l in SpH considered seed --- seed for the random number generator: 'random' or a positive integer N_previous_draws --- numuber of random number draws to discard first Nvar --- number of random variables (or time-series) compute_ORF_SpHs --- True (to compute tdiORF_SpHs) or False (to load from disk) *orfpaths --- file paths to save or to look for tdiORF_SpHs OUTPUT: t --- time labels of the time-series (N x 1 numpy array) n --- time-series (Nvar x N numpy array) """ Nvar = 3 #3 variables: A, E and T IJs = [ 'AA' , 'AE' , 'AT' , 'EE' , 'ET' , 'TT' ] #Explicitly label tdiORF_SpHs (Not really needed here, but this way they can be used for the analysis pipeline.) freqdict = mufls.get_freqs_from_duration_and_stime( stime , duration ) if compute_ORF_SpHs : Nindies = int( Nvar*(Nvar+1) / 2 ) if len( orfpaths ) < Nindies : raise InputError , 'You must enter at least %d orfpaths!' % Nindies [ make_arbitrary_tdiORF_SpHs( orfpaths[k] , freqdict['f'] , IJ=IJs[k] , lmax=lmax ) for k in range( Nindies ) ] f , comatrix = mufls.get_CovarMatrix( Nvar , Ppath , GWSpectralSlope, H0 , *orfpaths ) else : f , comatrix = mufls.get_CovarMatrix( Nvar , Ppath , GWSpectralSlope, H0 , *orfpaths ) if not np.allclose( f , freqdict['f'] ) : raise InputError , 'Frequencies of loaded covariance matrix do not match those of the fft. Try computing the tdiORF_SpHs first with compute_ORF_SpHs=True' t , n = mufls.get_noise_freq_domain_CovarMatrix( comatrix , freqdict['df'] , t0 , freqdict['parityN'] , seed=seed , N_previous_draws=N_previous_draws ) return t , n
comatrix = get_comatrix( freqdict['f'] ) for day in options.days : print 'Day %d' % day t0 = ( day - 1 )*dayinsecs t = t0 + options.stime * np.arange( N ) Npd_before_today = (day - 1) * Nseg * 2 * Nvar * freqdict['Nf'] s = 1 ; tails = [ None ]*Nvar ; TSs = [ [] for v in range( Nvar ) ] while s <= Nseg : print 'Segments (%d|%d)' % ( s , s+1 ) Npd_before_segl = Npd_before_today + (s-1)*2*Nvar*freqdict['Nf'] Npd_before_segr = Npd_before_today + s*2*Nvar*freqdict['Nf'] tl , tsl = mufls.get_noise_freq_domain_CovarMatrix(comatrix,freqdict['df'], t0,freqdict['parityN'], options.seed, Npd_before_segl ) tr , tsr = mufls.get_noise_freq_domain_CovarMatrix(comatrix,freqdict['df'], t0,freqdict['parityN'], options.seed, Npd_before_segr ) for v in range( Nvar ) : print 'v = ' , v if s == 1 : print 'tails[v]' , tails[v] else : print 'tails[v][:3]' , tails[v][:3] ts , tail = mufls.window_and_join( tsl[v] , tsr[v] , tails[v] ) TSs[ v ] += list( ts ) ; tails[ v ] = np.copy( tail ) print 'tails[v][:3]' , tails[v][:3]
( options , args ) = parser.parse_args() if len( args ) < 1 : parser.error( "You must specify a TSPATH! Type './x_simulate_defined_stationary_noise.py' " ) else : tspath = args[ 0 ] ; tsdir = os.path.dirname( tspath ) stime , duration , inittime , N_previous_draws = float(options.stime) , float(options.duration) , float(options.inittime) , int( options.N_previous_draws ) N = np.round( duration / stime ) if N % 2 == 0 : Nf = int( N/2 - 1 ) ; parityN = 'Even' else : Nf = int( ( N-1 ) / 2 ) ; parityN = 'Odd' df = 1 / (N*stime) f = df * np.arange( 1 , Nf + 1 ) comatrix = get_comatrix( f ) t , n = mufls.get_noise_freq_domain_CovarMatrix( comatrix , df , inittime , parityN , options.seed , N_previous_draws ) tscale = { 'Cadence1':stime , 'Offset1':inittime } tsdict = { 't':AS.Coarsable( t , **tscale ) , '1':AS.Coarsable( n[0] , **tscale ) , '2':AS.Coarsable( n[1] , **tscale ) , '3':AS.Coarsable( n[2] , **tscale ) } if tsdir not in glob.glob( tsdir ) : os.system( 'mkdir %s' % tsdir ) print 'saving time-series to disk...' file = open( tspath , 'wb' ) ; cpkl.dump( tsdict , file , -1 ) ; file.close()
for day in options.days: print 'Day %d' % day t0 = (day - 1) * dayinsecs t = t0 + options.stime * np.arange(N) Npd_before_today = (day - 1) * Nseg * 2 * Nvar * freqdict['Nf'] s = 1 tails = [None] * Nvar TSs = [[] for v in range(Nvar)] while s <= Nseg: print 'Segments (%d|%d)' % (s, s + 1) Npd_before_segl = Npd_before_today + (s - 1) * 2 * Nvar * freqdict['Nf'] Npd_before_segr = Npd_before_today + s * 2 * Nvar * freqdict['Nf'] tl, tsl = mufls.get_noise_freq_domain_CovarMatrix( comatrix, freqdict['df'], t0, freqdict['parityN'], options.seed, Npd_before_segl) tr, tsr = mufls.get_noise_freq_domain_CovarMatrix( comatrix, freqdict['df'], t0, freqdict['parityN'], options.seed, Npd_before_segr) for v in range(Nvar): print 'v = ', v if s == 1: print 'tails[v]', tails[v] else: print 'tails[v][:3]', tails[v][:3] ts, tail = mufls.window_and_join(tsl[v], tsr[v], tails[v]) TSs[v] += list(ts) tails[v] = np.copy(tail) print 'tails[v][:3]', tails[v][:3]