示例#1
0
    def psd(self,xstr,nfft=256,noverlap=0,coarsable=False):
        """Return the PSD(power spectral density) of the time-series

        Positional parameter:
        xstr -- string naming the observable, either 'A', 'E', or 'T'

        Keyword parameters:
        nfft -- length of the fast fourier transform (fft) (default 256)
        noverlap -- number of data points overlapping between segments (default 0)
        coarsable -- return the PSD as a Coarsable object (default False)
        
        OUTPUT:
        f -- frequencies 
        P -- PSD 

        Note:
        The PSD is calculated using pl.psd() with an additional factor of dt in the normalisation.
        This gives the correct dimension.

        """
        x = getattr(self,xstr)
        fs = 1. / x.Cadence1
        P , f = pl.psd( x.data , nfft , fs , noverlap=noverlap , scale_by_freq=False )
        P = P / fs
        if coarsable:
            scale = {'Offset1' : f[0] ,
                     'Cadence1': f[1] - f[0] }
            f = AS.Coarsable( f , **scale )
            P = AS.Coarsable( P , **scale )
        return f , P
示例#2
0
def G1Michelson_to_G1Sagnac( FT ) :

    L = 16.6782

    f = FT.s1.Offset1 + FT.s1.Cadence1 * np.arange( FT.s1.data.shape[0] )
    fdict = { 'Offset1' : FT.s1.Offset1 , 'Cadence1' : FT.s1.Cadence1 }

    Xdata , Ydata , Zdata = FT.s1.data , FT.s2.data , FT.s3.data
    e1 = np.exp( - 1j * 2 * np.pi * L * f )
    e2 = np.exp( - 1j * 4 * np.pi * L * f )
    e3 = np.exp( - 1j * 6 * np.pi * L * f )

    A = 1 - e1 + e2
    B = 1 - e1 - e2 + e3

    alphadata = ( A*Xdata + e1 * ( Ydata + Zdata ) ) / B
    betadata  = ( A*Ydata + e1 * ( Zdata + Xdata ) ) / B
    gammadata = ( A*Zdata + e1 * ( Xdata + Ydata ) ) / B


    alpha = AS.Coarsable( alphadata , **fdict )
    beta  = AS.Coarsable( betadata  , **fdict )
    gamma = AS.Coarsable( gammadata , **fdict )

    SagnacFT = AS.ShortTermFT( alpha , beta , gamma )
    
    return SagnacFT
示例#3
0
    def csd(self,xstr,ystr,nfft=256,noverlap=0,coarsable=False):
        """Return CSD(cross spectral density) of the time-series.

        Positional parameters:
        xstr -- string naming one observable, either 'A', 'E' or 'T'
        ystr -- string naming one observable, either 'A', 'E' or 'T'

        Keyword parameters:
        nfft -- length of fast fourier transform(fft) (default 256)
        noverlap -- number of data points overlapping between segments (default 0)
        coarsable -- return the CSD as a Coarsable object (default False)

        OUTPUT:
        f -- frequencies
        P -- CSD

        Note:
        The CPSD is calculated using pl.csd() with an additional factor of dt in the normalisation.
        If xstr='A' and ystr='E', then the CSD between A and E is returned.

        """
        x = getattr(self,xstr)
        y = getattr(self,ystr)
        fs = 1. / x.Cadence1
        P , f = pl.csd( x.data , y.data , nfft , fs , noverlap=noverlap )
        P = P / fs
        if coarsable:
            scale = {'Offset1' : f[0] ,
                     'Cadence1': f[1] - f[0] }
            f = AS.Coarsable( f , **scale )
            P = AS.Coarsable( P , **scale )
        return f , P
示例#4
0
文件: testsim.py 项目: qAp/LisaMapp
def make_arbitrary_tdiORF_SpHs( orfpath , f , IJ='AA' , lmax=0 ) :
    """
    This lets you set multipole moments of overlap-reduction function arbitrarily, and save them in the form\n
    {'OrfMultipleMoments':\n
    { 'ntrunc': lmax , 'f': f , 'Antenna': IJ , 'real': SpHreal , 'imag': SpHimag } }\n
    which is loadable by AnisotropySearch.OrfMultipleMoments()\n

    INPUT:
    orfpath --- file path to save the orfs\n
    f --- frequency/frequencies at which ORF will be computed
    IJ --- IJ of ORF
    lmax --- Maximum degree l for the SpHs
    OUTPUT:
    None
    """
    """ ###### This is where you define SpHs of real and imaginary parts of ORF. Note that the value returned is for the SpH defined in pyspharm."""  
    indxp = AS.getMLvec( lmax , m='p' )
    SpHimag = np.zeros( ( len(indxp) , f.shape[0] ) , dtype=complex )
    if IJ in [ 'AA' , 'EE' ,  'TT' ] :
        SpHreal = np.ones( ( len(indxp) , f.shape[0] ) , dtype=complex ) * 288. / np.sqrt( 2*np.pi )
    elif IJ in [ 'AT','ET','TA','TE', 'AE' , 'EA' ] :
        SpHreal = np.ones( ( len(indxp) , f.shape[0] ) , dtype=complex ) * 288. / np.sqrt( 2*np.pi )
    """ ###### """
    orfdict = {'OrfMultipleMoments':{ 'ntrunc':lmax , 'f':f , 'Antenna':IJ , 'real': SpHreal , 'imag': SpHimag } }
    orfdir = os.path.dirname( orfpath )
    if orfdir == '' :
        pass
    elif orfdir not in glob.glob( orfdir ) :
        os.system( 'mkdir -p %s' % orfdir )
    file = open( orfpath , 'wb' ) ; cpkl.dump( orfdict , file , -1 ) ; file.close()
    print " Orf multipole moments saved in %s " % orfpath
    return
示例#5
0
def FracPhase_to_FracFreq( FT ) :
    
    f = FT.s1.Offset1 + FT.s1.Cadence1 * np.arange( FT.s1.data.shape[0] )
    fdict = { 'Offset1' : FT.s1.Offset1 , 'Cadence1' : FT.s1.Cadence1 }

    phase1data , phase2data , phase3data = FT.s1.data , FT.s2.data , FT.s3.data

    a = 1 / ( 1j * 2 * np.pi * f )

    freq1data = phase1data * a
    freq2data = phase2data * a
    freq3data = phase3data * a

    freq1 = AS.Coarsable( freq1data , **fdict )
    freq2 = AS.Coarsable( freq2data , **fdict )
    freq3 = AS.Coarsable( freq3data , **fdict )

    freqFT = AS.ShortTermFT( freq1 , freq2 , freq3 )

    return freqFT
示例#6
0
def G1Sagnac_to_GmSagnac( FT ) :

    L = 16.6782

    f = FT.s1.Offset1 + FT.s1.Cadence1 * np.arange( FT.s1.data.shape[0] )
    fdict = { 'Offset1' : FT.s1.Offset1 , 'Cadence1' : FT.s1.Cadence1 }

    G1adata , G1bdata , G1cdata = FT.s1.data , FT.s2.data , FT.s3.data

    e3 = np.exp( - 1j * 6 * np.pi * L * f )

    Gmadata = ( e3 - 1 ) * G1adata
    Gmbdata = ( e3 - 1 ) * G1bdata
    Gmcdata = ( e3 - 1 ) * G1cdata
    
    Gma = AS.Coarsable( Gmadata , **fdict )
    Gmb = AS.Coarsable( Gmbdata , **fdict )
    Gmc = AS.Coarsable( Gmcdata , **fdict )
    
    GmSagnac = AS.ShortTermFT( Gma , Gmb , Gmc )
    
    return GmSagnac
示例#7
0
def GpretdiMichelson_to_G1Michelson( FT ) :

    L = 16.6782

    f = FT.s1.Offset1 + FT.s1.Cadence1 * np.arange( FT.s1.data.shape[0] )
    fdict = { 'Offset1' : FT.s1.Offset1 , 'Cadence1' : FT.s1.Cadence1 }

    Xdata , Ydata , Zdata = FT.s1.data , FT.s2.data , FT.s3.data

    e2 = np.exp( - 1j * 4 * np.pi * L * f )

    G1Xdata = ( e2 - 1 ) * Xdata
    G1Ydata = ( e2 - 1 ) * Ydata
    G1Zdata = ( e2 - 1 ) * Zdata

    G1X = AS.Coarsable( G1Xdata , **fdict )
    G1Y = AS.Coarsable( G1Ydata , **fdict )
    G1Z = AS.Coarsable( G1Zdata , **fdict )

    G1Michelson = AS.ShortTermFT( G1X , G1Y , G1Z )

    return G1Michelson
