Exemplo 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.get_measurements():
            t = self._station_history.get_measurements()[tstamp]['temperature']
            if unit == 'kelvin':
                temp = t
            if unit == 'celsius':
                temp = temputils.kelvin_to_celsius(t)
            if unit == 'fahrenheit':
                temp = temputils.kelvin_to_fahrenheit(t)
            result.append((tstamp, temp))
        return result
Exemplo n.º 2
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.get_measurements():
            t = self._station_history.get_measurements()[tstamp]['temperature']
            if unit == 'kelvin':
                temp = t
            if unit == 'celsius':
                temp = temputils.kelvin_to_celsius(t)
            if unit == 'fahrenheit':
                temp = temputils.kelvin_to_fahrenheit(t)
            result.append((tstamp, temp))
        return result
Exemplo n.º 3
0
 def test_average_temperature_with_different_temperature_units(self):
     avg = (266.85 + 266.25)/2.0
     expected_kelvin = avg
     expected_celsius = temputils.kelvin_to_celsius(avg)
     expected_fahrenheit = temputils.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'))
Exemplo n.º 4
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 temputils.kelvin_to_celsius(self._ten_cm_temp)
        if unit == 'fahrenheit':
            return temputils.kelvin_to_fahrenheit(self._ten_cm_temp)
        else:
            raise ValueError('Wrong temperature unit')
Exemplo n.º 5
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':
         result = average
     if unit == 'celsius':
         result = temputils.kelvin_to_celsius(average)
     if unit == 'fahrenheit':
         result = temputils.kelvin_to_fahrenheit(average)
     return result
Exemplo n.º 6
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':
         result = average
     if unit == 'celsius':
         result = temputils.kelvin_to_celsius(average)
     if unit == 'fahrenheit':
         result = temputils.kelvin_to_fahrenheit(average)
     return result
Exemplo n.º 7
0
 def min_temperature(self, unit='kelvin'):
     """Returns a tuple containing the min value in the temperature
     series preceeded 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'")
     minimum = min(self._purge_none_samples(self.temperature_series()),
                key=itemgetter(1))
     if unit == 'kelvin':
         result = minimum
     if unit == 'celsius':
         result = (minimum[0], temputils.kelvin_to_celsius(minimum[1]))
     if unit == 'fahrenheit':
         result = (minimum[0], temputils.kelvin_to_fahrenheit(minimum[1]))
     return result
Exemplo n.º 8
0
 def min_temperature(self, unit='kelvin'):
     """Returns a tuple containing the min value in the temperature
     series preceeded 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'")
     minimum = min(self._purge_none_samples(self.temperature_series()),
                key=itemgetter(1))
     if unit == 'kelvin':
         result = minimum
     if unit == 'celsius':
         result = (minimum[0], temputils.kelvin_to_celsius(minimum[1]))
     if unit == 'fahrenheit':
         result = (minimum[0], temputils.kelvin_to_fahrenheit(minimum[1]))
     return result
Exemplo n.º 9
0
 def test_kelvin_to_fahrenheit(self):
     kelvin = 301.0
     expected = 82.13
     result = temputils.kelvin_to_fahrenheit(kelvin)
     self.assertEqual(expected, result)
Exemplo n.º 10
0
 def test_kelvin_to_fahrenheit(self):
     kelvin = 301.0
     expected = 82.13
     result = temputils.kelvin_to_fahrenheit(kelvin)
     self.assertEqual(expected, result)