LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+b203dec576,g18429d2f64+358861cd2c,g199a45376c+0ba108daf9,g1fd858c14a+dd066899e3,g262e1987ae+ebfced1d55,g29ae962dfc+72fd90588e,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+b668f15bc5,g4595892280+3897dae354,g47891489e3+abcf9c3559,g4d44eb3520+fb4ddce128,g53246c7159+8c5ae1fdc5,g67b6fd64d1+abcf9c3559,g67fd3c3899+1f72b5a9f7,g74acd417e5+cb6b47f07b,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+abcf9c3559,g8d7436a09f+bcf525d20c,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+6054cc57f1,g97be763408+06f794da49,g9dd6db0277+1f72b5a9f7,ga681d05dcb+7e36ad54cd,gabf8522325+735880ea63,gac2eed3f23+abcf9c3559,gb89ab40317+abcf9c3559,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+1f72b5a9f7,gdab6d2f7ff+cb6b47f07b,gdc713202bf+1f72b5a9f7,gdfd2d52018+8225f2b331,ge365c994fd+375fc21c71,ge410e46f29+abcf9c3559,geaed405ab2+562b3308c0,gf9a733ac38+8c5ae1fdc5,w.2025.35
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.scarlet.lite.initialization Namespace Reference

Classes

class  FactorizedChi2Initialization
 
class  FactorizedInitialization
 
class  FactorizedWaveletInitialization
 

Functions

tuple[np.ndarray, Boxtrim_morphology (np.ndarray morph, float threshold=0, int padding=5, float|None bg_thresh=None)
 
tuple[Box, np.ndarray|None] init_monotonic_morph (np.ndarray detect, tuple[int, int] center, Box full_box, int padding=5, bool normalize=True, Monotonicity|None monotonicity=None, float threshold=0, int max_iter=0, int center_radius=1, float variance_factor=0)
 
np.ndarray multifit_spectra (Observation observation, Sequence[Image] morphs, Image|None model=None)
 

Variables

 logger = logging.getLogger("scarlet.lite.initialization")
 

Function Documentation

◆ init_monotonic_morph()

tuple[Box, np.ndarray | None] lsst.scarlet.lite.initialization.init_monotonic_morph ( np.ndarray detect,
tuple[int, int] center,
Box full_box,
int padding = 5,
bool normalize = True,
Monotonicity | None monotonicity = None,
float threshold = 0,
int max_iter = 0,
int center_radius = 1,
float variance_factor = 0 )
Initialize a morphology for a monotonic source

Parameters
----------
detect:
    The 2D detection image contained in `full_box`.
center:
    The center of the monotonic source.
full_box:
    The bounding box of `detect`.
padding:
    The number of pixels to grow the morphology in each direction.
    This can be useful if initializing a source with a kernel that
    is known to be narrower than the expected value of the source.
normalize:
    Whether or not to normalize the morphology.
monotonicity:
    When `monotonicity` is `None`,
    the component is initialized with only the
    monotonic pixels, otherwise the monotonicity operator is used to
    project the morphology to a monotonic solution.
threshold:
    The minimum value to use for trimming the
    morphology.
max_iter:
    The maximum number of iterations to use in the monotonicity operator.
    Only used if `monotonicity` is `None`.
center_radius:
    The amount that the center can be shifted to a local maximum.
    Only used if `monotonicity` is `None`.
variance_factor:
    The average variance in the image.
    This is used to allow pixels to be non-monotonic up to
    `variance` * `noise_rms`, so setting `variance = 0`
    will force strict monotonicity in the mask.
    Only used if `monotonicity` is `None`.

Returns
-------
bbox:
    The bounding box of the morphology.
morph:
    The initialized morphology.

Definition at line 78 of file initialization.py.

89) -> tuple[Box, np.ndarray | None]:
90 """Initialize a morphology for a monotonic source
91
92 Parameters
93 ----------
94 detect:
95 The 2D detection image contained in `full_box`.
96 center:
97 The center of the monotonic source.
98 full_box:
99 The bounding box of `detect`.
100 padding:
101 The number of pixels to grow the morphology in each direction.
102 This can be useful if initializing a source with a kernel that
103 is known to be narrower than the expected value of the source.
104 normalize:
105 Whether or not to normalize the morphology.
106 monotonicity:
107 When `monotonicity` is `None`,
108 the component is initialized with only the
109 monotonic pixels, otherwise the monotonicity operator is used to
110 project the morphology to a monotonic solution.
111 threshold:
112 The minimum value to use for trimming the
113 morphology.
114 max_iter:
115 The maximum number of iterations to use in the monotonicity operator.
116 Only used if `monotonicity` is `None`.
117 center_radius:
118 The amount that the center can be shifted to a local maximum.
119 Only used if `monotonicity` is `None`.
120 variance_factor:
121 The average variance in the image.
122 This is used to allow pixels to be non-monotonic up to
123 `variance` * `noise_rms`, so setting `variance = 0`
124 will force strict monotonicity in the mask.
125 Only used if `monotonicity` is `None`.
126
127 Returns
128 -------
129 bbox:
130 The bounding box of the morphology.
131 morph:
132 The initialized morphology.
133 """
134 center: tuple[int, int] = tuple(center[i] - full_box.origin[i] for i in range(2)) # type: ignore
135
136 if monotonicity is None:
137 _, morph, bounds = prox_monotonic_mask(
138 x=detect,
139 center=center,
140 center_radius=center_radius,
141 variance=variance_factor,
142 max_iter=max_iter,
143 )
144 bbox = bounds_to_bbox(bounds)
145 if bbox.shape == (1, 1) and morph[bbox.slices][0, 0] == 0:
146 return Box((0, 0)), None
147
148 if threshold > 0:
149 morph, bbox = trim_morphology(morph, threshold=threshold, padding=padding)
150
151 else:
152 morph = monotonicity(detect, center)
153
154 # truncate morph at thresh * bg_rms
155 morph, bbox = trim_morphology(morph, threshold=threshold, padding=padding)
156
157 # Shift the bounding box to account for the non-zero origin
158 bbox += full_box.origin
159
160 if np.max(morph) == 0:
161 return Box((0, 0), origin=full_box.origin), None
162
163 if normalize:
164 morph /= np.max(morph)
165
166 if padding is not None and padding > 0:
167 # Pad the morphology to allow it to grow
168 bbox = bbox.grow(padding)
169
170 # Ensure that the bounding box is inside the full box,
171 # even after padding.
172 bbox = bbox & full_box
173 return bbox, morph
174
175

