I don’t have an programming background, so please bear with me.
I need to find out the circular standard deviation of the rotation attributes from a set of features in degrees.
The built in AI in the PythonCaller has taken me as far as the code below. I have tried many different prompts, they use somewhat different methods to do the calculations, but all throw errors about missing methods or incorrect classes. It seems that the AI is unable to initialize the script “The FME way”, or I have not figured out the correct prompt.
What do I need to ad to the script in order to get the below working? My desired output is the circular_standard_deviation as a new attribute.
Another nooby question, what should I write in the box: Class to process features?
import math
import numpy as np
# Function to calculate circular standard deviation
def circular_standard_deviation(angles_deg):
angles_rad = np.deg2rad(angles_deg)
sin_sum = np.sum(np.sin(angles_rad))
cos_sum = np.sum(np.cos(angles_rad))
mean_angle = math.atan2(sin_sum, cos_sum)
R = np.sqrt(sin_sum**2 + cos_sum**2) / len(angles_deg)
deviation_rad = np.sqrt(-2 * np.log(R))
return deviation_rad
# FME function to initialize and calculate circular standard deviation
def fme_function(fme_feature):
angles_deg = fme_feature.getAttribute('angles_deg')
deviation_rad = circular_standard_deviation(angles_deg)
fme_feature.setAttribute('circular_standard_deviation', deviation_rad)