Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0d33ba9806+b932483eba,g0fba68d861+d53f2a615d,g1e78f5e6d3+1e869f36eb,g1ec0fe41b4+f536777771,g1fd858c14a+d5f4961c99,g35bb328faa+fcb1d3bbc8,g4af146b050+2e821d8f6b,g4d2262a081+b02c98aa00,g53246c7159+fcb1d3bbc8,g5a012ec0e7+b20b785ecb,g60b5630c4e+b932483eba,g67b6fd64d1+4086c0989b,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+7d8c31d03d,g8852436030+a639f189fc,g89139ef638+4086c0989b,g9125e01d80+fcb1d3bbc8,g94187f82dc+b932483eba,g989de1cb63+4086c0989b,g9f33ca652e+898eabdf38,g9f7030ddb1+b068313d7a,ga2b97cdc51+b932483eba,ga44b1db4f6+2bd830756e,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+f4f1608365,gb58c049af0+f03b321e39,gb89ab40317+4086c0989b,gcf25f946ba+a639f189fc,gd6cbbdb0b4+af3c3595f5,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+4078fef7e5,ge278dab8ac+d65b3c2b70,ge410e46f29+4086c0989b,gf67bdafdda+4086c0989b,gfe06eef73a+6e83fc67a4,v29.0.0.rc5
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
lsst.scarlet.lite.observation.Observation Class Reference
Inheritance diagram for lsst.scarlet.lite.observation.Observation:
lsst.scarlet.lite.models.fit_psf.FittedPsfObservation

Public Member Functions

 __init__ (self, np.ndarray|Image images, np.ndarray|Image variance, np.ndarray|Image weights, np.ndarray psfs, np.ndarray|None model_psf=None, np.ndarray|None noise_rms=None, Box|None bbox=None, tuple|None bands=None, int padding=3, str convolution_mode="fft")
 
tuple bands (self)
 
Box bbox (self)
 
Image convolve (self, Image image, str|None mode=None, bool grad=False)
 
float log_likelihood (self, Image model)
 
tuple[int, int, int] shape (self)
 
int n_bands (self)
 
npt.DTypeLike dtype (self)
 
tuple[int, int, int, int] convolution_bounds (self)
 

Static Public Member Functions

Observation empty (tuple[Any] bands, np.ndarray psfs, np.ndarray model_psf, Box bbox, npt.DTypeLike dtype)
 

Public Attributes

 images = images
 
 variance = _set_image_like(variance, bands, bbox)
 
 weights = _set_image_like(weights, bands, bbox)
 
 psfs = psfs
 
 mode = convolution_mode
 
 noise_rms = noise_rms
 
 model_psf = model_psf
 
 padding = padding
 
Fourier|None diff_kernel = cast(Fourier, match_kernel(psfs, model_psf, padding=padding))
 
Fourier|None grad_kernel = Fourier(diff_img[:, ::-1, ::-1])
 

Protected Attributes

tuple[int, int, int, int]|None _convolution_bounds = None
 

Detailed Description

A single observation

This class contains all of the observed images and derived
properties, like PSFs, variance map, and weight maps,
required for most optimizers.
This includes methods to match a scarlet model PSF to the oberved PSF
in each band.

Notes
-----
This is effectively a combination of the `Observation` and
`Renderer` class from scarlet main, greatly simplified due
to the assumptions that the observations are all resampled
onto the same pixel grid and that the `images` contain all
of the information for all of the model bands.

Parameters
----------
images:
    (bands, y, x) array of observed images.
variance:
    (bands, y, x) array of variance for each image pixel.
weights:
    (bands, y, x) array of weights to use when calculate the
    likelihood of each pixel.
psfs:
    (bands, y, x) array of the PSF image in each band.
model_psf:
    (bands, y, x) array of the model PSF image in each band.
    If `model_psf` is `None` then convolution is performed,
    which should only be done when the observation is a
    PSF matched coadd, and the scarlet model has the same PSF.
noise_rms:
    Per-band average noise RMS. If `noise_rms` is `None` then the mean
    of the sqrt of the variance is used.
bbox:
    The bounding box containing the model. If `bbox` is `None` then
    a `Box` is created that is the shape of `images` with an origin
    at `(0, 0)`.
padding:
    Padding to use when performing an FFT convolution.
convolution_mode:
    The method of convolution. This should be either "fft" or "real".

Definition at line 166 of file observation.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.scarlet.lite.observation.Observation.__init__ ( self,
np.ndarray | Image images,
np.ndarray | Image variance,
np.ndarray | Image weights,
np.ndarray psfs,
np.ndarray | None model_psf = None,
np.ndarray | None noise_rms = None,
Box | None bbox = None,
tuple | None bands = None,
int padding = 3,
str convolution_mode = "fft" )

Definition at line 212 of file observation.py.

