The relative humidity in RH %
        returns None if humidity measurement is disabled
424507
def humidity(self):
        
        self._read_temperature()
        hum = self._read_register(_BME280_REGISTER_HUMIDDATA, 2)
        #print("Humidity data: ", hum)
        adc = float(hum[0] << 8 | hum[1])
        #print("adc:", adc)

        # Algorithm from the BME280 driver
        # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c
        var1 = float(self._t_fine) - 76800.0
        #print("var1 ", var1)
        var2 = (self._humidity_calib[3] * 64.0 + (self._humidity_calib[4] / 16384.0) * var1)
        #print("var2 ",var2)
        var3 = adc - var2
        #print("var3 ",var3)
        var4 = self._humidity_calib[1] / 65536.0
        #print("var4 ",var4)
        var5 = (1.0 + (self._humidity_calib[2] / 67108864.0) * var1)
        #print("var5 ",var5)
        var6 = 1.0 + (self._humidity_calib[5] / 67108864.0) * var1 * var5
        #print("var6 ",var6)
        var6 = var3 * var4 * (var5 * var6)
        humidity = var6 * (1.0 - self._humidity_calib[0] * var6 / 524288.0)

        if humidity > _BME280_HUMIDITY_MAX:
            return _BME280_HUMIDITY_MAX
        if humidity < _BME280_HUMIDITY_MIN:
            return _BME280_HUMIDITY_MIN
        # else...
        return humidity
709463
def _parse_data(self):
        
        data = self._cache

        res = dict()
        res[MI_HUMIDITY] = float(data[9:13])
        res[MI_TEMPERATURE] = float(data[2:6])
        return res
597233
def _set_scan_parameters(self, interval=2100, window=2100, active=False):
        

        active_num = 0
        if bool(active):
            active_num = 1

        interval_num = int(interval*1000/625)
        window_num = int(window*1000/625)

        payload = struct.pack("<HHB", interval_num, window_num, active_num)

        try:
            response = self._send_command(6, 7, payload)
            if response.payload[0] != 0:
                return False, {'reason': "Could not set scanning parameters", 'error': response.payload[0]}
        except InternalTimeoutError:
            return False, {'reason': 'Timeout waiting for response'}

        return True, None
703760
def most_humid(self):
        
        max_humidity = 0
        most_humid = None
        for weather in self._forecast.get_weathers():
            h = weather.get_humidity()
            if h > max_humidity:
                max_humidity = h
                most_humid = weather
        return most_humid
283719
private function _temperature()
    {
        $ar_buf = array();
        switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
        case 'tcp':
            $lines = '';
            // Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
            $fp = @fsockopen('localhost', 7634, $errno, $errstr, 5);
            // if connected, read the output of the hddtemp daemon
            if ($fp) {
                while (!feof($fp)) {
                    $lines .= fread($fp, 1024);
                }
                fclose($fp);
            } else {
                $this->error->addError("HDDTemp error", $errno.", ".$errstr);
            }
            $lines = str_replace("||", "|\n|", $lines);
            $ar_buf = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
            break;
        case 'command':
            $strDrives = "";
            $strContent = "";
            $hddtemp_value = "";
            if (CommonFunctions::rfts("/proc/diskstats", $strContent, 0, 4096, false)) {
                $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
                foreach ($arrContent as $strLine) {
                    preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
                    if (! empty($arrSplit[2])) {
                        $strDrive = '/dev/'.$arrSplit[2];
                        if (file_exists($strDrive)) {
                            $strDrives = $strDrives.$strDrive.' ';
                        }
                    }
                }
            } else {
                if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) {
                    $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
                    foreach ($arrContent as $strLine) {
                        if (!preg_match("/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit)) {
                            preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
                        }
                        if (! empty($arrSplit[2])) {
                            $strDrive = '/dev/'.$arrSplit[2];
                            if (file_exists($strDrive)) {
                                $strDrives = $strDrives.$strDrive.' ';
                            }
                        }
                    }
                }
            }
            if (trim($strDrives) == "") {
                break;
            }
            if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value, PSI_DEBUG)) {
                $hddtemp_value = preg_split("/\n/", $hddtemp_value, -1, PREG_SPLIT_NO_EMPTY);
                foreach ($hddtemp_value as $line) {
                    $temp = preg_split("/:\s/", $line, 3);
                    if (count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
                        preg_match("/^([0-9]*)(.*)/", $temp[2], $ar_temp);
                        $temp[2] = trim($ar_temp[1]);
                        $temp[3] = trim($ar_temp[2]);
                        array_push($ar_buf, "|".implode("|", $temp)."|");
                    }
                }
            }
            break;
        default:
            $this->error->addConfigError("temperature()", "[sensor_hddtemp] ACCESS");
            break;
        }
        // Timo van Roermund: parse the info from the hddtemp daemon.
        foreach ($ar_buf as $line) {
            $data = array();
            if (preg_match("/\|(.*)\|(.*)\|(.*)\|(.*)\|/", $line, $data)) {
                if (trim($data[3]) != "ERR") {
                    // get the info we need
                    $dev = new SensorDevice();
                    $dev->setName($data[1] . ' (' . (strpos($data[2], "  ")?substr($data[2], 0, strpos($data[2], "  ")):$data[2]) . ')');
                    if (is_numeric($data[3])) {
                        $dev->setValue($data[3]);
                    }
//                    $dev->setMax(60);
                    $this->mbinfo->setMbTemp($dev);
                }
            }
        }
    }
