LSST Applications g0f08755f38+c89d42e150,g1635faa6d4+b6cf076a36,g1653933729+a8ce1bb630,g1a0ca8cf93+4c08b13bf7,g28da252d5a+f33f8200ef,g29321ee8c0+0187be18b1,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+e740673f1a,g5fbc88fb19+17cd334064,g7642f7d749+c89d42e150,g781aacb6e4+a8ce1bb630,g80478fca09+f8b2ab54e1,g82479be7b0+e2bd23ab8b,g858d7b2824+c89d42e150,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+065360aec4,gacf8899fa4+9553554aa7,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gbd46683f8f+ac57cbb13d,gc28159a63d+9634bc57db,gcf0d15dbbd+e37acf7834,gda3e153d99+c89d42e150,gda6a2b7d83+e37acf7834,gdaeeff99f8+1711a396fd,ge2409df99d+cb1e6652d6,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+02b11634a5,w.2024.45
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 167 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 213 of file observation.py.

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

Member Function Documentation

◆ bands()

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

Definition at line 268 of file observation.py.

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

◆ bbox()

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

Definition at line 273 of file observation.py.

273 def bbox(self) -> Box:
274 """The bounding box for the full observation."""
275 return self.images.bbox
276
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 368 of file observation.py.

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

◆ 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 277 of file observation.py.

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

◆ dtype()

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

Definition at line 363 of file observation.py.

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

◆ 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 376 of file observation.py.

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

◆ 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 336 of file observation.py.

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

◆ n_bands()

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

Definition at line 358 of file observation.py.

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

◆ shape()

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

Definition at line 353 of file observation.py.

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

Member Data Documentation

◆ _convolution_bounds

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

Definition at line 372 of file observation.py.

◆ diff_kernel

lsst.scarlet.lite.observation.Observation.diff_kernel

Definition at line 262 of file observation.py.

◆ grad_kernel

lsst.scarlet.lite.observation.Observation.grad_kernel

Definition at line 263 of file observation.py.

◆ images

lsst.scarlet.lite.observation.Observation.images

Definition at line 231 of file observation.py.

◆ mode

lsst.scarlet.lite.observation.Observation.mode

Definition at line 244 of file observation.py.

◆ model_psf

lsst.scarlet.lite.observation.Observation.model_psf

Definition at line 251 of file observation.py.

◆ noise_rms

lsst.scarlet.lite.observation.Observation.noise_rms

Definition at line 247 of file observation.py.

◆ padding

lsst.scarlet.lite.observation.Observation.padding

Definition at line 252 of file observation.py.

◆ psfs

lsst.scarlet.lite.observation.Observation.psfs

Definition at line 237 of file observation.py.

◆ variance

lsst.scarlet.lite.observation.Observation.variance

Definition at line 232 of file observation.py.

◆ weights

lsst.scarlet.lite.observation.Observation.weights

Definition at line 233 of file observation.py.


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