def pressure(self, unit_out=units.Pa):
     if self._check():
         return WSValue(
             self.obs_time(),
             self._convert_units(self._pressure, units.cds.mmHg, unit_out),
             unit_out)
     else:
         return False
Ejemplo n.º 2
0
    def sky_transparency(self, unit_out=units.pct):
        """
        Returns, in percent, the sky transparency
        :param unit_out:
        """
        if unit_out not in self.__accepted_transparency_unit__:
            raise OptionConversionException("Invalid transparency unit %s." % unit_out)

        return WSValue(datetime.datetime.utcnow(), np.random.rand() * 100, unit_out)
    def wind_direction(self, unit_out=units.degree):

        if self._check():
            return WSValue(
                self.obs_time(),
                self._convert_units(self._wind_dir, units.deg, unit_out),
                unit_out)
        else:
            return False
    def wind_speed(self, unit_out=units.meter / units.second):

        if self._check():
            return WSValue(
                self.obs_time(),
                self._convert_units(self._wind_speed,
                                    (imperial.mile / units.hour), unit_out),
                unit_out)
        else:
            return False
Ejemplo n.º 5
0
    def rain_rate(self, unit_out=units.imperial.inch / units.hour):
        """
        For testing purposes, it never rains.
        :param unit:
        :return:
        """

        if unit_out not in self.__accepted_precipitation_unit__:
            raise OptionConversionException("Invalid precipitation unit %s." % unit_out)

        return WSValue(datetime.datetime.utcnow(), 0, unit_out)
    def wind_direction(self, unit_out=units.degree):

        if self._results is None:
            return False

        if unit_out not in self.__accepted_direction_unit__:
            raise OptionConversionException("Invalid speed unit %s." %
                                            unit_out)

        return WSValue(
            self._results['utctime'],
            self._convert_units(self._results['wind_direction']['Value'],
                                units.deg, unit_out), unit_out)
    def wind_speed(self, unit_out=units.meter / units.second):

        if self._results is None:
            return False

        if unit_out not in self.__accepted_speed_units__:
            raise OptionConversionException("Invalid speed unit %s." %
                                            unit_out)

        return WSValue(
            self._results['utctime'],
            self._convert_units(self._results['wind_speed']['Value'],
                                (units.m / units.s), unit_out), unit_out)
    def temperature(self, unit_out=units.Celsius):

        if self._results is None:
            return False

        if unit_out not in self.__accepted_temperature_units__:
            raise OptionConversionException("Invalid temperature unit %s." %
                                            unit_out)

        return WSValue(
            self._results['utctime'],
            self._convert_units(self._results['temperature']['Value'],
                                units.Celsius, unit_out), unit_out)
    def humidity(self, unit_out=units.pct):

        if self._results is None:
            return False

        if unit_out not in self.__accepted_humidity_units__:
            raise OptionConversionException("Invalid humidity unit %s." %
                                            unit_out)

        return WSValue(
            self._results['utctime'],
            self._convert_units(self._results['humidity']['Value'], units.pct,
                                unit_out), unit_out)
Ejemplo n.º 10
0
    def humidity(self, unit_out=units.pct):

        if unit_out not in self.__accepted_humidity_units__:
            raise OptionConversionException("Invalid humidity unit %s." %
                                            unit_out)

        if self._check():
            return WSValue(
                self.obs_time(),
                self._convert_units(self._humidity, units.pct, unit_out),
                unit_out)
        else:
            return False
    def sky_transparency(self, unit_out=units.pct):

        if self._results is None:
            return False

        if unit_out not in self.__accepted_transparency_unit__:
            raise OptionConversionException(
                "Invalid sky transparency unit %s." % unit_out)

        return WSValue(
            self._results['utctime'],
            self._convert_units(self._results['sky_transparency']['Value'],
                                units.pct, unit_out), unit_out)
    def pressure(self, unit_out=units.Pa):

        if self._results is None:
            return False

        if unit_out not in self.__accepted_pressures_unit__:
            raise OptionConversionException("Invalid pressure unit %s." %
                                            unit_out)

        return WSValue(
            self._results['utctime'],
            self._convert_units(self._results['pressure']['Value'],
                                units.cds.mmHg, unit_out), unit_out)
Ejemplo n.º 13
0
    def temperature(self, unit_out=units.Celsius):

        if unit_out not in self.__accepted_temperature_units__:
            raise OptionConversionException("Invalid temperature unit %s." %
                                            unit_out)

        if self._check():
            return WSValue(
                self.obs_time(),
                self._convert_units(self._temperature, units.Celsius,
                                    unit_out), unit_out)
        else:
            return False
Ejemplo n.º 14
0
    def sky_transparency(self, unit_out=units.pct):
        """
        Returns, in percent, the sky transparency
        :param unit_out:
        """
        if unit_out not in self.__accepted_transparency_unit__:
            raise OptionConversionException("Invalid transparency unit %s." %
                                            unit_out)

        if self._results is not None:
            return WSValue(self._results['last_update'],
                           self._results['transparency'], unit_out)
        else:
            return False
