Skip to content

Commit

Permalink
compass node
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineBellemare committed Apr 14, 2024
1 parent ff2ea7a commit 08a3b86
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/goofi/nodes/analysis/compass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import numpy as np
from goofi.data import Data, DataType
from goofi.node import Node
from goofi.params import FloatParam

class compass(Node):
"""
A Goofi node that calculates the angle from Cartesian coordinates derived from
directional inputs (north, south, east, west).
"""

def config_input_slots():
return {
"north": DataType.ARRAY,
"south": DataType.ARRAY,
"east": DataType.ARRAY,
"west": DataType.ARRAY
}

def config_output_slots():
return {
"angle": DataType.ARRAY,
}

def process(self, north: Data, south: Data, east: Data, west: Data):
"""
Processes the input directions to compute the angle of the resultant vector
formed by the differences of west-east and north-south.
"""
if north is None or south is None or east is None or west is None:
return None
# Extract the float values from Data objects
north_val = north.data
south_val = south.data
east_val = east.data
west_val = west.data

# Calculate differences
horizontal_diff = west_val - east_val
vertical_diff = north_val - south_val

# Calculate the angle in radians
angle_radians = np.arctan2(vertical_diff, horizontal_diff)

# Convert angle to degrees and normalize to 0-360
angle_degrees = np.degrees(angle_radians)
if angle_degrees < 0:
angle_degrees += 360
# check if sf in metadata and add it to the output metadata


# Return the angle as a Data object
return {"angle": (angle_degrees, {})}

0 comments on commit 08a3b86

Please sign in to comment.