I'm trying to plot a 3d antenna radiation pattern using python (or js if possible) but my code is not working. Here is what my dataset looks like:
Theta [deg.] Phi [deg.] Abs(RCS )[dB(m^2)] Abs(Theta)[dB(m^2)] Phase(Theta)[deg.] Abs(Phi )[dB(m^2)] Phase(Phi )[deg.] Ax.Ratio[dB ]
---------------------------------------------------------------------------------------------------------------------------------------------------------
175.000 2.500 -4.083e+01 -4.117e+01 118.796 -5.208e+01 120.015 4.000e+01
177.500 2.500 -4.005e+01 -4.018e+01 118.327 -5.539e+01 117.213 4.000e+01
180.000 2.500 -4.054e+01 -4.055e+01 119.035 -6.585e+01 103.657 3.685e+01
0.000 5.000 -4.039e+01 -4.043e+01 52.496 -6.111e+01 247.581 3.244e+01
2.500 5.000 -4.028e+01 -4.039e+01 51.026 -5.616e+01 277.199 1.871e+01
5.000 5.000 -4.011e+01 -4.040e+01 52.497 -5.194e+01 295.813 1.265e+01
7.500 5.000 -4.016e+01 -4.043e+01 50.019 -5.247e+01 298.975 1.271e+01
10.000 5.000 -4.000e+01 -4.036e+01 50.000 -5.101e+01 306.994 1.091e+01
12.500 5.000 -4.026e+01 -4.064e+01 52.824 -5.102e+01 311.570 1.059e+01
Here are my functions for converting spherical to cartesian and vice-versa:
import math
import pandas as pd
import numpy as np
import plotly.graph_objects as go
def spherical_to_cartesian(theta, phi, rcs):
x = rcs * math.cos(phi) * math.sin(theta)
y = rcs * math.sin(phi) * math.sin(theta)
z = rcs * math.cos(theta)
return x, y, z
def get_transformed_dataframe(path):
df = pd.read_csv(path, sep="\s+", skiprows=2, header=None)
df.columns = ['theta', 'phi', 'rcs', 'abs(theta)', 'phase(theta)', 'abs(phi)', 'phase(phi)', 'ax.ratio']
result_df = df.apply(lambda x: spherical_to_cartesian(x.theta, x.phi, x.rcs), axis=1, result_type='expand')
result_df.columns = ['x', 'y', 'z']
result = df.join(result_df)
return result
df = get_transformed_dataframe('test.txt')
x, y, z = df.x, df.y, df.z
fig = go.Figure(data=[go.Surface(z=z, x=x, y=y)])
fig.update_layout(title='test')
fig.show()
This is my output, which shows nothing:
And this is the kind of output I'm trying to get:
Any idea what is wrong with my code, and how can I get closer to my desired output?