Ejemplo n.º 15
0
    def pressure(self, unit_out=units.Pa):
        """
        Pressure at 1.5 atm
        :param unit:
        :return:
        """

        pressure_reference = 1140.  # MM_HG

        if unit_out not in self.__accepted_pressures_unit__:
            raise OptionConversionException("Invalid pressure unit %s." % unit_out)

        pressure = self._convert_units(pressure_reference, units.cds.mmHg, unit_out)

        return WSValue(datetime.datetime.utcnow(), pressure, unit_out)
Ejemplo n.º 16
0
    def wind_speed(self, unit_out=units.meter / units.second):
        """
        Returns the wind speed in the chosen unit (Default: Meters per second).
        :param unit:  Unit in which the instrument should return the wind speed.
        :return: the wind speed.
        """

        reference_speed = 10  # M_PER_S

        if unit_out not in self.__accepted_speed_units__:
            raise OptionConversionException("Invalid speed unit %s." %
                                            unit_out)

        speed = self._convert_units(reference_speed,
                                    units.meter / units.second, unit_out)

        return WSValue(datetime.datetime.utcnow(), speed, unit_out)
Ejemplo n.º 17
0
    def humidity(self, unit_out=units.pct):
        """
        Returns the 100% relative humidity in the range between 20% and 100%.
        :param unit: Unit in which the instrument should return the humidity.
        :return: the humidity.
        """
        current_time = datetime.datetime.utcnow()

        if unit_out not in self.__accepted_humidity_units__:
            raise OptionConversionException("Invalid humidity unit %s." %
                                            unit_out)

        humidity = 40 * math.cos(self._hourinradians(current_time.hour)) + 60.

        humidity = self._convert_units(humidity, units.pct, unit_out)

        return WSValue(current_time, humidity, unit_out)
    def dew_point(self, unit_out=units.Celsius):
        """
        :param unit_out:
        :return:
        """

        if self._results is None:
            return False

        if unit_out not in self.__accepted_temperature_units__:
            raise OptionConversionException("Invalid dew point unit %s." %
                                            unit_out)

        return WSValue(
            self._results['utctime'],
            self._convert_units(self._results['dew_point']['Value'],
                                units.Celsius, unit_out), unit_out)
Ejemplo n.º 19
0
    def wind_direction(self, unit_out=units.degree):
        """
        Returns the wind direction in the chosen unit in the range between 0 to 360 degrees.
        :param unit:  Unit in which the instrument should return the angle.
        :return: the angle.
        """
        if unit_out not in self.__accepted_direction_unit__:
            raise OptionConversionException("Invalid direction unit %s." %
                                            unit_out)

        hour = datetime.datetime.utcnow().hour

        reference_direction = 180 * math.sin(self._hourinradians(hour)) + 180

        direction = self._convert_units(reference_direction, units.degree,
                                        unit_out)

        return WSValue(datetime.datetime.utcnow(), direction, unit_out)
Ejemplo n.º 20
0
    def dew_point(self, unit_out=units.Celsius):
        """
        Some simulations ran on 'http://www.cactus2000.de/uk/unit/masshum.shtml' suggests that
        the dew point at 1.5mm Hg and low temperatures are very low, around -20 C.
        Here I'm using -10 C.

        :param unit:  Unit in which the instrument should return the temperature.
        :return: the angle.
        """

        if unit_out not in self.__accepted_temperature_units__:
            raise OptionConversionException("Invalid temperature unit %s." % unit_out)

        temperature = self._convert_units(
            10,
            units.Celsius,
            unit_out,
            equivalencies=units.equivalencies.temperature())

        return WSValue(datetime.datetime.utcnow(), temperature, unit_out)
Ejemplo n.º 21
0
    def temperature(self, unit_out=units.Celsius):
        """
        Returns the temperature in the chosen unit in the range between -10 C and +40 C.
        :param unit:  Unit in which the instrument should return the temperature.
        :return: the temperature.
        """

        current_time = datetime.datetime.utcnow()

        if unit_out not in self.__accepted_temperature_units__:
            raise OptionConversionException("Invalid temperature unit %s." % unit_out)

        temperature = 25 * math.sin(self._hourinradians(current_time.hour) - math.pi / 2.) + 15.

        temperature = self._convert_units(
            temperature,
            units.Celsius,
            unit_out,
            equivalencies=units.equivalencies.temperature())

        return WSValue(current_time, temperature, unit_out)
Ejemplo n.º 22
0
    def dew_point(self, unit_out=units.Celsius):
        '''
        Calculates dew point according to the  Arden Buck equation (https://en.wikipedia.org/wiki/Dew_point).

        :param unit_out:
        :return:
        '''

        b = 18.678
        c = 257.14  # Celsius
        d = 235.5  # Celsius

        gamma_m = lambda T, RH: np.log(RH / 100. * np.exp((b - T / d) *
                                                          (T / (c + T))))
        Tdp = lambda T, RH: c * gamma_m(T, RH) / (b - gamma_m(T, RH))

        return WSValue(
            self.obs_time(),
            self._convert_units(
                Tdp(
                    self.temperature(units.deg_C).value,
                    self.humidity(units.pct).value), units.Celsius, unit_out),
            unit_out)