From b577fc5afe5f6b8124e93f6fa3052bdad4835cbf Mon Sep 17 00:00:00 2001 From: Thibault Barnouin Date: Tue, 1 Apr 2025 17:02:31 +0200 Subject: [PATCH] fix WCS computation, cdelt should not be sorted --- package/FOC_reduction.py | 12 ++++++------ package/lib/fits.py | 6 +++--- package/lib/utils.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package/FOC_reduction.py b/package/FOC_reduction.py index eab1da7..55bd806 100755 --- a/package/FOC_reduction.py +++ b/package/FOC_reduction.py @@ -45,8 +45,8 @@ def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop= display_bkg = True # Data binning - pxsize = 0.05 - pxscale = "arcsec" # pixel, arcsec or full + pxsize = 4 + pxscale = "px" # pixel, arcsec or full rebin_operation = "sum" # sum or average # Alignement @@ -59,15 +59,15 @@ def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop= # Smoothing smoothing_function = "combine" # gaussian_after, weighted_gaussian_after, gaussian, weighted_gaussian or combine - smoothing_FWHM = 0.075 # If None, no smoothing is done - smoothing_scale = "arcsec" # pixel or arcsec + smoothing_FWHM = 1.5 # If None, no smoothing is done + smoothing_scale = "px" # pixel or arcsec # Rotation rotate_North = True # Polarization map output - P_cut = 5 # if >=1.0 cut on the signal-to-noise else cut on the confidence level in Q, U - SNRi_cut = 5.0 # I measurments with SNR>30, which implies an uncertainty in P of 4.7%. + P_cut = 3 # if >=1.0 cut on the signal-to-noise else cut on the confidence level in Q, U + SNRi_cut = 1.0 # I measurments with SNR>30, which implies an uncertainty in P of 4.7%. flux_lim = None # lowest and highest flux displayed on plot, defaults to bkg and maximum in cut if None scale_vec = 3 step_vec = 1 # plot all vectors in the array. if step_vec = 2, then every other vector will be plotted if step_vec = 0 then all vectors are displayed at full length diff --git a/package/lib/fits.py b/package/lib/fits.py index 89177c1..af8c10b 100755 --- a/package/lib/fits.py +++ b/package/lib/fits.py @@ -16,7 +16,7 @@ from astropy.io import fits from astropy.wcs import WCS from .convex_hull import clean_ROI -from .utils import wcs_PA +from .utils import wcs_PA, princ_angle def get_obs_data(infiles, data_folder="", compute_flux=False): @@ -72,13 +72,13 @@ def get_obs_data(infiles, data_folder="", compute_flux=False): for key in keys: header.remove(key, ignore_missing=True) new_cdelt = np.linalg.eigvals(wcs.wcs.cd) - new_cdelt.sort() + # new_cdelt.sort() new_wcs.wcs.pc = wcs.wcs.cd.dot(np.diag(1.0 / new_cdelt)) new_wcs.wcs.cdelt = new_cdelt for key, val in new_wcs.to_header().items(): header[key] = val try: - _ = header["ORIENTAT"] + header["ORIENTAT"] = princ_angle(float(header["ORIENTAT"])) except KeyError: header["ORIENTAT"] = wcs_PA(new_wcs.wcs.pc[1, 0], np.diag(new_wcs.wcs.pc).mean()) diff --git a/package/lib/utils.py b/package/lib/utils.py index ee9fc5b..9e36dbc 100755 --- a/package/lib/utils.py +++ b/package/lib/utils.py @@ -177,4 +177,4 @@ def wcs_PA(PC21, PC22): orient = np.arccos(PC22) * 180.0 / np.pi elif (abs(PC21) < abs(PC22)) and (PC22 < 0): orient = -np.arccos(PC22) * 180.0 / np.pi - return orient + return princ_angle(orient)