back-calculate the voltage the airspeed sensor must have seen
420297
def airspeed_voltage(VFR_HUD, ratio=None):
    ''''''
    import mavutil
    mav = mavutil.mavfile_global
    if ratio is None:
        ratio = 1.9936 # APM default
    if 'ARSPD_RATIO' in mav.params:
        used_ratio = mav.params['ARSPD_RATIO']
    else:
        used_ratio = ratio
    if 'ARSPD_OFFSET' in mav.params:
        offset = mav.params['ARSPD_OFFSET']
    else:
        return -1
    airspeed_pressure = (pow(VFR_HUD.airspeed,2)) / used_ratio
    raw = airspeed_pressure + offset
    SCALING_OLD_CALIBRATION = 204.8
    voltage = 5.0 * raw / 4096
    return voltage
158817
def __we_c(cls, calib, tc, temp, we_v, ae_v):
        
        we_t = we_v - (calib.we_elc_mv / 1000.0)        # remove electronic we zero
        ae_t = ae_v - (calib.ae_elc_mv / 1000.0)        # remove electronic ae zero

        we_c = tc.correct(calib, temp, we_t, ae_t)

        # print("A4Datum__we_c: we_t:%f ae_t:%f we_c:%s" % (we_t, ae_t, we_c), file=sys.stderr)

        return we_c
632933
def windspeed(self, t):
        """"""
        ws = [0] * self.n

        for i in range(self.n):
            q = ceil(t / self.dt[i])
            q_prev = 0 if q == 0 else q - 1

            r = t % self.dt[i]
            r = 0 if abs(r) < 1e-6 else r

            if r == 0:
                ws[i] = self.speed[i][q]
            else:
                t1 = self.time[i][q_prev]
                s1 = self.speed[i][q_prev]
                s2 = self.speed[i][q]
                ws[i] = s1 + (t - t1) * (s2 - s1) / self.dt[i]

        return matrix(ws)