◆ multifit_spectra()

np.ndarray lsst.scarlet.lite.initialization.multifit_spectra ( Observation observation,
Sequence[Image] morphs,
Image | None model = None )
Fit the spectra of multiple components simultaneously

Parameters
----------
observation:
    The class containing the observation data.
morphs:
    The morphology of each component.
model:
    An optional model for sources that are not factorized,
    and thus will not have their spectra fit.
    This model is subtracted from the data before fitting the other
    spectra.

Returns
-------
spectra:
    The spectrum for each component, in the same order as `morphs`.

Definition at line 176 of file initialization.py.

180) -> np.ndarray:
181 """Fit the spectra of multiple components simultaneously
182
183 Parameters
184 ----------
185 observation:
186 The class containing the observation data.
187 morphs:
188 The morphology of each component.
189 model:
190 An optional model for sources that are not factorized,
191 and thus will not have their spectra fit.
192 This model is subtracted from the data before fitting the other
193 spectra.
194
195 Returns
196 -------
197 spectra:
198 The spectrum for each component, in the same order as `morphs`.
199 """
200 _bands = observation.bands
201 n_bands = len(_bands)
202 dtype = observation.images.dtype
203
204 if model is not None:
205 image = observation.images - model
206 else:
207 image = observation.images.copy()
208
209 morph_images = np.zeros((n_bands, len(morphs), image.data[0].size), dtype=dtype)
210 for idx, morph in enumerate(morphs):
211 _image = morph.repeat(observation.bands)
212 _image = Image.from_box(image.bbox, bands=image.bands).insert(_image)
213 morph_images[:, idx] = observation.convolve(_image).data.reshape(n_bands, -1)
214
215 spectra = np.zeros((len(morphs), n_bands), dtype=dtype)
216
217 for b in range(n_bands):
218 a = np.vstack(morph_images[b]).T
219 spectra[:, b] = np.linalg.lstsq(a, image[observation.bands[b]].data.flatten(), rcond=None)[0]
220 spectra[spectra < 0] = 0
221 return spectra
222
223

◆ trim_morphology()

tuple[np.ndarray, Box] lsst.scarlet.lite.initialization.trim_morphology ( np.ndarray morph,
float threshold = 0,
int padding = 5,
float | None bg_thresh = None )
Trim the morphology up to pixels above a threshold

Parameters
----------
morph:
    The morphology to be trimmed.
thresh:
    The morphology is trimmed to pixels above the threshold.
bg_thresh:
    Deprecated in favor of `thresh`.
padding:
    The amount to pad each side to allow the source to grow.

Returns
-------
morph:
    The trimmed morphology
box:
    The box that contains the morphology.

Definition at line 40 of file initialization.py.

45) -> tuple[np.ndarray, Box]:
46 """Trim the morphology up to pixels above a threshold
47
48 Parameters
49 ----------
50 morph:
51 The morphology to be trimmed.
52 thresh:
53 The morphology is trimmed to pixels above the threshold.
54 bg_thresh:
55 Deprecated in favor of `thresh`.
56 padding:
57 The amount to pad each side to allow the source to grow.
58
59 Returns
60 -------
61 morph:
62 The trimmed morphology
63 box:
64 The box that contains the morphology.
65 """
66 # Temporarily support bg_thresh
67 if bg_thresh is not None:
68 logger.warning("bg_thresh is deprecated and will be after v29.0. " "Use threshold instead.")
69 threshold = bg_thresh
70
71 # trim morph to pixels above threshold
72 mask = morph > threshold
73 morph[~mask] = 0
74 bbox = Box.from_data(morph, threshold=0).grow(padding)
75 return morph, bbox
76
77

Variable Documentation

◆ logger

lsst.scarlet.lite.initialization.logger = logging.getLogger("scarlet.lite.initialization")

Definition at line 37 of file initialization.py.