示例#8
0
def make_arbitrary_tdiORF_SpHs(orfpath, f, IJ='AA', lmax=0):
    """
    This lets you set multipole moments of overlap-reduction function arbitrarily, and save them in the form\n
    {'OrfMultipleMoments':\n
    { 'ntrunc': lmax , 'f': f , 'Antenna': IJ , 'real': SpHreal , 'imag': SpHimag } }\n
    which is loadable by AnisotropySearch.OrfMultipleMoments()\n

    INPUT:
    orfpath --- file path to save the orfs\n
    f --- frequency/frequencies at which ORF will be computed
    IJ --- IJ of ORF
    lmax --- Maximum degree l for the SpHs
    OUTPUT:
    None
    """
    """ ###### This is where you define SpHs of real and imaginary parts of ORF. Note that the value returned is for the SpH defined in pyspharm."""
    indxp = AS.getMLvec(lmax, m='p')
    SpHimag = np.zeros((len(indxp), f.shape[0]), dtype=complex)
    if IJ in ['AA', 'EE', 'TT']:
        SpHreal = np.ones((len(indxp), f.shape[0]),
                          dtype=complex) * 288. / np.sqrt(2 * np.pi)
    elif IJ in ['AT', 'ET', 'TA', 'TE', 'AE', 'EA']:
        SpHreal = np.ones((len(indxp), f.shape[0]),
                          dtype=complex) * 288. / np.sqrt(2 * np.pi)
    """ ###### """
    orfdict = {
        'OrfMultipleMoments': {
            'ntrunc': lmax,
            'f': f,
            'Antenna': IJ,
            'real': SpHreal,
            'imag': SpHimag
        }
    }
    orfdir = os.path.dirname(orfpath)
    if orfdir == '':
        pass
    elif orfdir not in glob.glob(orfdir):
        os.system('mkdir -p %s' % orfdir)
    file = open(orfpath, 'wb')
    cpkl.dump(orfdict, file, -1)
    file.close()
    print " Orf multipole moments saved in %s " % orfpath
    return
示例#9
0
def TransformMultipoles_Rot323( xlm , rphi , rthe , rpsi ) :

    xlm = np.copy( xlm )

    ntrunc = np.sqrt( xlm.shape[0] ) - 1
    if ( ntrunc % 1 ) != 0 :
        print "The length of the entered numpy array does not correspond to an integer ntrunc."
        raise ValueError

    indxpn = AS.getMLvec( ntrunc )

    ylm_rphi = np.array( [ np.exp( - 1j * ml[0] * rphi ) for ml in indxpn ] ) * xlm

    ylm_rthe = np.zeros( ylm_rphi.shape , dtype=ylm_rphi.dtype )
    for i , ml in enumerate( indxpn ) :
        m , l = ml
        nls   = [ ( n , l ) for n in range( -l , l + 1 , 1 ) ]
        ylns  = [ ylm_rphi[ indxpn.index( nl ) ] for nl in nls ]
        dlnms = [ WignerD( rthe , l , nl[0] , m ) for nl in nls ]
        ylm_rthe[ i ] = np.dot( np.array( dlnms ) , np.array( ylns ) )

    ylm_rpsi = np.array( [ np.exp( - 1j * ml[0] * rpsi ) for ml in indxpn ] ) * ylm_rthe
    return ylm_rpsi
    else :
        c12 = 2 * np.conj( Y1[ : (N+1)/2 ] ) * Y2[ : (N+1)/2 ] / (N*stime) ; f_c12 = df_c12 * np.arange( (N+1)/2 )
    Qc12 = AS.Coarsable( c12 , Offset1=f_c12[0] , Cadence1=df_c12 )
    Qf_c12 = AS.Coarsable( f_c12 , Offset1=f_c12[0] , Cadence1=df_c12 )

    p11l , f_p11l = pl.psd( y1l , nfft , fs , noverlap=noverlap )
    p11r , f_p11r = pl.psd( y1r , nfft , fs , noverlap=noverlap )
    p11 = ( p11l + p11r ) / 2 ; f_p11 = np.copy( f_p11l ) ; df_p11 = f_p11[1] - f_p11[0]
    Qp11 = AS.Coarsable( p11 , Offset1=f_p11[0] , Cadence1=df_p11 )
    Qf_p11 = AS.Coarsable( f_p11 , Offset1=f_p11[0] , Cadence1=df_p11 )
    p22l , f_p22l = pl.psd( y2l , nfft , fs , noverlap=noverlap )
    p22r , f_p22r = pl.psd( y2r , nfft , fs , noverlap=noverlap )
    p22 = ( p22l + p22r ) / 2 ; f_p22 = np.copy( f_p22l ) ; df_p22 = f_p22[1] - f_p22[0]
    Qp22 = AS.Coarsable( p22 , Offset1=f_p22[0] , Cadence1=df_p22 )

    Qff = AS.coarsefrequency( Qf_c12 , Qf_p11 ) ; Nf = Qff.data.shape[0]

    Qcc12 = Qc12.coarsegrain( Offset1=Qff.Offset1 , Cadence1=Qff.Cadence1 , N1=Qff.data.shape[0] )
    Qpp11 = Qp11.coarsegrain( Offset1=Qff.Offset1 , Cadence1=Qff.Cadence1 , N1=Qff.data.shape[0] )
    Qpp22 = Qp22.coarsegrain( Offset1=Qff.Offset1 , Cadence1=Qff.Cadence1 , N1=Qff.data.shape[0] )
    
    GG = (N*stime*Qff.Cadence1) * 4 * stime**2 * np.sum( 2. / (Qpp11.data * Qpp22.data) )
    XX = (N*stime*Qff.Cadence1) * 2 * stime * np.sum( 2*np.real( Qcc12.data ) / (Qpp11.data * Qpp22.data) )
    
    Ometer1 = XX / GG
    var_Ometer1 = 1. / GG * ( 1 +
                              (N*stime*Qff.Cadence1) * (2*stime)**4 * Omega**2 * np.sum( 2. / (Qpp11.data**2 * Qpp22.data**2) ) / GG )
    var_Ometer1_weak = 1. / GG 
    Ometers += [ Ometer ] ; Ometer1s += [ Ometer1 ]  ; var_Ometer1s += [ var_Ometer1 ] ; var_Ometer1s_weak += [ var_Ometer1_weak ]

Ometers = np.array( Ometers ) ; Ometer1s = np.array( Ometer1s ) ; var_Ometer1s = np.array( var_Ometer1s )
示例#11
0
文件: x_stdP.py 项目: qAp/LisaMapp
                  type='string',
                  nargs=1,
                  default='default',
                  help='Path to the strong signal bias matrix')

(options, args) = parser.parse_args()

if len(args) < 2:
    parser.error(
        'You must specify GPATH and STDPPATH! See Help: ./x_stdP.py -h')

Gpath, stdPpath = args[:2]

stdPdir = os.path.dirname(stdPpath)

fish = AS.FisherMatrix(Gpath, lmax=options.lmax)
if options.regMethod == 0:
    print 'Calculating unregularised inverse of Fisher matrix...'
    fishinv = fish.invert()
else:
    print "Calculating regularised inverse of Fisher matrix..."
    fish.regularise(regMethod=options.regMethod,
                    regCutoff=float(options.regCutoff))
    fishinv = fish.reginvert()

covarm = np.dot(fishinv, np.dot(fish.fish, fishinv))

if options.strong_signal:
    if options.Spath == 'default':
        Spath = os.path.dirname(stdPdir) + '/S/S.pkl'
    else:
