correct a bug where rotation doesn't update header when wcs.pc is identity

This commit is contained in:
Thibault Barnouin
2022-07-11 17:36:30 +02:00
parent 2c5d4212ac
commit e61984ae3d
55 changed files with 161 additions and 161 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 MiB

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 546 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 966 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 515 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 918 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 908 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 MiB

View File

@@ -16,94 +16,99 @@ from lib.deconvolve import from_file_psf
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from astropy.wcs import WCS from astropy.wcs import WCS
##### User inputs
## Input and output locations
#globals()['data_folder'] = "../data/NGC1068_x274020/"
#globals()['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/IC5063_x3nl030/"
#globals()['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/NGC1068_x14w010/"
#globals()['infiles'] = ['x14w0101t_c0f.fits','x14w0102t_c0f.fits','x14w0103t_c0f.fits',
# 'x14w0104t_c0f.fits','x14w0105p_c0f.fits','x14w0106t_c0f.fits']
#globals()['plots_folder'] = "../plots/NGC1068_x14w010/"
#globals()['data_folder'] = "../data/3C405_x136060/"
#globals()['infiles'] = ['x1360601t_c0f.fits','x1360602t_c0f.fits','x1360603t_c0f.fits']
#globals()['plots_folder'] = "../plots/3C405_x136060/"
#globals()['data_folder'] = "../data/CygnusA_x43w0/"
#globals()['infiles'] = ['x43w0101r_c0f.fits', 'x43w0102r_c0f.fits', 'x43w0103r_c0f.fits',
# 'x43w0104r_c0f.fits', 'x43w0105r_c0f.fits', 'x43w0106r_c0f.fits',
# 'x43w0107r_c0f.fits', 'x43w0108r_c0f.fits', 'x43w0109r_c0f.fits']
#globals()['infiles'] = ['x43w0201r_c0f.fits', 'x43w0202r_c0f.fits', 'x43w0203r_c0f.fits',
# 'x43w0204r_c0f.fits', 'x43w0205r_c0f.fits', 'x43w0206r_c0f.fits']
#globals()['plots_folder'] = "../plots/CygnusA_x43w0/"
#globals()['data_folder'] = "../data/3C109_x3mc010/"
#globals()['infiles'] = ['x3mc0101m_c0f.fits','x3mc0102m_c0f.fits','x3mc0103m_c0f.fits']
#globals()['plots_folder'] = "../plots/3C109_x3mc010/"
#globals()['data_folder'] = "../data/MKN463_x2rp030/"
#globals()['infiles'] = ['x2rp0201t_c0f.fits', 'x2rp0202t_c0f.fits', 'x2rp0203t_c0f.fits',
# 'x2rp0204t_c0f.fits', 'x2rp0205t_c0f.fits', 'x2rp0206t_c0f.fits',
# 'x2rp0207t_c0f.fits', 'x2rp0301t_c0f.fits', 'x2rp0302t_c0f.fits',
# 'x2rp0303t_c0f.fits', 'x2rp0304t_c0f.fits', 'x2rp0305t_c0f.fits',
# 'x2rp0306t_c0f.fits', 'x2rp0307t_c0f.fits']
#globals()['plots_folder'] = "../plots/MKN463_x2rp030/"
#globals()['data_folder'] = "../data/PG1630+377_x39510/"
#globals()['infiles'] = ['x3990201m_c0f.fits', 'x3990205m_c0f.fits', 'x3995101r_c0f.fits',
# 'x3995105r_c0f.fits', 'x3995109r_c0f.fits', 'x3995201r_c0f.fits',
# 'x3995205r_c0f.fits', 'x3990202m_c0f.fits', 'x3990206m_c0f.fits',
# 'x3995102r_c0f.fits', 'x3995106r_c0f.fits', 'x399510ar_c0f.fits',
# 'x3995202r_c0f.fits','x3995206r_c0f.fits']
#globals()['plots_folder'] = "../plots/PG1630+377_x39510/"
#globals()['data_folder'] = "../data/MKN3_x3nl010/"
#globals()['infiles'] = ['x3nl0101r_c0f.fits','x3nl0102r_c0f.fits','x3nl0103r_c0f.fits']
#globals()['plots_folder'] = "../plots/MKN3_x3nl010/"
#globals()['data_folder'] = "../data/MKN3_x3md010/"
#globals()['infiles'] = ['x3md0101r_c0f.fits', 'x3md0102r_c0f.fits', 'x3md0103r_c0f.fits']
#globals()['infiles'] = ['x3md0104r_c0f.fits', 'x3md0105r_c0f.fits', 'x3md0106r_c0f.fits']
#globals()['plots_folder'] = "../plots/MKN3_x3md010/"
#globals()['data_folder'] = "../data/MKN78_x3nl020/"
#globals()['infiles'] = ['x3nl0201r_c0f.fits','x3nl0202r_c0f.fits','x3nl0203r_c0f.fits']
#globals()['plots_folder'] = "../plots/MKN78_x3nl020/"
#globals()['data_folder'] = "../data/3C273_x0u20/"
#globals()['infiles'] = ['x0u20101t_c0f.fits','x0u20102t_c0f.fits','x0u20103t_c0f.fits',
# 'x0u20104t_c0f.fits','x0u20105t_c0f.fits','x0u20106t_c0f.fits',
# 'x0u20201t_c0f.fits','x0u20202t_c0f.fits','x0u20203t_c0f.fits',
# 'x0u20204t_c0f.fits','x0u20205t_c0f.fits','x0u20206t_c0f.fits',
# 'x0u20301t_c0f.fits','x0u20302t_c0f.fits','x0u20303t_c0f.fits',
# 'x0u20304t_c0f.fits','x0u20305t_c0f.fits','x0u20306t_c0f.fits']
#globals()['plots_folder'] = "../plots/3C273_x0u20/"
#BEWARE: 5 observations separated by 1 year each (1995, 1996, 1997, 1998, 1999)
#globals()['data_folder'] = "../data/M87/POS1/"
#globals()['infiles'] = ['x2py010ct_c0f.fits','x2py010dt_c0f.fits','x2py010et_c0f.fits','x2py010ft_c0f.fits'] #1995
#globals()['infiles'] = ['x3be010ct_c0f.fits','x3be010dt_c0f.fits','x3be010et_c0f.fits','x3be010ft_c0f.fits'] #1996
#globals()['infiles'] = ['x43r010km_c0f.fits','x43r010mm_c0f.fits','x43r010om_c0f.fits','x43r010rm_c0f.fits'] #1997
#globals()['infiles'] = ['x43r110kr_c0f.fits','x43r110mr_c0f.fits','x43r110or_c0f.fits','x43r110rr_c0f.fits'] #1998
#globals()['infiles'] = ['x43r210kr_c0f.fits','x43r210mr_c0f.fits','x43r210or_c0f.fits','x43r210rr_c0f.fits'] #1999
#globals()['plots_folder'] = "../plots/M87/POS1/"
#BEWARE: 5 observations separated by 1 year each (1995, 1996, 1997, 1998, 1999)
globals()['data_folder'] = "../data/M87/POS3/"
globals()['infiles'] = ['x2py030at_c0f.fits','x2py030bt_c0f.fits','x2py030ct_c0f.fits','x2py0309t_c0f.fits'] #1995
#globals()['infiles'] = ['x3be030at_c0f.fits','x3be030bt_c0f.fits','x3be030ct_c0f.fits','x3be0309t_c0f.fits'] #1996
#globals()['infiles'] = ['x43r030em_c0f.fits','x43r030gm_c0f.fits','x43r030im_c0f.fits','x43r030lm_c0f.fits'] #1997
#globals()['infiles'] = ['x43r130er_c0f.fits','x43r130fr_c0f.fits','x43r130ir_c0f.fits','x43r130lr_c0f.fits'] #1998
#globals()['infiles'] = ['x43r230er_c0f.fits','x43r230fr_c0f.fits','x43r230ir_c0f.fits','x43r230lr_c0f.fits'] #1999
globals()['plots_folder'] = "../plots/M87/POS3/"
def main(): 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/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/NGC1068_x14w010/"
# infiles = ['x14w0101t_c0f.fits','x14w0102t_c0f.fits','x14w0103t_c0f.fits',
# 'x14w0104t_c0f.fits','x14w0105p_c0f.fits','x14w0106t_c0f.fits']
# globals()['plots_folder'] = "../plots/NGC1068_x14w010/"
# globals()['data_folder'] = "../data/3C405_x136060/"
# infiles = ['x1360601t_c0f.fits','x1360602t_c0f.fits','x1360603t_c0f.fits']
# globals()['plots_folder'] = "../plots/3C405_x136060/"
# globals()['data_folder'] = "../data/CygnusA_x43w0/"
# infiles = ['x43w0101r_c0f.fits', 'x43w0102r_c0f.fits', 'x43w0103r_c0f.fits',
# 'x43w0104r_c0f.fits', 'x43w0105r_c0f.fits', 'x43w0106r_c0f.fits',
# 'x43w0107r_c0f.fits', 'x43w0108r_c0f.fits', 'x43w0109r_c0f.fits']
# infiles = ['x43w0201r_c0f.fits', 'x43w0202r_c0f.fits', 'x43w0203r_c0f.fits',
# 'x43w0204r_c0f.fits', 'x43w0205r_c0f.fits', 'x43w0206r_c0f.fits']
# globals()['plots_folder'] = "../plots/CygnusA_x43w0/"
# globals()['data_folder'] = "../data/3C109_x3mc010/"
# infiles = ['x3mc0101m_c0f.fits','x3mc0102m_c0f.fits','x3mc0103m_c0f.fits']
# globals()['plots_folder'] = "../plots/3C109_x3mc010/"
# globals()['data_folder'] = "../data/MKN463_x2rp030/"
# infiles = ['x2rp0201t_c0f.fits', 'x2rp0202t_c0f.fits', 'x2rp0203t_c0f.fits',
# 'x2rp0204t_c0f.fits', 'x2rp0205t_c0f.fits', 'x2rp0206t_c0f.fits',
# 'x2rp0207t_c0f.fits', 'x2rp0301t_c0f.fits', 'x2rp0302t_c0f.fits',
# 'x2rp0303t_c0f.fits', 'x2rp0304t_c0f.fits', 'x2rp0305t_c0f.fits',
# 'x2rp0306t_c0f.fits', 'x2rp0307t_c0f.fits']
# globals()['plots_folder'] = "../plots/MKN463_x2rp030/"
# globals()['data_folder'] = "../data/PG1630+377_x39510/"
# infiles = ['x3990201m_c0f.fits', 'x3990205m_c0f.fits', 'x3995101r_c0f.fits',
# 'x3995105r_c0f.fits', 'x3995109r_c0f.fits', 'x3995201r_c0f.fits',
# 'x3995205r_c0f.fits', 'x3990202m_c0f.fits', 'x3990206m_c0f.fits',
# 'x3995102r_c0f.fits', 'x3995106r_c0f.fits', 'x399510ar_c0f.fits',
# 'x3995202r_c0f.fits','x3995206r_c0f.fits']
# globals()['plots_folder'] = "../plots/PG1630+377_x39510/"
# globals()['data_folder'] = "../data/MKN3_x3nl010/"
# infiles = ['x3nl0101r_c0f.fits','x3nl0102r_c0f.fits','x3nl0103r_c0f.fits']
# globals()['plots_folder'] = "../plots/MKN3_x3nl010/"
# globals()['data_folder'] = "../data/MKN3_x3md010/"
# infiles = ['x3md0101r_c0f.fits', 'x3md0102r_c0f.fits', 'x3md0103r_c0f.fits']
# infiles = ['x3md0104r_c0f.fits', 'x3md0105r_c0f.fits', 'x3md0106r_c0f.fits']
# globals()['plots_folder'] = "../plots/MKN3_x3md010/"
# globals()['data_folder'] = "../data/MKN78_x3nl020/"
# infiles = ['x3nl0201r_c0f.fits','x3nl0202r_c0f.fits','x3nl0203r_c0f.fits']
# globals()['plots_folder'] = "../plots/MKN78_x3nl020/"
# globals()['data_folder'] = "../data/3C273_x0u20/"
# infiles = ['x0u20101t_c0f.fits','x0u20102t_c0f.fits','x0u20103t_c0f.fits','x0u20104t_c0f.fits','x0u20105t_c0f.fits','x0u20106t_c0f.fits','x0u20201t_c0f.fits','x0u20202t_c0f.fits','x0u20203t_c0f.fits','x0u20204t_c0f.fits','x0u20205t_c0f.fits','x0u20206t_c0f.fits','x0u20301t_c0f.fits','x0u20302t_c0f.fits','x0u20303t_c0f.fits','x0u20304t_c0f.fits','x0u20305t_c0f.fits','x0u20306t_c0f.fits']
# globals()['plots_folder'] = "../plots/3C273_x0u20/"
#BEWARE: 5 observations separated by 1 year each (1995, 1996, 1997, 1998, 1999)
globals()['data_folder'] = "../data/M87/POS1/"
# infiles = ['x2py010ct_c0f.fits','x2py010dt_c0f.fits','x2py010et_c0f.fits','x2py010ft_c0f.fits'] #1995
# infiles = ['x3be010ct_c0f.fits','x3be010dt_c0f.fits','x3be010et_c0f.fits','x3be010ft_c0f.fits'] #1996
# infiles = ['x43r010km_c0f.fits','x43r010mm_c0f.fits','x43r010om_c0f.fits','x43r010rm_c0f.fits'] #1997
# infiles = ['x43r110kr_c0f.fits','x43r110mr_c0f.fits','x43r110or_c0f.fits','x43r110rr_c0f.fits'] #1998
infiles = ['x43r210kr_c0f.fits','x43r210mr_c0f.fits','x43r210or_c0f.fits','x43r210rr_c0f.fits'] #1999
globals()['plots_folder'] = "../plots/M87/POS1/"
#BEWARE: 5 observations separated by 1 year each (1995, 1996, 1997, 1998, 1999)
# globals()['data_folder'] = "../data/M87/POS3/"
# infiles = ['x2py030at_c0f.fits','x2py030bt_c0f.fits','x2py030ct_c0f.fits','x2py0309t_c0f.fits'] #1995
# infiles = ['x3be030at_c0f.fits','x3be030bt_c0f.fits','x3be030ct_c0f.fits','x3be0309t_c0f.fits'] #1996
# infiles = ['x43r030em_c0f.fits','x43r030gm_c0f.fits','x43r030im_c0f.fits','x43r030lm_c0f.fits'] #1997
# infiles = ['x43r130er_c0f.fits','x43r130fr_c0f.fits','x43r130ir_c0f.fits','x43r130lr_c0f.fits'] #1998
# infiles = ['x43r230er_c0f.fits','x43r230fr_c0f.fits','x43r230ir_c0f.fits','x43r230lr_c0f.fits'] #1999
# globals()['plots_folder'] = "../plots/M87/POS3/"
## Reduction parameters ## Reduction parameters
# Deconvolution # Deconvolution
deconvolve = False deconvolve = False
@@ -123,7 +128,7 @@ def main():
# Data binning # Data binning
rebin = True rebin = True
if rebin: if rebin:
pxsize = 0.20 pxsize = 0.05
px_scale = 'arcsec' #pixel, arcsec or full px_scale = 'arcsec' #pixel, arcsec or full
rebin_operation = 'sum' #sum or average rebin_operation = 'sum' #sum or average
# Alignement # Alignement
@@ -131,7 +136,7 @@ def main():
display_data = False display_data = False
# Smoothing # Smoothing
smoothing_function = 'combine' #gaussian_after, weighted_gaussian_after, gaussian, weighted_gaussian or combine smoothing_function = 'combine' #gaussian_after, weighted_gaussian_after, gaussian, weighted_gaussian or combine
smoothing_FWHM = 0.20 #If None, no smoothing is done smoothing_FWHM = 0.07 #If None, no smoothing is done
smoothing_scale = 'arcsec' #pixel or arcsec smoothing_scale = 'arcsec' #pixel or arcsec
# Rotation # Rotation
rotate_stokes = True #rotation to North convention can give erroneous results rotate_stokes = True #rotation to North convention can give erroneous results
@@ -140,8 +145,8 @@ def main():
crop = False #Crop to desired ROI crop = False #Crop to desired ROI
final_display = True final_display = True
# Polarization map output # Polarization map output
figname = 'M87_POS1_1999_FOC' #target/intrument name figname = 'M87_POS3_1995_FOC' #target/intrument name
figtype = '_combine_FWHM020' #additionnal informations figtype = '_combine_FWHM005' #additionnal informations
SNRp_cut = 3. #P measurments with SNR>3 SNRp_cut = 3. #P measurments with SNR>3
SNRi_cut = 30. #I measurments with SNR>30, which implies an uncertainty in P of 4.7%. SNRi_cut = 30. #I measurments with SNR>30, which implies an uncertainty in P of 4.7%.
step_vec = 0 #plot all vectors in the array. if step_vec = 2, then every other vector will be plotted step_vec = 0 #plot all vectors in the array. if step_vec = 2, then every other vector will be plotted
@@ -198,8 +203,7 @@ def main():
## Step 3: ## Step 3:
# Rotate images to have North up # Rotate images to have North up
if rotate_stokes: if rotate_stokes:
alpha = headers[0]['orientat'] I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers = proj_red.rotate_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers, SNRi_cut=None)
I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers = proj_red.rotate_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers, -alpha, SNRi_cut=None)
# Compute polarimetric parameters (polarization degree and angle). # Compute polarimetric parameters (polarization degree and angle).
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) 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)

