Modified plotting scripts for thesis

This commit is contained in:
yosata committed 2022-06-17 10:41:02 +02:00
1 parent 914910e684
commit 1b3a1e0821
20 files changed
+76 -33

No files matched your search

+5 -4
View File
@@ -6,6 +6,7 @@ from scipy.optimize import leastsq
from matplotlib.ticker import FormatStrFormatter
from matplotlib.colors import LogNorm
import pyfftw
import os
from .misc import find_pixel_scale
class FourierOptics:
@@ -68,7 +69,7 @@ class FourierOptics:
_E_xy0[:] = np.fft.ifftshift(A) # use ifftshift to shift origin to start array
_IntensityNormFactor = np.sum(np.abs(_E_xy0)**2) # Factor to scale the intensity after the FFTs
_Az0 = pyfftw.empty_aligned((_n,_m), dtype='complex128')
_FFTW_Obj = pyfftw.FFTW( _E_xy0, _Az0, axes=(0,1), direction='FFTW_BACKWARD', threads=6, flags=('FFTW_ESTIMATE',))
_FFTW_Obj = pyfftw.FFTW( _E_xy0, _Az0, axes=(0,1), direction='FFTW_BACKWARD', threads=os.cpu_count(), flags=('FFTW_ESTIMATE',))
_FFTW_Obj()
# E-field at z=dz is the fourier transform of A(z=0)*e^(-ikz)
@@ -86,7 +87,7 @@ class FourierOptics:
_A_in = pyfftw.empty_aligned((_n,_m), dtype='complex128')
_A_in[:] = _Az0 * _phaseFactor
_FFTW_Obj2 = pyfftw.FFTW( _A_in, _E_xyz, axes=(0,1), direction='FFTW_FORWARD', threads=6, flags=('FFTW_ESTIMATE',))
_FFTW_Obj2 = pyfftw.FFTW( _A_in, _E_xyz, axes=(0,1), direction='FFTW_FORWARD', threads=os.cpu_count(), flags=('FFTW_ESTIMATE',))
_FFTW_Obj2()
_E_xyz = np.fft.fftshift(_E_xyz) # use fftshift to move the origin from edge to center
_E_xyz /= np.sqrt(_IntensityNormFactor) # Normalization back to initial energy.
@@ -213,7 +214,7 @@ class FourierOptics:
# Output of the FFT evaluated at frequency fx = x / (lambda * z)
_U_out = pyfftw.empty_aligned((_n,_m), dtype='complex128')
_FFTW_Obj = pyfftw.FFTW( np.fft.ifftshift(_U_in), _U_out, axes=(0,1), direction='FFTW_FORWARD', threads=6, flags=('FFTW_ESTIMATE',))
_FFTW_Obj = pyfftw.FFTW( np.fft.ifftshift(_U_in), _U_out, axes=(0,1), direction='FFTW_FORWARD', threads=os.cpu_count(), flags=('FFTW_ESTIMATE',))
_FFTW_Obj()
_U_out = np.fft.fftshift(_U_out)
@@ -365,7 +366,7 @@ class FourierOptics:
# Output of the FFT
_A_out = pyfftw.empty_aligned(PSF.shape, dtype='complex128')
_FFTW_Obj = pyfftw.FFTW( np.fft.ifftshift(_A_in), _A_out, axes=(0,1), direction='FFTW_FORWARD', threads=6, flags=('FFTW_ESTIMATE',))
_FFTW_Obj = pyfftw.FFTW( np.fft.ifftshift(_A_in), _A_out, axes=(0,1), direction='FFTW_FORWARD', threads=os.cpu_count(), flags=('FFTW_ESTIMATE',))
_FFTW_Obj()
_A_out = np.fft.fftshift(_A_out)
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

