def generate_vectors(earth_vel): """ Generate the velocity vectors. This will calculate the magnitude and direction of the water. If any of the data is marked bad in a bin, then the magnitude and direction will also be marked bad. Call this again and set the self.Magnitude and self.Direction when Bottom Track Velocity is available. :param earth_vel: Earth Velocities[bin][beam] :return: [magnitude], [direction] List with a value for each bin """ mag = [] dir = [] for bin_num in range(len(earth_vel)): # Calculate the magnitude and direction mag.append( Ensemble.calculate_magnitude(earth_vel[bin_num][0], earth_vel[bin_num][1], earth_vel[bin_num][2])) dir.append( Ensemble.calculate_direction(earth_vel[bin_num][0], earth_vel[bin_num][1])) return mag, dir
def get_vessel_speed(self): """ This will calculate the vessel speed (magnitude). You will need 3 beams of good data to calculate the vessel speed. If you do not have 3 beams or any of the velocities for a beam are bad, this will return BAD_VELOCITY. :return: Vessel speed or BAD_VELOCITY. """ # At least 3 beams needed if int(self.NumBeams) >= 3 and len(self.EarthVelocity) >= 3: return Ensemble.calculate_magnitude(self.EarthVelocity[0], self.EarthVelocity[1], self.EarthVelocity[2]) return Ensemble.BadVelocity
def test_magnitude(): east = 1.33 north = 1.45 vert = 0.3 result = Ensemble.calculate_magnitude(east, north, vert) assert 1.99 == pytest.approx(result, 0.01)