Dr. Arne Jachens

Set up the Raspberry Pi

no warranty for any of the provided information

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)>1:
                    #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

1HvcControl.py
2HvcHCSR04ultrasonic.py
3HvcMain.py
4HvcMotorDriver.py
5HvcOneWire.py
6HvcOperationMode.py
7HvcRaw2phys.py
8HvcReadSPI.py
9HvcSendI2C.py
10HvcSetGPIO.py
11HvcTables.py
12HvcWeather.py
13makeDoc.py

php

1HV_Admin_Login.php
2HV_colorMap.php
3HV_composeH2Oplot.php
4HV_config.php
5HV_H2Olevel.php
6HV_readOperationState.php
7HV_restart.php
8HV_serviceLog.php
9HV_setParameters.php
10HV_showHouse.php
11HV_showLog.php
12HV_showWeatherForecast.php
13HV_TempCal.php
14index.php
15readFilenames.php
16readNamedData.php

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