Esempio n. 1
0
def tsXML_to_psdXML(inxmlpath, outxmldir):
    '''
    Not too nice function for opening a TDIsignal xml file, reading the time-series' inside, calculate the PSDs for each, and then saving them in a similar xml file, but with the time-series replaced by PSDs.  Will have to do for now.
    '''
    inxml = lisaxml.readXML(inxmlpath)
    source = inxml.SourceData[0]
    lisa = inxml.LISAData
    tdiobs = inxml.TDIData[0]
    inxml.close()

    hr = 60.0**2
    patches = int(tdiobs.TimeSeries.Duration / hr)
    specAA = synthlisa.spect(tdiobs.A, tdiobs.TimeSeries.Cadence, patches)
    specEE = synthlisa.spect(tdiobs.E, tdiobs.TimeSeries.Cadence, patches)
    specTT = synthlisa.spect(tdiobs.T, tdiobs.TimeSeries.Cadence, patches)
    f = specAA[:, 0]
    pAA = specAA[:, 1]
    pEE = specEE[:, 1]
    pTT = specTT[:, 1]

    pobs = lisaxml.Observable('f,pAA,pEE,pTT', DataType='FractionalFrequency')
    pobs.TimeSeries = lisaxml.TimeSeries([f, pAA, pEE, pTT], 'f,pAA,pEE,pTT')
    pobs.TimeSeries.Cadence = f[1] - f[0]
    pobs.TimeSeries.Cadence_Unit = 'Hertz'
    pobs.TimeSeries.TimeOffset = 0
    pobs.TimeSeries.TimeOffset_Unit = 'Hertz'

    inxmlname = os.path.basename(inxmlpath)
    outxmlpath = outxmldir + re.sub('\.xml$', '', inxmlname) + '-psd.xml'
    outxml = lisaxml.lisaXML(outxmlpath, author='J.Yu')
    outxml.TDIData(pobs)
    outxml.LISAData(lisa)
    outxml.SourceData(source)
    outxml.close()
    return
Esempio n. 2
0
def tsXML_to_psdXML(inxmlpath,outxmldir):
    """
    Not too nice function for  opening a TDIsignal xml file, reading the time-series' inside, calculate the PSDs for each, and then saving them in a similar xml file, but with the PSDs saved as lisaxml's TimeSeries objects.  Will have to do for now.                                                                                                                               """
    inxml = lisaxml.readXML(inxmlpath)
    sources = inxml.SourceData
    lisa = inxml.LISAData
    tdiobs = inxml.TDIData[0]
    inxml.close()

    segduration = 2*60.0**2
    patches = int(tdiobs.TimeSeries.Duration/segduration)
    specAA = synthlisa.spect(tdiobs.A,tdiobs.TimeSeries.Cadence,patches)
    specEE = synthlisa.spect(tdiobs.E,tdiobs.TimeSeries.Cadence,patches)
    specTT = synthlisa.spect(tdiobs.T,tdiobs.TimeSeries.Cadence,patches)
    f = specAA[:,0]
    pAA = specAA[:,1]
    pEE = specEE[:,1]
    pTT = specTT[:,1]

    pobs = lisaxml.Observable('f,pAA,pEE,pTT',DataType = 'FractionalFrequency')
    pobs.TimeSeries = lisaxml.TimeSeries([f,pAA,pEE,pTT],'f,pAA,pEE,pTT')
    pobs.TimeSeries.Cadence = f[1] - f[0]
    pobs.TimeSeries.Cadence_Unit = 'Hertz'
    pobs.TimeSeries.TimeOffset = 0
    pobs.TimeSeries.TimeOffset_Unit = 'Hertz'

    inxmlname = os.path.basename(inxmlpath)
    outxmlpath = outxmldir + re.sub('\.xml$','',inxmlname) + '-psd.xml'
    outxml = lisaxml.lisaXML(outxmlpath,author='J.Yu')
    outxml.TDIData(pobs)
    outxml.LISAData(lisa)
    for source in sources:
        outxml.SourceData(source)
    outxml.close()
    return
def ComputeNorm(ser, sampling, PSD):
     size = Numeric.shape(ser)[0]
     if(Numeric.shape(PSD)[0] != size/2):
         print "wrong size of psd: ", pdlen, Numeric.shape(PSD)
         sys.exit(1)
     ser2 = synthlisa.spect(ser, sampling,0)
     norm = 0.0
     indx = 0
     #fout = open("psdTest.dat", 'w')
     for i in xrange(size/2-1):
        if (ser2[i][0] > fLow and ser2[i][0]<= fHigh):
	    norm += ser2[i][1]/PSD[i]
#	    record = str(ser2[i][0]) + spr + str(PSD[i]) + spr + str(2.0*norm) + "\n"
#	    fout.write(record)
	    indx = indx + 1
     norm = sqrt(2.0*norm)