986500
func (d *BME280Driver) calculateHumidity(rawH uint32) float32 {
	var rawT int32
	var err error
	var h float32

	rawT, err = d.rawTemp()
	if err != nil {
		return 0
	}

	_, tFine := d.calculateTemp(rawT)
	h = float32(tFine) - 76800

	if h == 0 {
		return 0 // TODO err is 'invalid data' from Bosch - include errors or not?
	}

	x := float32(rawH) - (float32(d.hc.h4)*64.0 +
		(float32(d.hc.h5) / 16384.0 * h))

	y := float32(d.hc.h2) / 65536.0 *
		(1.0 + float32(d.hc.h6)/67108864.0*h*
			(1.0+float32(d.hc.h3)/67108864.0*h))

	h = x * y
	h = h * (1 - float32(d.hc.h1)*h/524288)
	return h
}
1162426
def dew_point_temperature(self):
        """"""
        if self.sample_ok:
            temperature = self._get_value_opc_attr('temperature', 3)
            humidity = self._get_value_opc_attr('humidity', 3)
            if temperature is not None and humidity is not None:
                # Calc dew point temperature in celsius
                coef_a, coef_b, coef_c = 8.1332, 1762.39, 235.66
                part_press = 10 ** (coef_a - coef_b / (temperature + coef_c))
                dewp = - coef_c
                dewp -= coef_b / (log10(humidity * part_press / 100.) - coef_a)
                return dewp
        return None
797336
def _init_humidity(self):
        

        if not self._humidity_init:
            self._humidity_init = self._humidity.humidityInit()
            if not self._humidity_init:
                raise OSError('Humidity Init Failed')
1312500
def rho2sigma(self, rho0, Ra, Rs):
        
        return np.pi * rho0 * Ra * Rs / (Rs + Ra)
917001
def _clean_body_df(self, df):
        """"""
        if self.suffix == '-drvd.txt':
            df = df.dropna(subset=('temperature', 'reported_relative_humidity',
                           'u_wind', 'v_wind'), how='all').reset_index(drop=True)

            df.units = {'pressure': 'hPa',
                        'reported_height': 'meter',
                        'calculated_height': 'meter',
                        'temperature': 'Kelvin',
                        'temperature_gradient': 'Kelvin / kilometer',
                        'potential_temperature': 'Kelvin',
                        'potential_temperature_gradient': 'Kelvin / kilometer',
                        'virtual_temperature': 'Kelvin',
                        'virtual_potential_temperature': 'Kelvin',
                        'vapor_pressure': 'Pascal',
                        'saturation_vapor_pressure': 'Pascal',
                        'reported_relative_humidity': 'percent',
                        'calculated_relative_humidity': 'percent',
                        'u_wind': 'meter / second',
                        'u_wind_gradient': '(meter / second) / kilometer)',
                        'v_wind': 'meter / second',
                        'v_wind_gradient': '(meter / second) / kilometer)',
                        'refractive_index': 'unitless'}

        else:
            df['u_wind'], df['v_wind'] = get_wind_components(df['speed'],
                                                             np.deg2rad(df['direction']))
            df['u_wind'] = np.round(df['u_wind'], 1)
            df['v_wind'] = np.round(df['v_wind'], 1)

            df = df.dropna(subset=('temperature', 'direction', 'speed',
                           'dewpoint_depression', 'u_wind', 'v_wind'),
                           how='all').reset_index(drop=True)

            df['dewpoint'] = df['temperature'] - df['dewpoint_depression']

            df.drop('dewpoint_depression', axis=1, inplace=True)

            df.units = {'etime': 'second',
                        'pressure': 'hPa',
                        'height': 'meter',
                        'temperature': 'degC',
                        'dewpoint': 'degC',
                        'direction': 'degrees',
                        'speed': 'meter / second',
                        'u_wind': 'meter / second',
                        'v_wind': 'meter / second'}

        return df
1181126
def main():
    ''''''

    trig_pin = 17
    echo_pin = 27

    #  Create a distance reading with the hcsr04 sensor module
    value = sensor.Measurement(trig_pin, echo_pin)

    # The default sample_size is 11 and sample_wait is 0.1
    # Increase speed by lowering the sample_size and sample_wait
    # The effect of reducing sample_size is larger variance in readings
    # The effect of lowering sample_wait is higher cpu usage and sensor
    # instability if you push it with too fast of a value.
    # These two options have been added to allow you to tweak a 
    # more optimal setting for your application.

    # e.g.
    raw_measurement = value.raw_distance(sample_size=5, sample_wait=0.03)

    # Calculate the distance in centimeters
    metric_distance = value.distance_metric(raw_measurement)
    print("The Distance = {} centimeters".format(metric_distance))
