fix display for single observation

This commit is contained in:
2024-04-26 18:15:12 +02:00
parent 42ca956b25
commit b79c591ad7
4 changed files with 26 additions and 29 deletions

View File

@@ -18,14 +18,14 @@ from matplotlib.colors import LogNorm
def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop=False, interactive=False):
# Reduction parameters
# Deconvolution
deconvolve = False
deconvolve = True
if deconvolve:
# from lib.deconvolve import from_file_psf
psf = 'gaussian' # Can be user-defined as well
# psf = from_file_psf(data_folder+psf_file)
psf_FWHM = 0.028
psf_scale = 'arcsec'
psf_shape = (513, 513)
psf_FWHM = 3.1
psf_scale = 'px'
psf_shape = None # (151, 151)
iterations = 3
algo = "richardson"
@@ -33,19 +33,19 @@ def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop=
display_crop = False
# 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
error_sub_type = 'sturges' # sqrt, sturges, rice, scott, freedman-diaconis (default) or shape (example (51, 51))
subtract_error = 0.25
display_bkg = True
# Data binning
rebin = True
pxsize = 0.05
pxsize = 0.10
px_scale = 'arcsec' # pixel, arcsec or full
rebin_operation = 'sum' # sum or average
# Alignement
align_center = 'center' # If None will not align the images
display_align = False
display_align = True
display_data = False
# Smoothing

View File

@@ -551,7 +551,7 @@ def deconvolve_im(image, psf, alpha=0.1, error=None, iterations=20, clip=True,
norm_deconv = one_step_gradient(image=norm_image, psf=psf,
iterations=iterations, clip=clip, filter_epsilon=filter_epsilon)
elif algo.lower() in ['conjgrad', 'conj_grad', 'conjugate gradient']:
norm_deconv = conj_grad(image=norm_image, psf=psf, alpha=alpha,
norm_deconv = conjgrad(image=norm_image, psf=psf, alpha=alpha,
error=error, iterations=iterations)
else: # Defaults to Richardson-Lucy
norm_deconv = richardson_lucy(image=norm_image, psf=psf,

View File

@@ -102,6 +102,10 @@ def plot_obs(data_array, headers, rectangle=None, savename=None, plots_folder=""
convert = head['photflam']
r_ax, c_ax = r_pol[filt.lower()], c_pol[filt.lower()]
c_pol[filt.lower()] += 1
if shape[1] != 1:
ax_curr = ax[r_ax][c_ax]
else:
ax_curr = ax[r_ax]
# plots
vmin, vmax = convert*data[data > 0.].min()/10., convert*data[data > 0.].max()
for key, value in [["cmap", [["cmap", "gray"]]], ["norm", [["norm", LogNorm(vmin, vmax)]]]]:
@@ -112,28 +116,19 @@ def plot_obs(data_array, headers, rectangle=None, savename=None, plots_folder=""
kwargs[key_i] = val_i
# im = ax[r_ax][c_ax].imshow(convert*data, origin='lower', **kwargs)
data[data*convert < vmin*10.] = vmin*10./convert
im = ax[r_ax][c_ax].imshow(convert*data, origin='lower', **kwargs)
im = ax_curr.imshow(convert*data, origin='lower', **kwargs)
if rectangle is not None:
x, y, width, height, angle, color = rectangle[i]
ax[r_ax][c_ax].add_patch(Rectangle((x, y), width, height, angle=angle,
edgecolor=color, fill=False))
ax_curr.add_patch(Rectangle((x, y), width, height, angle=angle, edgecolor=color, fill=False))
# position of centroid
ax[r_ax][c_ax].plot([data.shape[1]/2, data.shape[1]/2], [0, data.shape[0]-1], '--', lw=1,
color='grey', alpha=0.5)
ax[r_ax][c_ax].plot([0, data.shape[1]-1], [data.shape[1]/2, data.shape[1]/2], '--', lw=1,
color='grey', alpha=0.5)
ax[r_ax][c_ax].annotate(instr+":"+rootname, color='white', fontsize=5, xy=(0.01, 1.00),
xycoords='axes fraction', verticalalignment='top',
horizontalalignment='left')
ax[r_ax][c_ax].annotate(filt, color='white', fontsize=10, xy=(0.01, 0.01),
xycoords='axes fraction', verticalalignment='bottom',
horizontalalignment='left')
ax[r_ax][c_ax].annotate(exptime, color='white', fontsize=5, xy=(1.00, 0.01),
xycoords='axes fraction', verticalalignment='bottom',
horizontalalignment='right')
ax_curr.plot([data.shape[1]/2, data.shape[1]/2], [0, data.shape[0]-1], '--', lw=1, color='grey', alpha=0.5)
ax_curr.plot([0, data.shape[1]-1], [data.shape[1]/2, data.shape[1]/2], '--', lw=1, color='grey', alpha=0.5)
ax_curr.annotate(instr+":"+rootname, color='white', fontsize=5, xy=(0.01, 1.00), xycoords='axes fraction', verticalalignment='top', horizontalalignment='left')
ax_curr.annotate(filt, color='white', fontsize=10, xy=(0.01, 0.01), xycoords='axes fraction', verticalalignment='bottom', horizontalalignment='left')
ax_curr.annotate(exptime, color='white', fontsize=5, xy=(1.00, 0.01), xycoords='axes fraction', verticalalignment='bottom', horizontalalignment='right')
fig.subplots_adjust(hspace=0.01, wspace=0.01, right=1.02)
fig.colorbar(im, ax=ax[:, :], location='right', shrink=0.75, aspect=50, pad=0.025, label=r"Flux [$ergs \cdot cm^{-2} \cdot s^{-1} \cdot \AA^{-1}$]")
fig.colorbar(im, ax=ax, location='right', shrink=0.75, aspect=50, pad=0.025, label=r"Flux [$ergs \cdot cm^{-2} \cdot s^{-1} \cdot \AA^{-1}$]")
if not (savename is None):
# fig.suptitle(savename)

View File

@@ -326,7 +326,7 @@ def crop_array(data_array, headers, error_array=None, data_mask=None, step=5, nu
def deconvolve_array(data_array, headers, psf='gaussian', FWHM=1., scale='px',
shape=(9, 9), iterations=20, algo='richardson'):
shape=None, iterations=20, algo='richardson'):
"""
Homogeneously deconvolve a data array using Richardson-Lucy iterative algorithm.
----------
@@ -379,6 +379,8 @@ def deconvolve_array(data_array, headers, psf='gaussian', FWHM=1., scale='px',
# Define Point-Spread-Function kernel
if psf.lower() in ['gauss', 'gaussian']:
if shape is None:
shape = np.min(data_array[0].shape)-2, np.min(data_array[0].shape)-2
kernel = gaussian_psf(FWHM=FWHM, shape=shape)
elif isinstance(psf, np.ndarray) and (len(psf.shape) == 2):
kernel = psf
@@ -388,7 +390,7 @@ def deconvolve_array(data_array, headers, psf='gaussian', FWHM=1., scale='px',
# Deconvolve images in the array using given PSF
deconv_array = np.zeros(data_array.shape)
for i, image in enumerate(data_array):
deconv_array[i] = deconvolve_im(image, kernel, iterations=iterations, clip=True, filter_epsilon=None, algo='richardson')
deconv_array[i] = deconvolve_im(image, kernel, iterations=iterations, clip=True, filter_epsilon=None, algo=algo)
return deconv_array