示例#12
0
    csdpath = csddir + '/d%03d.pkl' % day
    orfpath = orfdir + '/d%03d.pkl' % day
    psdpath = psddir + '/d%03d.pkl' % day

    if csdpath not in glob.glob(csdpath):
        print 'CSD not found at %s' % csdpath
        continue
    if orfpath not in glob.glob(orfpath):
        print 'Orf not found at %s' % orfpath
        continue
    if psdpath not in glob.glob(psdpath):
        print 'PSD not found at %s' % psdpath
        continue

    orf = AS.OrfMultipleMoments(orfpath)
    file = open(csdpath, 'rb')
    csddict = cpkl.load(file)
    file.close()
    file = open(psdpath, 'rb')
    psddict = cpkl.load(file)
    file.close()

    SSdata = AS.get_covariance_bias_matrix_for_the_day(
        orf, psddict, csddict, options.H0, options.GWslope, day, options.flow,
        options.fhigh, options.lmax)

    if firstavailable:
        Sdata = np.zeros(SSdata.shape, dtype=SSdata.dtype)
        print 'Calculating normalisation factor due to coarsegraining and windowing'
        tspath = tsdir + '/d%03d.pkl' % day
示例#13
0
        "You must specify CSDDIR!  Type './x_simulate_expected_signal_CSD.py -h' for help "
    )
else:
    csddir = args[0]

if options.whichtdi == 'ordinary':
    IJs = ['12', '13', '23']
elif options.whichtdi == 'optimal':
    IJs = ['AE', 'AT', 'ET']

if csddir not in glob.glob(csddir):
    os.system('mkdir %s' % csddir)

fdata = options.f0 + options.df * np.arange(options.Nf)
fscale = {'Offset1': options.f0, 'Cadence1': options.df}
f = AS.Coarsable(fdata, **fscale)

print "Calculating expected cross NSD..."
PIJdatas = [
    mlisar.get_tdiNSD(options.tditype, options.tdigen, IJ[0], IJ[1], fdata)
    for IJ in IJs
]
PIJs = [AS.Coarsable(PIJdata, **fscale) for PIJdata in PIJdatas]
P12, P13, P23 = PIJs
print 'done'

psddict = {'f': f, 'AE': P12, 'AT': P13, 'ET': P23}

file = open(csddir + 'd001.pkl', 'wb')
cpkl.dump(psddict, file, -1)
file.close()
示例#14
0
import sys
import glob
import cPickle as cpkl
import numpy as np
import AnisotropySearch as AS
import PostProcess as PP


GWslopes = [ 0 ]
IJs = [ 'AE' , 'AT'  , 'ET' , 'AE_AT' , 'AE_ET' , 'AT_ET' , 'AE_AT_ET' ]
lmax , nlon , nlat = 15 , 180 , 91
Ppath = '/gpfs1/JC0311443/workhere/stochasGW/Mapp/skymaps/library/sphericalharmonics/Y_l0_m0_x1e-34/Y_l0_m0.pkl'
GPnorm = 1e-40

file = open( Ppath , 'rb' ) ; P0 = cpkl.load( file ) ; file.close()
P0lm = AS.get_lmax_subset_from( np.copy( P0.xlm ) , lmax )

workdir = os.getcwd() + '/'

for slope in GWslopes :
    for IJ in IJs :
        print 'GWslope = %d , IJ = %s' % ( slope , IJ )
        Gpath = workdir + 'GW_slope_%d/%s/G/G.pkl' % ( slope , IJ )
        fish = AS.FisherMatrix( Gpath , lmax = lmax )
        Xlm = np.dot( fish.fish , P0lm )
        X0path = workdir + 'GW_slope_%d/%s/X/X.pkl' % ( slope , IJ )
        file = open( X0path ) ; X0 = cpkl.load( file ) ; file.close()
        X0lm = AS.get_lmax_subset_from( np.copy( X0.xlm ) , lmax )
        print 'The obtained X is the same as the product of the obtained Fisher mastrix and the injected P.' , np.allclose( Xlm , X0lm )
        print 'X0lm.shape , Xlm.shape = '  , X0lm.shape , ',' , Xlm.shape 
        print 'X0lm[ :10 ]'
        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]
        s += 2

    TSs = np.array(TSs)[:, :N]

    tscale = {'Cadence1': options.stime, 'Offset1': t0}
    tsdict = {
        't': AS.Coarsable(t, **tscale),
        '1': AS.Coarsable(TSs[0], **tscale),
        '2': AS.Coarsable(TSs[1], **tscale),
        '3': AS.Coarsable(TSs[2], **tscale)
    }
    if tsdir == '':
        pass
    elif tsdir not in glob.glob(tsdir):
        os.system('mkdir -p %s' % tsdir)
    print 'saving time-series to disk...'
    file = open(tsdir + '/d%03d.pkl' % day, 'wb')
    cpkl.dump(tsdict, file, -1)
    file.close()
示例#16
0
    
    orf = AS.OrfMultipleMoments( orfpath )
    
    xxx = AS.XXX_test( orf , psddict , csddict , options.GWslope , day , cIJdir=cIJdir )
    XX = xxx.getsummand( flow=options.flow , fhigh=options.fhigh , lmax=options.lmax )

    if firstavailable :
        X = np.zeros( np.shape(XX.data) , complex )
        firstavailable = False

    X += XX.data

file = open( tspath , 'rb' ) ; tsdict = cpkl.load( file ) ; file.close()
'normalise for coarsegraining and windowing with a Hanning window for both time-series'
ts = AS.TimeSeries( tsdict )
N = ts.t.data.shape[0] ; T = ts.t.Cadence1 * N ; df = xxx.fcoarse.Cadence1
window = np.hanning( N )
norm = ( np.sum( window**2 ) / N ) / ( np.sum( window**4 ) / N ) * T*df
map_X = AS.xlmSkyMap( xlm = norm * X )

if Xdir not in glob.glob( Xdir ) :
    os.system( 'mkdir -p %s' % Xdir )
file = open( Xpath , 'wb') ; cpkl.dump( map_X , file , -1 ) ; file.close()

days_skippedpath = Xdir + '/days_skipped.pkl'
file = open( days_skippedpath , 'wb' ) ; cpkl.dump( days_skipped , file , -1 ) ; file.close()




示例#17
0
parser.add_option( '--nlat' , action='store' , dest='nlat' , type='int' , default=91 ,
                   help='Number of latitudes to plot in the sky.' )

parser.add_option( '--plot_imag' , action='store_true' ,
                   help='Plot the imaginary part as well and save in the same directory as the real part.' )

( options , args ) = parser.parse_args()

if len( args ) < 2 :
    parser.error( 'You must specify SNRMAPPATH and FIGPATH! ' )

SNRmappath , figpath = args[ :2 ]

file = open( SNRmappath , 'rb' ) ; SNRmap = cpkl.load( file ) ; file.close()
SNRlm = AS.get_lmax_subset_from( SNRmap.xlm , options.lmax )
Smap = AS.xlmSkyMap( xlm = float( options.mapnorm ) * SNRlm )
Smap.xlm_to_plm() ; Smap.xlm_to_qlm()
Smap.create_sky( nlon=options.nlon , nlat=options.nlat )
Smap.plm_to_P() ; Smap.qlm_to_Q() ; Smap.PQ_to_X()

figdir = os.path.dirname( figpath )
if figdir not in glob.glob( figdir ) :
    os.system( 'mkdir -p %s' % figdir )
if options.plot_imag :
    Qpath = figdir + '/SNR_imag.png'
else :
    Qpath = None
PP.project_SkyMap( Smap , Ppath = figpath , Qpath = Qpath )

示例#18
0
文件: x_stdP.py 项目: qAp/LisaMapp
covarm = np.dot( fishinv , np.dot( fish.fish , fishinv ) )

if options.strong_signal :
    if options.Spath == 'default' :
        Spath = os.path.dirname( stdPdir ) + '/S/S.pkl'
    else :
        Spath = options.Spath

    if Spath not in glob.glob( Spath ) :
        print 'Cannot  locate the bias matrix, skipping...'
        pass
    else :
        print 'Including the strong signal bias...'
        file = open( Spath , 'rb' ) ; Sdict = cpkl.load( file ) ; file.close()
        Sdata = AS.get_lmax_subset_from( Sdict['S'].data , options.lmax )
        covarm = np.dot( fishinv , np.dot( ( fish.fish + Sdata ) , fishinv ) )