1037641
def _loglr(self):
        
        """
        # calculate <d-h|d-h> = <h|h> - 2<h|d> + <d|d> up to a constant
        p = self.current_params.copy()
        p.update(self.static_params)

        if self.time is None:
            self.time = p['tc']

        shloglr = hhloglr = 0
        for ifo in self.sh:
            fp, fc = self.det[ifo].antenna_pattern(p['ra'], p['dec'],
                                                   p['polarization'],
                                                   self.time)
            dt = self.det[ifo].time_delay_from_earth_center(p['ra'],
                                                            p['dec'],
                                                            self.time)
            ip = numpy.cos(p['inclination'])
            ic = 0.5 * (1.0 + ip * ip)
            htf = (fp * ip + 1.0j * fc * ic) / p['distance']

            sh = self.sh[ifo].at_time(p['tc'] + dt) * htf
            shloglr += sh
            hhloglr += self.hh[ifo] * abs(htf) ** 2.0

        vloglr = numpy.log(scipy.special.i0e(abs(shloglr)))
        vloglr += abs(shloglr) + hhloglr

        return float(vloglr)
1358334
def read_sensor(self, device_id, sensor_uri):
        """"""
        url = MINUT_DEVICES_URL + "/{device_id}/{sensor_uri}".format(
            device_id=device_id, sensor_uri=sensor_uri)
        res = self._request(url, request_type='GET', data={'limit': 1})
        if not res.get('values'):
            return None
        return res.get('values')[-1].get('value')
959648
def cmd_rccal(self, args):
        ''''''
        if len(args) < 1:
            self.print_cal_usage()
            return

        if (args[0] == "start"):
            if len(args) > 1:
                self.num_channels = int(args[1])
            print("Calibrating %u channels" % self.num_channels)
            print("WARNING: remove propellers from electric planes!!")
            print("Push return when ready to calibrate.")
            raw_input()

            self.clear_rc_cal()
            self.calibrating = True
        elif (args[0] == "done"):
            self.calibrating = False
            self.apply_rc_cal()
        else:
            self.print_cal_usage()
813569
private function _voltage()
    {
        if (isset($this->_buf['Voltage'])) foreach ($this->_buf['Voltage'] as $name=>$value) {
            $dev = new SensorDevice();
            $dev->setName($name);
            $dev->setValue($value);
            $this->mbinfo->setMbVolt($dev);
        }
    }
111765
def V(self, brightest=False):
        
        mags = self.get_photometry(brightest=brightest, convert=False)
        VT, dVT = mags['VT']
        BT, dBT = mags['BT']
        if (-0.25 < BT - VT < 2.0):
            (a, b, c, d) = (0.00097, 0.1334, 0.05486, 0.01998)
            V = (VT + a - b * (BT - VT) + c * (BT - VT)**2 -
                d * (BT - VT)**3)

            dVdVT = 1 + b - 2*c*(BT-VT) + 3*d*(BT-VT)**2
            dVdBT = -b + 2*c*(BT-VT) - 3*d*(BT-VT)**2
            dV = np.sqrt((dVdVT**2 * dVT**2) + (dVdBT**2*dBT**2))

        else:
            raise ValueError('BT-VT outside of range to convert')

        return V, dV
658772
def v2(self):
        """"""
        Vm = self.system.dae.y[self.v]
        Va = self.system.dae.y[self.a]
        return polar(Vm[self.a2], Va[self.a2])
1211728
def max_voltage_step(self):
        
        steps = [self.voltage_pairs[i].voltage
                 - self.voltage_pairs[i + 1].voltage
                 for i in range(len(self.voltage_pairs) - 1)]
        return max(steps) if len(steps) > 0 else 0
209523
def simxReadVisionSensor(clientID, sensorHandle, operationMode):
    '''
    
    '''

    detectionState = ct.c_ubyte()
    auxValues      = ct.POINTER(ct.c_float)()
    auxValuesCount = ct.POINTER(ct.c_int)()
    ret = c_ReadVisionSensor(clientID, sensorHandle, ct.byref(detectionState), ct.byref(auxValues), ct.byref(auxValuesCount), operationMode)
    
    auxValues2 = []
    if ret == 0:
        s = 0
        for i in range(auxValuesCount[0]):
            auxValues2.append(auxValues[s:s+auxValuesCount[i+1]])
            s += auxValuesCount[i+1]

        #free C buffers
        c_ReleaseBuffer(auxValues)
        c_ReleaseBuffer(auxValuesCount)

    return ret, bool(detectionState.value!=0), auxValues2
170819
def i_from_v(self, resistance_shunt, resistance_series, nNsVth, voltage,
                 saturation_current, photocurrent):
        
        return i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
                        saturation_current, photocurrent)
564280
def format_sensor(self, sensor):
        
        current_val = sensor.current
        if self.pango_enabled:
            percentage = self.percentage(sensor.current, sensor.critical)
            if self.dynamic_color:
                color = self.colors[int(percentage)]
                return self.format_pango(color, current_val)
        return current_val
1237350
private function _current()
    {
        foreach ($this->_buf as $sensor) {
            if (((isset($sensor['Sensor Type (Threshold)']) && ($sensor['Sensor Type (Threshold)'] == 'Current'))
                ||(isset($sensor['Sensor Type (Analog)']) && ($sensor['Sensor Type (Analog)'] == 'Current')))
               && isset($sensor['Unit']) && ($sensor['Unit'] == 'Amps')
               && isset($sensor['Value'])) {
                $dev = new SensorDevice();
                $dev->setName($sensor['Sensor']);
                $dev->setValue($sensor['Value']);
                if (isset($sensor['Upper Critical']) && (($max = $sensor['Upper Critical']) != "na")) {
                    $dev->setMax($max);
                }
                if (isset($sensor['Lower Critical']) && (($min = $sensor['Lower Critical']) != "na")) {
                    $dev->setMin($min);
                }
                if (isset($sensor['Status']) && (($status = $sensor['Status']) != "ok")) {
                    $dev->setEvent($status);
                }
                $this->mbinfo->setMbCurrent($dev);
            }
        }
    }
1165343
def find_good(control_board, actuation_steps, resistor_index, start_index,
              end_index):
    '''
    
    '''
    lower = start_index
    upper = end_index
    while lower < upper - 1:
        index = lower + (upper - lower) / 2
        v = actuation_steps[index]
        control_board.set_waveform_voltage(v)
        data = measure_board_rms(control_board)
        valid_data = data[data['divider resistor index'] >= 0]

        if (valid_data['divider resistor index'] < resistor_index).sum():
            # We have some measurements from another resistor.
            upper = index
        else:
            lower = index
    control_board.set_waveform_voltage(actuation_steps[lower])
    data = measure_board_rms(control_board)
    return lower, data
307537
def mach2cas(M, h):
    
    tas = mach2tas(M, h)
    cas = tas2cas(tas, h)
    return cas
734246
def value(self):
        
        if self.pwm_device.pin.frequency is None:
            return None
        else:
            try:
                return log2(
                    self.pwm_device.pin.frequency / self.mid_tone.frequency
                ) / self.octaves
            except ZeroDivisionError:
                return 0.0