Hamburger Hamburger

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

1/HvcLightControl.py
2/HvcHCSR04ultrasonic.py
3/HvcPV.py
4/HvcMotorDriver.py
5/HvcRollerShutter.py
6/manGenMqttMap.py
7/HvcReadSPI.py
8/HvcMqtt.py
9/HvcTables.py
10/HvcMain.py
11/HvcSetGPIO.py
12/HvcWifiRelay.py
13/HvcOperationMode.py
14/HvcControl.py
15/HvcRaw2phys.py
16/HvcWeather.py
17/HvcOneWire.py
18/makeDoc.py
19/HvcFronius.py
20/EnergyManager.py
21/HvcSendI2C.py

php

1/HV_colorMap.php
2/HV_Admin_Login.php
3/HV_readOperationState.php
4/HV_setParameters.php
5/HV_config.php
6/EM_handleJSON.php
7/index.php
8/readFilenames.php
9/HV_restart.php
10/HV_moveGate.php
11/HV_showLog.php
12/HV_RollerShutter.php
13/EM_editParameter.php
14/HV_serviceLog.php
15/HV_H2Olevel.php
16/HV_TempCal.php
17/HV_Fronius.php
18/EM_plot.php
19/readNamedData.php
20/HV_composeH2Oplot.php
21/HVdoc.php
22/HV_showWeatherForecast.php
23/HV_showHouse.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.