LSST Applications 29.1.0,g0fba68d861+6b120c4394,g123d84c11c+8c5ae1fdc5,g1ec0fe41b4+191117f6ec,g1fd858c14a+c8450ae71a,g3533f9d6cb+a04f9ee0ab,g35bb328faa+8c5ae1fdc5,g3f0dcc2b1b+7df08700bd,g4178042926+b4254969db,g44ba364a48+04455b336b,g53246c7159+8c5ae1fdc5,g60b5630c4e+a04f9ee0ab,g663da51e9b+b05e6e1875,g67b6fd64d1+250bf6acd3,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g8352419a5c+8c5ae1fdc5,g87e3079a85+d3fa38de54,g8852436030+cd899e2626,g89139ef638+250bf6acd3,g93a033419f+31ead11197,g989de1cb63+250bf6acd3,g9f33ca652e+f6053ecf14,ga1e959baac+5fbc491aed,ga2f891cd6c+a04f9ee0ab,gabe3b4be73+8856018cbb,gabf8522325+1f7e6d67b9,gac2eed3f23+250bf6acd3,gb1101e3267+0c331e9486,gb89ab40317+250bf6acd3,gcf25f946ba+cd899e2626,gd107969129+8964d67276,gd6cbbdb0b4+6bbecc8878,gde0f65d7ad+d65f9e019a,ge278dab8ac+eb3bbeb12f,ge410e46f29+250bf6acd3,gf5e32f922b+8c5ae1fdc5,gff02db199a+747430a128,gffe7e49bb4+a04f9ee0ab
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent Class Reference
Inheritance diagram for lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent:
lsst.scarlet.lite.component.FactorizedComponent lsst.scarlet.lite.component.Component

Public Member Functions

 __init__ (self, tuple bands, np.ndarray|Parameter spectrum, np.ndarray|Parameter morph, Box model_bbox, float|None bg_thresh=None, np.ndarray|None bg_rms=None, float floor=1e-20, list[tuple[int, int]]|None peaks=None, float min_area=0)
 
np.ndarray prox_spectrum (self, np.ndarray spectrum)
 
np.ndarray prox_morph (self, np.ndarray morph)
 
bool resize (self, Box model_box)
 
 __str__ (self)
 
 __repr__ (self)
 
np.ndarray morph (self)
 
tuple[int, int]|None peak (self)
 
tuple[int, int]|None component_center (self)
 
np.ndarray spectrum (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)
 
 update (self, int it, np.ndarray input_grad)
 
None parameterize (self, Callable parameterization)
 
Box bbox (self)
 
tuple bands (self)
 

Public Attributes

 peaks = peaks
 
 min_area = min_area
 
 bg_rms = bg_rms
 
 bg_thresh = bg_thresh
 
 floor = floor
 
 monotonicity = monotonicity
 
 padding = padding
 
 morph
 

Protected Attributes

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

Detailed Description

Implements a free-form component

With no constraints this component is typically either a garbage collector,
or part of a set of components to deconvolve an image by separating out
the different spectral components.

See `FactorizedComponent` for a list of parameters not shown here.

Parameters
----------
peaks: `list` of `tuple`
    A set of ``(cy, cx)`` peaks for detected sources.
    If peak is not ``None`` then only pixels in the same "footprint"
    as one of the peaks are included in the morphology.
    If `peaks` is ``None`` then there is no constraint applied.
min_area: float
    The minimum area for a peak.
    If `min_area` is not `None` then all regions of the morphology
    with fewer than `min_area` connected pixels are removed.

Definition at line 36 of file free_form.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent.__init__ ( self,
tuple bands,
np.ndarray | Parameter spectrum,
np.ndarray | Parameter morph,
Box model_bbox,
float | None bg_thresh = None,
np.ndarray | None bg_rms = None,
float floor = 1e-20,
list[tuple[int, int]] | None peaks = None,
float min_area = 0 )

Definition at line 58 of file free_form.py.

69 ):
70 super().__init__(
71 bands=bands,
72 spectrum=spectrum,
73 morph=morph,
74 bbox=model_bbox,
75 peak=None,
76 bg_rms=bg_rms,
77 bg_thresh=bg_thresh,
78 floor=floor,
79 )
80
81 self.peaks = peaks
82 self.min_area = min_area
83

Member Function Documentation

◆ __repr__()

lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent.__repr__ ( self)

Definition at line 139 of file free_form.py.

139 def __repr__(self):
140 return self.__str__()
141
142

◆ __str__()

lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent.__str__ ( self)

Definition at line 132 of file free_form.py.

132 def __str__(self):
133 return (
134 f"FactorizedFreeFormComponent(\n bands={self.bands}\n "
135 f"spectrum={self.spectrum})\n center={self.peak}\n "
136 f"morph_shape={self.morph.shape}"
137 )
138

◆ bands()

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

Definition at line 66 of file component.py.

66 def bands(self) -> tuple:
67 """The bands in the component model"""
68 return self._bands
69

◆ bbox()

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

Definition at line 61 of file component.py.

61 def bbox(self) -> Box:
62 """The bounding box that contains the component in the full image"""
63 return self._bbox
64

◆ component_center()

tuple[int, int] | None lsst.scarlet.lite.component.FactorizedComponent.component_center ( self)
inherited
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 182 of file component.py.

182 def component_center(self) -> tuple[int, int] | None:
183 """The center of the component in its bounding box
184
185 This is likely to be different than `Component.center`,
186 since `Component.center` is the center of the component in the
187 full model, whereas `component_center` is the center of the component
188 inside its bounding box.
189
190 Returns
191 -------
192 center:
193 The center of the component in its bounding box
194 """
195 _center = self.peak
196 if _center is None:
197 return None
198 center = (
199 _center[0] - self.bbox.origin[-2],
200 _center[1] - self.bbox.origin[-1],
201 )
202 return center
203

◆ get_model()

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

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

Definition at line 219 of file component.py.

219 def get_model(self) -> Image:
220 """Build the model from the spectrum and morphology"""
221 # The spectrum and morph might be Parameters,
222 # so cast them as arrays in the model.
223 spectrum = self.spectrum
224 morph = self.morph
225 model = spectrum[:, None, None] * morph[None, :, :]
226 return Image(model, bands=self.bands, yx0=cast(tuple[int, int], self.bbox.origin))
227

◆ grad_morph()

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

Definition at line 232 of file component.py.

232 def grad_morph(self, input_grad: np.ndarray, morph: np.ndarray, spectrum: np.ndarray):
233 """Gradient of the morph wrt. the component model"""
234 return np.einsum("i,i...", spectrum, input_grad)
235

◆ grad_spectrum()

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

Definition at line 228 of file component.py.

228 def grad_spectrum(self, input_grad: np.ndarray, spectrum: np.ndarray, morph: np.ndarray):
229 """Gradient of the spectrum wrt. the component model"""
230 return np.einsum("...jk,jk", input_grad, morph)
231

◆ morph()

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

Definition at line 210 of file component.py.

210 def morph(self) -> np.ndarray:
211 """The array of morphology values"""
212 return self._morph.x
213

◆ parameterize()

None lsst.scarlet.lite.component.FactorizedComponent.parameterize ( self,
Callable parameterization )
inherited
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 315 of file component.py.

315 def parameterize(self, parameterization: Callable) -> None:
316 """Convert the component parameter arrays into Parameter instances
317
318 Parameters
319 ----------
320 parameterization: Callable
321 A function to use to convert parameters of a given type into
322 a `Parameter` in place. It should take a single argument that
323 is the `Component` or `Source` that is to be parameterized.
324 """
325 # Update the spectrum and morph in place
326 parameterization(self)
327 # update the parameters
328 self._spectrum.grad = self.grad_spectrum
329 self._spectrum.prox = self.prox_spectrum
330 self._morph.grad = self.grad_morph
331 self._morph.prox = self.prox_morph
332

◆ peak()

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

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

Definition at line 171 of file component.py.

171 def peak(self) -> tuple[int, int] | None:
172 """The peak of the component
173
174 Returns
175 -------
176 peak:
177 The peak of the component
178 """
179 return self._peak
180

◆ prox_morph()

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

This is the main difference between an `SedComponent` and a
`FactorizedComponent`, since this component has fewer constraints.

Reimplemented from lsst.scarlet.lite.component.FactorizedComponent.

Definition at line 96 of file free_form.py.