variance = np.diag( covarm )
indxpn = AS.getMLvec( options.lmax )
for i , ml in enumerate( indxpn ) :
    if variance[i] < 0 :
        print "Warning: negative variance for (m,l)=(%d,%d)" % ml
        print "Taking the absolute value"
        variance[i] = np.abs( variance[i] )

stdP = np.sqrt( variance )

if stdPdir not in glob.glob( stdPdir ) :
    os.system( 'mkdir %s' % stdPdir )
file = open( stdPpath , 'wb' ) ; cpkl.dump( stdP , file , -1 ) ; file.close()
示例#19
0
import PostProcess as PP



mapdir = './'


l = 0                  #of Ylm
m = 0                  #of Ylm
Amplitude = 1e-38          #Real number only please!

nlon = 360
nlat = 181

ntrunc = 20
skymap = AS.xlmSkyMap( ntrunc=ntrunc )
if m % 2 == 0 :
    if m == 0:
        skymap.alter_ml( False , (m,l,Amplitude) )
    else:
        skymap.alter_ml( False , (m,l,Amplitude/2.) , (-m,l,Amplitude/2.) )
else:
    skymap.alter_ml( False , (m,l,Amplitude/2.) , (-m,l,-Amplitude/2.) )
skymap.xlm_to_plm()
skymap.xlm_to_qlm()
skymap.create_sky( nlon=nlon , nlat=nlat )
skymap.plm_to_P()
skymap.qlm_to_Q()
skymap.PQ_to_X()

示例#20
0
parser.add_option( '--nlat' , action='store' , dest='nlat' , type='int' , default=91 ,
                   help='Number of latitudes to plot in the sky.' )

parser.add_option( '--plot_imag' , action='store_true' ,
                   help='Plot the imaginary part as well and save in the same directory as the real part.' )

( options , args ) = parser.parse_args()

if len( args ) < 2 :
    parser.error( 'You must specify SIGMAPPATH and FIGPATH! ' )

sigmappath , figpath = args[ :2 ]

file = open( sigmappath , 'rb' ) ; sigmamap = cpkl.load( file ) ; file.close()
Smapdata = AS.get_lmax_subset_from( sigmamap.xlm , options.lmax )
Smap = AS.xlmSkyMap( xlm = options.mapnorm * Smapdata )
Smap.xlm_to_plm() ; Smap.xlm_to_qlm()
Smap.create_sky( nlon=options.nlon , nlat=options.nlat ) ; Smap.plm_to_P() ; Smap.qlm_to_Q()

figdir = os.path.dirname( figpath )
if figdir not in glob.glob( figdir ) :
    os.system( 'mkdir -p %s' % figdir )
if options.plot_imag :
    Qpath = figdir + '/S_imag.png'
else :
    Qpath = None
PP.project_SkyMap( Smap , Ppath = figpath , Qpath = Qpath )


示例#21
0
    y2r = n2r + hr
    """ Straight cross-correlation """
    Ometer = np.mean(y1 * y2)
    Ometer_ana, var_Ometer_ana = Omega, (var_n1 + Omega) * (
        var_n2 + Omega) / N + Omega**2 / N
    """ Cross-correlation with filtering """
    Y1 = stime * np.fft.fft(y1)
    Y2 = stime * np.fft.fft(y2)
    df_c12 = 1. / (N * stime)
    if N % 2 == 0:
        c12 = 2 * np.conj(Y1[:N / 2 + 1]) * Y2[:N / 2 + 1] / (N * stime)
        f_c12 = df_c12 * np.arange(N / 2 + 1)
    else:
        c12 = 2 * np.conj(Y1[:(N + 1) / 2]) * Y2[:(N + 1) / 2] / (N * stime)
        f_c12 = df_c12 * np.arange((N + 1) / 2)
    Qc12 = AS.Coarsable(c12, Offset1=f_c12[0], Cadence1=df_c12)
    Qf_c12 = AS.Coarsable(f_c12, Offset1=f_c12[0], Cadence1=df_c12)

    p11l, f_p11l = pl.psd(y1l, nfft, fs, noverlap=noverlap)
    p11r, f_p11r = pl.psd(y1r, nfft, fs, noverlap=noverlap)
    p11 = (p11l + p11r) / 2
    f_p11 = np.copy(f_p11l)
    df_p11 = f_p11[1] - f_p11[0]
    Qp11 = AS.Coarsable(p11, Offset1=f_p11[0], Cadence1=df_p11)
    Qf_p11 = AS.Coarsable(f_p11, Offset1=f_p11[0], Cadence1=df_p11)
    p22l, f_p22l = pl.psd(y2l, nfft, fs, noverlap=noverlap)
    p22r, f_p22r = pl.psd(y2r, nfft, fs, noverlap=noverlap)
    p22 = (p22l + p22r) / 2
    f_p22 = np.copy(f_p22l)
    df_p22 = f_p22[1] - f_p22[0]
    Qp22 = AS.Coarsable(p22, Offset1=f_p22[0], Cadence1=df_p22)
示例#22
0
( options , args ) = parser.parse_args()

if len( args ) < 2 :
    parser.error( "You must specify PSDDIR, directory containing PSDs, and AVGPSDDIR, directory to save average PSDs in!" )

psddir , avgpsddir = args


if avgpsddir not in glob.glob( avgpsddir ) :
    os.system( 'mkdir %s' % avgpsddir )

for day in options.days :

    print "++++ DAY %d ++++" % day

    dayl , dayr = day - 1 , day + 1
    psdpathl , psdpathr = ( psddir + 'd%03d.pkl' % dayl ) , ( psddir + 'd%03d.pkl' % dayr )

    if psdpathl not in glob.glob( psdpathl ) :
        print 'Left PSD not available on day %d. Nothing to do.' % day
        continue
    if psdpathr not in glob.glob( psdpathr ) :
        print 'Right PSD not available on day %d. Nothing to do.' % day
        continue

    print "PSDs of adjacent days available, taking the average...",
    AS.avg_psdPKL_avg( day , psdpathl , psdpathr , avgpsddir )
    print "done"

示例#23
0
(options, args) = parser.parse_args()

if len(args) < 2:
    parser.error(
        'You must specify GDIR and AVGSIGDIR! See Help: ./x_sigma_avg.py -h')

Gdir, avgsigdir = args[:2]

avgsigpath = avgsigdir + 'sigma_avg.pkl'

sigma_avgs = []
for lmax in range(options.lmax + 1):
    print 'Calculating average sigma from Fisher matrix truncated at lmax = %d' % lmax

    fish = AS.FisherMatrix(Gdir + 'G.pkl', lmax=lmax)
    if options.regMethod == 0:
        print 'Calculating unregularised inverse of Fisher matrix...'
        fishinv = fish.invert()
        print 'done'
    else:
        print "Calculating regularised inverse of Fisher matrix..."
        fish.regularise(regMethod=options.regMethod,
                        regCutoff=float(options.regCutoff))
        fishinv = fish.reginvert()

    covarm = np.dot(fishinv, np.dot(fish.fish, fishinv))
    map_sigma, lats, lons = AS.getSigmaMap(covarm, options.nlat, options.nlon)

    dlon = lons[1] - lons[0]
    dlat = lats[0] - lats[options.nlon]
示例#24
0
    psdpath = psddir + '/d%03d.pkl' % day
    orfpath = orfdir + '/d%03d.pkl' % day

    if tspath not in glob.glob( tspath ) :
        print 'Time-series not available on day %03d' % day ; days_skipped += [ day ] ; continue
    if psdpath not in glob.glob( psdpath ) :
        print 'PSD not available on day %03d' % day ; days_skipped += [ day ] ; continue
    if orfpath not in glob.glob( orfpath ) :
        print 'ORF not found at %s' % orfpath ; days_skipped += [ day ] ; continue
