0

I am trying to display a 3D plot of LHC and RHC data formatted like this (the first two columns are theta <0 to 180 deg> and phi <0,360>, the last two columns are irrelevant:

Step deg        Scan deg        RHC dB      LHC dB      Pol 0 deg       Pol 90 deg
0.000       0.000       13.778      39.157      293.607     209.672
0.000       0.300       13.778      39.157      293.007     210.272
0.000       0.600       13.778      39.157      292.407     210.872
0.000       0.900       13.778      39.157      291.807     211.472
0.000       1.200       13.778      39.157      291.207     212.072
0.000       1.500       13.778      39.157      290.607     212.672
0.000       1.800       13.778      39.157      290.007     213.272
0.000       2.100       13.778      39.157      289.407     213.872
0.000       2.400       13.778      39.157      288.807     214.472
0.000       2.700       13.778      39.157      288.207     215.072

The function I am using to convert the data is:

def spherical_to_cartesian(theta: np.ndarray, phi: np.ndarray, data: np.ndarray):
    # * data processing
    theta_rd = np.deg2rad(theta)
    phi_rd = np.deg2rad(phi)
    nth = len(np.unique(theta_rd))
    nph = len(np.unique(phi_rd))
    power = np.power(10, data/10)

    #converting from spherical to cartesian coords
    theta_rd = theta_rd.reshape([nth, nph])
    phi_rd = phi_rd.reshape([nth, nph])
    power = power.reshape([nth, nph])

    X = power * np.sin(theta_rd) * np.cos(phi_rd)
    Y = power * np.sin(theta_rd) * np.sin(phi_rd)
    Z = power * np.cos(theta_rd)
    
    Z = 10*np.log10(np.abs(Z))

    return [X,Y,Z]

, where data: np.ndarray represents either LHC data or RHC data. The plotting function goes like this:

    RHCP_cartesian = spherical_to_cartesian(theta, phi, RHCP)
    LHCP_cartesian = spherical_to_cartesian(theta, phi, LHCP)
    

    fig = make_subplots(
    rows=1, cols=2,
    specs=[[{ 'type': 'surface' } , { 'type': 'surface' }]],
    subplot_titles=('RHCP', 'LHCP')
    )
    
    fig.add_trace(
        go.Surface(x=RHCP_cartesian[0], y=RHCP_cartesian[1], z=RHCP_cartesian[2], surfacecolor=RHCP_cartesian[2], colorscale='mygbm', colorbar = dict(x=0.45, title = "Gain", thickness = 50)), row=1, col=1
    )

    fig.add_trace(
        go.Surface(x=LHCP_cartesian[0], y=LHCP_cartesian[1], z=LHCP_cartesian[2], surfacecolor=LHCP_cartesian[2], colorscale='mygbm', colorbar = dict(x=1, title = "Gain", thickness = 50)), row=1, col=2
    )

    layout = go.Layout(title=title)
    fig.update_layout(scene=dict(xaxis = dict(range=[np.min(RHCP_cartesian[0]),np.max(RHCP_cartesian[0])],), yaxis = dict(range=[np.min(RHCP_cartesian[1]),np.max(RHCP_cartesian[1])])))
    fig.update_layout(scene1=dict(xaxis = dict(range=[np.min(LHCP_cartesian[0]),np.max(LHCP_cartesian[0])],), yaxis = dict(range=[np.min(LHCP_cartesian[1]),np.max(LHCP_cartesian[1])])))
    fig.update_layout(autosize = True, margin = dict(l = 150, r = 150, t = 250, b = 250))
    plot(fig)

The results I am receiving are quite strange. My gain goes all the way to -200 dB which can not be possibly correct (the lowest value in the measured data is -94 dB) and the overall shape is just off. Patterns I tried consulting similar posts: Python - Plotting Antenna Radiation Pattern or Spherical coordinates plot in matplotlib , How can I plot a 3d antenna radiation pattern in python? however, I can not really find a solution.

sbzak
  • 1
  • 1

0 Answers0