96 def prox_morph(self, morph: np.ndarray) -> np.ndarray:
97 """Apply a prox-like update to the morphology
98
99 This is the main difference between an `SedComponent` and a
100 `FactorizedComponent`, since this component has fewer constraints.
101 """
102 from lsst.scarlet.lite.detect_pybind11 import get_connected_multipeak, get_footprints # type: ignore
103
104 if self.bg_thresh is not None and isinstance(self.bg_rms, np.ndarray):
105 bg_thresh = self.bg_rms * self.bg_thresh
106 # Enforce background thresholding
107 model = self.spectrum[:, None, None] * morph[None, :, :]
108 morph[np.all(model < bg_thresh[:, None, None], axis=0)] = 0
109 else:
110 # enforce positivity
111 morph[morph < 0] = 0
112
113 if self.peaks is not None:
114 footprint = get_connected_multipeak(morph, self.peaks, 0)
115 morph = morph * footprint
116
117 if self.min_area > 0:
118 footprints = get_footprints(morph, 4.0, self.min_area, 0, 0, False)
119 bbox = self.bbox.copy()
120 bbox.origin = (0, 0)
121 footprint_image = footprints_to_image(footprints, bbox)
122 morph = morph * (footprint_image > 0).data
123
124 if np.all(morph == 0):
125 morph[0, 0] = self.floor
126
127 return morph
128
MatrixB get_connected_multipeak(py::EigenDRef< const M > image, const std::vector< std::vector< int > > &centers, const double thresh=0)
Proximal operator to trim pixels not connected to one of the source centers.
std::vector< Footprint > get_footprints(py::EigenDRef< const M > image, const double min_separation, const int min_area, const double peak_thresh, const double footprint_thresh, const bool find_peaks=true, const int y0=0, const int x0=0)
Get all footprints in an image.

◆ prox_spectrum()

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

This differs from `FactorizedComponent` because an
`SedComponent` has the spectrum normalized to unity.

Reimplemented from lsst.scarlet.lite.component.FactorizedComponent.

Definition at line 84 of file free_form.py.

84 def prox_spectrum(self, spectrum: np.ndarray) -> np.ndarray:
85 """Apply a prox-like update to the spectrum
86
87 This differs from `FactorizedComponent` because an
88 `SedComponent` has the spectrum normalized to unity.
89 """
90 # prevent divergent spectrum
91 spectrum[spectrum < self.floor] = self.floor
92 # Normalize the spectrum
93 spectrum = spectrum / np.sum(spectrum)
94 return spectrum
95

◆ resize()

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

Reimplemented from lsst.scarlet.lite.component.FactorizedComponent.

Definition at line 129 of file free_form.py.

129 def resize(self, model_box: Box) -> bool:
130 return False
131

◆ shape()

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

Definition at line 215 of file component.py.

215 def shape(self) -> tuple:
216 """Shape of the resulting model image"""
217 return self.spectrum.shape + self.morph.shape
218

◆ spectrum()

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

Definition at line 205 of file component.py.

205 def spectrum(self) -> np.ndarray:
206 """The array of spectrum values"""
207 return self._spectrum.x
208

◆ update()

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

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

Definition at line 307 of file component.py.

307 def update(self, it: int, input_grad: np.ndarray):
308 """Update the spectrum and morphology parameters"""
309 # Store the input spectrum so that the morphology can
310 # have a consistent update
311 spectrum = self.spectrum.copy()
312 self._spectrum.update(it, input_grad, self.morph)
313 self._morph.update(it, input_grad, spectrum)
314

Member Data Documentation

◆ _bands

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

Definition at line 57 of file component.py.

◆ _bbox

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

Definition at line 58 of file component.py.

◆ _morph

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

Definition at line 161 of file component.py.

◆ _peak

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

Definition at line 162 of file component.py.

◆ _spectrum

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

Definition at line 160 of file component.py.

◆ bg_rms

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

Definition at line 163 of file component.py.

◆ bg_thresh

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

Definition at line 164 of file component.py.

◆ floor

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

Definition at line 166 of file component.py.

◆ min_area

lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent.min_area = min_area

Definition at line 82 of file free_form.py.

◆ monotonicity

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

Definition at line 167 of file component.py.

◆ morph

lsst.scarlet.lite.component.FactorizedComponent.morph
inherited

Definition at line 312 of file component.py.

◆ padding

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

Definition at line 168 of file component.py.

◆ peaks

lsst.scarlet.lite.models.free_form.FactorizedFreeFormComponent.peaks = peaks

Definition at line 81 of file free_form.py.


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