LSST Applications g00274db5b6+edbf708997,g00d0e8bbd7+edbf708997,g199a45376c+5137f08352,g1fd858c14a+1d4b6db739,g262e1987ae+f4d9505c4f,g29ae962dfc+7156fb1a53,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3e17d7035e+5b3adc59f5,g3fd5ace14f+852fa6fbcb,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+9f17e571f4,g67b6fd64d1+6dc8069a4c,g74acd417e5+ae494d68d9,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+536efcc10a,g7cc15d900a+d121454f8d,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d7436a09f+28c28d8d6d,g8ea07a8fe4+db21c37724,g92c671f44c+9f17e571f4,g98df359435+b2e6376b13,g99af87f6a8+b0f4ad7b8d,gac66b60396+966efe6077,gb88ae4c679+7dec8f19df,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gc24b5d6ed1+9f17e571f4,gca7fc764a6+6dc8069a4c,gcc769fe2a4+97d0256649,gd7ef33dd92+6dc8069a4c,gdab6d2f7ff+ae494d68d9,gdbb4c4dda9+9f17e571f4,ge410e46f29+6dc8069a4c,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.scarlet.lite.component.FactorizedComponent Class Reference
Inheritance diagram for lsst.scarlet.lite.component.FactorizedComponent:
lsst.scarlet.lite.component.Component lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent

Public Member Functions

 __init__ (self, tuple bands, Parameter|np.ndarray spectrum, Parameter|np.ndarray morph, Box bbox, tuple[int, int]|None peak=None, np.ndarray|None bg_rms=None, float|None bg_thresh=0.25, float floor=1e-20, Monotonicity|None monotonicity=None, int padding=5, bool is_symmetric=False)
 
tuple[int, int]|None peak (self)
 
tuple[int, int]|None component_center (self)
 
np.ndarray spectrum (self)
 
np.ndarray morph (self)
 
tuple shape (self)
 
Image get_model (self)
 
 grad_spectrum (self, np.ndarray input_grad, np.ndarray spectrum, np.ndarray morph)
 
 grad_morph (self, np.ndarray input_grad, np.ndarray morph, np.ndarray spectrum)
 
np.ndarray prox_spectrum (self, np.ndarray spectrum)
 
np.ndarray prox_morph (self, np.ndarray morph)
 
bool resize (self, Box model_box)
 
 update (self, int it, np.ndarray input_grad)
 
None parameterize (self, Callable parameterization)
 
ScarletComponentBaseData to_data (self)
 
 __str__ (self)
 
 __repr__ (self)
 
Box bbox (self)
 
tuple bands (self)
 

Public Attributes

 bg_rms = bg_rms
 
 bg_thresh = bg_thresh
 
 floor = floor
 
 monotonicity = monotonicity
 
 padding = padding
 
 is_symmetric = is_symmetric
 
 morph
 

Protected Attributes

 _spectrum = parameter(spectrum)
 
 _morph = parameter(morph)
 
tuple[int, int]|None _peak = peak
 
tuple _bands = bands
 
Box _bbox = bbox
 

Detailed Description

A component that can be factorized into spectrum and morphology
parameters.

Parameters
----------
bands:
    The bands of the spectral dimension, in order.
spectrum:
    The parameter to store and update the spectrum.
morph:
    The parameter to store and update the morphology.
peak:
    Location of the peak for the source.
bbox:
    The `Box` in the `model_bbox` that contains the source.
bg_rms:
    The RMS of the background used to threshold, grow,
    and shrink the component.
bg_thresh:
    The threshold to use for the background RMS.
    If `None`, no background thresholding is applied, otherwise
    a sparsity constraint is applied to the morpholigy that
    requires flux in at least one band to be bg_thresh multiplied by
    `bg_rms` in that band.
floor:
    Minimum value of the spectrum or center morphology pixel
    (depending on which is normalized).
monotonicity:
    The monotonicity operator to use for making the source monotonic.
    If this parameter is `None`, the source will not be made monotonic.
padding:
    The amount of padding to add to the component bounding box
    when resizing the component.
is_symmetric:
    Whether the component is symmetric or not.
    If `True`, the morphology will be symmetrized using
    `prox_uncentered_symmetry`.
    If `False`, the morphology will not be symmetrized.

Definition at line 130 of file component.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.scarlet.lite.component.FactorizedComponent.__init__ ( self,
tuple bands,
Parameter | np.ndarray spectrum,
Parameter | np.ndarray morph,
Box bbox,
tuple[int, int] | None peak = None,
np.ndarray | None bg_rms = None,
float | None bg_thresh = 0.25,
float floor = 1e-20,
Monotonicity | None monotonicity = None,
int padding = 5,
bool is_symmetric = False )