224 ):
225 # Convert the images to a multi-band `Image` and use the resulting
226 # bbox and bands.
227 images = _set_image_like(images, bands, bbox)
228 bands = images.bands
229 bbox = images.bbox
230 self.images = images
231 self.variance = _set_image_like(variance, bands, bbox)
232 self.weights = _set_image_like(weights, bands, bbox)
233 # make sure that the images and psfs have the same dtype
234 if psfs.dtype != images.dtype:
235 psfs = psfs.astype(images.dtype)
236 self.psfs = psfs
237
238 if convolution_mode not in [
239 "fft",
240 "real",
241 ]:
242 raise ValueError("convolution_mode must be either 'fft' or 'real'")
243 self.mode = convolution_mode
244 if noise_rms is None:
245 noise_rms = np.array(np.mean(np.sqrt(variance.data), axis=(1, 2)))
246 self.noise_rms = noise_rms
247
248 # Create a difference kernel to convolve the model to the PSF
249 # in each band
250 self.model_psf = model_psf
251 self.padding = padding
252 if model_psf is not None:
253 if model_psf.dtype != images.dtype:
254 self.model_psf = model_psf.astype(images.dtype)
255 self.diff_kernel: Fourier | None = cast(Fourier, match_kernel(psfs, model_psf, padding=padding))
256 # The gradient of a convolution is another convolution,
257 # but with the flipped and transposed kernel.
258 diff_img = self.diff_kernel.image
259 self.grad_kernel: Fourier | None = Fourier(diff_img[:, ::-1, ::-1])
260 else:
261 self.diff_kernel = None
262 self.grad_kernel = None
263
264 self._convolution_bounds: tuple[int, int, int, int] | None = None
265

Member Function Documentation

◆ bands()

tuple lsst.scarlet.lite.observation.Observation.bands ( self)
The bands in the observations.

Definition at line 267 of file observation.py.

267 def bands(self) -> tuple:
268 """The bands in the observations."""
269 return self.images.bands
270

◆ bbox()

Box lsst.scarlet.lite.observation.Observation.bbox ( self)
The bounding box for the full observation.

Definition at line 272 of file observation.py.

272 def bbox(self) -> Box:
273 """The bounding box for the full observation."""
274 return self.images.bbox
275

◆ convolution_bounds()

tuple[int, int, int, int] lsst.scarlet.lite.observation.Observation.convolution_bounds ( self)
Build the slices needed for convolution in real space

Definition at line 367 of file observation.py.

367 def convolution_bounds(self) -> tuple[int, int, int, int]:
368 """Build the slices needed for convolution in real space"""
369 if self._convolution_bounds is None:
370 coords = get_filter_coords(cast(Fourier, self.diff_kernel).image[0])
371 self._convolution_bounds = get_filter_bounds(coords.reshape(-1, 2))
372 return self._convolution_bounds
373

◆ convolve()

Image lsst.scarlet.lite.observation.Observation.convolve ( self,
Image image,
str | None mode = None,
bool grad = False )
Convolve the model into the observed seeing in each band.

Parameters
----------
image:
    The 3D image to convolve.
mode:
    The convolution mode to use.
    This should be "real" or "fft" or `None`,
    where `None` will use the default `convolution_mode`
    specified during init.
grad:
    Whether this is a backward gradient convolution
    (`grad==True`) or a pure convolution with the PSF.

Returns
-------
result:
    The convolved image.

Reimplemented in lsst.scarlet.lite.models.fit_psf.FittedPsfObservation.

Definition at line 276 of file observation.py.

276 def convolve(self, image: Image, mode: str | None = None, grad: bool = False) -> Image:
277 """Convolve the model into the observed seeing in each band.
278
279 Parameters
280 ----------
281 image:
282 The 3D image to convolve.
283 mode:
284 The convolution mode to use.
285 This should be "real" or "fft" or `None`,
286 where `None` will use the default `convolution_mode`
287 specified during init.
288 grad:
289 Whether this is a backward gradient convolution
290 (`grad==True`) or a pure convolution with the PSF.
291
292 Returns
293 -------
294 result:
295 The convolved image.
296 """
297 if grad:
298 kernel = self.grad_kernel
299 else:
300 kernel = self.diff_kernel
301
302 if kernel is None:
303 return image
304
305 if mode is None:
306 mode = self.mode
307 if mode == "fft":
308 result = fft_convolve(
309 Fourier(image.data),
310 kernel,
311 axes=(1, 2),
312 return_fourier=False,
313 )
314 elif mode == "real":
315 dy = image.shape[1] - kernel.image.shape[1]
316 dx = image.shape[2] - kernel.image.shape[2]
317 if dy < 0 or dx < 0:
318 # The image needs to be padded because it is smaller than
319 # the psf kernel
320 _image = image.data
321 newshape = list(_image.shape)
322 if dy < 0:
323 newshape[1] += kernel.image.shape[1] - image.shape[1]
324 if dx < 0:
325 newshape[2] += kernel.image.shape[2] - image.shape[2]
326 _image = _pad(_image, newshape)
327 result = convolve(_image, kernel.image, self.convolution_bounds)
328 result = centered(result, image.data.shape) # type: ignore
329 else:
330 result = convolve(image.data, kernel.image, self.convolution_bounds)
331 else:
332 raise ValueError(f"mode must be either 'fft' or 'real', got {mode}")
333 return Image(cast(np.ndarray, result), bands=image.bands, yx0=image.yx0)
334

