Ejemplo n.º 1
0
 def PlotWindSpeed(self, e, c, s, params):
   if s is not None:
     wind_g = s['wind_sensor']['wind_g']
     plot(s['time'], numpy_utils.Vec3Norm(wind_g), 'C1--',
          label='wind speed at wind sensor [sim]')
     wind_g = s['wing']['wind_g']
     plot(s['time'], numpy_utils.Vec3Norm(wind_g), 'C2:',
          label='wind speed at kite [sim]')
   # Plot the estimated wind speed last so that it will be on top.
   plot(c['time'], c['state_est']['wind_g']['speed_f'], 'C0-',
        linewidth=2, label='wind speed [est]')
Ejemplo n.º 2
0
 def PlotMagnetometer(self, g, s, params):
     mplot.PlotVec3(g['estimate']['time'],
                    g['input']['imu']['mag'],
                    label='mag')
     plot(g['estimate']['time'],
          numpy_utils.Vec3Norm(g['input']['imu']['mag']),
          'k--',
          label='mag norm')
Ejemplo n.º 3
0
def CheckOverTension(monitor_params, sim_telem):
  """Tests that the tether tension stays below upper limits."""
  max_tension = monitor_params['tether']['tension']['very_high']
  tether_force = sim_telem['tether']['end_force_g']
  log_max_tension = numpy.max(numpy_utils.Vec3Norm(tether_force))

  print ('Max tension in flight was %3.1f kN (limit %3.1f kN).'
         % (log_max_tension / 1000.0, max_tension / 1000.0))
  if log_max_tension > max_tension:
    raise FlightError('Over tension (%3.1f > %3.1f [N]).' %
                      (log_max_tension / 1000.0, max_tension / 1000.0))
Ejemplo n.º 4
0
  def testH5MathHelpers(self):
    num_samples = 10

    # A fake log file is used strictly to get appropriate dtypes for the Vec3
    # and Mat3 timeseries.
    with tempfile.NamedTemporaryFile(suffix='.h5', delete=False) as tmp:
      file_name = tmp.name
    log_file = test_util.CreateSampleHDF5File(file_name, 1)
    state_est = (log_file['messages']['kAioNodeControllerA']
                 ['kMessageTypeControlTelemetry']['message']['state_est'])
    vec3 = numpy.zeros(num_samples, dtype=state_est['Xg'].dtype)
    mat3 = numpy.zeros(num_samples, dtype=state_est['dcm_g2b'].dtype)
    log_file.close()
    os.remove(file_name)

    # Populate vec3 and mat3 with random data.
    for axis in ('x', 'y', 'z'):
      vec3[axis] = numpy.random.rand(num_samples)
    mat3['d'] = numpy.random.rand(num_samples, 3, 3)

    # Test Vec3ToArray. Values of `vec3` and `array` should be bitwise
    # identical, so equality is appropriate.
    array = numpy_utils.Vec3ToArray(vec3)
    for i, axis in enumerate(('x', 'y', 'z')):
      self.assertTrue((array[:, i] == vec3[axis]).all())

    # Test Vec3Norm.
    norm1 = (vec3['x']**2.0 + vec3['y']**2.0 + vec3['z']**2.0)**0.5
    norm2 = numpy_utils.Vec3Norm(vec3)
    self.assertTrue((numpy.abs(norm1 - norm2) < 1e-15).all())

    # Test Mat3Vec3Mult.
    mult = numpy_utils.Mat3Vec3Mult(mat3, vec3)
    for i in range(num_samples):
      b_expected = numpy.dot(
          mat3['d'][i],
          numpy.array([vec3['x'][i], vec3['y'][i], vec3['z'][i]]))
      self.assertTrue((numpy.abs(mult[i, :] - b_expected) < 1e-15).all())

    # Test Mat3TransVec3Mult.
    trans_mult = numpy_utils.Mat3TransVec3Mult(mat3, vec3)
    for i in range(num_samples):
      b_expected = numpy.dot(
          mat3['d'][i].T,
          numpy.array([vec3['x'][i], vec3['y'][i], vec3['z'][i]]))
      self.assertTrue((numpy.abs(trans_mult[i, :] - b_expected) < 1e-15).all())
Ejemplo n.º 5
0
    def PlotTurbulenceIntensity(self, c, window_minutes=5):
        assert isinstance(window_minutes, int)
        assert window_minutes >= 1
        df = pd.DataFrame(index=pd.to_timedelta(c['time'], unit='s'))
        df['wind_g_mag'] = numpy_utils.Vec3Norm(
            c['state_est']['wind_g']['vector'])
        df_1s = df.resample('1s', label='right').agg(['mean', 'std'])
        df_1s_nt = df_1s.xs('mean', level=1, axis='columns').rolling(
            window='%dT' % window_minutes, min_periods=window_minutes *
            60).agg(['mean', 'std']).shift(periods=(-window_minutes * 60) // 2,
                                           freq='s')

        df_1s_nt_ti = (df_1s_nt[('wind_g_mag', 'std')] /
                       df_1s_nt[('wind_g_mag', 'mean')])

        ylabel('TI (over %d-minute rolling calculations)' % window_minutes)
        plot(df_1s_nt_ti.keys().total_seconds(), df_1s_nt_ti)
Ejemplo n.º 6
0
 def PlotWindSpeedAloft(self, c):
     wind_aloft_g_mag = numpy_utils.Vec3Norm(
         c['state_est']['wind_aloft_g']['vector'])
     plot(c['time'], wind_aloft_g_mag)