Move P_int, PA_int computation in pipeline, replot NGC1068, MKN463, IC5063
This commit is contained in:
@@ -18,12 +18,12 @@ from lib.deconvolve import from_file_psf
|
||||
def main():
|
||||
##### User inputs
|
||||
## Input and output locations
|
||||
globals()['data_folder'] = "../data/NGC1068_x274020/"
|
||||
infiles = ['x274020at.c0f.fits','x274020bt.c0f.fits','x274020ct.c0f.fits',
|
||||
'x274020dt.c0f.fits','x274020et.c0f.fits','x274020ft.c0f.fits',
|
||||
'x274020gt.c0f.fits','x274020ht.c0f.fits','x274020it.c0f.fits']
|
||||
psf_file = 'NGC1068_f253m00.fits'
|
||||
globals()['plots_folder'] = "../plots/NGC1068_x274020/"
|
||||
# globals()['data_folder'] = "../data/NGC1068_x274020/"
|
||||
# infiles = ['x274020at.c0f.fits','x274020bt.c0f.fits','x274020ct.c0f.fits',
|
||||
# 'x274020dt.c0f.fits','x274020et.c0f.fits','x274020ft.c0f.fits',
|
||||
# 'x274020gt.c0f.fits','x274020ht.c0f.fits','x274020it.c0f.fits']
|
||||
# psf_file = 'NGC1068_f253m00.fits'
|
||||
# globals()['plots_folder'] = "../plots/NGC1068_x274020/"
|
||||
|
||||
# globals()['data_folder'] = "../data/NGC1068_x14w010/"
|
||||
# infiles = ['x14w0101t_c0f.fits','x14w0102t_c0f.fits','x14w0103t_c0f.fits',
|
||||
@@ -62,10 +62,10 @@ def main():
|
||||
# 'x3995202r_c0f.fits','x3995206r_c0f.fits']
|
||||
# globals()['plots_folder'] = "../plots/PG1630+377_x39510/"
|
||||
|
||||
# globals()['data_folder'] = "../data/IC5063_x3nl030/"
|
||||
# infiles = ['x3nl0301r_c0f.fits','x3nl0302r_c0f.fits','x3nl0303r_c0f.fits']
|
||||
# psf_file = 'IC5063_f502m00.fits'
|
||||
# globals()['plots_folder'] = "../plots/IC5063_x3nl030/"
|
||||
globals()['data_folder'] = "../data/IC5063_x3nl030/"
|
||||
infiles = ['x3nl0301r_c0f.fits','x3nl0302r_c0f.fits','x3nl0303r_c0f.fits']
|
||||
psf_file = 'IC5063_f502m00.fits'
|
||||
globals()['plots_folder'] = "../plots/IC5063_x3nl030/"
|
||||
|
||||
# globals()['data_folder'] = "../data/MKN3_x3nl010/"
|
||||
# infiles = ['x3nl0101r_c0f.fits','x3nl0102r_c0f.fits','x3nl0103r_c0f.fits']
|
||||
@@ -116,8 +116,8 @@ def main():
|
||||
rotate_stokes = True #rotation to North convention can give erroneous results
|
||||
rotate_data = False #rotation to North convention can give erroneous results
|
||||
# Polarization map output
|
||||
figname = 'NGC1068_FOC' #target/intrument name
|
||||
figtype = '_combine_FWHM020_wae' #additionnal informations
|
||||
figname = 'IC5063_FOC' #target/intrument name
|
||||
figtype = '_combine_FWHM020' #additionnal informations
|
||||
SNRp_cut = 10. #P measurments with SNR>3
|
||||
SNRi_cut = 100. #I measurments with SNR>30, which implies an uncertainty in P of 4.7%.
|
||||
step_vec = 1 #plot all vectors in the array. if step_vec = 2, then every other vector will be plotted
|
||||
@@ -127,41 +127,21 @@ def main():
|
||||
## Step 1:
|
||||
# Get data from fits files and translate to flux in erg/cm²/s/Angstrom.
|
||||
data_array, headers = proj_fits.get_obs_data(infiles, data_folder=data_folder, compute_flux=True)
|
||||
for data in data_array:
|
||||
if (data < 0.).any():
|
||||
print("ETAPE 1 : ", data)
|
||||
# Crop data to remove outside blank margins.
|
||||
print(">Crop")
|
||||
data_array, error_array, headers = proj_red.crop_array(data_array, headers, step=5, null_val=0., inside=True, display=display_crop, savename=figname, plots_folder=plots_folder)
|
||||
for data in data_array:
|
||||
if (data < 0.).any():
|
||||
print("ETAPE 2 : ", data)
|
||||
# Deconvolve data using Richardson-Lucy iterative algorithm with a gaussian PSF of given FWHM.
|
||||
if deconvolve:
|
||||
print(">Deconvolve")
|
||||
data_array = proj_red.deconvolve_array(data_array, headers, psf=psf, FWHM=psf_FWHM, scale=psf_scale, shape=psf_shape, iterations=iterations)
|
||||
# Estimate error from data background, estimated from sub-image of desired sub_shape.
|
||||
print(">Get error")
|
||||
data_array, error_array, headers = proj_red.get_error(data_array, headers, sub_shape=error_sub_shape, display=display_error, savename=figname+"_errors", plots_folder=plots_folder)
|
||||
for data in data_array:
|
||||
if (data < 0.).any():
|
||||
print("ETAPE 3 : ", data)
|
||||
# Rebin data to desired pixel size.
|
||||
Dxy = np.ones(2)
|
||||
if rebin:
|
||||
print(">Rebin")
|
||||
data_array, error_array, headers, Dxy = proj_red.rebin_array(data_array, error_array, headers, pxsize=pxsize, scale=px_scale, operation=rebin_operation)
|
||||
for data in data_array:
|
||||
if (data < 0.).any():
|
||||
print("ETAPE 4 : ", data)
|
||||
# Align and rescale images with oversampling.
|
||||
data_mask = np.zeros(data_array.shape[1:]).astype(bool)
|
||||
if px_scale.lower() not in ['full','integrate']:
|
||||
print(">Align")
|
||||
data_array, error_array, headers, data_mask = proj_red.align_data(data_array, headers, error_array, upsample_factor=int(Dxy.min()), ref_center=align_center, return_shifts=False)
|
||||
for data in data_array:
|
||||
if (data < 0.).any():
|
||||
print("ETAPE 5 : ", data)
|
||||
|
||||
if px_scale.lower() not in ['full','integrate']:
|
||||
vertex = image_hull((1.-data_mask),step=5,null_val=0.,inside=True)
|
||||
@@ -173,15 +153,11 @@ def main():
|
||||
# Rotate data to have North up
|
||||
ref_header = deepcopy(headers[0])
|
||||
if rotate_data:
|
||||
print(">Rotate data")
|
||||
alpha = ref_header['orientat']
|
||||
mrot = np.array([[np.cos(-alpha), -np.sin(-alpha)], [np.sin(-alpha), np.cos(-alpha)]])
|
||||
rectangle[0:2] = np.dot(mrot, np.asarray(rectangle[0:2]))+np.array(data_array.shape[1:])/2
|
||||
rectangle[4] = alpha
|
||||
data_array, error_array, headers, data_mask = proj_red.rotate_data(data_array, error_array, data_mask, headers, -ref_header['orientat'])
|
||||
for data in data_array:
|
||||
if (data < 0.).any():
|
||||
print("ETAPE 6 : ", data)
|
||||
#Plot array for checking output
|
||||
if display_data:
|
||||
proj_plots.plot_obs(data_array, headers, vmin=data_array.min(), vmax=data_array.max(), rectangle =[rectangle,]*data_array.shape[0], savename=figname+"_center_"+align_center, plots_folder=plots_folder)
|
||||
@@ -192,14 +168,12 @@ def main():
|
||||
# FWHM of FOC have been estimated at about 0.03" across 1500-5000 Angstrom band, which is about 2 detector pixels wide
|
||||
# see Jedrzejewski, R.; Nota, A.; Hack, W. J., A Comparison Between FOC and WFPC2
|
||||
# Bibcode : 1995chst.conf...10J
|
||||
print(">Compute Stokes")
|
||||
I_stokes, Q_stokes, U_stokes, Stokes_cov = proj_red.compute_Stokes(data_array, error_array, data_mask, headers, FWHM=smoothing_FWHM, scale=smoothing_scale, smoothing=smoothing_function)
|
||||
|
||||
## Step 3:
|
||||
# Rotate images to have North up
|
||||
ref_header = deepcopy(headers[0])
|
||||
if rotate_stokes:
|
||||
print(">Rotate stokes")
|
||||
alpha = ref_header['orientat']
|
||||
mrot = np.array([[np.cos(-alpha), -np.sin(-alpha)],
|
||||
[np.sin(-alpha), np.cos(-alpha)]])
|
||||
@@ -207,7 +181,6 @@ def main():
|
||||
rectangle[4] = alpha
|
||||
I_stokes, Q_stokes, U_stokes, Stokes_cov, headers, data_mask = proj_red.rotate_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers, -ref_header['orientat'], SNRi_cut=None)
|
||||
# Compute polarimetric parameters (polarization degree and angle).
|
||||
print(">Compute Pol")
|
||||
P, debiased_P, s_P, s_P_P, PA, s_PA, s_PA_P = proj_red.compute_pol(I_stokes, Q_stokes, U_stokes, Stokes_cov, headers)
|
||||
|
||||
## Step 4:
|
||||
|
||||
@@ -126,6 +126,10 @@ def save_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, P, debiased_P, s_P,
|
||||
header['targname'] = (ref_header['targname'], 'Target name')
|
||||
header['orientat'] = (ref_header['orientat'], 'Angle between North and the y-axis of the image')
|
||||
header['filename'] = (filename, 'Original filename')
|
||||
header['P_int'] = (ref_header['P_int'], 'Integrated polarization degree')
|
||||
header['P_int_err'] = (ref_header['P_int_err'], 'Integrated polarization degree error')
|
||||
header['PA_int'] = (ref_header['PA_int'], 'Integrated polarization angle')
|
||||
header['PA_int_err'] = (ref_header['PA_int_err'], 'Integrated polarization angle error')
|
||||
|
||||
#Create HDUList object
|
||||
hdul = fits.HDUList([])
|
||||
|
||||
@@ -233,7 +233,7 @@ def polarization_map(Stokes, data_mask=None, rectangle=None, SNRp_cut=3., SNRi_c
|
||||
|
||||
#Get image mask
|
||||
if data_mask is None:
|
||||
data_mask = np.ones(stkI.shape).astype(bool)
|
||||
data_mask = np.zeros(stkI.shape).astype(bool)
|
||||
|
||||
#Plot Stokes parameters map
|
||||
if display is None or display.lower() == 'default':
|
||||
@@ -353,43 +353,15 @@ def polarization_map(Stokes, data_mask=None, rectangle=None, SNRp_cut=3., SNRi_c
|
||||
ax.add_patch(Rectangle((x, y), width, height, angle=angle,
|
||||
edgecolor=color, fill=False))
|
||||
|
||||
# Compute integrated parameters and associated errors for pixels in the cut
|
||||
n_pix = mask.size
|
||||
I_int = stkI.data[mask].sum()
|
||||
Q_int = stkQ.data[mask].sum()
|
||||
U_int = stkU.data[mask].sum()
|
||||
I_int_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[0,0][mask]))
|
||||
Q_int_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[1,1][mask]))
|
||||
U_int_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[2,2][mask]))
|
||||
IQ_int_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[0,1][mask]**2))
|
||||
IU_int_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[0,2][mask]**2))
|
||||
QU_int_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[1,2][mask]**2))
|
||||
|
||||
P_int = np.sqrt(Q_int**2+U_int**2)/I_int
|
||||
P_int_err = (1./I_int)*np.sqrt((Q_int**2*Q_int_err**2 + U_int**2*U_int_err**2 + 2.*Q_int*U_int*QU_int_err)/(Q_int**2 + U_int**2) + ((Q_int/I_int)**2 + (U_int/I_int)**2)*I_int_err**2 - 2.*(Q_int/I_int)*IQ_int_err - 2.*(U_int/I_int)*IU_int_err)
|
||||
|
||||
PA_int = princ_angle((90./np.pi)*np.arctan2(U_int,Q_int))
|
||||
PA_int_err = (90./(np.pi*(Q_int**2 + U_int**2)))*np.sqrt(U_int**2*Q_int_err**2 + Q_int**2*U_int_err**2 - 2.*Q_int*U_int*QU_int_err)
|
||||
|
||||
# Compute integrated parameters and associated errors for all pixels
|
||||
#Get integrated values from header
|
||||
n_pix = stkI.data[data_mask].size
|
||||
I_diluted = stkI.data[data_mask].sum()
|
||||
Q_diluted = stkQ.data[data_mask].sum()
|
||||
U_diluted = stkU.data[data_mask].sum()
|
||||
I_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[0,0][data_mask]))
|
||||
Q_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[1,1][data_mask]))
|
||||
U_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[2,2][data_mask]))
|
||||
IQ_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[0,1][data_mask]**2))
|
||||
IU_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[0,2][data_mask]**2))
|
||||
QU_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(stk_cov.data[1,2][data_mask]**2))
|
||||
|
||||
P_diluted = np.sqrt(Q_diluted**2+U_diluted**2)/I_diluted
|
||||
P_diluted_err = (1./I_diluted)*np.sqrt((Q_diluted**2*Q_diluted_err**2 + U_diluted**2*U_diluted_err**2 + 2.*Q_diluted*U_diluted*QU_diluted_err)/(Q_diluted**2 + U_diluted**2) + ((Q_diluted/I_diluted)**2 + (U_diluted/I_diluted)**2)*I_diluted_err**2 - 2.*(Q_diluted/I_diluted)*IQ_diluted_err - 2.*(U_diluted/I_diluted)*IU_diluted_err)
|
||||
#P_diluted_err = np.sqrt(2/n_pix)*100.
|
||||
|
||||
PA_diluted = princ_angle((90./np.pi)*np.arctan2(U_diluted,Q_diluted))
|
||||
PA_diluted_err = (90./(np.pi*(Q_diluted**2 + U_diluted**2)))*np.sqrt(U_diluted**2*Q_diluted_err**2 + Q_diluted**2*U_diluted_err**2 - 2.*Q_diluted*U_diluted*QU_diluted_err)
|
||||
#PA_diluted_err = P_diluted_err/(2.*P_diluted)*180./np.pi
|
||||
P_diluted = Stokes[0].header['P_int']
|
||||
P_diluted_err = Stokes[0].header['P_int_err']
|
||||
PA_diluted = Stokes[0].header['PA_int']
|
||||
PA_diluted_err = Stokes[0].header['PA_int_err']
|
||||
|
||||
ax.annotate(r"$F_{{\lambda}}^{{int}}$({0:.0f} $\AA$) = {1} $ergs \cdot cm^{{-2}} \cdot s^{{-1}} \cdot \AA^{{-1}}$".format(pivot_wav,sci_not(I_diluted*convert_flux,I_diluted_err*convert_flux,2))+"\n"+r"$P^{{int}}$ = {0:.1f} $\pm$ {1:.1f} %".format(P_diluted*100.,P_diluted_err*100.)+"\n"+r"$\theta_{{P}}^{{int}}$ = {0:.1f} $\pm$ {1:.1f} °".format(PA_diluted,PA_diluted_err), color='white', fontsize=16, xy=(0.01, 0.92), xycoords='axes fraction')
|
||||
|
||||
|
||||
@@ -67,6 +67,17 @@ globals()['theta'] = np.array([180.*np.pi/180., 60.*np.pi/180., 120.*np.pi/180.]
|
||||
globals()['sigma_theta'] = np.array([3.*np.pi/180., 3.*np.pi/180., 3.*np.pi/180.])
|
||||
|
||||
|
||||
def princ_angle(ang):
|
||||
"""
|
||||
Return the principal angle in the 0-180° quadrant.
|
||||
"""
|
||||
while ang < 0.:
|
||||
ang += 180.
|
||||
while ang > 180.:
|
||||
ang -= 180.
|
||||
return ang
|
||||
|
||||
|
||||
def get_row_compressor(old_dimension, new_dimension, operation='sum'):
|
||||
"""
|
||||
Return the matrix that allows to compress an array from an old dimension of
|
||||
@@ -454,19 +465,9 @@ def get_error(data_array, headers, sub_shape=(15,15), display=False,
|
||||
#flatfielding uncertainties
|
||||
#estimated to less than 3%
|
||||
err_flat = data_array[i]*0.03
|
||||
if i==0:
|
||||
pr = data_array[i] > 0.
|
||||
print("Background error = {0:2.2f}%".format(np.median(error_array[i][pr]/data_array[i][pr]*100.)))
|
||||
print("Wavelength polarizer dependence error = {0:2.2f}%".format(np.median(err_wav[pr]/data_array[i][pr]*100.)))
|
||||
print("PSF polarizer difference error = {0:2.2f}%".format(np.median(err_psf[pr]/data_array[i][pr]*100.)))
|
||||
print("Flatfield polarizer difference error = {0:2.2f}%".format(np.median(err_flat[pr]/data_array[i][pr]*100.)))
|
||||
|
||||
error_array[i] = np.sqrt(error_array[i]**2 + err_wav**2 + err_psf**2 + err_flat**2)
|
||||
|
||||
if i==0:
|
||||
pr = data_array[i] > 0.
|
||||
print("Total estimated error = {0:2.2f}%".format(np.median(error_array[i][pr]/data_array[i][pr]*100.)))
|
||||
|
||||
background[i] = sub_image.sum()
|
||||
if (data_array[i] < 0.).any():
|
||||
print(data_array[i])
|
||||
@@ -610,11 +611,6 @@ def rebin_array(data_array, error_array, headers, pxsize, scale,
|
||||
new_error[mask] = np.sqrt(bin_ndarray(error**2*image,
|
||||
new_shape=new_shape, operation='sum')[mask]/sum_image[mask])
|
||||
rebinned_error.append(np.sqrt(rms_image**2 + new_error**2))
|
||||
if i==0:
|
||||
pr = rebin_data > 0.
|
||||
print("Rebin RMS error = {0:2.2f}%".format(np.median(rms_image[pr]/rebin_data[pr]*100.)))
|
||||
print("Rebin weigthed sum squarred error = {0:2.2f}%".format(np.median(new_error[pr]/rebin_data[pr]*100.)))
|
||||
print("Total rebin error = {0:2.2f}%".format(np.median(rebinned_error[0][pr]/rebin_data[pr]*100.)))
|
||||
|
||||
# Update header
|
||||
w = w.slice((np.s_[::Dxy[0]], np.s_[::Dxy[1]]))
|
||||
@@ -759,18 +755,8 @@ def align_data(data_array, headers, error_array=None, upsample_factor=1.,
|
||||
shifted_image = sc_shift(rescaled_image[i], prec_shift, cval=0.)
|
||||
error_shift = np.abs(rescaled_image[i] - shifted_image)/2.
|
||||
#sum quadratically the errors
|
||||
if i==0:
|
||||
pr = rescaled_image[0] > 0.
|
||||
print("Rescaled (aligned) error = {0:2.2f}%".format(np.median(rescaled_error[0][pr]/rescaled_image[0][pr]*100.)))
|
||||
print("Shift error = {0:2.2f}%".format(np.median(error_shift[pr]/rescaled_image[0][pr]*100.)))
|
||||
|
||||
rescaled_error[i] = np.sqrt(rescaled_error[i]**2 + error_shift**2)
|
||||
|
||||
if i==0:
|
||||
pr = rescaled_image[0] > 0.
|
||||
print("Total align error = {0:2.2f}%".format(np.median(rescaled_error[0][pr]/rescaled_image[0][pr]*100.)))
|
||||
#rescaled_error[i][1-rescaled_mask[i]] = 0.
|
||||
|
||||
shifts.append(shift)
|
||||
errors.append(error)
|
||||
|
||||
@@ -890,9 +876,6 @@ def smooth_data(data_array, error_array, data_mask, headers, FWHM=1.,
|
||||
else:
|
||||
raise ValueError("{} is not a valid smoothing option".format(smoothing))
|
||||
|
||||
pr = smoothed > 0.
|
||||
print("Smoothed error = {0:2.2f}%".format(np.median(error[pr]/smoothed[pr]*100.)))
|
||||
|
||||
return smoothed, error
|
||||
|
||||
|
||||
@@ -997,9 +980,6 @@ def polarizer_avg(data_array, error_array, data_mask, headers, FWHM=None,
|
||||
err120 = np.sqrt(np.sum(err120_array**2,axis=0))
|
||||
polerr_array = np.array([err0, err60, err120])
|
||||
|
||||
pr = pol0 > 0.
|
||||
print("Summed POL0 error = {0:2.2f}%".format(np.median(err0[pr]/pol0[pr]*100.)))
|
||||
|
||||
# Update headers
|
||||
for header in headers:
|
||||
if header['filtnam1']=='POL0':
|
||||
@@ -1034,9 +1014,6 @@ def polarizer_avg(data_array, error_array, data_mask, headers, FWHM=None,
|
||||
polarizer_cov[1,1] = err60**2
|
||||
polarizer_cov[2,2] = err120**2
|
||||
|
||||
pr = pol0 > 0.
|
||||
print("Total POL0 error = {0:2.2f}%".format(np.median(err0[pr]/pol0[pr]*100.)))
|
||||
|
||||
return polarizer_array, polarizer_cov
|
||||
|
||||
|
||||
@@ -1191,25 +1168,11 @@ def compute_Stokes(data_array, error_array, data_mask, headers,
|
||||
s_Q2_axis = np.sum([dQ_dtheta[i]**2 * sigma_theta[i]**2 for i in range(len(sigma_theta))],axis=0)
|
||||
s_U2_axis = np.sum([dU_dtheta[i]**2 * sigma_theta[i]**2 for i in range(len(sigma_theta))],axis=0)
|
||||
|
||||
prI = I_stokes > 0.
|
||||
print("Propagated I_stokes error = {0:2.2f}%".format(np.median(np.sqrt(Stokes_cov[0,0][prI])/I_stokes[prI]*100.)))
|
||||
print("Axis I_stokes error = {0:2.2f}%".format(np.median(np.sqrt(s_I2_axis[prI])/I_stokes[prI]*100.)))
|
||||
prQ = Q_stokes > 0.
|
||||
print("Propagated Q_stokes error = {0:2.2f}%".format(np.median(np.sqrt(Stokes_cov[1,1][prQ])/Q_stokes[prQ]*100.)))
|
||||
print("Axis Q_stokes error = {0:2.2f}%".format(np.median(np.sqrt(s_Q2_axis[prQ])/Q_stokes[prQ]*100.)))
|
||||
prU = U_stokes > 0.
|
||||
print("Propagated U_stokes error = {0:2.2f}%".format(np.median(np.sqrt(Stokes_cov[2,2][prU])/U_stokes[prU]*100.)))
|
||||
print("Axis U_stokes error = {0:2.2f}%".format(np.median(np.sqrt(s_U2_axis[prU])/U_stokes[prU]*100.)))
|
||||
|
||||
# Add quadratically the uncertainty to the Stokes covariance matrix
|
||||
Stokes_cov[0,0] += s_I2_axis
|
||||
Stokes_cov[1,1] += s_Q2_axis
|
||||
Stokes_cov[2,2] += s_U2_axis
|
||||
|
||||
print("Total I_stokes error = {0:2.2f}%".format(np.median(np.sqrt(Stokes_cov[0,0][prI])/I_stokes[prI]*100.)))
|
||||
print("Total Q_stokes error = {0:2.2f}%".format(np.median(np.sqrt(Stokes_cov[1,1][prQ])/Q_stokes[prQ]*100.)))
|
||||
print("Total U_stokes error = {0:2.2f}%".format(np.median(np.sqrt(Stokes_cov[2,2][prU])/U_stokes[prU]*100.)))
|
||||
|
||||
if not(FWHM is None) and (smoothing.lower() in ['gaussian_after','gauss_after']):
|
||||
Stokes_array = np.array([I_stokes, Q_stokes, U_stokes])
|
||||
Stokes_error = np.array([np.sqrt(Stokes_cov[i,i]) for i in range(3)])
|
||||
@@ -1220,6 +1183,31 @@ def compute_Stokes(data_array, error_array, data_mask, headers,
|
||||
|
||||
I_stokes, Q_stokes, U_stokes = Stokes_array
|
||||
Stokes_cov[0,0], Stokes_cov[1,1], Stokes_cov[2,2] = Stokes_error**2
|
||||
|
||||
#Compute integrated values for P, PA before any rotation
|
||||
mask = (1-data_mask).astype(bool)
|
||||
n_pix = I_stokes[mask].size
|
||||
I_diluted = I_stokes[mask].sum()
|
||||
Q_diluted = Q_stokes[mask].sum()
|
||||
U_diluted = U_stokes[mask].sum()
|
||||
I_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(Stokes_cov[0,0][mask]))
|
||||
Q_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(Stokes_cov[1,1][mask]))
|
||||
U_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(Stokes_cov[2,2][mask]))
|
||||
IQ_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(Stokes_cov[0,1][mask]**2))
|
||||
IU_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(Stokes_cov[0,2][mask]**2))
|
||||
QU_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(Stokes_cov[1,2][mask]**2))
|
||||
|
||||
P_diluted = np.sqrt(Q_diluted**2+U_diluted**2)/I_diluted
|
||||
P_diluted_err = (1./I_diluted)*np.sqrt((Q_diluted**2*Q_diluted_err**2 + U_diluted**2*U_diluted_err**2 + 2.*Q_diluted*U_diluted*QU_diluted_err)/(Q_diluted**2 + U_diluted**2) + ((Q_diluted/I_diluted)**2 + (U_diluted/I_diluted)**2)*I_diluted_err**2 - 2.*(Q_diluted/I_diluted)*IQ_diluted_err - 2.*(U_diluted/I_diluted)*IU_diluted_err)
|
||||
|
||||
PA_diluted = princ_angle((90./np.pi)*np.arctan2(U_diluted,Q_diluted))
|
||||
PA_diluted_err = (90./(np.pi*(Q_diluted**2 + U_diluted**2)))*np.sqrt(U_diluted**2*Q_diluted_err**2 + Q_diluted**2*U_diluted_err**2 - 2.*Q_diluted*U_diluted*QU_diluted_err)
|
||||
|
||||
for header in headers:
|
||||
header['P_int'] = (P_diluted, 'Integrated polarization degree')
|
||||
header['P_int_err'] = (P_diluted_err, 'Integrated polarization degree error')
|
||||
header['PA_int'] = (PA_diluted, 'Integrated polarization angle')
|
||||
header['PA_int_err'] = (PA_diluted_err, 'Integrated polarization angle error')
|
||||
|
||||
return I_stokes, Q_stokes, U_stokes, Stokes_cov
|
||||
|
||||
@@ -1317,11 +1305,6 @@ def compute_pol(I_stokes, Q_stokes, U_stokes, Stokes_cov, headers):
|
||||
s_P_P[np.isnan(s_P_P)] = fmax
|
||||
s_PA_P[np.isnan(s_PA_P)] = fmax
|
||||
|
||||
prP = P > 0.
|
||||
prPA = PA > 0.
|
||||
print("Propagated P error = {0:2.2f}%".format(np.median(s_P[prP]/P[prP]*100.)))
|
||||
print("Propagated PA error = {0:2.2f}%".format(np.median(s_PA[prPA]/PA[prPA]*100.)))
|
||||
|
||||
return P, debiased_P, s_P, s_P_P, PA, s_PA, s_PA_P
|
||||
|
||||
|
||||
@@ -1450,12 +1433,31 @@ def rotate_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers,
|
||||
new_U_stokes[np.isnan(new_U_stokes)] = 0.
|
||||
new_Stokes_cov[np.isnan(new_Stokes_cov)] = fmax
|
||||
|
||||
prI = new_I_stokes > 0.
|
||||
prQ = new_Q_stokes > 0.
|
||||
prU = new_U_stokes > 0.
|
||||
print("Propagated rotated I_stokes error = {0:2.2f}%".format(np.median(np.sqrt(new_Stokes_cov[0,0][prI])/new_I_stokes[prI]*100.)))
|
||||
print("Propagated rotated Q_stokes error = {0:2.2f}%".format(np.median(np.sqrt(new_Stokes_cov[1,1][prQ])/new_Q_stokes[prQ]*100.)))
|
||||
print("Propagated rotated U_stokes error = {0:2.2f}%".format(np.median(np.sqrt(new_Stokes_cov[2,2][prU])/new_U_stokes[prU]*100.)))
|
||||
#Compute updated integrated values for P, PA
|
||||
mask = (1-new_data_mask).astype(bool)
|
||||
n_pix = new_I_stokes[mask].size
|
||||
I_diluted = new_I_stokes[mask].sum()
|
||||
Q_diluted = new_Q_stokes[mask].sum()
|
||||
U_diluted = new_U_stokes[mask].sum()
|
||||
I_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(new_Stokes_cov[0,0][mask]))
|
||||
Q_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(new_Stokes_cov[1,1][mask]))
|
||||
U_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(new_Stokes_cov[2,2][mask]))
|
||||
IQ_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(new_Stokes_cov[0,1][mask]**2))
|
||||
IU_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(new_Stokes_cov[0,2][mask]**2))
|
||||
QU_diluted_err = np.sqrt(n_pix)*np.sqrt(np.sum(new_Stokes_cov[1,2][mask]**2))
|
||||
|
||||
P_diluted = np.sqrt(Q_diluted**2+U_diluted**2)/I_diluted
|
||||
P_diluted_err = (1./I_diluted)*np.sqrt((Q_diluted**2*Q_diluted_err**2 + U_diluted**2*U_diluted_err**2 + 2.*Q_diluted*U_diluted*QU_diluted_err)/(Q_diluted**2 + U_diluted**2) + ((Q_diluted/I_diluted)**2 + (U_diluted/I_diluted)**2)*I_diluted_err**2 - 2.*(Q_diluted/I_diluted)*IQ_diluted_err - 2.*(U_diluted/I_diluted)*IU_diluted_err)
|
||||
|
||||
PA_diluted = princ_angle((90./np.pi)*np.arctan2(U_diluted,Q_diluted))
|
||||
PA_diluted_err = (90./(np.pi*(Q_diluted**2 + U_diluted**2)))*np.sqrt(U_diluted**2*Q_diluted_err**2 + Q_diluted**2*U_diluted_err**2 - 2.*Q_diluted*U_diluted*QU_diluted_err)
|
||||
|
||||
for header in new_headers:
|
||||
header['P_int'] = (P_diluted, 'Integrated polarization degree')
|
||||
header['P_int_err'] = (P_diluted_err, 'Integrated polarization degree error')
|
||||
header['PA_int'] = (PA_diluted, 'Integrated polarization angle')
|
||||
header['PA_int_err'] = (PA_diluted_err, 'Integrated polarization angle error')
|
||||
|
||||
|
||||
return new_I_stokes, new_Q_stokes, new_U_stokes, new_Stokes_cov, new_headers, new_data_mask
|
||||
|
||||
@@ -1496,9 +1498,6 @@ def rotate_data(data_array, error_array, data_mask, headers, ang):
|
||||
cval=0.))
|
||||
new_error_array.append(sc_rotate(error_array[i], ang, order=5, reshape=False,
|
||||
cval=error_array.mean()))
|
||||
if i==0:
|
||||
pr = new_data_array[0] > 0.
|
||||
print("Rotated data error = {0:2.2f}%".format(np.median(new_error_array[0][pr]/new_data_array[0][pr]*100.)))
|
||||
new_data_array = np.array(new_data_array)
|
||||
new_data_mask = sc_rotate(data_mask, ang, order=5, reshape=False, cval=True)
|
||||
new_error_array = np.array(new_error_array)
|
||||
|
||||
@@ -3,7 +3,7 @@ from astropy.io import fits
|
||||
import numpy as np
|
||||
from plots import overplot_maps
|
||||
|
||||
Stokes_UV = fits.open("../../data/IC5063_x3nl030/IC5063_FOC_combine_FWHM020_pol_wae.fits")
|
||||
Stokes_UV = fits.open("../../data/IC5063_x3nl030/IC5063_FOC_combine_FWHM020_pol.fits")
|
||||
Stokes_18GHz = fits.open("../../data/IC5063_x3nl030/radio/IC5063.18GHz.fits")
|
||||
Stokes_24GHz = fits.open("../../data/IC5063_x3nl030/radio/IC5063.24GHz.fits")
|
||||
|
||||
@@ -12,9 +12,9 @@ levelsMorganti = np.array([1.,2.,3.,8.,16.,32.,64.,128.])
|
||||
#levels18GHz = np.array([0.6, 1.5, 3, 6, 12, 24, 48, 96])/100.*Stokes_18GHz[0].data.max()
|
||||
levels18GHz = levelsMorganti*0.28*1e-3
|
||||
A = overplot_maps(Stokes_UV, Stokes_18GHz)
|
||||
A.plot(levels=levels18GHz, SNRp_cut=10.0, SNRi_cut=100.0, savename='../../plots/IC5063_x3nl030/18GHz_overplot_forced_maxUV.png')
|
||||
A.plot(levels=levels18GHz, SNRp_cut=10.0, SNRi_cut=100.0, savename='../../plots/IC5063_x3nl030/18GHz_overplot.png')
|
||||
|
||||
#levels24GHz = np.array([1.,1.5, 3, 6, 12, 24, 48, 96])/100.*Stokes_24GHz[0].data.max()
|
||||
levels24GHz = levelsMorganti*0.46*1e-3
|
||||
B = overplot_maps(Stokes_UV, Stokes_24GHz)
|
||||
B.plot(levels=levels24GHz, SNRp_cut=10.0, SNRi_cut=100.0, savename='../../plots/IC5063_x3nl030/24GHz_overplot_forced_maxUV.png')
|
||||
B.plot(levels=levels24GHz, SNRp_cut=10.0, SNRi_cut=100.0, savename='../../plots/IC5063_x3nl030/24GHz_overplot.png')
|
||||
|
||||
Reference in New Issue
Block a user