LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
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
 
 variance
 
 weights
 
 psfs
 
 mode
 
 noise_rms
 
 model_psf
 
 padding
 
 diff_kernel
 
 grad_kernel
 

Protected Attributes

 _convolution_bounds
 

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" )

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

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
AmpInfoBoxKey bbox
Definition Amplifier.cc:117

◆ 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

lsst.scarlet.lite.observation.Observation._convolution_bounds
protected

Definition at line 371 of file observation.py.

◆ diff_kernel

lsst.scarlet.lite.observation.Observation.diff_kernel

Definition at line 261 of file observation.py.

◆ grad_kernel

lsst.scarlet.lite.observation.Observation.grad_kernel

Definition at line 262 of file observation.py.

◆ images

lsst.scarlet.lite.observation.Observation.images

Definition at line 230 of file observation.py.

◆ mode

lsst.scarlet.lite.observation.Observation.mode

Definition at line 243 of file observation.py.

◆ model_psf

lsst.scarlet.lite.observation.Observation.model_psf

Definition at line 250 of file observation.py.

◆ noise_rms

lsst.scarlet.lite.observation.Observation.noise_rms

Definition at line 246 of file observation.py.

◆ padding

lsst.scarlet.lite.observation.Observation.padding

Definition at line 251 of file observation.py.

◆ psfs

lsst.scarlet.lite.observation.Observation.psfs

Definition at line 236 of file observation.py.

◆ variance

lsst.scarlet.lite.observation.Observation.variance

Definition at line 231 of file observation.py.

◆ weights

lsst.scarlet.lite.observation.Observation.weights

Definition at line 232 of file observation.py.


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