better handling of patheffects for black borders
This commit is contained in:
@@ -158,7 +158,7 @@ def plot_obs(data_array, headers, rectangle=None, shifts=None, savename=None, pl
|
|||||||
# fig.suptitle(savename)
|
# fig.suptitle(savename)
|
||||||
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
||||||
savename += ".pdf"
|
savename += ".pdf"
|
||||||
fig.savefig(path_join(plots_folder, savename), bbox_inches="tight", dpi=150, facecolor="None")
|
fig.savefig(path_join(plots_folder, savename), bbox_inches="tight", dpi=150, facecolor="None", edgecolor="None")
|
||||||
plt.show()
|
plt.show()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ def plot_Stokes(Stokes, savename=None, plots_folder=""):
|
|||||||
savename += "_IQU.pdf"
|
savename += "_IQU.pdf"
|
||||||
else:
|
else:
|
||||||
savename = savename[:-4] + "_IQU" + savename[-4:]
|
savename = savename[:-4] + "_IQU" + savename[-4:]
|
||||||
fig.savefig(path_join(plots_folder, savename), bbox_inches="tight", dpi=150, facecolor="None")
|
fig.savefig(path_join(plots_folder, savename), bbox_inches="tight", dpi=150, facecolor="None", edgecolor="None")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -360,7 +360,7 @@ def polarization_map(
|
|||||||
if fig is None:
|
if fig is None:
|
||||||
ratiox = max(int(stkI.shape[1] / (stkI.shape[0])), 1)
|
ratiox = max(int(stkI.shape[1] / (stkI.shape[0])), 1)
|
||||||
ratioy = max(int((stkI.shape[0]) / stkI.shape[1]), 1)
|
ratioy = max(int((stkI.shape[0]) / stkI.shape[1]), 1)
|
||||||
fig = plt.figure(figsize=(7 * ratiox, 7 * ratioy), layout="constrained")
|
fig = plt.figure(figsize=(6 * ratiox, 6 * ratioy), layout="constrained")
|
||||||
if ax is None:
|
if ax is None:
|
||||||
ax = fig.add_subplot(111, projection=wcs)
|
ax = fig.add_subplot(111, projection=wcs)
|
||||||
ax.set(aspect="equal") # , ylim=[-0.05 * stkI.shape[0], 1.05 * stkI.shape[0]])
|
ax.set(aspect="equal") # , ylim=[-0.05 * stkI.shape[0], 1.05 * stkI.shape[0]])
|
||||||
@@ -495,19 +495,19 @@ def polarization_map(
|
|||||||
display = "snri"
|
display = "snri"
|
||||||
vmin, vmax = 0.0, np.max(SNRi[np.isfinite(SNRi)])
|
vmin, vmax = 0.0, np.max(SNRi[np.isfinite(SNRi)])
|
||||||
if np.floor(vmax - SNRi_cut) > 0.0:
|
if np.floor(vmax - SNRi_cut) > 0.0:
|
||||||
im = ax.imshow(SNRi, vmin=vmin, vmax=vmax, aspect="equal", cmap=kwargs["cmap"], alpha=1.0)
|
im = ax.imshow(SNRi, vmin=vmax, vmax=vmin, aspect="equal", cmap=kwargs["cmap"], alpha=1.0 - 0.75 * (SNRi <= 1.0))
|
||||||
levelsSNRi = np.linspace(SNRi_cut, vmax * 0.99, min(np.floor(vmax - P_cut).astype(int), 5)).astype(int)
|
levelsSNRi = np.linspace(SNRi_cut, vmax * 0.99, min(np.floor(vmax - P_cut).astype(int), 5)).astype(int)
|
||||||
print("SNRi contour levels : ", levelsSNRi)
|
print("SNRi contour levels : ", levelsSNRi)
|
||||||
ax.contour(SNRi, levels=levelsSNRi, colors="grey", linewidths=0.5)
|
ax.contour(SNRi, levels=levelsSNRi, colors="grey", linewidths=0.5)
|
||||||
else:
|
else:
|
||||||
im = ax.imshow(SNRi, aspect="equal", cmap=kwargs["cmap"], alpha=1.0)
|
im = ax.imshow(SNRi, aspect="equal", cmap=kwargs["cmap"], alpha=1.0)
|
||||||
fig.colorbar(im, ax=ax, aspect=50, shrink=0.50, pad=0.025, label=r"$I_{Stokes}/\sigma_{I}$")
|
fig.colorbar(im, ax=ax, aspect=50, shrink=0.60, pad=0.025, label=r"$I_{Stokes}/\sigma_{I}$")
|
||||||
elif display.lower() in ["snr", "snrp"]:
|
elif display.lower() in ["snr", "snrp"]:
|
||||||
# Display polarization degree signal-to-noise map
|
# Display polarization degree signal-to-noise map
|
||||||
display = "snrp"
|
display = "snrp"
|
||||||
vmin, vmax = 0.0, np.max(SNRp[np.isfinite(SNRp)])
|
vmin, vmax = 0.0, np.max(SNRp[np.isfinite(SNRp)])
|
||||||
if np.floor(vmax - SNRp_cut) > 0.0:
|
if np.floor(vmax - SNRp_cut) > 0.0:
|
||||||
im = ax.imshow(SNRp, vmin=vmin, vmax=vmax, aspect="equal", cmap=kwargs["cmap"], alpha=1.0)
|
im = ax.imshow(SNRp, vmin=vmin, vmax=vmax, aspect="equal", cmap=kwargs["cmap"], alpha=1.0 - 0.75 * (SNRp <= 1.0))
|
||||||
levelsSNRp = np.linspace(SNRp_cut, vmax * 0.99, min(np.floor(vmax - SNRp_cut).astype(int), 5)).astype(int)
|
levelsSNRp = np.linspace(SNRp_cut, vmax * 0.99, min(np.floor(vmax - SNRp_cut).astype(int), 5)).astype(int)
|
||||||
print("SNRp contour levels : ", levelsSNRp)
|
print("SNRp contour levels : ", levelsSNRp)
|
||||||
ax.contour(SNRp, levels=levelsSNRp, colors="grey", linewidths=0.5)
|
ax.contour(SNRp, levels=levelsSNRp, colors="grey", linewidths=0.5)
|
||||||
@@ -548,6 +548,8 @@ def polarization_map(
|
|||||||
plt.rcParams.update({"font.size": 10})
|
plt.rcParams.update({"font.size": 10})
|
||||||
px_size = wcs.wcs.get_cdelt()[0] * 3600.0
|
px_size = wcs.wcs.get_cdelt()[0] * 3600.0
|
||||||
px_sc = AnchoredSizeBar(ax.transData, 1.0 / px_size, "1 arcsec", 3, pad=0.25, sep=5, borderpad=0.25, frameon=False, size_vertical=0.005, color=font_color)
|
px_sc = AnchoredSizeBar(ax.transData, 1.0 / px_size, "1 arcsec", 3, pad=0.25, sep=5, borderpad=0.25, frameon=False, size_vertical=0.005, color=font_color)
|
||||||
|
for children in px_sc.txt_label.get_children() + px_sc.size_bar.get_children():
|
||||||
|
children.set_path_effects([withStroke(linewidth=2.0, foreground="k")])
|
||||||
north_dir = AnchoredDirectionArrows(
|
north_dir = AnchoredDirectionArrows(
|
||||||
ax.transAxes,
|
ax.transAxes,
|
||||||
"E",
|
"E",
|
||||||
@@ -563,15 +565,13 @@ def polarization_map(
|
|||||||
head_width=4.0,
|
head_width=4.0,
|
||||||
tail_width=1.0,
|
tail_width=1.0,
|
||||||
angle=-Stokes[0].header["orientat"],
|
angle=-Stokes[0].header["orientat"],
|
||||||
text_props={"ec": font_color, "fc": font_color, "alpha": 1, "lw": 0.5},
|
text_props={"color": font_color, "alpha": 1, "lw": 0.1, "path_effects": [withStroke(linewidth=2.0, foreground=bkg_color)]},
|
||||||
arrow_props={"ec": font_color, "fc": font_color, "alpha": 1, "lw": 0.5},
|
arrow_props={"color": font_color, "alpha": 1, "lw": 0.1, "path_effects": [withStroke(linewidth=2.0, foreground=bkg_color)]},
|
||||||
)
|
)
|
||||||
for children in north_dir.box.get_children() + [px_sc.__dict__[child].get_children()[0] for child in ["txt_label", "size_bar"]]:
|
|
||||||
children.set_path_effects([withStroke(linewidth=2.0, foreground=bkg_color)])
|
|
||||||
ax.add_artist(px_sc)
|
ax.add_artist(px_sc)
|
||||||
ax.add_artist(north_dir)
|
ax.add_artist(north_dir)
|
||||||
|
|
||||||
if display.lower() in ["i", "pf", "p", "pa"] and step_vec != 0:
|
if display.lower() in ["i", "pf", "p", "pa", "snrp"] and step_vec != 0:
|
||||||
if scale_vec == -1:
|
if scale_vec == -1:
|
||||||
poldata[np.isfinite(poldata)] = 1.0 / 2.0
|
poldata[np.isfinite(poldata)] = 1.0 / 2.0
|
||||||
step_vec = 1
|
step_vec = 1
|
||||||
@@ -600,7 +600,7 @@ def polarization_map(
|
|||||||
pol_sc = AnchoredSizeBar(
|
pol_sc = AnchoredSizeBar(
|
||||||
ax.transData, scale_vec, r"$P$= 100 %", 4, pad=0.25, sep=5, borderpad=0.25, frameon=False, size_vertical=0.005, color=font_color
|
ax.transData, scale_vec, r"$P$= 100 %", 4, pad=0.25, sep=5, borderpad=0.25, frameon=False, size_vertical=0.005, color=font_color
|
||||||
)
|
)
|
||||||
for children in [pol_sc.__dict__[child].get_children()[0] for child in ["txt_label", "size_bar"]]:
|
for children in pol_sc.txt_label.get_children() + pol_sc.size_bar.get_children():
|
||||||
children.set_path_effects([withStroke(linewidth=2.0, foreground=bkg_color)])
|
children.set_path_effects([withStroke(linewidth=2.0, foreground=bkg_color)])
|
||||||
ax.add_artist(pol_sc)
|
ax.add_artist(pol_sc)
|
||||||
|
|
||||||
@@ -644,7 +644,7 @@ def polarization_map(
|
|||||||
if savename is not None:
|
if savename is not None:
|
||||||
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
||||||
savename += ".pdf"
|
savename += ".pdf"
|
||||||
fig.savefig(path_join(plots_folder, savename), bbox_inches="tight", dpi=300, facecolor="None")
|
fig.savefig(path_join(plots_folder, savename), bbox_inches="tight", dpi=300, facecolor="None", edgecolor="None")
|
||||||
|
|
||||||
return fig, ax
|
return fig, ax
|
||||||
|
|
||||||
@@ -1165,7 +1165,7 @@ class overplot_radio(align_maps):
|
|||||||
if savename is not None:
|
if savename is not None:
|
||||||
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
||||||
savename += ".pdf"
|
savename += ".pdf"
|
||||||
self.fig_overplot.savefig(savename, bbox_inches="tight", dpi=150, facecolor="None")
|
self.fig_overplot.savefig(savename, bbox_inches="tight", dpi=150, facecolor="None", edgecolor="None")
|
||||||
|
|
||||||
self.fig_overplot.canvas.draw()
|
self.fig_overplot.canvas.draw()
|
||||||
|
|
||||||
@@ -1376,7 +1376,7 @@ class overplot_chandra(align_maps):
|
|||||||
if savename is not None:
|
if savename is not None:
|
||||||
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
||||||
savename += ".pdf"
|
savename += ".pdf"
|
||||||
self.fig_overplot.savefig(savename, bbox_inches="tight", dpi=150, facecolor="None")
|
self.fig_overplot.savefig(savename, bbox_inches="tight", dpi=150, facecolor="None", edgecolor="None")
|
||||||
|
|
||||||
self.fig_overplot.canvas.draw()
|
self.fig_overplot.canvas.draw()
|
||||||
|
|
||||||
@@ -1644,7 +1644,7 @@ class overplot_pol(align_maps):
|
|||||||
if savename is not None:
|
if savename is not None:
|
||||||
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
||||||
savename += ".pdf"
|
savename += ".pdf"
|
||||||
self.fig_overplot.savefig(savename, bbox_inches="tight", dpi=150, facecolor="None")
|
self.fig_overplot.savefig(savename, bbox_inches="tight", dpi=150, facecolor="None", edgecolor="None")
|
||||||
|
|
||||||
self.fig_overplot.canvas.draw()
|
self.fig_overplot.canvas.draw()
|
||||||
|
|
||||||
@@ -1821,7 +1821,7 @@ class align_pol(object):
|
|||||||
if savename is not None:
|
if savename is not None:
|
||||||
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
|
||||||
savename += ".pdf"
|
savename += ".pdf"
|
||||||
fig.savefig(savename, bbox_inches="tight", dpi=150, facecolor="None")
|
fig.savefig(savename, bbox_inches="tight", dpi=150, facecolor="None", edgecolor="None")
|
||||||
|
|
||||||
plt.show(block=True)
|
plt.show(block=True)
|
||||||
return fig, ax
|
return fig, ax
|
||||||
@@ -2829,7 +2829,7 @@ class pol_map(object):
|
|||||||
# save_fig.suptitle(r"{0:s} with $SNR_{{p}} \geq$ {1:d} and $SNR_{{I}} \geq$ {2:d}".format(self.targ, int(self.SNRp), int(self.SNRi)))
|
# save_fig.suptitle(r"{0:s} with $SNR_{{p}} \geq$ {1:d} and $SNR_{{I}} \geq$ {2:d}".format(self.targ, int(self.SNRp), int(self.SNRi)))
|
||||||
if expression[-4:] not in [".png", ".jpg", ".pdf"]:
|
if expression[-4:] not in [".png", ".jpg", ".pdf"]:
|
||||||
expression += ".pdf"
|
expression += ".pdf"
|
||||||
save_fig.savefig(expression, bbox_inches="tight", dpi=150, facecolor="None")
|
save_fig.savefig(expression, bbox_inches="tight", dpi=150, facecolor="None", edgecolor="None")
|
||||||
plt.close(save_fig)
|
plt.close(save_fig)
|
||||||
text_save.set_val("")
|
text_save.set_val("")
|
||||||
ax_snr_reset.set(visible=True)
|
ax_snr_reset.set(visible=True)
|
||||||
@@ -3057,6 +3057,8 @@ class pol_map(object):
|
|||||||
color="white",
|
color="white",
|
||||||
fontproperties=fontprops,
|
fontproperties=fontprops,
|
||||||
)
|
)
|
||||||
|
for children in px_sc.txt_label.get_children() + px_sc.size_bar.get_children():
|
||||||
|
children.set_path_effects([withStroke(linewidth=2.0, foreground="k")])
|
||||||
north_dir = AnchoredDirectionArrows(
|
north_dir = AnchoredDirectionArrows(
|
||||||
ax.transAxes,
|
ax.transAxes,
|
||||||
"E",
|
"E",
|
||||||
@@ -3073,11 +3075,9 @@ class pol_map(object):
|
|||||||
tail_width=1.0,
|
tail_width=1.0,
|
||||||
angle=-self.Stokes[0].header["orientat"],
|
angle=-self.Stokes[0].header["orientat"],
|
||||||
color="white",
|
color="white",
|
||||||
text_props={"ec": "w", "fc": "w", "alpha": 1, "lw": 0.5},
|
text_props={"ec": "w", "fc": "w", "alpha": 1, "lw": 0.5, "path_effects": [withStroke(linewidth=2.0, foreground="k")]},
|
||||||
arrow_props={"ec": "w", "fc": "w", "alpha": 1, "lw": 0.5},
|
arrow_props={"ec": "w", "fc": "w", "alpha": 1, "lw": 0.5, "path_effects": [withStroke(linewidth=2.0, foreground="k")]},
|
||||||
)
|
)
|
||||||
for children in north_dir.box.get_children() + px_sc.txt_label.get_children() + px_sc.size_bar.get_children():
|
|
||||||
children.set_path_effects([withStroke(linewidth=2.0, foreground="k")])
|
|
||||||
if hasattr(self, "px_sc"):
|
if hasattr(self, "px_sc"):
|
||||||
self.px_sc.remove()
|
self.px_sc.remove()
|
||||||
self.px_sc = px_sc
|
self.px_sc = px_sc
|
||||||
|
|||||||
Reference in New Issue
Block a user