<jupyter_start><jupyter_text>CRES or Loop<jupyter_code>plot_antennas = ['loop1']
plot_sparams = ['S24']
plot_rads = [6.0, 8.0, 10.0]
plot_z = [0.0]
plot_runs = [4,5,6]

ifreq = 400
plot_freqs = [data_pd[data_pd['antenna'] == plot_antennas[0]]['Freq(Hz)'].unique()[ifreq]]
#print(plot_freqs)

plot_data = data_pd[(data_pd['antenna'].isin(plot_antennas)) & (data_pd['radius'].isin(plot_rads)) & 
                    (data_pd['run'].isin(plot_runs)) & (data_pd['Freq(Hz)'].isin(plot_freqs))]

x_list = []
phase_list = []
mag_list = []

for run in plot_runs:
    x = np.array(plot_data[plot_data['run'] == run]['angle'])
    #x[np.argwhere(x>180)] -=360
    y1 = np.array(plot_data[plot_data['run'] == run]['S24(PHASE)'])
    y2 = np.array(plot_data[plot_data['run'] == run]['S24(MAG)'])
    y1 = y1[np.argsort(x)]
    y2 = y2[np.argsort(x)]
   
    x = np.sort(x)
    
    y1 -= y1[0]
    #y1 = np.unwrap(y1, discont=np.pi)
    
    #smooth_kern = np.ones(4) / 4
    #y1 = np.convolve(smooth_kern, y1, mode='same')
    y1 = np.degrees(y1)
    
    
    x_list.append(x)
    phase_list.append(y1)
    mag_list.append(y2)


fig1 = plt.figure(figsize=(16,7))
ax1 = plt.subplot(121)
ax2 = plt.subplot(122, polar=True)
for run in [0,1,2]:
    #if run == 2:
    #    phase_list[run] = ((phase_list[run][0:52]))
    #    mag_list[run] = ((mag_list[run][0:52]))
    #    x_list[run] = ((x_list[run][0:52]))
    #    phase_list[run][np.argwhere(x_list[run] >= 312)] -= 360
    #if run == 1:
        #phase_list[run] = ((phase_list[run][0:52]))
        #mag_list[run] = ((mag_list[run][0:52]))
        #x_list[run] = ((x_list[run][0:52]))
    #    phase_list[run][np.argwhere(x_list[run] >= 270)] += 360
    #if run == 0:
    #    phase_list[run][np.argwhere(x_list[run] >= 168)] -= 360
    ax1.plot(x_list[run], phase_list[run], label=f'Run {run + 1}')
    ax2.plot(np.radians(x_list[run]), mag_list[run], label=f'Run {run + 1}')
    ax2.set_ylim(-95,-35)
    ax1.legend(loc=1)
    ax2.legend(loc=1)
    #print(np.arange(0, 360, 6)[25:35])
#ax1.set_xlim(-60, 60)
ax1.set_title(f'Antenna: {plot_antennas[0]}, Freq: {plot_freqs[0] * 1e-9: .2f} (GHz), {plot_sparams[0]} Unwrapped Phase (deg)')
ax2.set_title(f'Antenna: {plot_antennas[0]}, Freq: {plot_freqs[0] * 1e-9: .2f} (GHz), {plot_sparams[0]} Magnitude (dB)')

#plt.savefig('/Users/ziegler/plots/21517_loop2_mag_and_phase_f3.png')

corrected_phase_list = []
for run in [0,1,2]:
    y = phase_list[run]
#    if run == 2:
#        y[np.argwhere(x_list[run] >= 138)] -= 360
    if run == 0 or run ==1:
        y[np.argwhere(x_list[run] >= 132)] += 360
    corrected_phase_list.append(y)
        


def fit_fun(x, a, b, c, d):
    return a * x + b * np.sin((2 * np.pi * x / 360) + c) + d

fig2 = plt.figure(figsize=(8,6))
ax3 = plt.subplot(111)
colors = ['tab:blue', 'tab:red', 'tab:green', 'tab:orange']
for run in [0,1,2]:
    p, cov = optim.curve_fit(fit_fun, x_list[run], phase_list[run])
    #print(np.degrees(p[1]) % 360)
    ax3.plot(x_list[run], corrected_phase_list[run], color=colors[run], label=f'Run {run+1}, Amp. {p[1]: .2f}')
    ax3.plot(x_list[run], fit_fun(x_list[run], p[0], p[1], p[2], p[3]), color=colors[run])
    #ax3.plot(x_list[run], phase_list[run])
    #ax3.plot(x_list[run], fit_fun(x_list[run], p[0], p[1], p[2], p[3]), label='Fit')
    #ax3.plot(x_list[run], p[0] * x_list[run] + p[3], label=f'Linear, Slope {p[0]: .2f}')
    #ax3.plot(x_list[run], p[1] * np.sin(2 * np.pi * x_list[run] / 360 + p[2]) + p[3], label=f'Sine, Amp {p[1]: .2f}')
    