Definition at line 171 of file component.py.

184 ):
185 # Initialize all of the base attributes
186 super().__init__(
187 bands=bands,
188 bbox=bbox,
189 )
190 self._spectrum = parameter(spectrum)
191 self._morph = parameter(morph)
192 self._peak = peak
193 self.bg_rms = bg_rms
194 self.bg_thresh = bg_thresh
195
196 self.floor = floor
197 self.monotonicity = monotonicity
198 self.padding = padding
199 self.is_symmetric = is_symmetric
200

Member Function Documentation

◆ __repr__()

lsst.scarlet.lite.component.FactorizedComponent.__repr__ ( self)

Definition at line 395 of file component.py.

395 def __repr__(self):
396 return self.__str__()
397
398

◆ __str__()

lsst.scarlet.lite.component.FactorizedComponent.__str__ ( self)

Definition at line 388 of file component.py.

388 def __str__(self):
389 result = (
390 f"FactorizedComponent<\n bands={self.bands},\n center={self.peak},\n "
391 f"spectrum={self.spectrum},\n morph_shape={self.morph.shape}\n>"
392 )
393 return result
394

◆ bands()

tuple lsst.scarlet.lite.component.Component.bands ( self)
inherited
The bands in the component model

Definition at line 71 of file component.py.

71 def bands(self) -> tuple:
72 """The bands in the component model"""
73 return self._bands
74

◆ bbox()

Box lsst.scarlet.lite.component.Component.bbox ( self)
inherited
The bounding box that contains the component in the full image

Definition at line 66 of file component.py.

66 def bbox(self) -> Box:
67 """The bounding box that contains the component in the full image"""
68 return self._bbox
69

◆ component_center()

tuple[int, int] | None lsst.scarlet.lite.component.FactorizedComponent.component_center ( self)
The center of the component in its bounding box

This is likely to be different than `Component.center`,
since `Component.center` is the center of the component in the
full model, whereas `component_center` is the center of the component
inside its bounding box.

Returns
-------
center:
    The center of the component in its bounding box

Definition at line 213 of file component.py.

213 def component_center(self) -> tuple[int, int] | None:
214 """The center of the component in its bounding box
215
216 This is likely to be different than `Component.center`,
217 since `Component.center` is the center of the component in the
218 full model, whereas `component_center` is the center of the component
219 inside its bounding box.
220
221 Returns
222 -------
223 center:
224 The center of the component in its bounding box
225 """
226 _center = self.peak
227 if _center is None:
228 return None
229 center = (
230 _center[0] - self.bbox.origin[-2],
231 _center[1] - self.bbox.origin[-1],
232 )
233 return center
234

◆ get_model()

Image lsst.scarlet.lite.component.FactorizedComponent.get_model ( self)
Build the model from the spectrum and morphology

Reimplemented from lsst.scarlet.lite.component.Component.

Definition at line 250 of file component.py.

250 def get_model(self) -> Image:
251 """Build the model from the spectrum and morphology"""
252 # The spectrum and morph might be Parameters,
253 # so cast them as arrays in the model.
254 spectrum = self.spectrum
255 morph = self.morph
256 model = spectrum[:, None, None] * morph[None, :, :]
257 return Image(model, bands=self.bands, yx0=cast(tuple[int, int], self.bbox.origin))
258

◆ grad_morph()

lsst.scarlet.lite.component.FactorizedComponent.grad_morph ( self,
np.ndarray input_grad,
np.ndarray morph,
np.ndarray spectrum )
Gradient of the morph wrt. the component model

Definition at line 263 of file component.py.

263 def grad_morph(self, input_grad: np.ndarray, morph: np.ndarray, spectrum: np.ndarray):
264 """Gradient of the morph wrt. the component model"""
265 return np.einsum("i,i...", spectrum, input_grad)
266

◆ grad_spectrum()

lsst.scarlet.lite.component.FactorizedComponent.grad_spectrum ( self,
np.ndarray input_grad,
np.ndarray spectrum,
np.ndarray morph )
Gradient of the spectrum wrt. the component model

Definition at line 259 of file component.py.

259 def grad_spectrum(self, input_grad: np.ndarray, spectrum: np.ndarray, morph: np.ndarray):
260 """Gradient of the spectrum wrt. the component model"""
261 return np.einsum("...jk,jk", input_grad, morph)
262

◆ morph()

np.ndarray lsst.scarlet.lite.component.FactorizedComponent.morph ( self)
The array of morphology values

Definition at line 241 of file component.py.

