Ejemplo n.º 1
0
    def temperature_series(self, unit='kelvin'):
        """Returns the temperature time series relative to the meteostation, in
        the form of a list of tuples, each one containing the couple
        timestamp-value

        :param unit: the unit of measure for the temperature values. May be
            among: '*kelvin*' (default), '*celsius*' or '*fahrenheit*'
        :type unit: str
        :returns: a list of tuples
        :raises: ValueError when invalid values are provided for the unit of
            measure
        """
        if unit not in ('kelvin', 'celsius', 'fahrenheit'):
            raise ValueError("Invalid value for parameter 'unit'")
        result = []
        for tstamp in self.station_history.measurements:
            t = self.station_history.measurements[tstamp]['temperature']
            if unit == 'kelvin':
                temp = t
            elif unit == 'celsius':
                temp = measurables.kelvin_to_celsius(t)
            else:
                temp = measurables.kelvin_to_fahrenheit(t)
            result.append((tstamp, temp))
        return result
Ejemplo n.º 2
0
 def test_average_temperature_with_different_temperature_units(self):
     avg = (266.85 + 266.25)/2.0
     expected_kelvin = avg
     expected_celsius = measurables.kelvin_to_celsius(avg)
     expected_fahrenheit = measurables.kelvin_to_fahrenheit(avg)
     self.assertEqual(expected_kelvin,
                      self.__instance.average_temperature(unit='kelvin'))
     self.assertEqual(expected_celsius,
                      self.__instance.average_temperature(unit='celsius'))
     self.assertEqual(expected_fahrenheit,
                      self.__instance.average_temperature(unit='fahrenheit'))
Ejemplo n.º 3
0
    def ten_cm_temp(self, unit='kelvin'):
        """Returns the soil temperature measured 10 cm below surface

        :param unit: the unit of measure for the temperature value. May be:
            '*kelvin*' (default), '*celsius*' or '*fahrenheit*'
        :type unit: str
        :returns: a float
        :raises: ValueError when unknown temperature units are provided

        """
        if unit == 'kelvin':
            return self._ten_cm_temp
        if unit == 'celsius':
            return measurables.kelvin_to_celsius(self._ten_cm_temp)
        if unit == 'fahrenheit':
            return measurables.kelvin_to_fahrenheit(self._ten_cm_temp)
        else:
            raise ValueError('Wrong temperature unit')
Ejemplo n.º 4
0
 def average_temperature(self, unit='kelvin'):
     """Returns the average value in the temperature series
     
     :param unit: the unit of measure for the temperature values. May be
         among: '*kelvin*' (default), '*celsius*' or '*fahrenheit*'
     :type unit: str
     :returns: a float
     :raises: ValueError when invalid values are provided for the unit of
         measure or the measurement series is empty
     """
     if unit not in ('kelvin', 'celsius', 'fahrenheit'):
         raise ValueError("Invalid value for parameter 'unit'")
     average = self._average(
         self._purge_none_samples(self.temperature_series()))
     if unit == 'kelvin':
         return average
     elif unit == 'celsius':
         return measurables.kelvin_to_celsius(average)
     else:
         return measurables.kelvin_to_fahrenheit(average)
Ejemplo n.º 5
0
 def max_temperature(self, unit='kelvin'):
     """Returns a tuple containing the max value in the temperature
     series preceded by its timestamp
     
     :param unit: the unit of measure for the temperature values. May be
         among: '*kelvin*' (default), '*celsius*' or '*fahrenheit*'
     :type unit: str
     :returns: a tuple
     :raises: ValueError when invalid values are provided for the unit of
         measure or the measurement series is empty
     """
     if unit not in ('kelvin', 'celsius', 'fahrenheit'):
         raise ValueError("Invalid value for parameter 'unit'")
     maximum = max(self._purge_none_samples(self.temperature_series()),
                   key=itemgetter(1))
     if unit == 'kelvin':
         return maximum
     elif unit == 'celsius':
         return (maximum[0], measurables.kelvin_to_celsius(maximum[1]))
     else:
         return (maximum[0], measurables.kelvin_to_fahrenheit(maximum[1]))
Ejemplo n.º 6
0
    def update_event(self, input_called=-1):
        temp_dict = self.input(0)

        if self.input(1) != 'kelvin':
            for key in list(temp_dict.keys()):
                item = temp_dict[key]
                if item is not None:
                    if self.input(1) == 'celsius':
                        temp_dict[key] = kelvin_to_celsius(item)
                    elif self.input(1) == 'fahrenheit':
                        temp_dict[key] = kelvin_to_fahrenheit(item)
            # temp_dict = kelvin_dict_to(temp_dict, self.input(1)) doesn't work with NoneType values -.- which happen to persist
        
        temp = temp_dict['temp']
        temp_kf = temp_dict['temp_kf']
        temp_max = temp_dict['temp_max']
        temp_min = temp_dict['temp_min']
        feels_like = temp_dict['feels_like']
        
        self.set_output_val(0, temp)
        self.set_output_val(1, temp_kf)
        self.set_output_val(2, temp_min)
        self.set_output_val(3, temp_max)
        self.set_output_val(4, feels_like)
Ejemplo n.º 7
0
 def test_kelvin_to_fahrenheit(self):
     kelvin = 301.0
     expected = 82.13
     result = measurables.kelvin_to_fahrenheit(kelvin)
     self.assertEqual(expected, result)