From 72a6938437618790c68e5e3efaba321c8104d876 Mon Sep 17 00:00:00 2001 From: Thibault Barnouin Date: Thu, 11 Jul 2024 15:11:57 +0200 Subject: [PATCH 1/2] some plot fix --- package/FOC_reduction.py | 8 ++++---- package/lib/plots.py | 27 +++++++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/package/FOC_reduction.py b/package/FOC_reduction.py index d93e453..17cf3d1 100755 --- a/package/FOC_reduction.py +++ b/package/FOC_reduction.py @@ -36,7 +36,7 @@ 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 = 1.0 + subtract_error = 2.0 display_bkg = False # Data binning @@ -54,8 +54,8 @@ 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 = 2.0 # If None, no smoothing is done - smoothing_scale = "px" # pixel or arcsec + smoothing_FWHM = 1.50 # If None, no smoothing is done + smoothing_scale = "px" # pixel or arcsec # Rotation rotate_North = True @@ -401,7 +401,7 @@ def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop= deepcopy(Stokes_hdul), data_mask, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, savename=figname, plots_folder=plots_folder, display="integrate" ) elif pxscale.lower() not in ["full", "integrate"]: - proj_plots.pol_map(Stokes_hdul, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, flux_lim=flux_lim) + proj_plots.pol_map(Stokes_hdul, SNRp_cut=SNRp_cut, SNRi_cut=SNRi_cut, step_vec=step_vec, scale_vec=scale_vec, flux_lim=flux_lim) return outfiles diff --git a/package/lib/plots.py b/package/lib/plots.py index 9cba169..4906941 100755 --- a/package/lib/plots.py +++ b/package/lib/plots.py @@ -326,7 +326,7 @@ def polarization_map( plt.rcdefaults() ratiox = max(int(stkI.shape[1]/(stkI.shape[0])),1) ratioy = max(int((stkI.shape[0])/stkI.shape[1]),1) - fig, ax = plt.subplots(figsize=(6*ratiox, 6*ratioy), layout="compressed", subplot_kw=dict(projection=wcs)) + fig, ax = plt.subplots(figsize=(7*ratiox, 7*ratioy), layout="compressed", subplot_kw=dict(projection=wcs)) ax.set(aspect="equal", fc="k", ylim=[-stkI.shape[0]*0.10,stkI.shape[0]*1.15]) # fig.subplots_adjust(hspace=0, wspace=0, left=0.102, right=1.02) @@ -449,8 +449,8 @@ def polarization_map( ax.transAxes, "E", "N", - length=-0.05, - fontsize=0.02, + length=-0.07, + fontsize=0.03, loc=1, aspect_ratio=-(stkI.shape[1]/(stkI.shape[0]*1.25)), sep_y=0.01, @@ -670,7 +670,7 @@ class align_maps(object): length=-0.08, fontsize=0.03, loc=1, - aspect_ratio=-(self.map_data.shape[1]/self.map_data.shape[0]), + aspect_ratio=-(self.map_ax.get_xbound()[1]-self.map_ax.get_xbound()[0])/(self.map_ax.get_ybound()[1]-self.map_ax.get_ybound()[0]), sep_y=0.01, sep_x=0.01, angle=-self.map_header["orientat"], @@ -722,13 +722,13 @@ class align_maps(object): ) if "ORIENTAT" in list(self.other_header.keys()): north_dir2 = AnchoredDirectionArrows( - self.map_ax.transAxes, + self.other_ax.transAxes, "E", "N", length=-0.08, fontsize=0.03, loc=1, - aspect_ratio=-(self.other_data.shape[1]/self.other_data.shape[0]), + aspect_ratio=-(self.other_ax.get_xbound()[1]-self.other_ax.get_xbound()[0])/(self.other_ax.get_ybound()[1]-self.other_ax.get_ybound()[0]), sep_y=0.01, sep_x=0.01, angle=-self.other_header["orientat"], @@ -1272,7 +1272,9 @@ class overplot_pol(align_maps): pol[SNRi < SNRi_cut] = np.nan plt.rcParams.update({"font.size": 16}) - self.fig_overplot, self.ax_overplot = plt.subplots(figsize=(11, 10), subplot_kw=dict(projection=self.other_wcs)) + ratiox = max(int(stkI.shape[1]/stkI.shape[0]),1) + ratioy = max(int(stkI.shape[0]/stkI.shape[1]),1) + self.fig_overplot, self.ax_overplot = plt.subplots(figsize=(10*ratiox, 10*ratioy), subplot_kw=dict(projection=self.other_wcs)) self.fig_overplot.subplots_adjust(hspace=0, wspace=0, bottom=0.1, left=0.1, top=0.80, right=1.02) self.ax_overplot.set_xlabel(label="Right Ascension (J2000)") @@ -1327,11 +1329,12 @@ class overplot_pol(align_maps): ) # Display full size polarization vectors + px_scale = self.wcs_UV.wcs.get_cdelt()[0]/self.other_wcs.wcs.get_cdelt()[0] if scale_vec is None: - self.scale_vec = 2.0 + self.scale_vec = 2.0*px_scale pol[np.isfinite(pol)] = 1.0 / 2.0 else: - self.scale_vec = scale_vec + self.scale_vec = scale_vec*px_scale step_vec = 1 self.X, self.Y = np.meshgrid(np.arange(stkI.shape[1]), np.arange(stkI.shape[0])) self.U, self.V = pol * np.cos(np.pi / 2.0 + pang * np.pi / 180.0), pol * np.sin(np.pi / 2.0 + pang * np.pi / 180.0) @@ -1348,8 +1351,8 @@ class overplot_pol(align_maps): headwidth=0.0, headlength=0.0, headaxislength=0.0, - width=0.5, - linewidth=0.75, + width=0.5*px_scale, + linewidth=0.3*px_scale, color="white", edgecolor="black", transform=self.ax_overplot.get_transform(self.wcs_UV), @@ -1388,7 +1391,7 @@ class overplot_pol(align_maps): length=-0.08, fontsize=0.03, loc=1, - aspect_ratio=-(stkI.shape[1]/stkI.shape[0]), + aspect_ratio=-(self.ax_overplot.get_xbound()[1]-self.ax_overplot.get_xbound()[0])/(self.ax_overplot.get_ybound()[1]-self.ax_overplot.get_ybound()[0]), sep_y=0.01, sep_x=0.01, angle=-self.Stokes_UV[0].header["orientat"], From 1c60e875e8a2f03c6bc0ae60e5ffec377f49d4ef Mon Sep 17 00:00:00 2001 From: Thibault Barnouin Date: Tue, 16 Jul 2024 11:40:40 +0200 Subject: [PATCH 2/2] np.mat to np.asmatrix for Numpy 2.0 --- package/lib/reduction.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/lib/reduction.py b/package/lib/reduction.py index 2b6f736..a9ce0f1 100755 --- a/package/lib/reduction.py +++ b/package/lib/reduction.py @@ -217,9 +217,9 @@ def bin_ndarray(ndarray, new_shape, operation="sum"): elif operation.lower() in ["mean", "average", "avg"]: ndarray = ndarray.mean(-1 * (i + 1)) else: - row_comp = np.mat(get_row_compressor(ndarray.shape[0], new_shape[0], operation)) - col_comp = np.mat(get_column_compressor(ndarray.shape[1], new_shape[1], operation)) - ndarray = np.array(row_comp * np.mat(ndarray) * col_comp) + row_comp = np.asmatrix(get_row_compressor(ndarray.shape[0], new_shape[0], operation)) + col_comp = np.asmatrix(get_column_compressor(ndarray.shape[1], new_shape[1], operation)) + ndarray = np.array(row_comp * np.asmatrix(ndarray) * col_comp) return ndarray