241 def morph(self) -> np.ndarray:
242 """The array of morphology values"""
243 return self._morph.x
244

◆ parameterize()

None lsst.scarlet.lite.component.FactorizedComponent.parameterize ( self,
Callable parameterization )
Convert the component parameter arrays into Parameter instances

Parameters
----------
parameterization: Callable
    A function to use to convert parameters of a given type into
    a `Parameter` in place. It should take a single argument that
    is the `Component` or `Source` that is to be parameterized.

Reimplemented from lsst.scarlet.lite.component.Component.

Definition at line 353 of file component.py.

353 def parameterize(self, parameterization: Callable) -> None:
354 """Convert the component parameter arrays into Parameter instances
355
356 Parameters
357 ----------
358 parameterization: Callable
359 A function to use to convert parameters of a given type into
360 a `Parameter` in place. It should take a single argument that
361 is the `Component` or `Source` that is to be parameterized.
362 """
363 # Update the spectrum and morph in place
364 parameterization(self)
365 # update the parameters
366 self._spectrum.grad = self.grad_spectrum
367 self._spectrum.prox = self.prox_spectrum
368 self._morph.grad = self.grad_morph
369 self._morph.prox = self.prox_morph
370

◆ peak()

tuple[int, int] | None lsst.scarlet.lite.component.FactorizedComponent.peak ( self)
The peak of the component

Returns
-------
peak:
    The peak of the component

Definition at line 202 of file component.py.

202 def peak(self) -> tuple[int, int] | None:
203 """The peak of the component
204
205 Returns
206 -------
207 peak:
208 The peak of the component
209 """
210 return self._peak
211

◆ prox_morph()

np.ndarray lsst.scarlet.lite.component.FactorizedComponent.prox_morph ( self,
np.ndarray morph )
Apply a prox-like update to the morphology

Reimplemented in lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent.

Definition at line 274 of file component.py.

