fix display for single observation
This commit is contained in:
@@ -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):
|
def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop=False, interactive=False):
|
||||||
# Reduction parameters
|
# Reduction parameters
|
||||||
# Deconvolution
|
# Deconvolution
|
||||||
deconvolve = False
|
deconvolve = True
|
||||||
if deconvolve:
|
if deconvolve:
|
||||||
# from lib.deconvolve import from_file_psf
|
# from lib.deconvolve import from_file_psf
|
||||||
psf = 'gaussian' # Can be user-defined as well
|
psf = 'gaussian' # Can be user-defined as well
|
||||||
# psf = from_file_psf(data_folder+psf_file)
|
# psf = from_file_psf(data_folder+psf_file)
|
||||||
psf_FWHM = 0.028
|
psf_FWHM = 3.1
|
||||||
psf_scale = 'arcsec'
|
psf_scale = 'px'
|
||||||
psf_shape = (513, 513)
|
psf_shape = None # (151, 151)
|
||||||
iterations = 3
|
iterations = 3
|
||||||
algo = "richardson"
|
algo = "richardson"
|
||||||
|
|
||||||
@@ -33,19 +33,19 @@ def main(target=None, proposal_id=None, infiles=None, output_dir="./data", crop=
|
|||||||
display_crop = False
|
display_crop = False
|
||||||
|
|
||||||
# Background estimation
|
# Background estimation
|
||||||
error_sub_type = 'freedman-diaconis' # sqrt, sturges, rice, scott, freedman-diaconis (default) or shape (example (51, 51))
|
error_sub_type = 'sturges' # sqrt, sturges, rice, scott, freedman-diaconis (default) or shape (example (51, 51))
|
||||||
subtract_error = 0.50
|
subtract_error = 0.25
|
||||||
display_bkg = False
|
display_bkg = True
|
||||||
|
|
||||||
# Data binning
|
# Data binning
|
||||||
rebin = True
|
rebin = True
|
||||||
pxsize = 0.05
|
pxsize = 0.10
|
||||||
px_scale = 'arcsec' # pixel, arcsec or full
|
px_scale = 'arcsec' # pixel, arcsec or full
|
||||||
rebin_operation = 'sum' # sum or average
|
rebin_operation = 'sum' # sum or average
|
||||||
|
|
||||||
# Alignement
|
# Alignement
|
||||||
align_center = 'center' # If None will not align the images
|
align_center = 'center' # If None will not align the images
|
||||||
display_align = False
|
display_align = True
|
||||||
display_data = False
|
display_data = False
|
||||||
|
|
||||||
# Smoothing
|
# Smoothing
|
||||||
|
|||||||
@@ -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,
|
norm_deconv = one_step_gradient(image=norm_image, psf=psf,
|
||||||
iterations=iterations, clip=clip, filter_epsilon=filter_epsilon)
|
iterations=iterations, clip=clip, filter_epsilon=filter_epsilon)
|
||||||
elif algo.lower() in ['conjgrad', 'conj_grad', 'conjugate gradient']:
|
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)
|
error=error, iterations=iterations)
|
||||||
else: # Defaults to Richardson-Lucy
|
else: # Defaults to Richardson-Lucy
|
||||||
norm_deconv = richardson_lucy(image=norm_image, psf=psf,
|
norm_deconv = richardson_lucy(image=norm_image, psf=psf,
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ def plot_obs(data_array, headers, rectangle=None, savename=None, plots_folder=""
|
|||||||
convert = head['photflam']
|
convert = head['photflam']
|
||||||
r_ax, c_ax = r_pol[filt.lower()], c_pol[filt.lower()]
|
r_ax, c_ax = r_pol[filt.lower()], c_pol[filt.lower()]
|
||||||
c_pol[filt.lower()] += 1
|
c_pol[filt.lower()] += 1
|
||||||
|
if shape[1] != 1:
|
||||||
|
ax_curr = ax[r_ax][c_ax]
|
||||||
|
else:
|
||||||
|
ax_curr = ax[r_ax]
|
||||||
# plots
|
# plots
|
||||||
vmin, vmax = convert*data[data > 0.].min()/10., convert*data[data > 0.].max()
|
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)]]]]:
|
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
|
kwargs[key_i] = val_i
|
||||||
# im = ax[r_ax][c_ax].imshow(convert*data, origin='lower', **kwargs)
|
# im = ax[r_ax][c_ax].imshow(convert*data, origin='lower', **kwargs)
|
||||||
data[data*convert < vmin*10.] = vmin*10./convert
|
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:
|
if rectangle is not None:
|
||||||
x, y, width, height, angle, color = rectangle[i]
|
x, y, width, height, angle, color = rectangle[i]
|
||||||
ax[r_ax][c_ax].add_patch(Rectangle((x, y), width, height, angle=angle,
|
ax_curr.add_patch(Rectangle((x, y), width, height, angle=angle, edgecolor=color, fill=False))
|
||||||
edgecolor=color, fill=False))
|
|
||||||
# position of centroid
|
# position of centroid
|
||||||
ax[r_ax][c_ax].plot([data.shape[1]/2, data.shape[1]/2], [0, data.shape[0]-1], '--', lw=1,
|
ax_curr.plot([data.shape[1]/2, data.shape[1]/2], [0, data.shape[0]-1], '--', lw=1, color='grey', alpha=0.5)
|
||||||
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[r_ax][c_ax].plot([0, data.shape[1]-1], [data.shape[1]/2, data.shape[1]/2], '--', lw=1,
|
ax_curr.annotate(instr+":"+rootname, color='white', fontsize=5, xy=(0.01, 1.00), xycoords='axes fraction', verticalalignment='top', horizontalalignment='left')
|
||||||
color='grey', alpha=0.5)
|
ax_curr.annotate(filt, color='white', fontsize=10, xy=(0.01, 0.01), xycoords='axes fraction', verticalalignment='bottom', horizontalalignment='left')
|
||||||
ax[r_ax][c_ax].annotate(instr+":"+rootname, color='white', fontsize=5, xy=(0.01, 1.00),
|
ax_curr.annotate(exptime, color='white', fontsize=5, xy=(1.00, 0.01), xycoords='axes fraction', verticalalignment='bottom', horizontalalignment='right')
|
||||||
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')
|
|
||||||
|
|
||||||
fig.subplots_adjust(hspace=0.01, wspace=0.01, right=1.02)
|
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):
|
if not (savename is None):
|
||||||
# fig.suptitle(savename)
|
# fig.suptitle(savename)
|
||||||
|
|||||||
@@ -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',
|
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.
|
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
|
# Define Point-Spread-Function kernel
|
||||||
if psf.lower() in ['gauss', 'gaussian']:
|
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)
|
kernel = gaussian_psf(FWHM=FWHM, shape=shape)
|
||||||
elif isinstance(psf, np.ndarray) and (len(psf.shape) == 2):
|
elif isinstance(psf, np.ndarray) and (len(psf.shape) == 2):
|
||||||
kernel = psf
|
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
|
# Deconvolve images in the array using given PSF
|
||||||
deconv_array = np.zeros(data_array.shape)
|
deconv_array = np.zeros(data_array.shape)
|
||||||
for i, image in enumerate(data_array):
|
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
|
return deconv_array
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user