Heating and Ventilation Control
/HvcTables
Keine Erläuterungen gefunden.
import numpy as np class HvcTables: """ Calibration of the HV-Control is done via tables. """ def __init__(self): """ Read the tables initially. """ self.tables={} with open("Configuration/HvcCalibration.dat", "r") as f: for line in f: if line[0]==" #": #create new numpy table tmp = line.split(" #") name = tmp[1] self.tables[name] = np.empty((0,2), float) elif len(line)>3: #put point to table tmp = line.split() x = float(tmp[0]) y = float(tmp[1]) self.tables[name] = np.append(self.tables[name], np.array([[x, y]]), axis=0) def names(self): """ Looks for the tables available. """ tableNames = self.tables.keys() return tableNames def showTable(self,name): """ Show a specific table. """ message = name+"\n" table = self.tables[name] for i in range(len(table)): message = message + str(table[i,0])+"\t"+str(table[i,1])+"\n" return message def interpol(self,x,tableName,mode): """ For arbitrary input 'x' the points of the table are interpolated. Exceeding the specified range, you may choose whether to saturate or to extrapolate. """ table = self.tables[tableName] NoPoints = len(table) xMin = table[0,0] yMin = table[0,1] xMax = table[NoPoints-1,0] yMax = table[NoPoints-1,1] if mode=="saturate": if x< xMin: x=xMin y=yMin return y if x>xMax: x=xMax y=yMax return y #inter- or extra-polate if x<=xMin: x1=table[1,0] y1=table[1,1] y=yMin+(y1-yMin)/(x1-xMin)*(x-xMin); return y if x>=xMax: x1=table[NoPoints-2,0] y1=table[NoPoints-2,1] y=yMax+(yMax-y1)/(xMax-x1)*(x-xMax); return y #interpolate table for p in range(NoPoints-1): xLeft=table[p,0] yLeft=table[p,1] xRight=table[p+1,0] yRight=table[p+1,1] if xLeft<x and x<=xRight: y=yLeft+(yRight-yLeft)/(xRight-xLeft)*(x-xLeft) return y if __name__ == "__main__": tables = HvcTables() tablesNames = tables.names() print(tablesNames) thisTableStr = tables.showTable("KTY") print(thisTableStr) y = tables.interpol(2000,"KTY","saturate") print("y should be 46.49, interpolation retured "+('{:.2f}'.format(y)) )
python
php
Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.