#        print 'ORF not availalbe on day %03d' % day ; days_skipped += [ day ] ; continue

    print "Time-series, psd and orf all available on day %03d. " % day
    print "First available day?"  , firstavailable

    file = open( tspath , 'rb' ) ; tsdict = cpkl.load( file ) ; file.close()
    ts = AS.TimeSeries( tsdict )
    if options.scale_ts :
        ts.scale_by( options.scale_ts )

    file = open( psdpath , 'rb' ) ; psddict = cpkl.load( file ) ; file.close()
    
    orf = AS.OrfMultipleMoments( orfpath )
    
    xxx = AS.XXX( orf , psddict , ts , options.H0, options.GWslope , day , cIJdir=cIJdir )
    XX = xxx.getsummand( flow=options.flow , fhigh=options.fhigh , lmax=options.lmax , window=options.window )

    if firstavailable :
        X = np.zeros( np.shape(XX.data) , complex )
        print 'Calculating normalisation factor due to coarsegraining and windowing'
        N = xxx.ts.t.data.shape[0] ; T = xxx.ts.t.Cadence1 * N ; df = xxx.fcoarse.Cadence1
        if options.window == 'None' :
示例#25
0
    action='store_true',
    help=
    'Plot the imaginary part as well and save in the same directory as the real part.'
)

(options, args) = parser.parse_args()

if len(args) < 2:
    parser.error('You must specify SIGMAPPATH and FIGPATH! ')

sigmappath, figpath = args[:2]

file = open(sigmappath, 'rb')
sigmamap = cpkl.load(file)
file.close()
Smapdata = AS.get_lmax_subset_from(sigmamap.xlm, options.lmax)
Smap = AS.xlmSkyMap(xlm=options.mapnorm * Smapdata)
Smap.xlm_to_plm()
Smap.xlm_to_qlm()
Smap.create_sky(nlon=options.nlon, nlat=options.nlat)
Smap.plm_to_P()
Smap.qlm_to_Q()

figdir = os.path.dirname(figpath)
if figdir not in glob.glob(figdir):
    os.system('mkdir -p %s' % figdir)
if options.plot_imag:
    Qpath = figdir + '/S_imag.png'
else:
    Qpath = None