View File

@@ -52,25 +52,20 @@ def get_obs_data(infiles, data_folder="", compute_flux=False):
new_wcs = wcs.WCS(header).deepcopy() new_wcs = wcs.WCS(header).deepcopy()
if new_wcs.wcs.has_cd() or (new_wcs.wcs.cdelt == np.array([1., 1.])).all(): if new_wcs.wcs.has_cd() or (new_wcs.wcs.cdelt == np.array([1., 1.])).all():
# Update WCS with relevant information # Update WCS with relevant information
HST_aper = 2400. # HST aperture in mm
f_ratio = header['f_ratio']
px_dim = np.array([25., 25.]) # Pixel dimension in µm
if header['pxformt'].lower() == 'zoom':
px_dim[0] = 50.
#new_cdelt = 206.3/3600.*px_dim/(f_ratio*HST_aper)
new_cdelt = np.abs(np.linalg.eig(new_wcs.wcs.cd)[0])
if new_wcs.wcs.has_cd(): if new_wcs.wcs.has_cd():
old_cd = new_wcs.wcs.cd old_cd = new_wcs.wcs.cd
del new_wcs.wcs.cd del new_wcs.wcs.cd
keys = list(new_wcs.to_header().keys())+['CD1_1','CD1_2','CD2_1','CD2_2'] keys = list(new_wcs.to_header().keys())+['CD1_1','CD1_2','CD2_1','CD2_2']
for key in keys: for key in keys:
header.remove(key, ignore_missing=True) header.remove(key, ignore_missing=True)
new_cdelt = np.linalg.eig(old_cd)[0]
elif (new_wcs.wcs.cdelt == np.array([1., 1.])).all() and \ elif (new_wcs.wcs.cdelt == np.array([1., 1.])).all() and \
(new_wcs.array_shape in [(512, 512),(1024,512),(512,1024),(1024,1024)]): (new_wcs.array_shape in [(512, 512),(1024,512),(512,1024),(1024,1024)]):
old_cd = new_wcs.wcs.pc old_cd = new_wcs.wcs.pc
new_wcs.wcs.pc = np.dot(old_cd, np.diag(1./new_cdelt)) new_wcs.wcs.pc = np.dot(old_cd, np.diag(1./new_cdelt))
new_wcs.wcs.cdelt = new_cdelt new_wcs.wcs.cdelt = new_cdelt
header.update(new_wcs.to_header()) for key, val in new_wcs.to_header().items():
header[key] = val
if compute_flux: if compute_flux:
for i in range(len(infiles)): for i in range(len(infiles)):