#    fout.close()     
     #print "indx = ", indx
     #norm = sqrt(2.0 *numpy.sum(ser2[1:,1]/PSD))
     return norm
def ComputeNorm(ser, sampling, PSD):
     size = Numeric.shape(ser)[0]
     if(Numeric.shape(PSD)[0] != size/2):
         print "wrong size of psd: ", pdlen, Numeric.shape(PSD)
         sys.exit(1)
     ser2 = synthlisa.spect(ser, sampling,0)
     norm = 0.0
     indx = 0
    # fout = open("dChiTest.dat", 'w')
     for i in xrange(size/2-1):
        if (ser2[i][0] > 1.e-5 and ser2[i][0]<0.009):
	    norm += ser2[i][1]/PSD[i]
#	    record = str(ser2[i][0]) + "    " + str(2.0*norm) + "\n"
#	    fout.write(record)
	    indx = indx + 1
     norm = sqrt(2.0*norm)
 #    fout.close()     
     #print "indx = ", indx
     #norm = sqrt(2.0 *numpy.sum(ser2[1:,1]/PSD))
     return norm
# reading Key file

Injtdifile = lisaxml.readXML(Injfile)
Injsources = Injtdifile.getLISASources()[0]
tdi = Injtdifile.getTDIObservables()[0]
Injtdifile.close()
sampling = tdi.TimeSeries.Cadence
X = tdi.Xf
A = (2.0*tdi.Xf -tdi.Yf - tdi.Zf)/3.0
E = (tdi.Zf - tdi.Yf)/math.sqrt(3.0)
#XX = synthlisa.spect(X, sampling, 0)
#fr = XX[1:,0]


Specdat = synthlisa.spect(Adata,sampling,0)
fr = Specdat[1:,0]
PSDdat = Specdat[1:,1] 
"""
Sigfilout = open("AEsigCheck1.dat", 'w') 
for i in xrange(len(A)):
   record = str(sampling*float(i)) + spr + str(A[i]) + spr + str(E[i]) + "\n"
   Sigfilout.write(record)
Sigfilout.close()   
sys.exit(0);
"""

if (EMRIchal):
   IndX = len(A)
   for i in xrange(len(A)-1, 1, -1):
      if (A[i] != 0.0):
        parser.error("I don't recognize the set of TDI observables!")

    [t, X, Y, Z] = numpy.transpose(
        synthlisa.getobs(samples,
                         options.timestep,
                         obsset,
                         options.inittime,
                         display=options.verbose))

# Computing SNR....

if options.debugSNR or hasattr(allsources[0], 'RequestSN'):
    # this is |\tilde{h}|^2 * dt/N
    sampling = ts.Cadence

    hX = synthlisa.spect(X, sampling, 0)
    hY = synthlisa.spect(Y, sampling, 0)
    hZ = synthlisa.spect(Z, sampling, 0)

    # get frequencies, skip DC
    fr = hX[1:, 0]

    om = 2.0 * pi * fr

    # instrument noise (was 2.5, 1.8)
    if options.armlength == 'Standard':
        Spm = 2.5e-48 * (1.0 + (fr / 1.0e-4)**-2) * fr**(-2)
        Sop = 1.8e-37 * fr**2
    else:
        print "Warning: adopting eLISA noise parameters for non-standard armlength"
        Spm = 6.00 - 48 * (1.0 + (fr / 1.0e-4)**-2) * fr**(-2)
        obsstr = 't,X1f,X2f,X3f'
    elif options.observables == 'Sagnac':
        obsset = [tdi.alpham,tdi.betam,tdi.gammam,tdi.zetam]
        obsstr = 'alphaf,betaf,gammaf,zetaf'
    else:
        parser.error("I don't recognize the set of TDI observables!")

    [t,X,Y,Z] = numpy.transpose(synthlisa.getobs(samples,options.timestep,obsset,options.inittime,display=options.verbose))

# Computing SNR....

if options.debugSNR or hasattr(allsources[0],'RequestSN'):
    # this is |\tilde{h}|^2 * dt/N
    sampling = ts.Cadence
    
    hX = synthlisa.spect(X,sampling,0)
    hY = synthlisa.spect(Y,sampling,0)
    hZ = synthlisa.spect(Z,sampling,0)
    
    # get frequencies, skip DC
    fr = hX[1:,0]
    
    om = 2.0 * pi * fr
    
    # instrument noise (was 2.5, 1.8)
    if options.armlength == 'Standard':
        Spm = 2.5e-48 * (1.0 + (fr/1.0e-4)**-2) * fr**(-2)
        Sop = 1.8e-37 * fr**2
    else:
        print "Warning: adopting eLISA noise parameters for non-standard armlength"
        Spm = 6.00e-48 * (1.0 + (1.0e-4/fr)) * fr**(-2)