◆ dtype()

npt.DTypeLike lsst.scarlet.lite.observation.Observation.dtype ( self)
The dtype of the observation is the dtype of the images

Definition at line 362 of file observation.py.

362 def dtype(self) -> npt.DTypeLike:
363 """The dtype of the observation is the dtype of the images"""
364 return self.images.dtype
365

◆ empty()

Observation lsst.scarlet.lite.observation.Observation.empty ( tuple[Any] bands,
np.ndarray psfs,
np.ndarray model_psf,
Box bbox,
npt.DTypeLike dtype )
static

Definition at line 375 of file observation.py.

377 ) -> Observation:
378 dummy_image = np.zeros((len(bands),) + bbox.shape, dtype=dtype)
379
380 return Observation(
381 images=dummy_image,
382 variance=dummy_image,
383 weights=dummy_image,
384 psfs=psfs,
385 model_psf=model_psf,
386 noise_rms=np.zeros((len(bands),), dtype=dtype),
387 bbox=bbox,
388 bands=bands,
389 convolution_mode="real",
390 )

◆ log_likelihood()

float lsst.scarlet.lite.observation.Observation.log_likelihood ( self,
Image model )
Calculate the log likelihood of the given model

Parameters
----------
model:
    Model to compare with the observed images.

Returns
-------
result:
    The log-likelihood of the given model.

Definition at line 335 of file observation.py.

335 def log_likelihood(self, model: Image) -> float:
336 """Calculate the log likelihood of the given model
337
338 Parameters
339 ----------
340 model:
341 Model to compare with the observed images.
342
343 Returns
344 -------
345 result:
346 The log-likelihood of the given model.
347 """
348 result = 0.5 * -np.sum((self.weights * (self.images - model) ** 2).data)
349 return result
350

◆ n_bands()

int lsst.scarlet.lite.observation.Observation.n_bands ( self)
The number of bands in the observation

Definition at line 357 of file observation.py.

357 def n_bands(self) -> int:
358 """The number of bands in the observation"""
359 return self.images.shape[0]
360

◆ shape()

tuple[int, int, int] lsst.scarlet.lite.observation.Observation.shape ( self)
The shape of the images, variance, etc.

Definition at line 352 of file observation.py.

352 def shape(self) -> tuple[int, int, int]:
353 """The shape of the images, variance, etc."""
354 return cast(tuple[int, int, int], self.images.shape)
355

Member Data Documentation

◆ _convolution_bounds

tuple[int, int, int, int] | None lsst.scarlet.lite.observation.Observation._convolution_bounds = None
protected

Definition at line 264 of file observation.py.

◆ diff_kernel

Fourier | None lsst.scarlet.lite.observation.Observation.diff_kernel = cast(Fourier, match_kernel(psfs, model_psf, padding=padding))

Definition at line 255 of file observation.py.

◆ grad_kernel

Fourier | None lsst.scarlet.lite.observation.Observation.grad_kernel = Fourier(diff_img[:, ::-1, ::-1])

Definition at line 259 of file observation.py.

◆ images

lsst.scarlet.lite.observation.Observation.images = images

Definition at line 230 of file observation.py.

◆ mode

lsst.scarlet.lite.observation.Observation.mode = convolution_mode

Definition at line 243 of file observation.py.

◆ model_psf

lsst.scarlet.lite.observation.Observation.model_psf = model_psf

Definition at line 250 of file observation.py.

◆ noise_rms

lsst.scarlet.lite.observation.Observation.noise_rms = noise_rms

Definition at line 246 of file observation.py.

◆ padding

lsst.scarlet.lite.observation.Observation.padding = padding

Definition at line 251 of file observation.py.

◆ psfs

lsst.scarlet.lite.observation.Observation.psfs = psfs

Definition at line 236 of file observation.py.

◆ variance

lsst.scarlet.lite.observation.Observation.variance = _set_image_like(variance, bands, bbox)

Definition at line 231 of file observation.py.

◆ weights

lsst.scarlet.lite.observation.Observation.weights = _set_image_like(weights, bands, bbox)

Definition at line 232 of file observation.py.


The documentation for this class was generated from the following file: