more reformatting

This commit is contained in:
2024-07-01 16:57:36 +02:00
parent 5397246f34
commit 6879a8b551
3 changed files with 15 additions and 15 deletions

View File

@@ -63,15 +63,15 @@ def display_bkg(data, background, std_bkg, headers, histograms=None, binning=Non
ax.set_xlabel("Observation date and time")
ax.set_ylabel(r"Flux [$ergs \cdot cm^{-2} \cdot s^{-1} \cdot \AA^{-1}$]")
plt.legend()
if not (savename is None):
if savename is not None:
this_savename = deepcopy(savename)
if not savename[-4:] in [".png", ".jpg", ".pdf"]:
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
this_savename += "_background_flux.pdf"
else:
this_savename = savename[:-4] + "_background_flux" + savename[-4:]
fig.savefig(path_join(plots_folder, this_savename), bbox_inches="tight")
if not (histograms is None):
if histograms is not None:
filt_obs = {"POL0": 0, "POL60": 0, "POL120": 0}
fig_h, ax_h = plt.subplots(figsize=(10, 6), constrained_layout=True)
for i, (hist, bins) in enumerate(zip(histograms, binning)):
@@ -85,7 +85,7 @@ def display_bkg(data, background, std_bkg, headers, histograms=None, binning=Non
label=headers[i]["filtnam1"] + " (Obs " + str(filt_obs[headers[i]["filtnam1"]]) + ")",
)
ax_h.plot([background[i] * convert_flux[i], background[i] * convert_flux[i]], [hist.min(), hist.max()], "x--", color="C{0:d}".format(i), alpha=0.8)
if not (coeff is None):
if coeff is not None:
# ax_h.plot(bins*convert_flux[i], gausspol(bins, *coeff[i]), '--', color="C{0:d}".format(i), alpha=0.8)
ax_h.plot(bins * convert_flux[i], gauss(bins, *coeff[i]), "--", color="C{0:d}".format(i), alpha=0.8)
ax_h.set_xscale("log")
@@ -95,9 +95,9 @@ def display_bkg(data, background, std_bkg, headers, histograms=None, binning=Non
ax_h.set_ylabel(r"Number of pixels in bin")
ax_h.set_title("Histogram for each observation")
plt.legend()
if not (savename is None):
if savename is not None:
this_savename = deepcopy(savename)
if not savename[-4:] in [".png", ".jpg", ".pdf"]:
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
this_savename += "_histograms.pdf"
else:
this_savename = savename[:-4] + "_histograms" + savename[-4:]
@@ -113,7 +113,7 @@ def display_bkg(data, background, std_bkg, headers, histograms=None, binning=Non
# plots
im2 = ax2.imshow(data0, norm=LogNorm(data0[data0 > 0.0].mean() / 10.0, data0.max()), origin="lower", cmap="gray")
ax2.imshow(bkg_data0, origin="lower", cmap="Reds", alpha=0.5)
if not (rectangle is None):
if rectangle is not None:
x, y, width, height, angle, color = rectangle[0]
ax2.add_patch(Rectangle((x, y), width, height, edgecolor=color, fill=False, lw=2))
ax2.annotate(
@@ -128,14 +128,14 @@ def display_bkg(data, background, std_bkg, headers, histograms=None, binning=Non
fig2.subplots_adjust(hspace=0, wspace=0, right=1.0)
fig2.colorbar(im2, ax=ax2, location="right", aspect=50, pad=0.025, label=r"Flux [$ergs \cdot cm^{-2} \cdot s^{-1} \cdot \AA^{-1}$]")
if not (savename is None):
if savename is not None:
this_savename = deepcopy(savename)
if not savename[-4:] in [".png", ".jpg", ".pdf"]:
if savename[-4:] not in [".png", ".jpg", ".pdf"]:
this_savename += "_" + filt + "_background_location.pdf"
else:
this_savename = savename[:-4] + "_" + filt + "_background_location" + savename[-4:]
fig2.savefig(path_join(plots_folder, this_savename), bbox_inches="tight")
if not (rectangle is None):
if rectangle is not None:
plot_obs(
data,
headers,
@@ -145,7 +145,7 @@ def display_bkg(data, background, std_bkg, headers, histograms=None, binning=Non
savename=savename + "_background_location",
plots_folder=plots_folder,
)
elif not (rectangle is None):
elif rectangle is not None:
plot_obs(data, headers, vmin=data[data > 0.0].min(), vmax=data[data > 0.0].max(), rectangle=rectangle)
plt.show()
@@ -325,7 +325,7 @@ def bkg_hist(data, error, mask, headers, sub_type=None, subtract_error=True, dis
for i, image in enumerate(data):
# Compute the Count-rate histogram for the image
n_mask = np.logical_and(mask, image > 0.0)
if not (sub_type is None):
if sub_type is not None:
if isinstance(sub_type, int):
n_bins = sub_type
elif sub_type.lower() in ["sqrt"]:

View File

@@ -1079,7 +1079,7 @@ def polarizer_avg(data_array, error_array, data_mask, headers, FWHM=None, scale=
err120 = np.sqrt(np.sum(err120_array**2, axis=0)) / pol120_t
polerr_array = np.array([err0, err60, err120])
if not (FWHM is None) and (smoothing.lower() in ["gaussian", "gauss", "weighted_gaussian", "weight_gauss"]):
if (FWHM is not None) and (smoothing.lower() in ["gaussian", "gauss", "weighted_gaussian", "weight_gauss"]):
# Smooth by convoluting with a gaussian each polX image.
pol_array, polerr_array = smooth_data(pol_array, polerr_array, data_mask, pol_headers, FWHM=FWHM, scale=scale, smoothing=smoothing)
pol0, pol60, pol120 = pol_array
@@ -1251,7 +1251,7 @@ def compute_Stokes(data_array, error_array, data_mask, headers, FWHM=None, scale
I_stokes[i, j], Q_stokes[i, j], U_stokes[i, j] = np.dot(coeff_stokes, pol_flux[:, i, j]).T
Stokes_cov[:, :, i, j] = np.dot(coeff_stokes, np.dot(pol_cov[:, :, i, j], coeff_stokes.T))
if not (FWHM is None) and (smoothing.lower() in ["weighted_gaussian_after", "weight_gauss_after", "gaussian_after", "gauss_after"]):
if (FWHM is not None) and (smoothing.lower() in ["weighted_gaussian_after", "weight_gauss_after", "gaussian_after", "gauss_after"]):
smoothing = smoothing.lower()[:-6]
Stokes_array = np.array([I_stokes, Q_stokes, U_stokes])
Stokes_error = np.array([np.sqrt(Stokes_cov[i, i]) for i in range(3)])

View File

@@ -41,7 +41,7 @@ def sci_not(v, err, rnd=1, out=str):
else:
output[0] += r" $\pm$ {0}".format(round(err * 10**power, rnd))
output.append(round(err * 10**power, rnd))
if out == str:
if out is str:
return output[0] + r")e{0}".format(-power)
else:
return *output[1:], -power