+17 -6
View File
@@ -32,10 +32,11 @@ def plot_colourline(x,y,c, ax):
if __name__ == '__main__':
plt.rc('font', family='serif')
plt.rc('text', usetex=True)
plt.rc('axes', labelsize='large')
# Load in the results from centroid_shift_analysis.py
rms_zern_nm, r_airy_zern_mas, r_err_zern_airy_mas, strehl_list_zern = load_variable('./data/centroid_shift_zernikes.pkl')
rms_psd_nm, r_airy_psd_mas, r_err_psd_airy_mas, strehl_list_psd = load_variable('./data/centroid_shift_psd.pkl')
rms_zern_nm, r_airy_zern_mas, r_err_zern_airy_mas, strehl_list_zern = load_variable('./data/WFE frequency analysis/centroid_shift_zernikes.pkl')
rms_psd_nm, r_airy_psd_mas, r_err_psd_airy_mas, strehl_list_psd = load_variable('./data/WFE frequency analysis/centroid_shift_psd.pkl')
# Convert the errors to logarithmic space, assuming small errors.
log_err_zern_airy_mas = 0.434 * r_err_zern_airy_mas / r_airy_zern_mas
@@ -43,7 +44,7 @@ if __name__ == '__main__':
# Plot the resulting WFE scaling relation
fig = plt.figure(figsize=(9,7))
fig = plt.figure(figsize=(6.4,4.8))
ax1 = fig.add_subplot(111)
ax1.errorbar((0.8138)*rms_zern_nm, r_airy_zern_mas, yerr=log_err_zern_airy_mas, color='k',
linestyle='none', capsize=3,
@@ -66,13 +67,23 @@ if __name__ == '__main__':
ax1.legend(fontsize=18)
ax1.grid(True, alpha=0.3, which='major')
ax1.grid(True, alpha=0.1, which='minor')
ax1.tick_params(labelsize=18)
ax1.tick_params(axis='both', which='both', direction='in', labelsize=16, zorder=-1,)
cb = fig.colorbar(im, ax=ax1)
cb.set_label(label='Strehl', size=18)
cb.ax.tick_params(labelsize=18)
plt.savefig('./figures/WFE_scaling_relation_obscured_airy.png', bbox_inches='tight', transparent=True)
plt.savefig('./figures/WFE_scaling_relation_obscured_airy.pdf', bbox_inches='tight', transparent=True)
# plt.savefig('./figures/WFE_scaling_relation_obscured_airy.png', bbox_inches='tight', transparent=True)
# plt.savefig('./figures/WFE_scaling_relation_obscured_airy.pdf', bbox_inches='tight', transparent=True)
plt.tight_layout()
figtitle = 'new_WFE_scaling_relation_obscured_airy'
if figtitle:
plt.savefig('{}.pdf'.format(figtitle),
bbox_inches='tight',
transparent=False,
facecolor=(1, 1, 0, 0.0))
plt.savefig('{}.png'.format(figtitle),
bbox_inches='tight',
transparent=False,
facecolor=(1, 1, 0, 0.0))
plt.show()
+20 -10
View File
@@ -25,7 +25,7 @@ def append_to_existing_data(A, filename):
def plot_some_stuff():
fig = plt.figure(figsize=(9,7))
fig = plt.figure(figsize=(6.4,4.8))
ax = fig.add_subplot(111)
ax2 = ax.twiny()
@@ -52,11 +52,21 @@ def plot_some_stuff():
ax2.set_xlabel('$\\sigma/\\lambda$', fontsize=18)
ax.legend(fontsize=18)
ax.grid(True, alpha=0.3)
ax.tick_params(labelsize=18)
ax2.tick_params(labelsize=18)
ax.tick_params(axis='both', which='both', direction='in', labelsize=16, zorder=-1,)
ax2.tick_params(axis='both', which='both', direction='in', labelsize=16, zorder=-1,)
plt.tight_layout()
plt.savefig('./figures/SR_relation_WFE_on_ADC_p1_obscured.png', bbox_inches='tight', transparent=True)
plt.savefig('./figures/SR_relation_WFE_on_ADC_p1_obscured.pdf', bbox_inches='tight', transparent=True)
# plt.savefig('./figures/SR_relation_WFE_on_ADC_p1_obscured.png', bbox_inches='tight', transparent=True)
# plt.savefig('./figures/SR_relation_WFE_on_ADC_p1_obscured.pdf', bbox_inches='tight', transparent=True)
figtitle = 'new_SR_relation_WFE_on_ADC_p1_obscured'
if figtitle:
plt.savefig('{}.pdf'.format(figtitle),
bbox_inches='tight',
transparent=False,
facecolor=(1, 1, 0, 0.0))
plt.savefig('{}.png'.format(figtitle),
bbox_inches='tight',
transparent=False,
facecolor=(1, 1, 0, 0.0))
plt.show()
if __name__ == '__main__':
@@ -65,11 +75,11 @@ if __name__ == '__main__':
plt.rc('axes', labelsize='large')
l = 1.49e-3
rmsList = load_variable('./data/SR_RMS_values_obscured.pkl')
strehl_zern_complete = load_variable('./data/SR_strehl_zern_obscured.pkl')
strehl_psd_complete = load_variable('./data/SR_strehl_psd_obscured.pkl')
rms_zern_list_complete = load_variable('./data/SR_rms_zern_complete_obscured.pkl')
rms_psd_list_complete = load_variable('./data/SR_rms_psd_complete_obscured.pkl')
rmsList = load_variable('./data/Strehl relation analysis/SR_RMS_values_obscured.pkl')
strehl_zern_complete = load_variable('./data/Strehl relation analysis/SR_strehl_zern_obscured.pkl')
strehl_psd_complete = load_variable('./data/Strehl relation analysis/SR_strehl_psd_obscured.pkl')
rms_zern_list_complete = load_variable('./data/Strehl relation analysis/SR_rms_zern_complete_obscured.pkl')
rms_psd_list_complete = load_variable('./data/Strehl relation analysis/SR_rms_psd_complete_obscured.pkl')
mean_strehl_zern = np.mean(strehl_zern_complete, axis=0)
err_strehl_zern = np.std(strehl_zern_complete, axis=0)
+34 -13
View File
@@ -27,8 +27,8 @@ if __name__ == '__main__':
###############################
# Load in the data
r_airy, r_err_airy = load_variable('./data/lowpass_frequency_filter_airy_distance.pkl')
x0_airy, y0_airy, x0_airy_err, y0_airy_err = load_variable('./data/lowpass_frequency_filter_airy_locations.pkl')
r_airy, r_err_airy = load_variable('./data/WFE frequency analysis/lowpass_frequency_filter_airy_distance.pkl')
x0_airy, y0_airy, x0_airy_err, y0_airy_err = load_variable('./data/WFE frequency analysis/lowpass_frequency_filter_airy_locations.pkl')
central_frequencies = np.asarray([0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 25,
30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 120, 140, 160, 180, 200,
220, 250, 280, 310, 340, 370, 400, 450, 500])
@@ -37,19 +37,30 @@ if __name__ == '__main__':
r_err_airy_mas = r_err_airy * platescale
# Plotting the centroid shift for all bandpasses
fig = plt.figure(figsize=(9,7))
fig = plt.figure(figsize=(6.4,4.8))
ax1 = fig.add_subplot(111)
ax1.scatter(central_frequencies, r_airy_mas, edgecolor='k', facecolors='none', alpha=0.7)
ax1.set_xscale('log')
ax1.set_xlabel('Cut-off Frequency of the lowpass filter ($\\rho/\\rho_c$)', fontsize=18)
ax1.set_ylabel('Centroid shift (mas)', fontsize=18)
ax1.tick_params(labelsize=18)
ax1.tick_params(axis='both', which='both', direction='in', labelsize=16, zorder=-1,)
ax1.grid(True, alpha=0.3, which='major')
ax1.grid(True, alpha=0.1, which='minor')
ax1.set_xlim([0.3,550])
plt.tight_layout()
plt.savefig('./figures/wfe_frequency_analysis/lowpass_spatial_freq_distance.png', bbox_inches='tight', transparent=True)
plt.savefig('./figures/wfe_frequency_analysis/lowpass_spatial_freq_distance.pdf', bbox_inches='tight', transparent=True)
figtitle = 'new_lowpass_spatial_freq_distance'
if figtitle:
plt.savefig('{}.pdf'.format(figtitle),
bbox_inches='tight',
transparent=False,
facecolor=(1, 1, 0, 0.0))
plt.savefig('{}.png'.format(figtitle),
bbox_inches='tight',
transparent=False,
facecolor=(1, 1, 0, 0.0))
plt.show()
# plt.savefig('./figures/wfe_frequency_analysis/lowpass_spatial_freq_distance.png', bbox_inches='tight', transparent=True)
# plt.savefig('./figures/wfe_frequency_analysis/lowpass_spatial_freq_distance.pdf', bbox_inches='tight', transparent=True)
@@ -60,9 +71,9 @@ if __name__ == '__main__':
################################
# Load in the data
r_airy, r_err_airy = load_variable('./data/bandpass_frequency_filter_airy_distance.pkl')
x0_airy, y0_airy, x0_airy_err, y0_airy_err = load_variable('./data/bandpass_frequency_filter_airy_locations.pkl')
central_frequencies = load_variable('./data/bandpass_frequency_filter_central_frequencies.pkl')
r_airy, r_err_airy = load_variable('./data/WFE frequency analysis/bandpass_frequency_filter_airy_distance.pkl')
x0_airy, y0_airy, x0_airy_err, y0_airy_err = load_variable('./data/WFE frequency analysis/bandpass_frequency_filter_airy_locations.pkl')
central_frequencies = load_variable('./data/WFE frequency analysis/bandpass_frequency_filter_central_frequencies.pkl')
print(central_frequencies, len(central_frequencies), len(r_airy))
r_airy_mas = r_airy * platescale
r_err_airy_mas = r_err_airy * platescale
@@ -77,7 +88,7 @@ if __name__ == '__main__':
# Plotting the centroid shift for all bandpasses
fig = plt.figure(figsize=(9,7))
fig = plt.figure(figsize=(6.4,4.8))
ax1 = fig.add_subplot(111)
ax1.scatter(central_frequencies, r_airy_mas, edgecolor='k', facecolors='none', alpha=0.7)
ax1.plot(central_frequencies[2:], 10**best_fit_y[2:], 'b-', alpha=0.5, label='Best fit: $y = 0.030 x^{-0.602}$')
@@ -85,13 +96,23 @@ if __name__ == '__main__':
ax1.set_yscale('log')
ax1.set_xlabel('Central Frequency of the bandpass filter ($\\rho/\\rho_c$)', fontsize=18)
ax1.set_ylabel('Centroid shift (mas)', fontsize=18)
ax1.tick_params(labelsize=18)
ax1.tick_params(axis='both', which='both', direction='in', labelsize=16, zorder=-1,)
ax1.grid(True, alpha=0.3, which='major')
ax1.grid(True, alpha=0.1, which='minor')
ax1.set_xlim([0.3,550])
ax1.set_ylim([10**-6, 10**0])
ax1.legend(fontsize=18)
plt.tight_layout()
plt.savefig('./figures/wfe_frequency_analysis/bandpass_spatial_freq_distance.png', bbox_inches='tight', transparent=True)
plt.savefig('./figures/wfe_frequency_analysis/bandpass_spatial_freq_distance.pdf', bbox_inches='tight', transparent=True)
figtitle = 'bandpass_spatial_freq_distance'
if figtitle:
plt.savefig('{}.pdf'.format(figtitle),
bbox_inches='tight',
transparent=False,
facecolor=(1, 1, 0, 0.0))
plt.savefig('{}.png'.format(figtitle),
bbox_inches='tight',
transparent=False,
facecolor=(1, 1, 0, 0.0))
# plt.savefig('./figures/wfe_frequency_analysis/bandpass_spatial_freq_distance.png', bbox_inches='tight', transparent=True)
# plt.savefig('./figures/wfe_frequency_analysis/bandpass_spatial_freq_distance.pdf', bbox_inches='tight', transparent=True)
plt.show()