PP.project_SkyMap(Smap, Ppath=figpath, Qpath=Qpath)
示例#26
0
( 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()

示例#27
0
    print "---- DAY %d ----" % day
    tspath = tsdir + '/d%03d.pkl' % day
    if tspath not in glob.glob( tspath ) :
        print 'Time-series NOT found at %s' % tspath
        continue

    psdpath = psddir + 'd%03d.pkl' % day
    if psdpath in glob.glob( psdpath ) :
        print 'psd/%s exists. Nothing to do.' % psdpath
        continue

    print "Time-series available on day %03d, calculating its PSDs... " % day ,

    file = open( tspath , 'rb' ) ; tsdict = cpkl.load( file ) ; file.close()

    ts = AS.TimeSeries( tsdict )
    if options.scale_ts :
        ts.scale_by( options.scale_ts )

    t , n1 , n2 , n3 = ts.t.data , ts.A.data , ts.E.data , ts.T.data
    stime = ts.t.Cadence1 ; inittime = ts.t.Offset1 ; N = t.shape[0]

    nfft = int( options.segduration / stime ) ; noverlap = nfft / 2 ; fs = 1. / stime

    P11data , fdata = mymlab.psd( n1 , nfft , fs , noverlap = noverlap )
    P22data , fdata = mymlab.psd( n2 , nfft , fs , noverlap = noverlap )
    P33data , fdata = mymlab.psd( n3 , nfft , fs , noverlap = noverlap )

    f0 = fdata[0] ; df = fdata[1] - fdata[0] ; fscale = { 'Offset1':f0 , 'Cadence1':df }
    f = AS.Coarsable( fdata , **fscale )
    P11 = AS.Coarsable( P11data , **fscale )
示例#28
0
文件: x_P.py 项目: qAp/LisaMapp

fish = AS.FisherMatrix( Gpath , lmax=options.lmax )
if options.regMethod == 0 :
    print 'Calculating unregularised inverse of Fisher matrix...'
    fishinv = fish.invert()
else :
    print "Calculating regularised inverse of Fisher matrix..."
    fish.regularise( regMethod=options.regMethod , regCutoff=float( options.regCutoff ) )
    fishinv = fish.reginvert()

if options.N_keptSV : 
    print 'Number of eigenvalues kept = ' , fish.N_keptSV

file = open( Xpath , 'rb' ) ; map_X = cpkl.load( file ) ; file.close()
Xlm = AS.get_lmax_subset_from( map_X.xlm , options.lmax )

Pdata = np.dot( fishinv , Xlm )

Pmap = AS.xlmSkyMap( xlm = options.mapnorm * Pdata )
Pmap.xlm_to_plm() ; Pmap.xlm_to_qlm()
Pmap.create_sky( nlon = options.nlon , nlat = options.nlat )
Pmap.plm_to_P() ; Pmap.qlm_to_Q() ; Pmap.PQ_to_X()

Pdir = os.path.dirname( Ppath )
if Pdir not in glob.glob( Pdir ) :
    os.system( 'mkdir -p %s' % Pdir )
file = open( Ppath , 'wb' ) ; cpkl.dump( Pmap , file , -1 ) ; file.close()


示例#29
0
#!/usr/bin/env python
import os
import sys
import glob
import cPickle as cpkl
import numpy as np
import AnisotropySearch as AS

IJs = ["AE", "AT", "ET", "AE_AT", "AE_ET", "AT_ET", "AE_AT_ET"]
injPpath = "/gpfs1/JC0311443/workhere/stochasGW/Mapp/skymaps/library/sphericalharmonics/Y_l0_m0_x1e-34/Y_l0_m0.pkl"
anadir = "GW_slope_0_test1/"
m, l, lmax = 0, 0, 15
scale_Plm = 1.0

indxpn = AS.getMLvec(lmax)

""" Load injected Plm """
file = open(injPpath)
P0 = cpkl.load(file)
file.close()


""" Load clean map of Plm """
Plms = []
for IJ in IJs:
    Ppath = "%s/%s/P/P_lmax_%d.pkl" % (anadir, IJ, lmax)
    file = open(Ppath, "rb")
    P = cpkl.load(file)
    file.close()
    Plms += [P.plm[indxpn.index((m, l))] * scale_Plm]
示例#30
0


if True not in [ proj_X ,
                 proj_P , save_P , 
                 proj_sigmamap , save_sigmamap , 
                 proj_SNRmap , save_SNRmap ,
                 proj_stdP ] :
    print "Nothing to do."

if proj_X :
    print "Plotting X"
    mapnorm = 1.
    Xpath = Xdir + 'X.pkl'
    file = open( Xpath , 'rb' ) ; map_X = cpkl.load( file ) ; file.close()
    Xlm = AS.get_lmax_subset_from( map_X.xlm , lmax )
    Xmap = AS.xlmSkyMap( xlm = mapnorm * Xlm )
    Xmap.xlm_to_plm() ; Xmap.xlm_to_qlm()
    Xmap.create_sky( nlon=nlon , nlat=nlat )
    Xmap.plm_to_P() ; Xmap.qlm_to_Q()
    projdir = 'post_process/figures/X/'
    if projdir not in glob.glob( projdir ) :
        os.system( 'mkdir -p %s' % projdir )
    PP.project_SkyMap( Xmap , Ppath = projdir + 'Xreal.png' )
    


if True in [ proj_P , save_P ,
             proj_sigmamap , save_sigmamap ,
             proj_SNRmap , save_SNRmap ,
             proj_stdP ] :
示例#31
0
parser.add_option( '--lmax' , action='store' , dest='lmax' , type='int' , default=15 ,
                   help='l up to which to truncate the X and G.' )

parser.add_option( '--mapnorm' , action='store' , dest='mapnorm' , type='string' , default='1.' ,
                   help='Scalar factor to scale all multipole moments before plotting.' )

( options , args ) = parser.parse_args()

if len( args ) < 2 :
    parser.error( 'You must specify GPATH and SIGMAPPATH! See Help: ./x_sigmamap.py -h' )

Gpath , sigmappath = args[ :2 ]

fish = AS.FisherMatrix( Gpath , lmax = options.lmax )
fish.regularise( regMethod = options.regMethod , regCutoff = float( options.regCutoff ) )
regfishinv = fish.reginvert()
covarm = np.dot( regfishinv , np.dot( fish.fish , regfishinv ) )

map_sigma , lats , lons = AS.getSigmaMap( covarm , options.nlat , options.nlon )
mapdata = np.reshape( map_sigma , ( options.nlat , options.nlon ) )
sigmamap = AS.XSkyMap( X = float( options.mapnorm ) * mapdata ) ; sigmamap.X_to_P() ; sigmamap.X_to_Q()
sigmamap.ntrunc_equals( options.lmax ) ; sigmamap.P_to_plm() ; sigmamap.Q_to_qlm() ; sigmamap.plmqlm_to_xlm()

sigmapdir = os.path.dirname( sigmappath )
if sigmapdir not in glob.glob( sigmapdir ) :
    os.system( 'mkdir %s' % sigmapdir )
file = open( sigmappath , 'wb' ) ; cpkl.dump( sigmamap , file , -1 ) ; file.close()



示例#32
0
文件: x_P_to_TS.py 项目: qAp/LisaMapp
        print "Initial times:" , t0l , ',' , t0r
        print ""
        if options.seed == 'None' :
            shortftl = AS.CSpectra_to_ShortTermFT( cspec_dict , seed=None ) ; shortftr = AS.CSpectra_to_ShortTermFT( cspec_dict , seed=None )
        else :
            seedl = int( options.seed ) + ( day - 1 )*Nseg + seg ; seedr = int( options.seed ) + ( day - 1 )*Nseg + ( seg + 1 )
            print 'seeds: left, right' , seedl , seedr
            shortftl = AS.CSpectra_to_ShortTermFT( cspec_dict , seed=seedl ) ; shortftr = AS.CSpectra_to_ShortTermFT( cspec_dict , seed=seedr )
        stsl = AS.InverseFT( shortftl , Neven=True , tOffset=t0l ) ; stsr = AS.InverseFT( shortftr , Neven=True , tOffset=t0r )
        if i == 0 :
            Offset  = stsl.s1.Offset1 ; Cadence = stsl.s1.Cadence1
        joinrems = [ AS.WindowAndJoin( getattr( stsl , s ) , getattr( stsr , s ) , leftover = getattr( leftover , s , None ) ) for s in slist ]
        joins = [ joinrem[0] for joinrem in joinrems ]  
        rems  = [ joinrem[1] for joinrem in joinrems ]
        rem_dict = dict( zip( slist , rems ) )
        leftover = AS.sTimeSeries( **rem_dict )
        oldandnews = zip( [ Ajoins , Ejoins , Tjoins ] , joins )
        [ oldandnew[0].append( oldandnew[1].data ) for oldandnew in oldandnews ]
        
    tsdatas = [ np.concatenate( tuple( Ijoins ) ) for Ijoins in [ Ajoins , Ejoins , Tjoins ]  ]

    numberofsamplesinaday = int( duration / Cadence )
    
    onedaytsdatas = [ tsdata[ : numberofsamplesinaday ] for tsdata in tsdatas ]
    
    tscoarsables = [ AS.Coarsable( onedaytsdata , Offset1=Offset , Cadence1=Cadence ) for onedaytsdata in onedaytsdatas ]
    
    tsdict = dict( zip( [ '1' , '2' , '3' ] , tscoarsables ) )
    tsdict['t'] = AS.Coarsable( Offset + Cadence * np.arange( numberofsamplesinaday ) , Offset1=Offset , Cadence1=Cadence )

    if tsdir not in glob.glob( tsdir ) :
示例#33
0
import numpy as np
import matplotlib.pyplot as plt
import myLISAmodule as mlisar
import AnisotropySearch as AS





t0s = [ 100 ]
m , l = 3 , 5
tdiORF_SpH_dir = 'data_nlon_220_nlat_111/'
fig_dir = 'figures_f_vs_tdiORF_SpHs_nlon_220_nlat_111/' 


indxpn = AS.getMLvec( l , 'pn' ) ; k = indxpn.index( (m,l) )

for t0 in t0s :

    orf = AS.OrfMultipleMoments( tdiORF_SpH_dir + 'orf_t0_%.1f.pkl' % t0 )
    glm = orf.getMultipleMoments( 'pn' , l )
    f = glm.Offset1 + glm.Cadence1 * np.arange( glm.data.shape[1] )
    glmdata = glm.data[ k , : ]

    fig_dir = fig_dir + 't0_%.1f/' % t0
    if fig_dir not in glob.glob( fig_dir ) :
        os.system( 'mkdir -p %s' % fig_dir )

    fig = plt.figure()
    fig.suptitle( 'tdiORF SpH: l = %d , m = %d , t0 = %.1f' % ( l , m , t0 ) )
    ax = fig.add_subplot( 311 )
示例#34
0
文件: x_SNRmap.py 项目: qAp/LisaMapp
    parser.error( 'You must specify at least GPATH, XPATH and SNRMAPPATH! Type ./x_SNRmap.py -h' )

Gpath , Xpath , SNRmappath = args[ :3 ]

fish = AS.FisherMatrix( Gpath , lmax=options.lmax )
if options.regMethod == 0 :
    print 'Calculating unregularised inverse of Fisher matrix...'
    fishinv = fish.invert()
    print 'done'
else :
    print "Calculating regularised inverse of Fisher matrix..."
    fish.regularise( regMethod=options.regMethod , regCutoff=float( options.regCutoff ) )
    fishinv = fish.reginvert()

file = open( Xpath , 'rb' ) ; map_X = cpkl.load( file ) ; file.close()
Xlm = AS.get_lmax_subset_from( map_X.xlm , options.lmax )

Pdata = np.dot( fishinv , Xlm )
Pmap = AS.xlmSkyMap( xlm = Pdata )
Pmap.xlm_to_plm() ; Pmap.xlm_to_qlm()
Pmap.create_sky( nlon = options.nlon , nlat = options.nlat )
Pmap.plm_to_P() ; Pmap.qlm_to_Q() ; Pmap.PQ_to_X()

covarm = np.dot( fishinv , np.dot( fish.fish , fishinv ) )
map_sigma , lats , lons = AS.getSigmaMap( covarm , options.nlat , options.nlon )
mapdata = np.reshape( map_sigma , ( options.nlat , options.nlon ) )
sigmamap = AS.XSkyMap( X = mapdata ) ; sigmamap.X_to_P() ; sigmamap.X_to_Q()
sigmamap.ntrunc_equals( options.lmax ) ; sigmamap.P_to_plm() ; sigmamap.Q_to_qlm() ; sigmamap.plmqlm_to_xlm()

SNRdata = Pmap.P / sigmamap.P
SNRmap = AS.XSkyMap( X = float( options.mapnorm ) * SNRdata ) ; SNRmap.X_to_P() ; SNRmap.X_to_Q()
示例#35
0
(options, args) = parser.parse_args()

if len(args) < 2:
    parser.error(
        'You must specify at least an XPATH and a NETWORKXPATH! ( See help: x_network_X.py -h )'
    )
else:
    Xpaths = args[:-1]
    netXpath = args[-1]

for i, Xpath in enumerate(Xpaths):
    file = open(Xpath, 'rb')
    X = cpkl.load(file)
    file.close()
    if i == 0:
        netXdata = np.copy(X.xlm)
        lmax = X.ntrunc
    else:
        netXdata += np.copy(X.xlm)

netX = AS.xlmSkyMap(xlm=netXdata)

netXdir = os.path.dirname(netXpath)
if netXdir not in glob.glob(netXdir):
    os.system('mkdir -p %s' % netXdir)

file = open(netXpath, 'wb')
cpkl.dump(netX, file, -1)
file.close()
示例#36
0
parser.add_option( '--Nf' , action='store' , dest='Nf' , type='string' , nargs=1 , default='5' , help='Number of frequencies' )

parser.add_option( '--IJ' , action='store' , dest='IJ' , type='string' , nargs=1 , default='AA' , help='IJ of ORF' )

parser.add_option( '--lmax' , action='store' , dest='lmax' , type='string' , nargs=1 , default='0' , help='Maximum degree l for the SpHs' )

( options , args ) = parser.parse_args()
if len( args ) < 1 :
    parser.error( 'You must specify ORFPATH, the file path to save the tdiORF_SpHs!' )
else :
    orfpath = args[ 0 ]


f = options.f0 + options.df * np.arange( options.Nf )
indxp = AS.getMLvec( options.lmax , 'p' )

SpHreal = np.ones( ( len( indxp ) , options.Nf ) ) * arbitrary_SpHreal_ML( f )
SpHimag = np.ones( ( len( indxp ) , options.Nf ) ) * arbitrary_SpHimag_ML( f )

orfdict = {'OrfMultipleMoments': { 'ntrunc': options.lmax , 'f': f , 'Antenna': options.IJ , 'real': SpHreal , 'imag': SpHimag } }

orfdir = os.path.dirname( orfpath )
if orfdir not in glob.glob( orfdir ) :
    os.system( 'mkdir -p %s' % orfdir )
file = open( orfpath , 'wb' ) ; cpkl.dump( orfdict , file , -1 ) ; file.close()
print " Orf multipole moments saved in %s " % orfpath



示例#37
0
nlat, nlon = setup['postproc']['nlat'], setup['postproc']['nlon']

if True not in [
        proj_X, proj_P, save_P, proj_sigmamap, save_sigmamap, proj_SNRmap,
        save_SNRmap, proj_stdP
]:
    print "Nothing to do."

if proj_X:
    print "Plotting X"
    mapnorm = 1.
    Xpath = Xdir + 'X.pkl'
    file = open(Xpath, 'rb')
    map_X = cpkl.load(file)
    file.close()
    Xlm = AS.get_lmax_subset_from(map_X.xlm, lmax)
    Xmap = AS.xlmSkyMap(xlm=mapnorm * Xlm)
    Xmap.xlm_to_plm()
    Xmap.xlm_to_qlm()
    Xmap.create_sky(nlon=nlon, nlat=nlat)
    Xmap.plm_to_P()
    Xmap.qlm_to_Q()
    projdir = 'post_process/figures/X/'
    if projdir not in glob.glob(projdir):
        os.system('mkdir -p %s' % projdir)
    PP.project_SkyMap(Xmap, Ppath=projdir + 'Xreal.png')

if True in [
        proj_P, save_P, proj_sigmamap, save_sigmamap, proj_SNRmap, save_SNRmap,
        proj_stdP
]:
示例#38
0
文件: x_SNRmap.py 项目: qAp/LisaMapp
                  action='store',
                  dest='mapnorm',
                  type='string',
                  default='1.',
                  help='Scalar factor to scale the map plotting.')

