From a1767de88471528507d0e229474e7e262a3e2d95 Mon Sep 17 00:00:00 2001 From: Thibault Barnouin Date: Thu, 2 May 2024 17:12:41 +0200 Subject: [PATCH] propagate options to multiple reductions, default SNRi_cut to 3 --- src/FOC_reduction.py | 10 +++++----- src/lib/plots.py | 20 ++++++++++---------- src/lib/reduction.py | 4 ++++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/FOC_reduction.py b/src/FOC_reduction.py index 0b029d9..4b3bc84 100755 --- a/src/FOC_reduction.py +++ b/src/FOC_reduction.py @@ -35,11 +35,11 @@ def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop= # Background estimation error_sub_type = 'freedman-diaconis' # sqrt, sturges, rice, scott, freedman-diaconis (default) or shape (example (51, 51)) subtract_error = 0.50 - display_bkg = False + display_bkg = True # Data binning rebin = True - pxsize = 0.10 + pxsize = 0.05 px_scale = 'arcsec' # pixel, arcsec or full rebin_operation = 'sum' # sum or average @@ -50,7 +50,7 @@ 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.20 # If None, no smoothing is done + smoothing_FWHM = 0.075 # If None, no smoothing is done smoothing_scale = 'arcsec' # pixel or arcsec # Rotation @@ -58,7 +58,7 @@ def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop= rotate_stokes = True # Polarization map output - SNRp_cut = 3. # P measurments with SNR>3 + SNRp_cut = 5. # P measurments with SNR>3 SNRi_cut = 3. # 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 vec_scale = 3 @@ -78,7 +78,7 @@ def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop= target, products = retrieve_products(target, proposal_id, output_dir=output_dir) prod = products.pop() for prods in products: - main(target=target, infiles=["/".join(pr) for pr in prods], output_dir=output_dir) + main(target=target, infiles=["/".join(pr) for pr in prods], output_dir=output_dir, crop=crop, interactive=interactive) data_folder = prod[0][0] try: plots_folder = data_folder.replace("data", "plots") diff --git a/src/lib/plots.py b/src/lib/plots.py index cca65ee..e357348 100755 --- a/src/lib/plots.py +++ b/src/lib/plots.py @@ -200,7 +200,7 @@ def plot_Stokes(Stokes, savename=None, plots_folder=""): return 0 -def polarisation_map(Stokes, data_mask=None, rectangle=None, SNRp_cut=3., SNRi_cut=30., +def polarisation_map(Stokes, data_mask=None, rectangle=None, SNRp_cut=3., SNRi_cut=3., flux_lim=None, step_vec=1, vec_scale=2., savename=None, plots_folder="", display="default"): """ Plots polarisation map from Stokes HDUList. @@ -673,7 +673,7 @@ class overplot_radio(align_maps): Inherit from class align_maps in order to get the same WCS on both maps. """ - def overplot(self, levels=None, SNRp_cut=3., SNRi_cut=30., vec_scale=2, savename=None, **kwargs): + def overplot(self, levels=None, SNRp_cut=3., SNRi_cut=3., vec_scale=2, savename=None, **kwargs): self.Stokes_UV = self.map self.wcs_UV = self.map_wcs # Get Data @@ -780,7 +780,7 @@ class overplot_radio(align_maps): self.fig_overplot.canvas.draw() - def plot(self, levels=None, SNRp_cut=3., SNRi_cut=30., savename=None, **kwargs) -> None: + def plot(self, levels=None, SNRp_cut=3., SNRi_cut=3., savename=None, **kwargs) -> None: while not self.aligned: self.align() self.overplot(levels=levels, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, savename=savename, **kwargs) @@ -793,7 +793,7 @@ class overplot_chandra(align_maps): Inherit from class align_maps in order to get the same WCS on both maps. """ - def overplot(self, levels=None, SNRp_cut=3., SNRi_cut=30., vec_scale=2, zoom=1, savename=None, **kwargs): + def overplot(self, levels=None, SNRp_cut=3., SNRi_cut=3., vec_scale=2, zoom=1, savename=None, **kwargs): self.Stokes_UV = self.map self.wcs_UV = self.map_wcs # Get Data @@ -899,7 +899,7 @@ class overplot_chandra(align_maps): self.fig_overplot.canvas.draw() - def plot(self, levels=None, SNRp_cut=3., SNRi_cut=30., zoom=1, savename=None, **kwargs) -> None: + def plot(self, levels=None, SNRp_cut=3., SNRi_cut=3., zoom=1, savename=None, **kwargs) -> None: while not self.aligned: self.align() self.overplot(levels=levels, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, zoom=zoom, savename=savename, **kwargs) @@ -912,7 +912,7 @@ class overplot_pol(align_maps): Inherit from class align_maps in order to get the same WCS on both maps. """ - def overplot(self, levels=None, SNRp_cut=3., SNRi_cut=30., vec_scale=2., savename=None, **kwargs): + def overplot(self, levels=None, SNRp_cut=3., SNRi_cut=3., vec_scale=2., savename=None, **kwargs): self.Stokes_UV = self.map self.wcs_UV = self.map_wcs # Get Data @@ -1019,7 +1019,7 @@ class overplot_pol(align_maps): self.fig_overplot.canvas.draw() - def plot(self, levels=None, SNRp_cut=3., SNRi_cut=30., vec_scale=2., savename=None, **kwargs) -> None: + def plot(self, levels=None, SNRp_cut=3., SNRi_cut=3., vec_scale=2., savename=None, **kwargs) -> None: while not self.aligned: self.align() self.overplot(levels=levels, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, vec_scale=vec_scale, savename=savename, **kwargs) @@ -1059,7 +1059,7 @@ class align_pol(object): self.kwargs = kwargs - def single_plot(self, curr_map, wcs, v_lim=None, ax_lim=None, SNRp_cut=3., SNRi_cut=30., savename=None, **kwargs): + def single_plot(self, curr_map, wcs, v_lim=None, ax_lim=None, SNRp_cut=3., SNRi_cut=3., savename=None, **kwargs): # Get data stkI = curr_map['I_STOKES'].data stk_cov = curr_map['IQU_COV_MATRIX'].data @@ -1150,7 +1150,7 @@ class align_pol(object): self.wcs, self.wcs_other[i] = curr_align.align() self.aligned[i] = curr_align.aligned - def plot(self, SNRp_cut=3., SNRi_cut=30., savename=None, **kwargs): + def plot(self, SNRp_cut=3., SNRi_cut=3., savename=None, **kwargs): while not self.aligned.all(): self.align() eps = 1e-35 @@ -1737,7 +1737,7 @@ class pol_map(object): Class to interactively study polarisation maps. """ - def __init__(self, Stokes, SNRp_cut=3., SNRi_cut=30., flux_lim=None, selection=None): + def __init__(self, Stokes, SNRp_cut=3., SNRi_cut=3., flux_lim=None, selection=None): if isinstance(Stokes, str): Stokes = fits.open(Stokes) diff --git a/src/lib/reduction.py b/src/lib/reduction.py index 23551b5..8d46219 100755 --- a/src/lib/reduction.py +++ b/src/lib/reduction.py @@ -952,6 +952,10 @@ def polarizer_avg(data_array, error_array, data_mask, headers, FWHM=None, scale= err60_array = error_array[is_pol60] err120_array = error_array[is_pol120] + # For a single observation, combination amount to a weighted gaussian + if np.max([is_pol0.sum(), is_pol60.sum(), is_pol120.sum()]) == 1 and smoothing.lower() in ['combine', 'combining']: + smoothing = 'weighted_gaussian' + if (FWHM is not None) and (smoothing.lower() in ['combine', 'combining']): # Smooth by combining each polarizer images pol0, err0 = smooth_data(pol0_array, err0_array, data_mask, headers0, FWHM=FWHM, scale=scale, smoothing=smoothing)