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_direction(self): """ This will calculate the vessel direction. You will need 2 beams of good data to calculate the vessel speed. If you do not have 2 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) >= 2 and len(self.EarthVelocity) >= 2: return Ensemble.calculate_direction(self.EarthVelocity[0], self.EarthVelocity[1]) return Ensemble.BadVelocity
def test_direction(): east = 1.33 north = 1.45 result = Ensemble.calculate_direction(east, north) assert 42.52 == pytest.approx(result, 0.01)