(options, args) = parser.parse_args()

if len(args) < 3:
    parser.error(
        'You must specify at least GPATH, XPATH and SNRMAPPATH! Type ./x_SNRmap.py -h'
    )

Gpath, Xpath, SNRmappath = args[:3]

fish = AS.FisherMatrix(Gpath, lmax=options.lmax)
if options.regMethod == 0:
    print 'Calculating unregularised inverse of Fisher matrix...'
    fishinv = fish.invert()
    print 'done'
else:
    print "Calculating regularised inverse of Fisher matrix..."
    fish.regularise(regMethod=options.regMethod,
                    regCutoff=float(options.regCutoff))
    fishinv = fish.reginvert()

file = open(Xpath, 'rb')
map_X = cpkl.load(file)
file.close()
Xlm = AS.get_lmax_subset_from(map_X.xlm, options.lmax)
示例#39
0
usage = """
$prog [ XPATH,... ] NETWORKXPATH\n
XPATH --- path to file of Xs to be summed(can have more than one)
NETWORKXPATH --- path to file in which to save network X
"""
parser = optparse.OptionParser( usage = usage )

( options , args ) = parser.parse_args()

if len( args ) < 2 :
    parser.error( 'You must specify at least an XPATH and a NETWORKXPATH! ( See help: x_network_X.py -h )' )
else :
    Xpaths = args[ : -1 ] ; netXpath = args[ -1 ]

for i , Xpath in enumerate( Xpaths ) :
    file = open( Xpath , 'rb' ) ; X = cpkl.load( file ) ; file.close()
    if i == 0 :
        netXdata = np.copy( X.xlm )
        lmax = X.ntrunc
    else :
        netXdata += np.copy( X.xlm )

netX = AS.xlmSkyMap( xlm = netXdata )

netXdir = os.path.dirname( netXpath )
if netXdir not in glob.glob( netXdir ) :
    os.system( 'mkdir -p %s' % netXdir )

file = open( netXpath , 'wb') ; cpkl.dump( netX , file , -1 ) ; file.close()
示例#40
0
文件: x_P_to_TS.py 项目: qAp/LisaMapp
for day in options.days:

    print ""
    print "==== Day %d ====" % day
    print ""

    T0 = (day - 1) * duration

    orfpaths = [
        orfdir +
        'tdiI_%s_tdiJ_%s_lmax_%d_f0_%f_df_%f_Nf_%d_g00_9/data/orf_d%03d.pkl' %
        (IJ[0], IJ[1], options.lmax, options.f0, options.df, options.Nf, day)
        for IJ in IJlist
    ]
    orfs = [AS.OrfMultipleMoments(orfpath) for orfpath in orfpaths]

    cspecs = [AS.Convolve(orf, skymap, options.GWslope) for orf in orfs]
    cspec_dict = dict(zip(XYlist, cspecs))
    """>>>>> Sort the covariance matrix elements into PSDs and CSDs and save them to disk """
    psddict = {
        'f': orf.f,
        'AA': cspec_dict['11'],
        'EE': cspec_dict['22'],
        'TT': cspec_dict['33']
    }
    csddict = {
        'f': orf.f,
        'AE': cspec_dict['12'],
        'AT': cspec_dict['13'],
        'ET': cspec_dict['23']
示例#41
0
文件: plot_P.py 项目: qAp/LisaMapp
    action='store_true',
    help=
    'Plot the imaginary part as well and save in the same directory as the real part.'
)

(options, args) = parser.parse_args()

if len(args) < 2:
    parser.error('You must specify PPATH and FIGPATH! ')

Ppath, figpath = args[:2]

file = open(Ppath, 'rb')
map_P = cpkl.load(file)
file.close()
Plm = AS.get_lmax_subset_from(map_P.xlm, options.lmax)
Pmap = AS.xlmSkyMap(xlm=options.mapnorm * Plm)
Pmap.xlm_to_plm()
Pmap.xlm_to_qlm()
Pmap.create_sky(nlon=options.nlon, nlat=options.nlat)
Pmap.plm_to_P()
Pmap.qlm_to_Q()

figdir = os.path.dirname(figpath)
PP.SkyMap_to_datfile(Pmap, 'temporary.dat')
if options.plot_imag:
    PP.project_SkyMap('temporary.dat',
                      Ppath=figpath,
                      Qpath=figdir + '/P_imag.png')
else:
    PP.project_SkyMap('temporary.dat', Ppath=figpath)
示例#42
0
    if tspath not in glob.glob(tspath):
        print 'Time-series not found on day %d. Nothing to do.' % day
        continue

    csdpath = csddir + 'd%03d.pkl' % day
    if csdpath in glob.glob(csdpath):
        print '%s exists. Nothing to do.' % csdpath
        continue

    print "Time-series available on day %03d, calculating its CSDs... " % day,

    file = open(tspath, 'rb')
    tsdict = cpkl.load(file)
    file.close()

    ts = AS.TimeSeries(tsdict)
    if options.scale_ts:
        ts.scale_by(options.scale_ts)

    t, n1, n2, n3 = ts.t.data, ts.A.data, ts.E.data, ts.T.data
    stime = ts.t.Cadence1
    inittime = ts.t.Offset1
    N = t.shape[0]

    nfft = int(options.segduration / stime)
    noverlap = nfft / 2
    fs = 1. / stime

    P12data, fdata = mymlab.csd(n1, n2, nfft, fs, noverlap=noverlap)
    P13data, fdata = mymlab.csd(n1, n3, nfft, fs, noverlap=noverlap)
    P23data, fdata = mymlab.csd(n2, n3, nfft, fs, noverlap=noverlap)
