def aquireGreens(greenFile,args): # define strem to load the greens in time green=Stream() # displacement o velocity ivel = args.dva # max number of stations (i.e.: distance) allowed. # when modify this value, modify also the same value # range, vred and t0 into FKRPROG and recomplie Max_nr_dists = 100 # dim(n2) (4097) # read twice the Green.1 file. One to access integers and one for reals F = FortranFile(greenFile) I = FortranFile(greenFile) # First Line of header. This line is an mix float-int array h_1f = F.readReals() h_1i = I.readInts() alpha = h_1f[0] depth = h_1f[1] fl = h_1f[2] fu = h_1f[3] dt = h_1f[4] n1 = h_1i[5] n2 = h_1i[6] df = h_1f[7] nyq = h_1i[8] nrange = h_1i[9] nskip = h_1i[10] # Second Line of header. This line is a 10 integer vector (isrc in code) # If h_2i[j] == 1 then compute green for this source element # else do not. h_2f = F.readReals() # Usealess for this line but neaded # to place pointers at the end of this array # for next header line h_2i = I.readInts() isrc = h_2i # Third Line of header. Mix float-int array. All float and one int # this heder inludes 6 float arry with 70 elemnts and one integer(nmax) # after the first 4 vectors. # Name of vectors and constant: # d(70),a(70),b(70),rho(70),nmax(1),qa(70),qb(70) h_3f = F.readReals() h_3i = I.readInts() beg = 0 inc = 70 d = h_3f[beg:beg+inc] beg = beg+inc a = h_3f[beg:beg+inc] beg = beg+inc b = h_3f[beg:beg+inc] beg = beg+inc rho = h_3f[beg:beg+inc] beg = beg+inc mmax = h_3i[beg:beg+1] beg = beg+1 qa = h_3f[beg:beg+inc] beg = beg+inc qb = h_3f[beg:beg+inc] # 4th line: range of distances, vred and t0 # this refers to stations lines into earth model # maximum station allowed in 100 and is hardcoded into # FKRPROG.f To extend the number of stationallowed, modify the code # recomplie and modify parameters at the beginn of this procedure # Vectors of float h_4f = F.readReals() h_4i = I.readInts() beg = 0 inc = Max_nr_dists Range = h_4f[beg:beg+inc] beg = beg+inc vred = h_4f[beg:beg+inc] beg = beg+inc t0 = h_4f[beg:beg+inc] # 5th line --> loop over distances to access cmplx spectral values # 3 loops: # 1 i: 1->n2 (n2=npts/2) - omega(float),nkk(int) # 2 j: 1->nrange # 3 k: 1->10 # read(aa),(bb) --> gg(j,i,k)=cmplx(sngl(aa),sngl(bb)) omega = [0.0 for x in range(0,n2+0)] freq = [0.0 for x in range(0,n2+0)] # (complex spectral matrix) # z --- k: foundamental mts # y --- i: (npts/2). nyq = npts/2 + 1 # x --- j: distsances gg = [ [ [ 0.0 for z in range(0,10+0)] \ for y in range(0,n2+0)] \ for x in range(0,nrange+0)] for i in range(0,n2+0): h_5f = F.readReals() omega[i] = h_5f[0] for j in range(0,nrange+0): for k in range(0,10+0): FF = F.readDouble() aa = complex(FF[0],FF[1]) gg[j][i][k] = aa # here we have the resulting matrix gg with complex spectra values # for each distance, each mtfound, take vector of complex (generate data(j), # make conjg, add complex for nyq, spectra->time, damping, # integration if required(disp) pi = acos(-1.0) twpi = 2.*pi n = 2 * (nyq-1) nm = n2 npoint = n rep = 'n' tau = dt fmax = fu inst = 0 for j in range(0,nrange+0): t0x = (Range[j])/(vred[j]) yr = 0.0 for k in range(0,10+0): if (isrc[k] ==1): # inizialize data data = numpy.array(numpy.zeros(n2+0+n2),dtype=complex) # data = [0.0 for x in range(0,n2+0+n2)] for i in range(0,n2+0): # arrange data data[i] = gg[j][i][k] # arrang frequency freq = i*df if(freq < df): freq = 0.01*df om = twpi * freq for i in range(n2+0,nyq): data[i] = complex(0.0,0.0) # conjug for i in range(1,n2+0): data[n+0-i] = data[i].conjugate() data[0] = complex(0.0,0.0) data[nyq-1] = complex(0.0,0.0) # From spectraToTime data = four1(data,n,1,dt,df) # Apply damping factor fac = exp(alpha*t0x) dfac = exp(alpha*dt) for i in range(len(data)): data[i]=(data[i])*fac fac = fac * dfac # velocity to displavement if required if(ivel=='1'): data=velTodisData(data,dt) # put data into trace prel = 0 prel = int(eval(args.pre) / eval(args.delta)) length=numpy.arange(len(data)+prel)*0.0 t=Trace(length) for i in range(len(data)): t.data[i+prel]=data[i] t.stats['delta'] = dt t.stats['dist'] = Range[j] name = 'GREEN_' + str(t.stats['dist']) t.stats['station'] = name # update stats and apply -1 for tss,xds,zss,zdd if k==7: t.stats['channel'] = 'tss' for i in range(len(data)): t.data[i] = t.data[i]*(-1) if k==4: t.stats['channel'] = 'tds' for i in range(len(data)): t.data[i] = t.data[i]*(+1) if k==6: t.stats['channel'] = 'xss' for i in range(len(data)): t.data[i] = t.data[i]*(+1) if k==3: t.stats['channel'] = 'xds' for i in range(len(data)): t.data[i] = t.data[i]*(-1) if k==1: t.stats['channel'] = 'xdd' for i in range(len(data)): t.data[i] = t.data[i]*(+1) if k==5: t.stats['channel'] = 'zss' for i in range(len(data)): t.data[i] = t.data[i]*(-1) if k==2: t.stats['channel'] = 'zds' for i in range(len(data)): t.data[i] = t.data[i]*(+1) if k==0: t.stats['channel'] = 'zdd' for i in range(len(data)): t.data[i] = t.data[i]*(-1) if k==8: t.stats['channel'] = 'ex1' # t.data[i] = t.data[i] # if(args.iso=='1'): # for i in range(len(data)): # t.data[i] = 0.0 # else: # for i in range(len(data)): # t.data[i] = 0.0 if k==9: t.stats['channel'] = 'ex2' # t.data[i] = t.data[i] # if(args.iso=='1'): # for i in range(len(data)): # t.data[i] = 0.0 # else: # for i in range(len(data)): # t.data[i] = 0.0 green.append(t) return green
xsun=-8.0 # input file name inputfilei='../ubgaiaerr/gaiaei-out.dat' inputfiled='../ubgaiaerr/gaiaed-out.dat' # reading binary data f=FortranFile(inputfilei) nset=f.readInts() print ' input Number of stars =',nset f.close() f=FortranFile(inputfiled) i=0 rdata=np.zeros((nset,27)) while i < nset: rdata[i,:]=f.readReals('d') i+=1 f.close() # parallax (mas) -> arcsec paradet=rdata[:,8]/1000.0 # only chose positive parallax and < 16 kpc away sindx=np.where(paradet > 1.0/(16.0*1.0e3)) # counting using parallax parado=paradet[sindx] nse=len(parado) print ' Number of stars (D<16 kpc)=',nse # set the data ...o (error added), ...e (error)
def aquireGreens(greenFile, args): # define strem to load the greens in time green = Stream() # displacement o velocity ivel = args.dva # max number of stations (i.e.: distance) allowed. # when modify this value, modify also the same value # range, vred and t0 into FKRPROG and recomplie Max_nr_dists = 100 # dim(n2) (4097) # read twice the Green.1 file. One to access integers and one for reals F = FortranFile(greenFile) I = FortranFile(greenFile) # First Line of header. This line is an mix float-int array h_1f = F.readReals() h_1i = I.readInts() alpha = h_1f[0] depth = h_1f[1] fl = h_1f[2] fu = h_1f[3] dt = h_1f[4] n1 = h_1i[5] n2 = h_1i[6] df = h_1f[7] nyq = h_1i[8] nrange = h_1i[9] nskip = h_1i[10] # Second Line of header. This line is a 10 integer vector (isrc in code) # If h_2i[j] == 1 then compute green for this source element # else do not. h_2f = F.readReals() # Usealess for this line but neaded # to place pointers at the end of this array # for next header line h_2i = I.readInts() isrc = h_2i # Third Line of header. Mix float-int array. All float and one int # this heder inludes 6 float arry with 70 elemnts and one integer(nmax) # after the first 4 vectors. # Name of vectors and constant: # d(70),a(70),b(70),rho(70),nmax(1),qa(70),qb(70) h_3f = F.readReals() h_3i = I.readInts() beg = 0 inc = 70 d = h_3f[beg:beg + inc] beg = beg + inc a = h_3f[beg:beg + inc] beg = beg + inc b = h_3f[beg:beg + inc] beg = beg + inc rho = h_3f[beg:beg + inc] beg = beg + inc mmax = h_3i[beg:beg + 1] beg = beg + 1 qa = h_3f[beg:beg + inc] beg = beg + inc qb = h_3f[beg:beg + inc] # 4th line: range of distances, vred and t0 # this refers to stations lines into earth model # maximum station allowed in 100 and is hardcoded into # FKRPROG.f To extend the number of stationallowed, modify the code # recomplie and modify parameters at the beginn of this procedure # Vectors of float h_4f = F.readReals() h_4i = I.readInts() beg = 0 inc = Max_nr_dists Range = h_4f[beg:beg + inc] beg = beg + inc vred = h_4f[beg:beg + inc] beg = beg + inc t0 = h_4f[beg:beg + inc] # 5th line --> loop over distances to access cmplx spectral values # 3 loops: # 1 i: 1->n2 (n2=npts/2) - omega(float),nkk(int) # 2 j: 1->nrange # 3 k: 1->10 # read(aa),(bb) --> gg(j,i,k)=cmplx(sngl(aa),sngl(bb)) omega = [0.0 for x in range(0, n2 + 0)] freq = [0.0 for x in range(0, n2 + 0)] # (complex spectral matrix) # z --- k: foundamental mts # y --- i: (npts/2). nyq = npts/2 + 1 # x --- j: distsances gg = [ [ [ 0.0 for z in range(0,10+0)] \ for y in range(0,n2+0)] \ for x in range(0,nrange+0)] for i in range(0, n2 + 0): h_5f = F.readReals() omega[i] = h_5f[0] for j in range(0, nrange + 0): for k in range(0, 10 + 0): FF = F.readDouble() aa = complex(FF[0], FF[1]) gg[j][i][k] = aa # here we have the resulting matrix gg with complex spectra values # for each distance, each mtfound, take vector of complex (generate data(j), # make conjg, add complex for nyq, spectra->time, damping, # integration if required(disp) pi = acos(-1.0) twpi = 2. * pi n = 2 * (nyq - 1) nm = n2 npoint = n rep = 'n' tau = dt fmax = fu inst = 0 for j in range(0, nrange + 0): t0x = (Range[j]) / (vred[j]) yr = 0.0 for k in range(0, 10 + 0): if (isrc[k] == 1): # inizialize data data = numpy.array(numpy.zeros(n2 + 0 + n2), dtype=complex) # data = [0.0 for x in range(0,n2+0+n2)] for i in range(0, n2 + 0): # arrange data data[i] = gg[j][i][k] # arrang frequency freq = i * df if (freq < df): freq = 0.01 * df om = twpi * freq for i in range(n2 + 0, nyq): data[i] = complex(0.0, 0.0) # conjug for i in range(1, n2 + 0): data[n + 0 - i] = data[i].conjugate() data[0] = complex(0.0, 0.0) data[nyq - 1] = complex(0.0, 0.0) # From spectraToTime data = four1(data, n, 1, dt, df) # Apply damping factor fac = exp(alpha * t0x) dfac = exp(alpha * dt) for i in range(len(data)): data[i] = (data[i]) * fac fac = fac * dfac # velocity to displavement if required if (ivel == '1'): data = velTodisData(data, dt) # put data into trace prel = 0 prel = int(eval(args.pre) / eval(args.delta)) length = numpy.arange(len(data) + prel) * 0.0 t = Trace(length) for i in range(len(data)): t.data[i + prel] = data[i] t.stats['delta'] = dt t.stats['dist'] = Range[j] name = 'GREEN_' + str(t.stats['dist']) t.stats['station'] = name # update stats and apply -1 for tss,xds,zss,zdd if k == 7: t.stats['channel'] = 'tss' for i in range(len(data)): t.data[i] = t.data[i] * (-1) if k == 4: t.stats['channel'] = 'tds' for i in range(len(data)): t.data[i] = t.data[i] * (+1) if k == 6: t.stats['channel'] = 'xss' for i in range(len(data)): t.data[i] = t.data[i] * (+1) if k == 3: t.stats['channel'] = 'xds' for i in range(len(data)): t.data[i] = t.data[i] * (-1) if k == 1: t.stats['channel'] = 'xdd' for i in range(len(data)): t.data[i] = t.data[i] * (+1) if k == 5: t.stats['channel'] = 'zss' for i in range(len(data)): t.data[i] = t.data[i] * (-1) if k == 2: t.stats['channel'] = 'zds' for i in range(len(data)): t.data[i] = t.data[i] * (+1) if k == 0: t.stats['channel'] = 'zdd' for i in range(len(data)): t.data[i] = t.data[i] * (-1) if k == 8: t.stats['channel'] = 'ex1' # t.data[i] = t.data[i] # if(args.iso=='1'): # for i in range(len(data)): # t.data[i] = 0.0 # else: # for i in range(len(data)): # t.data[i] = 0.0 if k == 9: t.stats['channel'] = 'ex2' # t.data[i] = t.data[i] # if(args.iso=='1'): # for i in range(len(data)): # t.data[i] = 0.0 # else: # for i in range(len(data)): # t.data[i] = 0.0 green.append(t) return green
# magnitude limit vmaglim=16.5 # assumed rotation velocity at 8 kpc vrotsun=220.0 # assumed M_v of RC, V-I colour mvrc=1.2714 virc=1.0 # solar metallicity zsun=np.float(0.019) f=FortranFile(inputfile) i=0 rdata=np.zeros((nset,10)) while i < nset: rdata[i,:]=f.readReals('d') i+=1 f.close() print ' Number of stars=',nset # set date # position (kpc) xs=rdata[:,0] ys=rdata[:,1] zs=rdata[:,2] # velocity (km/s) vxs=rdata[:,3] vys=rdata[:,4] vzs=rdata[:,5] # particle mass (Msun)
# magnitude limit vmaglim = 16.5 # assumed rotation velocity at 8 kpc vrotsun = 220.0 # assumed M_v of RC, V-I colour mvrc = 1.2714 virc = 1.0 # solar metallicity zsun = np.float(0.019) f = FortranFile(inputfile) i = 0 rdata = np.zeros((nset, 10)) while i < nset: rdata[i, :] = f.readReals("d") i += 1 f.close() print " Number of stars=", nset # set date # position (kpc) xs = rdata[:, 0] ys = rdata[:, 1] zs = rdata[:, 2] # velocity (km/s) vxs = rdata[:, 3] vys = rdata[:, 4] vzs = rdata[:, 5] # particle mass (Msun)