274 def prox_morph(self, morph: np.ndarray) -> np.ndarray:
275 """Apply a prox-like update to the morphology"""
276 # Get the peak position in the current bbox
277 shape = morph.shape
278 if self.peak is None:
279 peak = (shape[0] // 2, shape[1] // 2)
280 else:
281 peak = (
282 self.peak[0] - self.bbox.origin[-2],
283 self.peak[1] - self.bbox.origin[-1],
284 )
285
286 # monotonicity
287 if self.monotonicity is not None:
288 morph = self.monotonicity(morph, cast(tuple[int, int], self.component_center))
289
290 # symmetry
291 if self.is_symmetric:
292 # Apply the symmetry operator
293 morph = prox_uncentered_symmetry(morph, peak, fill=0.0)
294
295 if self.bg_thresh is not None and self.bg_rms is not None:
296 bg_thresh = self.bg_rms * self.bg_thresh
297 # Enforce background thresholding
298 model = self.spectrum[:, None, None] * morph[None, :, :]
299 morph[np.all(model < bg_thresh[:, None, None], axis=0)] = 0
300 else:
301 # enforce positivity
302 morph[morph < 0] = 0
303
304 # prevent divergent morphology
305 morph[peak] = np.max([morph[peak], self.floor])
306
307 # Ensure that the morphology is finite
308 morph[~np.isfinite(morph)] = 0
309
310 # Normalize the morphology
311 max_value = np.max(morph)
312 if max_value > 0:
313 morph[:] = morph / max_value
314 return morph
315

◆ prox_spectrum()

np.ndarray lsst.scarlet.lite.component.FactorizedComponent.prox_spectrum ( self,
np.ndarray spectrum )
Apply a prox-like update to the spectrum

Reimplemented in lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent.

Definition at line 267 of file component.py.

267 def prox_spectrum(self, spectrum: np.ndarray) -> np.ndarray:
268 """Apply a prox-like update to the spectrum"""
269 # prevent divergent spectrum
270 spectrum[spectrum < self.floor] = self.floor
271 spectrum[~np.isfinite(spectrum)] = self.floor
272 return spectrum
273

◆ resize()

bool lsst.scarlet.lite.component.FactorizedComponent.resize ( self,
Box model_box )
Test whether or not the component needs to be resized

Reimplemented from lsst.scarlet.lite.component.Component.

Reimplemented in lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent.

Definition at line 316 of file component.py.

316 def resize(self, model_box: Box) -> bool:
317 """Test whether or not the component needs to be resized"""
318 # No need to resize if there is no size threshold.
319 # To allow box sizing but no thresholding use `bg_thresh=0`.
320 if self.bg_thresh is None or self.bg_rms is None:
321 return False
322
323 model = self.spectrum[:, None, None] * self.morph[None, :, :]
324 bg_thresh = self.bg_rms * self.bg_thresh
325 significant = np.any(model >= bg_thresh[:, None, None], axis=0)
326 if np.sum(significant) == 0:
327 # There are no significant pixels,
328 # so make a small box around the center
329 center = self.peak
330 if center is None:
331 center = (0, 0)
332 new_box = Box((1, 1), center).grow(self.padding) & model_box
333 else:
334 new_box = (
335 Box.from_data(significant, threshold=0).grow(self.padding) + self.bbox.origin # type: ignore
336 ) & model_box
337 if new_box == self.bbox:
338 return False
339
340 old_box = self.bbox
341 self._bbox = new_box
342 self._morph.resize(old_box, new_box)
343 return True
344

◆ shape()

tuple lsst.scarlet.lite.component.FactorizedComponent.shape ( self)
Shape of the resulting model image

Definition at line 246 of file component.py.

246 def shape(self) -> tuple:
247 """Shape of the resulting model image"""
248 return self.spectrum.shape + self.morph.shape
249

◆ spectrum()

np.ndarray lsst.scarlet.lite.component.FactorizedComponent.spectrum ( self)
The array of spectrum values

Definition at line 236 of file component.py.

236 def spectrum(self) -> np.ndarray:
237 """The array of spectrum values"""
238 return self._spectrum.x
239

◆ to_data()

ScarletComponentBaseData lsst.scarlet.lite.component.FactorizedComponent.to_data ( self)
Convert the component to persistable ScarletComponentBaseData

Returns
-------
component_data: ScarletComponentBaseData
    The data object containing the component information

Reimplemented from lsst.scarlet.lite.component.Component.

Definition at line 371 of file component.py.

371 def to_data(self) -> ScarletComponentBaseData:
372 """Convert the component to persistable ScarletComponentBaseData
373
374 Returns
375 -------
376 component_data: ScarletComponentBaseData
377 The data object containing the component information
378 """
379 from .io import ScarletFactorizedComponentData
380
381 return ScarletFactorizedComponentData(
382 origin=self.bbox.origin, # type: ignore
383 peak=self.peak, # type: ignore
384 spectrum=self.spectrum,
385 morph=self.morph,
386 )
387

◆ update()

lsst.scarlet.lite.component.FactorizedComponent.update ( self,
int it,
np.ndarray input_grad )
Update the spectrum and morphology parameters

Reimplemented from lsst.scarlet.lite.component.Component.

Definition at line 345 of file component.py.

345 def update(self, it: int, input_grad: np.ndarray):
346 """Update the spectrum and morphology parameters"""
347 # Store the input spectrum so that the morphology can
348 # have a consistent update
349 spectrum = self.spectrum.copy()
350 self._spectrum.update(it, input_grad, self.morph)
351 self._morph.update(it, input_grad, spectrum)
352

Member Data Documentation

◆ _bands

tuple lsst.scarlet.lite.component.Component._bands = bands
protectedinherited

Definition at line 62 of file component.py.

◆ _bbox

Box lsst.scarlet.lite.component.Component._bbox = bbox
protectedinherited

Definition at line 63 of file component.py.

◆ _morph

lsst.scarlet.lite.component.FactorizedComponent._morph = parameter(morph)
protected

Definition at line 191 of file component.py.

◆ _peak

tuple[int, int] | None lsst.scarlet.lite.component.FactorizedComponent._peak = peak
protected

Definition at line 192 of file component.py.

◆ _spectrum

lsst.scarlet.lite.component.FactorizedComponent._spectrum = parameter(spectrum)
protected

Definition at line 190 of file component.py.

◆ bg_rms

lsst.scarlet.lite.component.FactorizedComponent.bg_rms = bg_rms

Definition at line 193 of file component.py.

◆ bg_thresh

lsst.scarlet.lite.component.FactorizedComponent.bg_thresh = bg_thresh

Definition at line 194 of file component.py.

◆ floor

lsst.scarlet.lite.component.FactorizedComponent.floor = floor

Definition at line 196 of file component.py.

◆ is_symmetric

lsst.scarlet.lite.component.FactorizedComponent.is_symmetric = is_symmetric

Definition at line 199 of file component.py.

◆ monotonicity

lsst.scarlet.lite.component.FactorizedComponent.monotonicity = monotonicity

Definition at line 197 of file component.py.

◆ morph

lsst.scarlet.lite.component.FactorizedComponent.morph

Definition at line 350 of file component.py.

◆ padding

lsst.scarlet.lite.component.FactorizedComponent.padding = padding

Definition at line 198 of file component.py.


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