示例#43
0
文件: x_S.py 项目: qAp/LisaMapp
    orfpath = orfdir + '/d%03d.pkl' % day
    psdpath = psddir + '/d%03d.pkl' % day

    if csdpath not in glob.glob( csdpath ) :
        print 'CSD not found at %s' % csdpath ; continue
    if orfpath not in glob.glob( orfpath ) :
        print 'Orf not found at %s' % orfpath ; continue
    if psdpath not in glob.glob( psdpath ) :
        print 'PSD not found at %s' % psdpath ; continue

    orf = AS.OrfMultipleMoments( orfpath )
    file = open( csdpath , 'rb' ) ; csddict = cpkl.load( file ) ; file.close()
    file = open( psdpath , 'rb' ) ; psddict = cpkl.load( file ) ; file.close()
    
    SSdata = AS.get_covariance_bias_matrix_for_the_day( orf , psddict , csddict ,
                                                        options.H0, options.GWslope ,
                                                        day , options.flow , options.fhigh , options.lmax )
    
    if firstavailable :
        Sdata = np.zeros( SSdata.shape , dtype = SSdata.dtype )
        print 'Calculating normalisation factor due to coarsegraining and windowing'
        tspath = tsdir + '/d%03d.pkl' % day
        file = open( tspath , 'rb' ) ; tsdict = cpkl.load( file ) ; file.close() ; ts = AS.TimeSeries( tsdict )
        N = ts.t.data.shape[0] ; T = ts.t.Cadence1 * N 
        fcoarse = AS.coarsefrequency( orf.f , psddict['f'] , csddict['f'] ) ; df = fcoarse.Cadence1
        if options.window == 'None' :
            window = np.ones( N )
        elif options.window == 'hanning' :
            window = np.hanning( N )
        norm = ( np.sum( window**2 ) / N )**2 / ( np.sum( window**4 ) / N ) * T*df        
        firstavailable = False
示例#44
0
[file.close() for file in files]

s1datas = [
    float(options.mergs[k][0]) * tsdicts[k]['1'].data for k in range(Nmerg)
]
s2datas = [
    float(options.mergs[k][0]) * tsdicts[k]['2'].data for k in range(Nmerg)
]
s3datas = [
    float(options.mergs[k][0]) * tsdicts[k]['3'].data for k in range(Nmerg)
]

s1data = np.sum(np.array(s1datas), 0)
s2data = np.sum(np.array(s2datas), 0)
s3data = np.sum(np.array(s3datas), 0)

t = tsdicts[0]['t']
tscale = {'Offset1': t.Offset1, 'Cadence1': t.Cadence1}
s1 = AS.Coarsable(s1data, **tscale)
s2 = AS.Coarsable(s2data, **tscale)
s3 = AS.Coarsable(s3data, **tscale)

tsdict = {'t': t, '1': s1, '2': s2, '3': s3}

tsdir = os.path.dirname(tspath)
if tsdir not in glob.glob(tsdir):
    os.system('mkdir -p %s' % tsdir)
file = open(tspath, 'wb')
cpkl.dump(tsdict, file, -1)
file.close()
lmax_max = setup['maxlike']['lmax']
Gdir = setup['maxlike']['Gdir']
figdir = setup['sigma_avg']['figdir']
nlon , nlat = setup['sigma_avg']['nlon'] , setup['sigma_avg']['nlat']



lmaxs = range( lmax_max + 1 )
sigma_avgs = []
for lmax in lmaxs :
    print 'Calculating average sigma at lmax = %d' % lmax
    
    fish = AS.FisherMatrix( Gdir + 'G.pkl' , lmax = lmax )
    fishinv = fish.invert()
    map_sigma , lats , lons = AS.getSigmaMap( fishinv , nlat , nlon )

    dlon = lons[1] - lons[0] ; dlat = lats[0] - lats[nlon]
    dOmega = np.radians( dlon ) * np.radians( dlat ) * np.sin( np.pi/2 - np.radians( lats ) )

    sigma_avg = np.sum( dOmega * map_sigma ) / ( lmax + 1 )**2
    sigma_avgs += [ sigma_avg ]


if figdir not in glob.glob( figdir ) :
    os.system( 'mkdir %s' % figdir )
    
fig = plt.figure()
ax = fig.add_subplot( 111 )
ax.plot( lmaxs , sigma_avgs )
ax.set_title( 'average standard deviation vs lmax' )
示例#46
0
import sys
import cPickle as cpkl
import AnisotropySearch as AS
import PostProcess as PP

mapdir = './'

l = 0  #of Ylm
m = 0  #of Ylm
Amplitude = 1e-38  #Real number only please!

nlon = 360
nlat = 181

ntrunc = 20
skymap = AS.xlmSkyMap(ntrunc=ntrunc)
if m % 2 == 0:
    if m == 0:
        skymap.alter_ml(False, (m, l, Amplitude))
    else:
        skymap.alter_ml(False, (m, l, Amplitude / 2.), (-m, l, Amplitude / 2.))
else:
    skymap.alter_ml(False, (m, l, Amplitude / 2.), (-m, l, -Amplitude / 2.))
skymap.xlm_to_plm()
skymap.xlm_to_qlm()
skymap.create_sky(nlon=nlon, nlat=nlat)
skymap.plm_to_P()
skymap.qlm_to_Q()
skymap.PQ_to_X()

mapname = 'Y_l%d_m%d.pkl' % (l, m)
elif options.whichtdi == 'optimal':
    IIs = ['AE', 'AT', 'ET']

if csddir not in glob.glob(csddir):
    os.system('mkdir %s' % csddir)

for day in options.days:

    print "~~~~~~~ Day %d ~~~~~~~" % day
    orfids = [(options.tditype, options.tdigen, II[0], options.tditype,
               options.tdigen, II[1], options.f0, options.df, options.Nf, day)
              for II in IIs]
    orfpaths = [(
        orfdir +
        'tdiI_%s_%s_%s_tdiJ_%s_%s_%s_lmax_20_f0_%f_df_%f_Nf_%d/data_nlon_120_nlat_61/orf_d%03d.pkl'
        % orfid) for orfid in orfids]
    orfs = [AS.OrfMultipleMoments(orfpath) for orfpath in orfpaths]

    PIJs = [AS.Convolve(orf, skymap, options.GWslope) for orf in orfs]

    P12, P13, P23 = PIJs

    fdata = P12.Offset1 + P12.Cadence1 * np.arange(P12.data.shape[0])
    f = AS.Coarsable(fdata, Offset1=P12.Offset1, Cadence1=P12.Cadence1)

    csddict = {'f': f, 'AE': P12, 'AT': P13, 'ET': P23}

    file = open(csddir + 'd%03d.pkl' % day, 'wb')
    cpkl.dump(csddict, file, -1)
    file.close()
示例#48
0
parser = optparse.OptionParser( 'Usage: ./x_simulate_noise.py SETUP.pkl' )
( options , args ) = parser.parse_args()
if len( args ) < 1 :
    parser.error( 'You must specify a SETUP.pkl containing input parameters!' )
file = open( args[0] , 'rb' ) ; setup = cpkl.load( file ) ; file.close()


tditype , tdigen , whichtdis = setup['tditype'] , setup['tdigen'] , setup['whichtdis']
stime , duration , inittime , seed = setup['stime'] , setup['duration'] , setup['inittime'] , setup['seed']
tspath = setup['tspath']


tsdir = '/'.join( re.split( '/' , tspath )[:-1] ) + '/'
print tsdir
if not tspath in glob.glob( tspath ) :
    t , n = mlisar.get_tdiNoise_freq_domain_CovarMatrix( tditype , tdigen , whichtdis ,
                                                         stime , duration , inittime , seed )
    tscale = { 'Cadence1':stime , 'Offset1':inittime }
    tsdict = {}
    tsdict['1'] , tsdict['2'] , tsdict['3'] = AS.Coarsable( n[0] , **tscale ) , AS.Coarsable( n[1] , **tscale ) , AS.Coarsable( n[2] , **tscale )
    tsdict['t'] = AS.Coarsable( t , **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()
else :
    print '%s already saved to disk.  Nothing to do.' % tspath