from sense_hat import SenseHat
import numpy as np

class FixedHat(SenseHat):


    RPI_CPU_THERMAL_ZONE = '/sys/class/thermal/thermal_zone0/temp' 		
    WATER_MOLAR_MASS = 18 # [g/mol]
    GAS_CONSTANT = 0.0623665 # [mmHg * m^3 * K^-1 * mol^-1]


    def __init__(self, temp_cpu_factor=1.5):
        self._temp_cpu_factor = temp_cpu_factor
        super(FixedHat, self).__init__()

    def _sat_vapor_density(self, temp):
	"""
        Returns saturation vapor density in g/m^3 for the given temperature
        """
	
        temp_kelvin = self._to_kelvin(temp)

        # Saturation vapor pressure [mmHg] according to August-Roche-Magnus 
        # formula, temp in Celsius
        psat = (0.61078 * 7.501) * np.exp((17.2694 * temp) / (238.3 + temp))
        return self.WATER_MOLAR_MASS / (self.GAS_CONSTANT * temp_kelvin) * psat

    def _to_kelvin(self, T):
        """
        Returns temperature in Kelvin
        """

	return T + 273.15

    def get_temperature_from_humidity(self):
        """
        Returns the temperature in Celsius accounting for the influence 
        from the CPU temperature
        """

        temp_humidity = super(FixedHat, self).get_temperature_from_humidity()
        temp_cpu = int(open(self.RPI_CPU_THERMAL_ZONE).read()) / 1e3
        temp_increase_cpu = (temp_cpu - temp_humidity) / self._temp_cpu_factor
        return temp_humidity - temp_increase_cpu

    def get_absolute_humidity(self):
    	"""
    	Returns absolute humidity using relative humidity and temperature 
        measured by senseHat
    	"""
	
        relative_humidity = super(FixedHat, self).get_humidity()
    	temp_humidity = super(FixedHat, self).get_temperature_from_humidity()	
    	sat_vapor_density = self._sat_vapor_density(temp_humidity)
    	return relative_humidity * 0.01 * sat_vapor_density

    def get_humidity(self):
        """
        Returns the percentage of relative humidity for the calculated
        temperature accounting for the influence from the CPU temperature
        """

        absolute_humidity = self.get_absolute_humidity()
        temp_humidity = self.get_temperature_from_humidity()
        sat_vapor_density = self._sat_vapor_density(temp_humidity)
	return (absolute_humidity / sat_vapor_density) * 100


    def get_pressure(self):
        """
        Returns the pressure in Millibars for the adjusted temperature 
        (in Kelvin)
        """

        temp_pressure = super(FixedHat, self).get_temperature_from_pressure()
        pressure = super(FixedHat, self).get_pressure()
        temp_adjusted = self.get_temperature_from_humidity()
        
        return (self._to_kelvin(temp_adjusted) * pressure) \
            / self._to_kelvin(temp_pressure)

@@ -1,12 +1,33 @@
+from math import exp%0A
 from sense_h
@@ -48,27 +48,8 @@
 eHat
-%0Aimport numpy as np
 %0A%0Acl
@@ -144,11 +144,8 @@
 emp'
- %09%09
 %0A   
@@ -200,25 +200,27 @@
 T = 
-0.0623665 # %5BmmHg
+8.3144598e-3 # %5BhPa
  * m
@@ -570,177 +570,169 @@
   # 
-Saturation vapor pressure %5BmmHg%5D according to August-Roche-Magnus %0A        # formula, temp in Celsius%0A        psat = (0.61078 * 7.501) * np.
+Alduchov, O. and R. Eskridge, 1996:%0A        # Improved Magnus Form Approximation of Saturation Vapor Pressure%0A        psat = 6.1094 * 
 exp(
-(
 17.
-2694
+625
  * temp
-)
  / (2
-38.3
+43.04
  + t
@@ -736,16 +736,24 @@
 + temp))
+ # %5BhPa%5D
 %0A       
@@ -1687,17 +1687,16 @@
 midity()
-%09
 %0A    %09sa

Use improved Magnus form of sat. vap. density