fout1.close()


###  Computing quadratures if needed (we do not need pi/2)
if options.phasemax:
#   injfile =  Injfile[:-18]+'_piby2-tdi-frequency.xml'
#   Injtdifile = lisaxml.readXML(injfile)
#   tdipiby2 = Injtdifile.getTDIObservables()[0]
#   Xpiby2 = tdipiby2.Xf
#   Injtdifile.close()
   injfile =  Injfile[:-15]+'_0-tdi-strain.xml'
   Injtdifile = lisaxml.readXML(injfile)
   tdi0 = Injtdifile.getTDIObservables()[0]
   X0 = tdi0.Xs

XX = synthlisa.spect(X, sampling, 0)
fr = XX[1:,0]

# Compute noise spectral density

om = 2.0 * pi * fr
L  = 16.6782

# instrument noise

Spm = 2.5e-48 * (1.0 + (fr/1.0e-4)**-2) * fr**(-2)
Sop = 1.8e-37 * fr**2

Synx = 16.0 * numpy.sin(om*L)**2 * (2.0 * (1.0 + numpy.cos(om*L)**2) * Spm + Sop)
Synxy = -4.0 * numpy.sin(2.0*om*L)*numpy.sin(om*L) * ( Sop + 4.*Spm )
Syn = 2.0 * (Synx - Synxy)/3.0
nyquistf = 0.5/sampling
print "Cadence = ", sampling, "   Nyquist freq = ", nyquistf

print "Deaing with data file:", Datafile
challname = ""
if ( re.search('challenge3.2', Datafile) != None ):
  challname = "3.2"
elif ( re.search('challenge3.3', Datafile) != None ):
  challname = "3.3"
elif ( re.search('challenge3.4', Datafile) != None ):
  challname = "3.4"
  fHigh = nyquistf
  print "challenge3.4 -> upper frequency is extended to nyquist frequency"

Specdat = synthlisa.spect(Adata,sampling,0)
fr = Specdat[1:,0]
PSDdat = Specdat[1:,1]

# computing useful number of points
pdlen3 = samples/2
freqs = Numeric.arange(0,pdlen3+1,dtype='d') * (nyquistf / pdlen3)
ind = 0
for i in xrange(pdlen3):
    if (freqs[i] > fLow and freqs[i]<= fHigh):
        ind += 1    

ind = ind*2
print "data size = ", samples
print "number of used points ", ind, "corresponds to the freq range: ", fLow, "-", fHigh
Esempio n. 10
0
nyquistf = 0.5 / sampling
print "Cadence = ", sampling, "   Nyquist freq = ", nyquistf

print "Deaing with data file:", Datafile
challname = ""
if (re.search('challenge3.2', Datafile) != None):
    challname = "3.2"
elif (re.search('challenge3.3', Datafile) != None):
    challname = "3.3"
elif (re.search('challenge3.4', Datafile) != None):
    challname = "3.4"
    fHigh = nyquistf
    print "challenge3.4 -> upper frequency is extended to nyquist frequency"

Specdat = synthlisa.spect(Adata, sampling, 0)
fr = Specdat[1:, 0]
PSDdat = Specdat[1:, 1]

# computing useful number of points
pdlen3 = samples / 2
freqs = Numeric.arange(0, pdlen3 + 1, dtype='d') * (nyquistf / pdlen3)
ind = 0
for i in xrange(pdlen3):
    if (freqs[i] > fLow and freqs[i] <= fHigh):
        ind += 1

ind = ind * 2
print "data size = ", samples
print "number of used points ", ind, "corresponds to the freq range: ", fLow, "-", fHigh
"""
Esempio n. 11
0
                X.append(tdiData.Zs)

        
    print " --> time step =" , stime , "s"
    patches = 64

    # use Blackman windowing for spectra

    mywindow = 'blackman'

    # compute spectra, averaging "patches" overlapping segments of time series
    if (options.verbose):
        print " --> Compute spectrums ..."
    sX = []
    for iSim in xrange(len(X)):
        sX.append(synthlisa.spect(X[iSim],stime,patches,win=mywindow))

    if (options.verbose):
        print " --> Normalized spectrums ..."
    f = sX[0][1:,0]
    for iSim in xrange(len(sX)):
        if ( (UsedSim[iSim] == 'SL') or (UsedSim[iSim] == 'LC') ):
            # go to a spectrum of phase (from frequency)
            sX[iSim][1:,1] = sX[iSim][1:,1] / (2 * math.pi * f)**2
        else:
            # go to a spectrum of phase (from strain)
            scale = 1e10 / 299792458.0
            sX[iSim][1:,1] = scale**2 * sX[iSim][1:,1]


    # Record output data