View File

@@ -462,8 +462,8 @@ class align_maps(object):
data = self.map[0].data data = self.map[0].data
other_data = self.other_map[0].data other_data = self.other_map[0].data
plt.rcParams.update({'font.size': 16}) plt.rcParams.update({'font.size': 10})
self.fig = plt.figure(figsize=(25,15)) self.fig = plt.figure(figsize=(10,10))
#Plot the UV map #Plot the UV map
self.ax1 = self.fig.add_subplot(121, projection=self.wcs_map) self.ax1 = self.fig.add_subplot(121, projection=self.wcs_map)
self.ax1.set_facecolor('k') self.ax1.set_facecolor('k')
@@ -522,8 +522,10 @@ class align_maps(object):
#Selection button #Selection button
self.axapply = self.fig.add_axes([0.80, 0.01, 0.1, 0.04]) self.axapply = self.fig.add_axes([0.80, 0.01, 0.1, 0.04])
self.bapply = Button(self.axapply, 'Apply reference') self.bapply = Button(self.axapply, 'Apply reference')
self.bapply.label.set_fontsize(8)
self.axreset = self.fig.add_axes([0.60, 0.01, 0.1, 0.04]) self.axreset = self.fig.add_axes([0.60, 0.01, 0.1, 0.04])
self.breset = Button(self.axreset, 'Leave as is') self.breset = Button(self.axreset, 'Leave as is')
self.breset.label.set_fontsize(8)
def get_aligned_wcs(self): def get_aligned_wcs(self):
return self.wcs_map, self.wcs_other return self.wcs_map, self.wcs_other
@@ -751,7 +753,8 @@ class overplot_pol(align_maps):
class align_pol(object): class align_pol(object):
def __init__(self, maps, **kwargs): def __init__(self, maps, **kwargs):
maps = np.array(maps) order = np.argsort(np.array([curr[0].header['mjd-obs'] for curr in maps]))
maps = np.array(maps)[order]
self.ref_map, self.other_maps = maps[0], maps[1:] self.ref_map, self.other_maps = maps[0], maps[1:]
self.wcs = WCS(self.ref_map[0].header) self.wcs = WCS(self.ref_map[0].header)
@@ -797,13 +800,16 @@ class align_pol(object):
plt.rcdefaults() plt.rcdefaults()
fig = plt.figure(figsize=(10,10)) fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection=wcs) ax = fig.add_subplot(111, projection=wcs)
ax.set(xlabel="Right Ascension (J2000)", ylabel="Declination (J2000)", facecolor='k') ax.set(xlabel="Right Ascension (J2000)", ylabel="Declination (J2000)", facecolor='k',
title="target {0:s} observed on {1:s}".format(curr_map[0].header['targname'], curr_map[0].header['date-obs']))
fig.subplots_adjust(hspace=0, wspace=0, right=0.9) fig.subplots_adjust(hspace=0, wspace=0, right=0.9)
cbar_ax = fig.add_axes([0.95, 0.12, 0.01, 0.75]) cbar_ax = fig.add_axes([0.95, 0.12, 0.01, 0.75])
if not ax_lim is None: if not ax_lim is None:
lim = np.concatenate([wcs.world_to_pixel(ax_lim[i]) for i in range(len(ax_lim))]) lim = np.concatenate([wcs.world_to_pixel(ax_lim[i]) for i in range(len(ax_lim))])
x_lim, y_lim = lim[0::2], lim[1::2] x_lim, y_lim = lim[0::2], lim[1::2]
print(x_lim[0], y_lim[0], wcs.pixel_to_world(x_lim[0], y_lim[0]))
print(x_lim[1], y_lim[1], wcs.pixel_to_world(x_lim[1], y_lim[1]))
ax.set(xlim=x_lim,ylim=y_lim) ax.set(xlim=x_lim,ylim=y_lim)
if v_lim is None: if v_lim is None:
@@ -856,9 +862,11 @@ class align_pol(object):
vmin, vmax = np.min([vmin, np.min(self.ref_map[0].data[self.ref_map[0].data > 0.])]), np.max([vmax, np.max(self.ref_map[0].data[self.ref_map[0].data > 0.])]) vmin, vmax = np.min([vmin, np.min(self.ref_map[0].data[self.ref_map[0].data > 0.])]), np.max([vmax, np.max(self.ref_map[0].data[self.ref_map[0].data > 0.])])
v_lim = np.array([vmin, vmax]) v_lim = np.array([vmin, vmax])
fig, ax = self.single_plot(self.ref_map, self.wcs, v_lim = v_lim, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, savename=savename, **kwargs) fig, ax = self.single_plot(self.ref_map, self.wcs, v_lim = v_lim, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, savename=savename+'_0', **kwargs)
x_lim, y_lim = ax.get_xlim(), ax.get_ylim() x_lim, y_lim = ax.get_xlim(), ax.get_ylim()
ax_lim = np.array([self.wcs.pixel_to_world(x_lim[i], y_lim[i]) for i in range(len(x_lim))]) ax_lim = np.array([self.wcs.pixel_to_world(x_lim[i], y_lim[i]) for i in range(len(x_lim))])
print(x_lim[0], y_lim[0], ax_lim[0])
print(x_lim[1], y_lim[1], ax_lim[1])
for i, curr_map in enumerate(self.other_maps): for i, curr_map in enumerate(self.other_maps):
self.single_plot(curr_map, self.wcs_other[i], v_lim=v_lim, ax_lim=ax_lim, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, savename=savename+'_'+str(i+1), **kwargs) self.single_plot(curr_map, self.wcs_other[i], v_lim=v_lim, ax_lim=ax_lim, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, savename=savename+'_'+str(i+1), **kwargs)

