def deltaCg(w_f1, w_f0, a=False, ref=False, l_p0=l_p0, l_p1=l_p1): ''' Inputs: - w_f1 = fuel used at the second point - w_f0 = fuel used at beginning of cg shift - a = if True, returns absolute value of shift in cg, otherwise it return positive or negative value accordingly - ref = if True, outputs data for reference data, otherwise it outputs data for actual flight Outputs: - The shift in cg, given in m w_fuel_dcg = w_fuel_ref if ref else w_fuel idx_pax = -3 l_p0 = np.array([131,131,214,214,251,251,288,288,170])*inc l_p1 = np.array([131,131,214,214,251,251,288,288,170])*inc l_p1[idx_pax] = 134*inc w_pax_dcg = w_pass_ref if ref else w_pass m_f0 = interpolate(fuel_cg[:,0],fuel_cg[:,1],w_fuel_dcg-w_f0) m_f1 = interpolate(fuel_cg[:,0],fuel_cg[:,1],w_fuel_dcg-w_f1) m_p0 = l_p0*w_pax_dcg m_p1 = l_p1*w_pax_dcg x_cg0 = (sum(m_p0)+m_oew+m_f0)/(sum(w_pax_dcg)+w_oew+(w_fuel_dcg-w_f0)) x_cg1 = (sum(m_p1)+m_oew+m_f1)/(sum(w_pax_dcg)+w_oew+(w_fuel_dcg-w_f1)) ''' if ref: m_f0 = interpolate(fuel_cg[:, 0], fuel_cg[:, 1], w_fuel_ref - w_f0) m_f1 = interpolate(fuel_cg[:, 0], fuel_cg[:, 1], w_fuel_ref - w_f1) #l_p0 = np.array([131,131,214,214,251,251,288,288,170])*inc #l_p1 = np.array([131,131,214,214,251,251,134,288,170])*inc m_p0 = l_p0 * w_pass_ref m_p1 = l_p1 * w_pass_ref x_cg0 = (sum(m_p0) + m_oew + m_f0) / (sum(w_pass_ref) + w_oew + (w_fuel_ref - w_f0)) x_cg1 = (sum(m_p1) + m_oew + m_f1) / (sum(w_pass_ref) + w_oew + (w_fuel_ref - w_f1)) else: m_f0 = interpolate(fuel_cg[:, 0], fuel_cg[:, 1], w_fuel - w_f0) m_f1 = interpolate(fuel_cg[:, 0], fuel_cg[:, 1], w_fuel - w_f1) #l_p0 = np.array([131,131,214,214,251,251,288,288,170])*inc #l_p1 = np.array([131,131,214,214,251,251,134,288,170])*inc m_p0 = l_p0 * w_pass m_p1 = l_p1 * w_pass x_cg0 = (sum(m_p0) + m_oew + m_f0) / (sum(w_pass_ref) + w_oew + (w_fuel - w_f0)) x_cg1 = (sum(m_p1) + m_oew + m_f1) / (sum(w_pass_ref) + w_oew + (w_fuel - w_f1)) return abs(x_cg1 - x_cg0) if a else x_cg1 - x_cg0
def mapper(self, _, line): """ The mapper loads a track and yields its ramp factor """ t = track.load_track(line) segments = t['segments'] duration = t['duration'] xdata = [] ydata = [] for i in xrange(len(segments)): seg = segments[i] sloudness = seg['loudness_max'] sstart = seg['start'] + seg['loudness_max_time'] xdata.append( sstart ) ydata.append( sloudness ) if duration > 20: idata = tools.interpolate(xdata, ydata, int(duration) * 10) smooth = tools.smooth(idata, 20) samp = tools.sample(smooth, self.SIZE) ndata = tools.rnormalize(samp, -60, 0) if self.DUMP: for i, (x, y) in enumerate(zip(self.MATCH, ndata)): print i, x, y if self.VECTOR: yield (t['artist_name'], t['title'], t['track_id']), ndata else: distance = tools.distance(self.MATCH, ndata) yield (t['artist_name'], t['title'], t['track_id']), distance
def mapper(self, _, line): """ The mapper loads a track and yields its ramp factor """ t = track.load_track(line) segments = t['segments'] duration = t['duration'] xdata = [] ydata = [] for i in xrange(len(segments)): seg = segments[i] sloudness = seg['loudness_max'] sstart = seg['start'] + seg['loudness_max_time'] xdata.append(sstart) ydata.append(sloudness) if duration > 20: idata = tools.interpolate(xdata, ydata, int(duration) * 10) smooth = tools.smooth(idata, 20) samp = tools.sample(smooth, self.SIZE) ndata = tools.rnormalize(samp, -60, 0) if self.DUMP: for i, (x, y) in enumerate(zip(self.MATCH, ndata)): print i, x, y if self.VECTOR: yield (t['artist_name'], t['title'], t['track_id']), ndata else: distance = tools.distance(self.MATCH, ndata) yield (t['artist_name'], t['title'], t['track_id']), distance
##Conversion factors lbs = 0.45359 #kg inc = 0.0254 #m g = 9.81 #m/s^2 w_fuel = 2640 * lbs * g w_fuel_ref = 4050 * lbs * g ##Generate input data fuel_cg = np.genfromtxt("cg_data/fuel_cg.dat", delimiter=",") fuel_cg = np.column_stack( (fuel_cg[:, 0] * g * lbs, fuel_cg[:, 1] * lbs * g * inc * 100)) #convert to metric system m_fuel = interpolate(fuel_cg[:, 0], fuel_cg[:, 1], w_fuel) m_fuel_ref = interpolate(fuel_cg[:, 0], fuel_cg[:, 1], w_fuel_ref) w_pass = np.genfromtxt("cg_data/pass_w.dat") * g l_pass = np.array([131, 131, 214, 214, 251, 251, 288, 288, 170]) * inc m_pass = l_pass * w_pass w_pass_ref = np.genfromtxt("cg_data/pass_w_ref.dat") * g l_pass = np.array([131, 131, 214, 214, 251, 251, 288, 288, 170]) * inc m_pass_ref = l_pass * w_pass_ref w_oew = 9165.0 * lbs * g l_oew = 291.65 * inc m_oew = 2672953.5 * inc * lbs * g x_cg = (sum(m_pass) + m_oew + m_fuel) / (w_fuel + sum(w_pass) + w_oew)
def __init__(self, machine, name, **keys): super(self.__class__, self).__init__( machine, name ) if 'Filename' in keys.keys(): self.Filename= str(keys['Filename']) else: raise ValueError("Input Filename Required") if 'Sigma' in keys.keys(): self.Sigma= float(keys['Sigma']) else: raise ValueError("Sigma Required") if 'OutputFilename' in keys.keys(): self.OFilename= str(keys['OutputFilename']) else: raise ValueError("Output filename Required") check = False checka = False checkb = False checkc = False if 'ForcefieldSize' in keys.keys(): ForcefieldSize = keys['ForcefieldSize'] else: check = True ForcefieldSize = [15.562592,13.4776,25.413607] if 'ForcefieldStepSize' in keys.keys(): STEPSIZE = keys['ForcefieldStepSize'] else: raise ValueError("ERROR: No Force field step size specified") stepx = STEPSIZE[0] stepy = STEPSIZE[1] stepz = STEPSIZE[2] if 'LatticeVectora' in keys.keys(): LatticeVectora = keys['LatticeVectora'] else: checka = True if 'LatticeVectorb' in keys.keys(): LatticeVectorb = keys['LatticeVectorb'] else: checkb = True if 'LatticeVectorc' in keys.keys(): LatticeVectorc = keys['LatticeVectorc'] else: checkc = True if 'ZCutOff' in keys.keys(): ZCutOff = keys['ZCutOff'] else: ZCutOff = [0,0] MakeSquare = False if 'MakeSquare' in keys.keys(): MakeSquare = keys['MakeSquare'] else: MakeSquare = False fo = open(self.OFilename, "w") f = open(self.Filename, "r") print "Reading in file: "+ self.Filename size=[0,0,0] index = [0,0,0] NumberOfPoints=[0,0,0] Points=[0,0,0] NumberOfAtoms=0 Vx =[0,0,0] Vy =[0,0,0] Vz =[0,0,0] linelen = 0 check = False linenumber=0 for line in f: if linenumber == 2: size[0] = (float(line.split()[0])**2 + float(line.split()[1])**2 + float(line.split()[2])**2) ** (0.5) Vx[0] = float(line.split()[0]) Vx[1] = float(line.split()[1]) Vx[2] = float(line.split()[2]) if linenumber == 3: size[1] = (float(line.split()[0])**2 + float(line.split()[1])**2 + float(line.split()[2])**2) ** (0.5) Vy[0] = float(line.split()[0]) Vy[1] = float(line.split()[1]) Vy[2] = float(line.split()[2]) if linenumber == 4: size[2] = (float(line.split()[0])**2 + float(line.split()[1])**2 + float(line.split()[2])**2) ** (0.5) Vz[0] = float(line.split()[0]) Vz[1] = float(line.split()[1]) Vz[2] = float(line.split()[2]) #Find number of atoms if linenumber == 6: for i in range(0, (len(line.split())) ): NumberOfAtoms += float(line.split()[i]) #find number of points if linenumber == NumberOfAtoms+9: NumberOfPoints[0]= int(line.split()[0]) NumberOfPoints[1]= int(line.split()[1]) NumberOfPoints[2]= int(line.split()[2]) V = [[[0 for k in xrange( int (NumberOfPoints[2]) ) ] for j in xrange( int (NumberOfPoints[1]) )] for i in xrange(int (NumberOfPoints[0]) )] if linenumber > NumberOfAtoms+9: for i in range(0, (len(line.split())) ): V[ index[0] ][ index[1] ] [ index[2] ] = float (line.split()[i]) index[0] = index[0] +1 if index [0] == NumberOfPoints[0]: index[0] = 0 index[1] = index [1] +1 if index [1] == NumberOfPoints[1]: index[1] = 0 index[2] = index[2] +1 if len(line.split()) == 0: break linenumber = linenumber + 1 if check == True: ForcefieldSize = [Vx[0],Vy[1],Vz[2]] if checka == True: LatticeVectora = [Vx[0],Vx[1],Vx[2]] if checkb == True: LatticeVectorb = [Vy[0],Vy[1],Vy[2]] if checkc == True: LatticeVectorc = [Vz[0],Vz[1],Vz[2]] print "File read in" f.close() #Find step size dx = float(size[0]/NumberOfPoints[0]) dy = float(size[1]/NumberOfPoints[1]) dz = float(size[2]/NumberOfPoints[2]) Datax = len(V) Datay = len(V[0]) Dataz = len(V[0][0]) Lattice = [ [Vx[0] ,Vx[1] , Vx[2]], [Vy[0] ,Vy[1] , Vy[2] ], [Vz[0] ,Vz[1] , Vz[2]] ] GridDim = [ Datax , Datay , Dataz ] Lattice=np.array(Lattice) GridDim=np.array(GridDim) V=np.array(V) OUT = gauss(Lattice,GridDim,V,self.Sigma) #Start making it square if check == True: ForcefieldSize = [Vx[0],Vy[1],Vz[2]] if checka == True: LatticeVectora = [Vx[0],Vx[1],Vx[2]] if checkb == True: LatticeVectorb = [Vy[0],Vy[1],Vy[2]] if checkc == True: LatticeVectorc = [Vz[0],Vz[1],Vz[2]] #For coord transform find: ax = LatticeVectora[0] ay = LatticeVectora[1] az = LatticeVectora[2] bx = LatticeVectorb[0] by = LatticeVectorb[1] bz = LatticeVectorb[2] cx = LatticeVectorc[0] cy = LatticeVectorc[1] cz = LatticeVectorc[2] maga = math.sqrt (LatticeVectora[0]*LatticeVectora[0] + LatticeVectora[1]*LatticeVectora[1] + LatticeVectora[2]*LatticeVectora[2]) magb = math.sqrt (LatticeVectorb[0]*LatticeVectorb[0] + LatticeVectorb[1]*LatticeVectorb[1] + LatticeVectorb[2]*LatticeVectorb[2]) magc = math.sqrt (LatticeVectorc[0]*LatticeVectorc[0] + LatticeVectorc[1]*LatticeVectorc[1] + LatticeVectorc[2]*LatticeVectorc[2]) print "Interpolating" x = 0 y = 0 z = 0 counter = [0,0,0] sizex = math.ceil(ForcefieldSize[0] / stepx) sizey = math.ceil(ForcefieldSize[1] / stepy) sizez = math.ceil(ForcefieldSize[2] / stepz) U = [[[0 for k in xrange( int (sizez) ) ] for j in xrange( int (sizey) )] for i in xrange(int (sizex) )] xarray = [] yarray = [] zarray = [] #Build the 3d interpolated square grid while x <= ForcefieldSize[0]: while y<=ForcefieldSize[1]: while z <= ForcefieldSize[2]: #Find the transformed coordiante posx = maga*(bz*cy*x - by*cz*x - bz*cx*y + bx*cz*y + by*cx*z - bx*cy*z)/ (az*by*cx - ay*bz*cx - az*bx*cy + ax*bz*cy + ay*bx*cz - ax*by*cz) posy = magb*(az*cy*x - ay*cz*x - az*cx*y + ax*cz*y + ay*cx*z - ax*cy*z)/ (-(az*by*cx) + ay*bz*cx + az*bx*cy - ax*bz*cy - ay*bx*cz + ax*by*cz) posz = magc*(az*by*x - ay*bz*x - az*bx*y + ax*bz*y + ay*bx*z - ax*by*z)/ (az*by*cx - ay*bz*cx - az*bx*cy + ax*bz*cy + ay*bx*cz - ax*by*cz) ans = tools.interpolate(OUT,[dx,dy,dz],posx,posy,posz) U[ counter[0] ][ counter[1] ][ counter[2] ] = ans z+=stepz counter[2]+=1 counter[1] += 1 counter[2] = 0 z = 0 y += stepy counter[0] += 1 counter[1] = 0 counter[2] = 0 y = 0 z = 0 x += stepx #Output the Potential print "Writing to File" for x in range(0, int (sizex) ): for y in range(0,int(sizey) ): for z in range(0+ZCutOff[0],int(sizez-ZCutOff[1]) ): fo.write(str(x+1)+" "+str(y+1)+" "+str(z+1)+" " + str(U[x][y][z]) + "\n") ''' print "Writing to File" for x in range(0,Datax): for y in range(0,Datay): for z in range(0,Dataz): #print x,y,z fo.write(str(x+1)+" "+str(y+1)+" "+str(z+1)+" "+str(OUT[x][y][z]) + "\n") ''' fo.close()
def __init__(self, machine, name, **keys): super(self.__class__, self).__init__(machine, name) A = 0.13 f0 = 1.553e6 K = 130 if 'filename' in keys.keys(): FILENAME = keys["filename"] else: raise NameError("Missing filename") if 'NumberOfPoints' in keys.keys(): NumberOfPoints = keys["NumberOfPoints"] else: raise NameError("Missing NumberOfPoints") if 'K' in keys.keys(): K = keys["K"] else: raise NameError("Missing K") if 'A' in keys.keys(): A = keys["A"] else: raise NameError("Missing A") if 'f0' in keys.keys(): f0 = keys["f0"] else: raise NameError("Missing f0") res = [51, 51, 201] if 'res' in keys.keys(): res = keys["res"] step = [] if 'step' in keys.keys(): step = keys["step"] else: raise NameError("Missing step") NumberOfUnitCells = [1, 1, 1] if 'NumberOfFFCells' in keys.keys(): NumberOfUnitCells = keys["NumberOfFFCells"] convertion = 1 if 'convertion' in keys.keys(): convertion = keys["convertion"] zHeight = None if 'zHeight' in keys.keys(): zHeight = keys["zHeight"] OutputFile = "" if 'OutputFile' in keys.keys(): OutputFile = keys["OutputFile"] else: raise NameError("Missing OutputFile") OscRes = 100 if 'OscRes' in keys.keys(): OscRes = keys["OscRes"] if 'TipPos' in keys.keys(): TipPos = keys["TipPos"] arrayx = linspace( TipPos[0], (step[0] * NumberOfPoints[0] * NumberOfUnitCells[0]) + TipPos[0], res[0]) arrayy = linspace( TipPos[1], (step[1] * NumberOfPoints[1] * NumberOfUnitCells[1]) + TipPos[1], res[1]) arrayz = linspace( A, (step[2] * NumberOfPoints[2] * NumberOfUnitCells[2]) + TipPos[2], res[2]) if 'ScanType' in keys.keys(): ScanType = keys["ScanType"] if ScanType != "Vertical": if ScanType != "Lateral": print "ERROR: Scan type can only be Vertical or Lateral" sys.exit() if zHeight != None and ScanType == "Lateral": arrayz = [zHeight] if ScanType == "Vertical": arrayx = [TipPos[0]] arrayy = [TipPos[1]] if 'MinMaxz' in keys.keys(): MinMaxz = keys["MinMaxz"] arrayz = linspace(MinMaxz[0], MinMaxz[1], res[2]) force = [] FF = open(FILENAME, 'r') Data = [[[0 for k in xrange(int(NumberOfPoints[2]))] for j in xrange(int(NumberOfPoints[1]))] for i in xrange(int(NumberOfPoints[0]))] for line in FF: i = int(line.split()[0]) - 1 j = int(line.split()[1]) - 1 k = int(line.split()[2]) - 1 Data[i][j][k] = float(line.split()[3]) * convertion counter = 0 linecounter = 0 xpos = 0 ypos = 0 Resultsx = [] Resultsy = [] Resultsz = [] Resultsdf = [] ForceTest = [] for ypos in arrayy: linecounter += 1 print "Running line number " + str(linecounter) for xpos in arrayx: for z in arrayz: #Solve the integral from 0 to 2pi Integral = 0 size = OscRes x = linspace(0, 2 * pi, size) #Find x_0 pos = float(z + A * cos(x[0])) Force = tools.interpolate(Data, step, xpos, ypos, pos) #Force= tools.interpolate(Data,[0.705,0.705,0.1],xpos,ypos,pos) Integral += cos(x[0]) * Force #x_1 tp x _ size-1 for i in range(1, size - 1): pos = float(z + A * cos(x[i])) Force = tools.interpolate(Data, step, xpos, ypos, pos) #Force= tools.interpolate(Data,[0.705,0.705,0.1],xpos,ypos,pos) if i % 2 == 0: #Is even Integral += 2 * cos(x[i]) * Force if i % 2 != 0: #Is odd Integral += 4 * cos(x[i]) * Force #Find x_size_n pos = float(z + A * cos(x[size - 1])) Force = tools.interpolate(Data, step, xpos, ypos, pos) #Force= tools.interpolate(Data,[0.705,0.705,0.1],xpos,ypos,pos) Integral += cos(x[size - 1]) * Force Integral = Integral * ((x[0] - x[size - 1]) / (len(x) - 1)) / 3 FreqShift = Integral * f0 / (2 * pi * K * A) Resultsx.append(xpos) Resultsy.append(ypos) Resultsz.append(z) Resultsdf.append(FreqShift) W = open(OutputFile, 'w') counter = 0 for i in range(0, len(Resultsx)): W.write( str(Resultsx[i]) + " " + str(Resultsy[i]) + " " + str(Resultsz[i]) + " " + str(Resultsdf[i]) + "\n") oldy = Resultsy[i] counter += 1 W.close() self.SetInputs(**keys)