Hi all, sorry for the very long message. Following up with this post Pass input parameters to a script using pythonshell node
I'm trying to pass 4 arguments (altitude, azimuth, solar radiation), from an MQTT server to a script using the pythonshell node. I first passed the incoming values to a file that has this basic format:
{"1":10.9,"2":121.0,"3":52.7,"4":238.09}
("1": altitude, "2": direct solar, "3": diffuse solar, "4": azimuth)
They correspond to the msg.parts.index of the payload as set in a join-node.
The script is copied below, there is a preceeding step to create a numpy array, and to calculate the azimuth, I included it so its easier to understand the script. I edited the script to assign index values to the arguments using sys.argv[1] to the "main"
# numpy array for feature values
X = np.empty(5).reshape(1, 5)
# azimuth sin and azimuth cos
max_a = 123.456
azimuth_sin = np.sin((2*np.pi*azimuth/max_a))
azimuth_cos = np.cos((2*np.pi*azimuth/max_a))
# set vector values
X[:,0] = altitude
X[:,1] = direct_solar
X[:,2] = diffuse_solar
X[:,3] = azimuth_sin
X[:,4] = azimuth_cos
new = self.model_new.predict(X)
return new
if __name__ == "__main__":
predict = Mymodel()
new = predict.return_predictions(
altitude=sys.argv[1],
direct_solar=sys.argv[2],
diffuse_solar=sys.argv[3],
azimuth=sys.argv[4],
print(new)
ERROR:
exit code: 1, Traceback (most recent call last):
File "test-prediction.py", line 46, in <module>
diffuse solar=sys.argv[2],
IndexError: list index out of range
I'd to ask if this is the best approach, or if there is other way you can suggest to pass the arguments. Also, it could be that the format given in the output file is also causing issues due to the special characters (" : ,), or if it would be better to give the values in a single column.
I'd appreciate your help, thank you