929349
def read(self, vals):
        
        i = 0
        if len(vals[i]) == 0:
            self.year = None
        else:
            self.year = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.month = None
        else:
            self.month = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.day = None
        else:
            self.day = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.hour = None
        else:
            self.hour = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.minute = None
        else:
            self.minute = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.data_source_and_uncertainty_flags = None
        else:
            self.data_source_and_uncertainty_flags = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.dry_bulb_temperature = None
        else:
            self.dry_bulb_temperature = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.dew_point_temperature = None
        else:
            self.dew_point_temperature = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.relative_humidity = None
        else:
            self.relative_humidity = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.atmospheric_station_pressure = None
        else:
            self.atmospheric_station_pressure = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.extraterrestrial_horizontal_radiation = None
        else:
            self.extraterrestrial_horizontal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.extraterrestrial_direct_normal_radiation = None
        else:
            self.extraterrestrial_direct_normal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.horizontal_infrared_radiation_intensity = None
        else:
            self.horizontal_infrared_radiation_intensity = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.global_horizontal_radiation = None
        else:
            self.global_horizontal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.direct_normal_radiation = None
        else:
            self.direct_normal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.diffuse_horizontal_radiation = None
        else:
            self.diffuse_horizontal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.global_horizontal_illuminance = None
        else:
            self.global_horizontal_illuminance = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.direct_normal_illuminance = None
        else:
            self.direct_normal_illuminance = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.diffuse_horizontal_illuminance = None
        else:
            self.diffuse_horizontal_illuminance = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.zenith_luminance = None
        else:
            self.zenith_luminance = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.wind_direction = None
        else:
            self.wind_direction = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.wind_speed = None
        else:
            self.wind_speed = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.total_sky_cover = None
        else:
            self.total_sky_cover = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.opaque_sky_cover = None
        else:
            self.opaque_sky_cover = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.visibility = None
        else:
            self.visibility = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.ceiling_height = None
        else:
            self.ceiling_height = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.present_weather_observation = None
        else:
            self.present_weather_observation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.present_weather_codes = None
        else:
            self.present_weather_codes = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.precipitable_water = None
        else:
            self.precipitable_water = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.aerosol_optical_depth = None
        else:
            self.aerosol_optical_depth = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.snow_depth = None
        else:
            self.snow_depth = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.days_since_last_snowfall = None
        else:
            self.days_since_last_snowfall = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.albedo = None
        else:
            self.albedo = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.liquid_precipitation_depth = None
        else:
            self.liquid_precipitation_depth = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.liquid_precipitation_quantity = None
        else:
            self.liquid_precipitation_quantity = vals[i]
        i += 1
786392
def request_set_sensor_inactive(self, req, sensor_name):
        """"""
        sensor = self.get_sensor(sensor_name)
        ts, status, value = sensor.read()
        sensor.set_value(value, sensor.INACTIVE, ts)
        return('ok',)
529838
def hourly_relative_humidity(self):
        """"""
        dpt_data = self._humidity_condition.hourly_dew_point_values(
            self._dry_bulb_condition)
        rh_data = [rel_humid_from_db_dpt(x, y) for x, y in zip(
            self._dry_bulb_condition.hourly_values, dpt_data)]
        return self._get_daily_data_collections(
            fraction.RelativeHumidity(), '%', rh_data)
843028
def rel_humid_from_db_enth(db_temp, enthalpy, b_press=101325):
    
    assert enthalpy >= 0, 'enthalpy must be' \
        'greater than 0. Got {}'.format(str(enthalpy))
    hr = (enthalpy - (1.006 * db_temp)) / ((1.84 * db_temp) + 2501)
    rel_humid = rel_humid_from_db_hr(db_temp, hr, b_press)
    return rel_humid
1002903
def measurement_time_typical(self):
        """"""
        meas_time_ms = 1.0
        if self.overscan_temperature != OVERSCAN_DISABLE:
            meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_temperature))
        if self.overscan_pressure != OVERSCAN_DISABLE:
            meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_pressure) + 0.5)
        if self.overscan_humidity != OVERSCAN_DISABLE:
            meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.5)
        return meas_time_ms
964360
def get_hum(self, raw = False):
        
        self.bus.write_byte(self.address, self.TRIG_RH_noHOLD); # start humidity measurement
        time.sleep(0.1)

        data = self.bus.read_i2c_block(self.address, 2)

        value = data[0]<<8 | data[1]
        value &= ~0b11    # trow out status bits
        humidity = (-6.0 + 125.0*(value/65536.0))

        if raw:                 # raw sensor output, useful for getting an idea of sensor failure status
            return humidity

        else:

            if humidity > 100.0:        # limit values to relevant physical variable (values out of that limit is sensor error state and are dependent on specific sensor piece)
                return 100.0
            elif humidity < 0.0:
                return 0.0
            else:
                return humidity