ax3.legend(loc=3)
ax3.set_xlabel('Angle (deg)')
ax3.set_ylabel('Phase (deg)')
ax3.set_title(f'Fits to Corrected Phases. Antenna: {plot_antennas[0]}, Freq: {plot_freqs[0] * 1e-9: .2f} (GHz), {plot_sparams[0]}')
#plt.savefig('/Users/ziegler/plots/21513_cres2_phase_fit.png')<jupyter_output><empty_output><jupyter_text>Dipole<jupyter_code>plot_antennas = ['dipole1']
plot_sparams = ['S24']
plot_rads = [10.0]
plot_z = [0.0]
plot_runs = [1,2]

ifreq = 500
plot_freqs = [data_pd[data_pd['antenna'] == plot_antennas[0]]['Freq(Hz)'].unique()[ifreq]]
print(plot_freqs)

axes_phase = plot_phase_dipole(data_pd, plot_antennas, plot_rads, plot_runs, plot_freqs, x='angle', y=plot_sparams)
axes_phase.set_title('F = %.3f GHz, R=%.1f cm' % (plot_freqs[0] * 1e-9, plot_rads[0]))
axes_phase.legend(loc=0)
axes_phase.set_xlabel('Angle (deg)')
axes_phase.set_ylabel('Phase (Rad)')
plt.tight_layout()
plt.savefig('/Users/ziegler/plots/21510_dipole1_phase.png')

axes_mag = plot_mag_dipole(data_pd, plot_antennas, plot_rads, plot_runs, plot_freqs, x='angle', y=plot_sparams)
axes_mag.set_title('F = %.3f GHz, R=%.1f cm' % (plot_freqs[0] * 1e-9, plot_rads[0]))
axes_mag.legend(loc=0)
axes_mag.set_xlabel('Angle (deg)')
axes_mag.set_ylabel('Mag (dB)')
plt.tight_layout()
plt.savefig('/Users/ziegler/plots/21510_dipole1_mag.png')
plot_antennas = ['dipole1']
plot_rads = [9.0]
plot_z = [0.0, 1.0, -1.0]

cres1_freqs = data_pd[data_pd['antenna'] == 'cres1']['Freq(Hz)'].unique()
loop1_freqs = data_pd[data_pd['antenna'] == 'loop1']['Freq(Hz)'].unique()
dipole1_freqs = data_pd[data_pd['antenna'] == 'dipole1']['Freq(Hz)'].unique()

plot_freqs = [dipole1_freqs[0]]

#plot_mag(data_pd, plot_antennas, plot_rads, plot_z, plot_freqs, x='angle', y='S42(MAG)')

axes_phase = plot_phase_dipole(data_pd, plot_antennas, plot_rads, plot_z, plot_freqs, x='angle', y='S42(PHASE)')
axes_phase.set_title('Dipole1 Spatial Phase, F = %.3f GHz, R=%.1f cm' % (plot_freqs[0] * 1e-9, plot_rads[0]))
axes_phase.legend(loc=0, title='z offset')
axes_phase.set_xlabel('Angle (deg)')
axes_phase.set_ylabel('Phase (rad)')
#plt.savefig('/Users/ziegler/plots/2021429_loop1_phase_meas_rad9cm.png')<jupyter_output><empty_output><jupyter_text>plots for a specific frequency<jupyter_code>listdata = []
M = 2
for path in datapathlist:
    listdata.append(vna_to_pd(path))


frequencies = listdata[0]['Freq(Hz)'].unique()
plot_freq_ind = 100
plot_freq = frequencies[plot_freq_ind]
#print(listdata[0].loc[listdata[0]['Freq(Hz)'] == plot_freq])
plot_data = (listdata[M].loc[listdata[M]['Freq(Hz)'] == plot_freq])
plot_data = plot_data.iloc[np.argsort(plot_data['pos'])]

fig1 = plt.figure(figsize=(7,5)) 
ax1 = plt.subplot(1, 1, 1)

ax1.plot(plot_data['pos'], plot_data['S42(MAG)'], '.', color='tab:blue')
ax2 = ax1.twinx()
ax2.plot(plot_data['pos'], np.degrees(np.unwrap(np.radians(np.asarray(plot_data['S42(PHASE)'])))), color='tab:orange')
#ax1.set_ylim(-50, -60)

#fig2 = plt.figure(figsize=(7,5)) 
#ax3 = plt.subplot(1, 1, 1, projection = 'polar')

#ax3.plot(np.asarray(plot_data['S42(PHASE)']), np.ones(len(plot_data['S42(PHASE)'])), '.')

plot_data<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21488848704038577, 'fraction_numerical': 0.052742616033755275, 'mean_word_length': 5.231924882629108, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '322378', 'license': 'MIT', 'n_tokens_mistral': 3235, 'n_tokens_neox': 3027, 'n_words': 433, 'path': 'analysis/vna/.ipynb_checkpoints/3152021_cres_transmitter_characterization-checkpoint.ipynb', 'repo_name': 'zieglerad/romulus', 'size': '6636'}