Skip to content

Commit 543a5be

Browse files
authored
Merge pull request #225 from punch-mission/viz-kernels
add visualization for kernels
2 parents ca4ffb4 + 2d63339 commit 543a5be

File tree

3 files changed

+65
-57
lines changed

3 files changed

+65
-57
lines changed

docs/source/example.ipynb

Lines changed: 36 additions & 44 deletions
Large diffs are not rendered by default.

regularizepsf/psf.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,23 @@ def visualize_psfs(self,
337337
colorbar_label="Normalized brightness",
338338
imshow_args=imshow_args)
339339

340-
def visualize_kernels(self,
340+
def visualize_ffts(self,
341341
fig: mpl.figure.Figure | None = None,
342342
fig_scale: int = 1,
343343
all_patches: bool = False, imshow_args: dict | None = None) -> None: # noqa: ANN002, ANN003
344-
"""Visualize the transfer kernels."""
344+
"""Visualize the fft of the PSF."""
345345
imshow_args = KERNEL_IMSHOW_ARGS_DEFAULT if imshow_args is None else imshow_args
346346

347-
extent = np.max(np.abs(self._fft_cube.values))
347+
arr = np.abs(np.fft.fftshift(np.fft.ifft2(self._fft_cube.values)))
348+
extent = np.max(np.abs(arr))
348349
if 'vmin' not in imshow_args:
349-
imshow_args['vmin'] = extent
350+
imshow_args['vmin'] = -extent
350351
if 'vmax' not in imshow_args:
351352
imshow_args['vmax'] = extent
352353

353354
return visualize_grid(
354-
self._fft_cube, all_patches=all_patches, fig=fig,
355+
IndexedCube(self._fft_cube.coordinates, arr),
356+
all_patches=all_patches, fig=fig,
355357
fig_scale=fig_scale, colorbar_label="Transfer kernel amplitude",
356358
imshow_args=imshow_args)
357359

regularizepsf/transform.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
from typing import TYPE_CHECKING
66

77
import h5py
8+
import matplotlib as mpl
89
import numpy as np
910
import scipy
1011
from astropy.io import fits
1112

1213
from regularizepsf.exceptions import InvalidCoordinateError
1314
from regularizepsf.util import IndexedCube
15+
from regularizepsf.visualize import KERNEL_IMSHOW_ARGS_DEFAULT, visualize_grid
1416

1517
if TYPE_CHECKING:
1618
import pathlib
@@ -138,14 +140,25 @@ def slice_padded_image(coordinate: tuple[int, int]) -> tuple[slice, slice]:
138140
2 * self.psf_shape[1] : image.shape[1] + 2 * self.psf_shape[1],
139141
]
140142

141-
def visualize(self) -> None:
142-
"""Visualize the PSFTransform.
143-
144-
Returns
145-
-------
146-
None
147-
148-
"""
143+
def visualize(self,
144+
fig: mpl.figure.Figure | None = None,
145+
fig_scale: int = 1,
146+
all_patches: bool = False, imshow_args: dict | None = None) -> None: # noqa: ANN002, ANN003
147+
"""Visualize the transfer kernels."""
148+
imshow_args = KERNEL_IMSHOW_ARGS_DEFAULT if imshow_args is None else imshow_args
149+
150+
arr = np.abs(np.fft.fftshift(np.fft.ifft2(self._transfer_kernel.values)))
151+
extent = np.max(np.abs(arr))
152+
if 'vmin' not in imshow_args:
153+
imshow_args['vmin'] = -extent
154+
if 'vmax' not in imshow_args:
155+
imshow_args['vmax'] = extent
156+
157+
return visualize_grid(
158+
IndexedCube(self._transfer_kernel.coordinates, arr),
159+
all_patches=all_patches, fig=fig,
160+
fig_scale=fig_scale, colorbar_label="Transfer kernel amplitude",
161+
imshow_args=imshow_args)
149162

150163
def save(self, path: pathlib.Path) -> None:
151164
"""Save a PSFTransform to a file. Supports h5 and FITS.
@@ -173,6 +186,7 @@ def save(self, path: pathlib.Path) -> None:
173186
name="transfer_imag", quantize_level=32)]).writeto(path)
174187
else:
175188
raise NotImplementedError(f"Unsupported file type {path.suffix}. Change to .h5 or .fits.")
189+
176190
@classmethod
177191
def load(cls, path: pathlib.Path) -> ArrayPSFTransform:
178192
"""Load a PSFTransform object. Supports h5 and FITS.

0 commit comments

Comments
 (0)