View File

@@ -651,7 +651,7 @@ def rebin_array(data_array, error_array, headers, pxsize, scale,
if scale.lower() in ['px', 'pixel']: if scale.lower() in ['px', 'pixel']:
Dxy = np.array([pxsize,]*2) Dxy = np.array([pxsize,]*2)
elif scale.lower() in ['arcsec','arcseconds']: elif scale.lower() in ['arcsec','arcseconds']:
Dxy = np.floor(pxsize/w.wcs.cdelt/3600.).astype(int) Dxy = np.floor(pxsize/np.abs(w.wcs.cdelt)/3600.).astype(int)
elif scale.lower() in ['full','integrate']: elif scale.lower() in ['full','integrate']:
Dxy = np.floor(image.shape).astype(int) Dxy = np.floor(image.shape).astype(int)
else: else:
@@ -1389,7 +1389,7 @@ def compute_pol(I_stokes, Q_stokes, U_stokes, Stokes_cov, headers):
def rotate_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers, def rotate_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers,
ang, SNRi_cut=None): ang=None, SNRi_cut=None):
""" """
Use scipy.ndimage.rotate to rotate I_stokes to an angle, and a rotation Use scipy.ndimage.rotate to rotate I_stokes to an angle, and a rotation
matrix to rotate Q, U of a given angle in degrees and update header matrix to rotate Q, U of a given angle in degrees and update header
@@ -1411,9 +1411,10 @@ def rotate_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers,
2D boolean array delimiting the data to work on. 2D boolean array delimiting the data to work on.
headers : header list headers : header list
List of headers corresponding to the reduced images. List of headers corresponding to the reduced images.
ang : float ang : float, optional
Rotation angle (in degrees) that should be applied to the Stokes Rotation angle (in degrees) that should be applied to the Stokes
parameters parameters. If None, will rotate to have North up.
Defaults to None.
SNRi_cut : float, optional SNRi_cut : float, optional
Cut that should be applied to the signal-to-noise ratio on I. Cut that should be applied to the signal-to-noise ratio on I.
Any SNR < SNRi_cut won't be displayed. If None, cut won't be applied. Any SNR < SNRi_cut won't be displayed. If None, cut won't be applied.
@@ -1450,6 +1451,11 @@ def rotate_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers,
U_stokes[i,j] = eps*np.sqrt(Stokes_cov[2,2][i,j]) U_stokes[i,j] = eps*np.sqrt(Stokes_cov[2,2][i,j])
#Rotate I_stokes, Q_stokes, U_stokes using rotation matrix #Rotate I_stokes, Q_stokes, U_stokes using rotation matrix
if ang is None:
ang = np.zeros((len(headers),))
for i,head in enumerate(headers):
ang[i] = -head['orientat']
ang = ang.mean()
alpha = ang*np.pi/180. alpha = ang*np.pi/180.
mrot = np.array([[1., 0., 0.], mrot = np.array([[1., 0., 0.],
[0., np.cos(2.*alpha), np.sin(2.*alpha)], [0., np.cos(2.*alpha), np.sin(2.*alpha)],
@@ -1490,33 +1496,22 @@ def rotate_Stokes(I_stokes, Q_stokes, U_stokes, Stokes_cov, data_mask, headers,
#Update headers to new angle #Update headers to new angle
new_headers = [] new_headers = []
mrot = np.array([[np.cos(-alpha), -np.sin(-alpha)], mrot = np.array([[np.cos(-alpha), -np.sin(-alpha)],
[np.sin(-alpha), np.cos(-alpha)]]) [np.sin(-alpha), np.cos(-alpha)]])
for header in headers: for header in headers:
new_header = deepcopy(header) new_header = deepcopy(header)
new_header['orientat'] = header['orientat'] + ang new_header['orientat'] = header['orientat'] + ang
new_wcs = WCS(header).deepcopy() new_wcs = WCS(header).deepcopy()
if new_wcs.wcs.has_cd(): # CD matrix
# Update WCS with relevant information new_wcs.wcs.pc = np.dot(mrot, new_wcs.wcs.pc)
HST_aper = 2400. # HST aperture in mm print(new_wcs.wcs.pc)
f_ratio = header['f_ratio']
px_dim = np.array([25., 25.]) # Pixel dimension in µm
if ref_header['pxformt'].lower() == 'zoom':
px_dim[0] = 50.
#new_cdelt = 206.3/3600.*px_dim/(f_ratio*HST_aper)
new_cdelt = np.abs(np.linalg.eig(new_wcs.wcs.cd)[0])
old_cd = new_wcs.wcs.cd
del new_wcs.wcs.cd
keys = ['CD1_1','CD1_2','CD2_1','CD2_2']
for key in keys:
new_header.remove(key, ignore_missing=True)
new_wcs.wcs.pc = np.dot(mrot, np.dot(old_cd, np.diag(1./new_cdelt)))
new_wcs.wcs.cdelt = new_cdelt
elif new_wcs.wcs.has_pc(): # PC matrix + CDELT
newpc = np.dot(mrot, new_wcs.wcs.get_pc())
new_wcs.wcs.pc = newpc
new_wcs.wcs.crpix = np.dot(mrot, new_wcs.wcs.crpix - old_center[::-1]) + new_center[::-1] new_wcs.wcs.crpix = np.dot(mrot, new_wcs.wcs.crpix - old_center[::-1]) + new_center[::-1]
new_wcs.wcs.set() new_wcs.wcs.set()
new_header.update(new_wcs.to_header()) for key, val in new_wcs.to_header().items():
new_header.set(key,val)
if new_wcs.wcs.pc[0,0] == 1.:
new_header.set('PC1_1',1.)
if new_wcs.wcs.pc[1,1] == 1.:
new_header.set('PC2_2',1.)
new_headers.append(new_header) new_headers.append(new_header)
@@ -1619,33 +1614,18 @@ def rotate_data(data_array, error_array, data_mask, headers, ang):
#Update headers to new angle #Update headers to new angle
new_headers = [] new_headers = []
mrot = np.array([[np.cos(-alpha), -np.sin(-alpha)], mrot = np.array([[np.cos(-alpha), -np.sin(-alpha)],
[np.sin(-alpha), np.cos(-alpha)]]) [np.sin(-alpha), np.cos(-alpha)]])
for header in headers: for header in headers:
new_header = deepcopy(header) new_header = deepcopy(header)
new_header['orientat'] = header['orientat'] + ang new_header['orientat'] = header['orientat'] + ang
new_wcs = WCS(header).deepcopy() new_wcs = WCS(header).deepcopy()
if new_wcs.wcs.has_cd(): # CD matrix
# Update WCS with relevant information new_wcs.wcs.pc = np.dot(mrot, new_wcs.wcs.pc)
HST_aper = 2400. # HST aperture in mm
f_ratio = ref_header['f_ratio']
px_dim = np.array([25., 25.]) # Pixel dimension in µm
if ref_header['pxformt'].lower() == 'zoom':
px_dim[0] = 50.
new_cdelt = 206.3/3600.*px_dim/(f_ratio*HST_aper)
old_cd = new_wcs.wcs.cd
del new_wcs.wcs.cd
keys = ['CD1_1','CD1_2','CD2_1','CD2_2']
for key in keys:
new_header.remove(key, ignore_missing=True)
new_wcs.wcs.pc = np.dot(mrot, np.dot(old_cd, np.diag(1./new_cdelt)))
new_wcs.wcs.cdelt = new_cdelt
elif new_wcs.wcs.has_pc(): # PC matrix + CDELT
newpc = np.dot(mrot, new_wcs.wcs.get_pc())
new_wcs.wcs.pc = newpc
new_wcs.wcs.crpix = np.dot(mrot, new_wcs.wcs.crpix - old_center[::-1]) + new_center[::-1] new_wcs.wcs.crpix = np.dot(mrot, new_wcs.wcs.crpix - old_center[::-1]) + new_center[::-1]
new_wcs.wcs.set() new_wcs.wcs.set()
new_header.update(new_wcs.to_header()) for key, val in new_wcs.to_header().items():
new_header[key] = val
new_headers.append(new_header) new_headers.append(new_header)
globals()['theta'] = theta - alpha globals()['theta'] = theta - alpha

View File

@@ -45,15 +45,28 @@ from matplotlib.colors import LogNorm
#G = overplot_pol(Stokes_UV, Stokes_IR, norm=LogNorm(vmin=1e-17,vmax=5e-15), cmap='inferno_r') #G = overplot_pol(Stokes_UV, Stokes_IR, norm=LogNorm(vmin=1e-17,vmax=5e-15), cmap='inferno_r')
#G.plot(SNRp_cut=3.0, SNRi_cut=60.0, savename='../plots/IC5063_x3nl030/IR_overplot_forced.png', norm=LogNorm(vmin=1e-17,vmax=5e-15), cmap='inferno_r') #G.plot(SNRp_cut=3.0, SNRi_cut=60.0, savename='../plots/IC5063_x3nl030/IR_overplot_forced.png', norm=LogNorm(vmin=1e-17,vmax=5e-15), cmap='inferno_r')
data_folder = "../data/M87/POS1/" #data_folder1 = "../data/M87/POS1/"
plots_folder = "../plots/M87/POS1/" #plots_folder1 = "../plots/M87/POS1/"
basename = "M87_005_log_core" #basename1 = "test"
M87_95 = fits.open(data_folder+"M87_POS1_1995_FOC_combine_FWHM005.fits") #M87_1_95 = fits.open(data_folder1+"M87_POS1_1995_FOC_combine_FWHM005.fits")
M87_96 = fits.open(data_folder+"M87_POS1_1996_FOC_combine_FWHM005.fits") #M87_1_96 = fits.open(data_folder1+"M87_POS1_1996_FOC_combine_FWHM005.fits")
M87_97 = fits.open(data_folder+"M87_POS1_1997_FOC_combine_FWHM005.fits") #M87_1_97 = fits.open(data_folder1+"M87_POS1_1997_FOC_combine_FWHM005.fits")
M87_98 = fits.open(data_folder+"M87_POS1_1998_FOC_combine_FWHM005.fits") #M87_1_98 = fits.open(data_folder1+"M87_POS1_1998_FOC_combine_FWHM005.fits")
M87_99 = fits.open(data_folder+"M87_POS1_1999_FOC_combine_FWHM005.fits") #M87_1_99 = fits.open(data_folder1+"M87_POS1_1999_FOC_combine_FWHM005.fits")
#
#H = align_pol(np.array([M87_1_95,M87_1_96,M87_1_97,M87_1_98,M87_1_99]))#, norm=LogNorm())
#H.plot(SNRp_cut=3.0, SNRi_cut=30.0, savename=plots_folder1+'animated_loop/'+basename1, norm=LogNorm())
#command("convert -delay 20 -loop 0 {0:s}animated_loop/{1:s}*.png {0:s}animated_loop/{1:s}.gif && rm {0:s}animated_loop/{1:s}*.png".format(plots_folder1, basename1))
H = align_pol(np.array([M87_95,M87_96,M87_97,M87_98,M87_99]), norm=LogNorm()) data_folder3 = "../data/M87/POS3/"
H.plot(SNRp_cut=3.0, SNRi_cut=30.0, savename=plots_folder+'animated_loop/'+basename, norm=LogNorm()) plots_folder3 = "../plots/M87/POS3/"
command("convert -delay 20 -loop 0 {0:s}animated_loop/{1:s}*.png {0:s}animated_loop/{1:s}.gif && rm {0:s}animated_loop/{1:s}*.png".format(plots_folder, basename)) basename3 = "test"
M87_3_95 = fits.open(data_folder3+"M87_POS3_1995_FOC_combine_FWHM005.fits")
M87_3_96 = fits.open(data_folder3+"M87_POS3_1996_FOC_combine_FWHM005.fits")
M87_3_97 = fits.open(data_folder3+"M87_POS3_1997_FOC_combine_FWHM005.fits")
M87_3_98 = fits.open(data_folder3+"M87_POS3_1998_FOC_combine_FWHM005.fits")
M87_3_99 = fits.open(data_folder3+"M87_POS3_1999_FOC_combine_FWHM005.fits")
I = align_pol(np.array([M87_3_95,M87_3_96,M87_3_97,M87_3_98,M87_3_99]))#, norm=LogNorm())
I.plot(SNRp_cut=3.0, SNRi_cut=30.0, savename=plots_folder3+'animated_loop/'+basename3, norm=LogNorm())
command("convert -delay 20 -loop 0 {0:s}animated_loop/{1:s}*.png {0:s}animated_loop/{1:s}.gif && rm {0:s}animated_loop/{1:s}*.png".format(plots_folder3, basename3))