Skip to content

Sources

PointSource

Bases: Source

A simple point source with a spectrum, position and flux.

UML

UML

Attributes:

Name Type Description
position (Array, radians)

The (x, y) on-sky position of this object.

flux (float, photons)

The flux of the object.

spectrum Spectrum

The spectrum of this object, represented by a Spectrum object.

Source code in src/dLux/sources.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
class PointSource(Source):
    """
    A simple point source with a spectrum, position and flux.

    ??? abstract "UML"
        ![UML](../../assets/uml/PointSource.png)

    Attributes
    ----------
    position : Array, radians
        The (x, y) on-sky position of this object.
    flux : float, photons
        The flux of the object.
    spectrum : Spectrum
        The spectrum of this object, represented by a Spectrum object.
    """

    position: Array
    flux: float

    def __init__(
        self: Source,
        wavelengths: Array = None,
        position: Array = np.zeros(2),
        flux: float = 1.0,
        weights: Array = None,
        spectrum: Spectrum() = None,
    ):
        """
        Parameters
        ----------
        wavelengths : Array, metres = None
            The array of wavelengths at which the spectrum is defined. This input is
            ignored if a Spectrum object is provided.
        position : Array, radians = np.zeros(2)
            The (x, y) on-sky position of this object.
        flux : float, photons = 1.
            The flux of the object.
        spectrum : Spectrum = None
            The spectrum of this object, represented by a Spectrum object.
        """
        # Position and Flux
        self.position = np.asarray(position, dtype=float)
        self.flux = float(flux)

        if self.position.shape != (2,):
            raise ValueError("position must be a 1d array of shape (2,).")

        super().__init__(
            wavelengths=wavelengths, weights=weights, spectrum=spectrum
        )

    def model(
        self: Source,
        optics: Optics,
        return_wf: bool = False,
        return_psf: bool = False,
    ) -> Array:
        """
        Models the source object through the provided optics.

        Parameters
        ----------
        optics : Optics
            The optics through which to model the source object.
        return_wf : bool = False
            Should the Wavefront object be returned instead of the psf Array?
        return_psf : bool = False
            Should the PSF object be returned instead of the psf Array?

        Returns
        -------
        object : Array, Wavefront, PSF
            if `return_wf` is False and `return_psf` is False, returns the psf Array.
            if `return_wf` is True and `return_psf` is False, returns the Wavefront
                object.
            if `return_wf` is False and `return_psf` is True, returns the PSF object.
        """
        self = self.normalise()
        weights = self.weights * self.flux
        return optics.propagate(
            self.wavelengths, self.position, weights, return_wf, return_psf
        )

__init__(wavelengths=None, position=np.zeros(2), flux=1.0, weights=None, spectrum=None)

Parameters:

Name Type Description Default
wavelengths Array, metres = None

The array of wavelengths at which the spectrum is defined. This input is ignored if a Spectrum object is provided.

None
position Array, radians = np.zeros(2)

The (x, y) on-sky position of this object.

zeros(2)
flux float, photons = 1.

The flux of the object.

1.0
spectrum Spectrum = None

The spectrum of this object, represented by a Spectrum object.

None
Source code in src/dLux/sources.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def __init__(
    self: Source,
    wavelengths: Array = None,
    position: Array = np.zeros(2),
    flux: float = 1.0,
    weights: Array = None,
    spectrum: Spectrum() = None,
):
    """
    Parameters
    ----------
    wavelengths : Array, metres = None
        The array of wavelengths at which the spectrum is defined. This input is
        ignored if a Spectrum object is provided.
    position : Array, radians = np.zeros(2)
        The (x, y) on-sky position of this object.
    flux : float, photons = 1.
        The flux of the object.
    spectrum : Spectrum = None
        The spectrum of this object, represented by a Spectrum object.
    """
    # Position and Flux
    self.position = np.asarray(position, dtype=float)
    self.flux = float(flux)

    if self.position.shape != (2,):
        raise ValueError("position must be a 1d array of shape (2,).")

    super().__init__(
        wavelengths=wavelengths, weights=weights, spectrum=spectrum
    )

model(optics, return_wf=False, return_psf=False)

Models the source object through the provided optics.

Parameters:

Name Type Description Default
optics Optics

The optics through which to model the source object.

required
return_wf bool = False

Should the Wavefront object be returned instead of the psf Array?

False
return_psf bool = False

Should the PSF object be returned instead of the psf Array?

False

Returns:

Name Type Description
object (Array, Wavefront, PSF)

if return_wf is False and return_psf is False, returns the psf Array. if return_wf is True and return_psf is False, returns the Wavefront object. if return_wf is False and return_psf is True, returns the PSF object.

Source code in src/dLux/sources.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
def model(
    self: Source,
    optics: Optics,
    return_wf: bool = False,
    return_psf: bool = False,
) -> Array:
    """
    Models the source object through the provided optics.

    Parameters
    ----------
    optics : Optics
        The optics through which to model the source object.
    return_wf : bool = False
        Should the Wavefront object be returned instead of the psf Array?
    return_psf : bool = False
        Should the PSF object be returned instead of the psf Array?

    Returns
    -------
    object : Array, Wavefront, PSF
        if `return_wf` is False and `return_psf` is False, returns the psf Array.
        if `return_wf` is True and `return_psf` is False, returns the Wavefront
            object.
        if `return_wf` is False and `return_psf` is True, returns the PSF object.
    """
    self = self.normalise()
    weights = self.weights * self.flux
    return optics.propagate(
        self.wavelengths, self.position, weights, return_wf, return_psf
    )

PointSources

Bases: Source

A set of point sources with the same spectrum, but different positions and fluxes.

UML

UML

Attributes:

Name Type Description
position (Array, radians)

The ((x0, y0), (x1, y1), ...) on-sky positions of these sources.

flux (Array, photons)

The fluxes of the sources.

spectrum Spectrum

The spectrum of this object, represented by a Spectrum object.

Source code in src/dLux/sources.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
class PointSources(Source):
    """
    A set of point sources with the same spectrum, but different positions and fluxes.

    ??? abstract "UML"
        ![UML](../../assets/uml/PointSources.png)

    Attributes
    ----------
    position : Array, radians
        The ((x0, y0), (x1, y1), ...) on-sky positions of these sources.
    flux : Array, photons
        The fluxes of the sources.
    spectrum : Spectrum
        The spectrum of this object, represented by a Spectrum object.
    """

    position: Array
    flux: Array

    def __init__(
        self: Source,
        wavelengths: Array = None,
        position: Array = np.zeros((1, 2)),
        flux: Array = None,
        weights: Array = None,
        spectrum: Spectrum() = None,
    ):
        """
        Parameters
        ----------
        wavelengths : Array, metres
            The array of wavelengths at which the spectrum is defined.
        position : Array, radians = np.zeros((1, 2))
            The (x, y) on-sky position of this object.
        flux : Array, photons = None
            The flux of the object.
        weights : Array = None
            The spectral weights of the object.
        spectrum : Spectrum = None
            The spectrum of this object, represented by a Spectrum object.
        """
        super().__init__(
            spectrum=spectrum, wavelengths=wavelengths, weights=weights
        )

        # More complex parameter checks here because of extra dims
        self.position = np.asarray(position, dtype=float)
        if self.position.ndim != 2:
            raise ValueError("position must be a 2d array.")

        if flux is None:
            self.flux = np.ones(len(self.position))
        else:
            self.flux = np.asarray(flux, dtype=float)

            if self.flux.ndim != 1:
                raise ValueError("flux must be a 1d array.")

            if len(self.flux) != len(self.position):
                raise ValueError(
                    "Length of flux must be equal to length of " "positions."
                )

    def model(
        self: Source,
        optics: Optics,
        return_wf: bool = False,
        return_psf: bool = False,
    ) -> Array:
        """
        Models the source object through the provided optics.

        Parameters
        ----------
        optics : Optics
            The optics through which to model the source object.
        return_wf : bool = False
            Should the Wavefront object be returned instead of the psf Array?
        return_psf : bool = False
            Should the PSF object be returned instead of the psf Array?

        Returns
        -------
        object : Array, Wavefront, PSF
            if `return_wf` is False and `return_psf` is False, returns the psf Array.
            if `return_wf` is True and `return_psf` is False, returns the Wavefront
                object.
            if `return_wf` is False and `return_psf` is True, returns the PSF object.
        """
        if return_wf and return_psf:
            raise ValueError(
                "return_wf and return_psf cannot both be True. "
                "Please choose one."
            )
        self = self.normalise()
        weights = self.weights[None, :] * self.flux[:, None]
        prop_fn = lambda position, weight: optics.propagate(
            self.wavelengths, position, weight, return_wf=True
        )
        wfs = filter_vmap(prop_fn)(self.position, weights)

        if return_wf:
            return wfs
        if return_psf:
            return PSF(wfs.psf.sum((0, 1)), wfs.pixel_scale.mean())
        else:
            return wfs.psf.sum((0, 1))

__init__(wavelengths=None, position=np.zeros((1, 2)), flux=None, weights=None, spectrum=None)

Parameters:

Name Type Description Default
wavelengths (Array, metres)

The array of wavelengths at which the spectrum is defined.

None
position Array, radians = np.zeros((1, 2))

The (x, y) on-sky position of this object.

zeros((1, 2))
flux Array, photons = None

The flux of the object.

None
weights Array = None

The spectral weights of the object.

None
spectrum Spectrum = None

The spectrum of this object, represented by a Spectrum object.

None
Source code in src/dLux/sources.py
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
def __init__(
    self: Source,
    wavelengths: Array = None,
    position: Array = np.zeros((1, 2)),
    flux: Array = None,
    weights: Array = None,
    spectrum: Spectrum() = None,
):
    """
    Parameters
    ----------
    wavelengths : Array, metres
        The array of wavelengths at which the spectrum is defined.
    position : Array, radians = np.zeros((1, 2))
        The (x, y) on-sky position of this object.
    flux : Array, photons = None
        The flux of the object.
    weights : Array = None
        The spectral weights of the object.
    spectrum : Spectrum = None
        The spectrum of this object, represented by a Spectrum object.
    """
    super().__init__(
        spectrum=spectrum, wavelengths=wavelengths, weights=weights
    )

    # More complex parameter checks here because of extra dims
    self.position = np.asarray(position, dtype=float)
    if self.position.ndim != 2:
        raise ValueError("position must be a 2d array.")

    if flux is None:
        self.flux = np.ones(len(self.position))
    else:
        self.flux = np.asarray(flux, dtype=float)

        if self.flux.ndim != 1:
            raise ValueError("flux must be a 1d array.")

        if len(self.flux) != len(self.position):
            raise ValueError(
                "Length of flux must be equal to length of " "positions."
            )

model(optics, return_wf=False, return_psf=False)

Models the source object through the provided optics.

Parameters:

Name Type Description Default
optics Optics

The optics through which to model the source object.

required
return_wf bool = False

Should the Wavefront object be returned instead of the psf Array?

False
return_psf bool = False

Should the PSF object be returned instead of the psf Array?

False

Returns:

Name Type Description
object (Array, Wavefront, PSF)

if return_wf is False and return_psf is False, returns the psf Array. if return_wf is True and return_psf is False, returns the Wavefront object. if return_wf is False and return_psf is True, returns the PSF object.

Source code in src/dLux/sources.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
def model(
    self: Source,
    optics: Optics,
    return_wf: bool = False,
    return_psf: bool = False,
) -> Array:
    """
    Models the source object through the provided optics.

    Parameters
    ----------
    optics : Optics
        The optics through which to model the source object.
    return_wf : bool = False
        Should the Wavefront object be returned instead of the psf Array?
    return_psf : bool = False
        Should the PSF object be returned instead of the psf Array?

    Returns
    -------
    object : Array, Wavefront, PSF
        if `return_wf` is False and `return_psf` is False, returns the psf Array.
        if `return_wf` is True and `return_psf` is False, returns the Wavefront
            object.
        if `return_wf` is False and `return_psf` is True, returns the PSF object.
    """
    if return_wf and return_psf:
        raise ValueError(
            "return_wf and return_psf cannot both be True. "
            "Please choose one."
        )
    self = self.normalise()
    weights = self.weights[None, :] * self.flux[:, None]
    prop_fn = lambda position, weight: optics.propagate(
        self.wavelengths, position, weight, return_wf=True
    )
    wfs = filter_vmap(prop_fn)(self.position, weights)

    if return_wf:
        return wfs
    if return_psf:
        return PSF(wfs.psf.sum((0, 1)), wfs.pixel_scale.mean())
    else:
        return wfs.psf.sum((0, 1))

BinarySource

Bases: Source

A binary source parameterised by the position, flux, separation, position_angle, and contrast between the two sources.

UML

UML

Attributes:

Name Type Description
position (Array, radians)

The mean (x, y) on-sky position of this object.

mean_flux (float, photons)

The mean flux of the sources.

separation (float, radians)

The separation of the two sources in radians.

position_angle (float, radians)

The position angle between the two sources measured clockwise from the vertical axis.

contrast float

The contrast ratio between the two sources.

spectrum Spectrum

The spectrum of this object, represented by a Spectrum object.

Source code in src/dLux/sources.py
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
class BinarySource(Source):
    """
    A binary source parameterised by the position, flux, separation, position_angle,
    and contrast between the two sources.

    ??? abstract "UML"
        ![UML](../../assets/uml/BinarySource.png)

    Attributes
    ----------
    position : Array, radians
        The mean (x, y) on-sky position of this object.
    mean_flux : float, photons
        The mean flux of the sources.
    separation : float, radians
        The separation of the two sources in radians.
    position_angle : float, radians
        The position angle between the two sources measured clockwise from the
        vertical axis.
    contrast : float
        The contrast ratio between the two sources.
    spectrum : Spectrum
        The spectrum of this object, represented by a Spectrum object.
    """

    position: Array
    mean_flux: float
    separation: float
    position_angle: float
    contrast: float

    def __init__(
        self: Source,
        wavelengths: Array = None,
        position: Array = np.zeros(2),
        mean_flux: float = 1.0,
        separation: float = 0.0,
        position_angle: float = np.pi / 2,
        contrast: float = 1.0,
        spectrum: Spectrum() = None,
        weights: Array = None,
    ):
        """
        Parameters
        ----------
        wavelengths : Array, metres = None
            The array of wavelengths at which the spectrum is defined.
        position : Array, radians = np.zeros(2)
            The (x, y) on-sky position of this object.
        mean_flux : float, photons = 1.
            The mean flux of the sources.
        separation : float, radians = 0.
            The separation of the two sources in radians.
        position_angle : float, radians = np.pi / 2
            The position angle between the two sources measured clockwise from the
            vertical axis.
        contrast : float = 1.
            The contrast ratio between the two sources.
        spectrum : Spectrum = None
            The spectrum of this object, represented by a Spectrum object.
        """
        wavelengths = np.asarray(wavelengths, dtype=float)
        if weights is None:
            weights = np.ones((2, len(wavelengths)))

        # Position and Flux
        self.position = np.asarray(position, dtype=float)
        self.mean_flux = float(mean_flux)

        if self.position.shape != (2,):
            raise ValueError("position must be a 1d array of shape (2,).")

        # Binary values
        self.separation = float(separation)
        self.position_angle = float(position_angle)
        self.contrast = float(contrast)

        super().__init__(
            wavelengths=wavelengths,
            spectrum=spectrum,
            weights=weights,
        )

    def model(
        self: Source,
        optics: Optics,
        return_wf: bool = False,
        return_psf: bool = False,
    ) -> Array:
        """
        Models the source object through the provided optics.

        Parameters
        ----------
        optics : Optics
            The optics through which to model the source object.
        return_wf : bool = False
            Should the Wavefront object be returned instead of the psf Array?
        return_psf : bool = False
            Should the PSF object be returned instead of the psf Array?

        Returns
        -------
        object : Array, Wavefront, PSF
            if `return_wf` is False and `return_psf` is False, returns the psf Array.
            if `return_wf` is True and `return_psf` is False, returns the Wavefront
                object.
            if `return_wf` is False and `return_psf` is True, returns the PSF object.
        """
        # Normalise and get input values
        self = self.normalise()
        positions = dlu.positions_from_sep(
            self.position, self.separation, self.position_angle
        )
        flux = dlu.fluxes_from_contrast(self.mean_flux, self.contrast)
        weights = self.weights * flux[:, None]

        # Return wf case is simple
        prop_fn = lambda position, weight: optics.propagate(
            self.wavelengths, position, weight, return_wf, return_psf
        )
        output = filter_vmap(prop_fn)(positions, weights)

        # Return wf is simple case
        if return_wf:
            return output

        # Return psf just requires constructing object
        if return_psf:
            return PSF(output.data.sum(0), output.pixel_scale.mean())

        # Return array is simple
        return output.sum(0)

__init__(wavelengths=None, position=np.zeros(2), mean_flux=1.0, separation=0.0, position_angle=np.pi / 2, contrast=1.0, spectrum=None, weights=None)

Parameters:

Name Type Description Default
wavelengths Array, metres = None

The array of wavelengths at which the spectrum is defined.

None
position Array, radians = np.zeros(2)

The (x, y) on-sky position of this object.

zeros(2)
mean_flux float, photons = 1.

The mean flux of the sources.

1.0
separation float, radians = 0.

The separation of the two sources in radians.

0.0
position_angle float, radians = np.pi / 2

The position angle between the two sources measured clockwise from the vertical axis.

pi / 2
contrast float = 1.

The contrast ratio between the two sources.

1.0
spectrum Spectrum = None

The spectrum of this object, represented by a Spectrum object.

None
Source code in src/dLux/sources.py
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
def __init__(
    self: Source,
    wavelengths: Array = None,
    position: Array = np.zeros(2),
    mean_flux: float = 1.0,
    separation: float = 0.0,
    position_angle: float = np.pi / 2,
    contrast: float = 1.0,
    spectrum: Spectrum() = None,
    weights: Array = None,
):
    """
    Parameters
    ----------
    wavelengths : Array, metres = None
        The array of wavelengths at which the spectrum is defined.
    position : Array, radians = np.zeros(2)
        The (x, y) on-sky position of this object.
    mean_flux : float, photons = 1.
        The mean flux of the sources.
    separation : float, radians = 0.
        The separation of the two sources in radians.
    position_angle : float, radians = np.pi / 2
        The position angle between the two sources measured clockwise from the
        vertical axis.
    contrast : float = 1.
        The contrast ratio between the two sources.
    spectrum : Spectrum = None
        The spectrum of this object, represented by a Spectrum object.
    """
    wavelengths = np.asarray(wavelengths, dtype=float)
    if weights is None:
        weights = np.ones((2, len(wavelengths)))

    # Position and Flux
    self.position = np.asarray(position, dtype=float)
    self.mean_flux = float(mean_flux)

    if self.position.shape != (2,):
        raise ValueError("position must be a 1d array of shape (2,).")

    # Binary values
    self.separation = float(separation)
    self.position_angle = float(position_angle)
    self.contrast = float(contrast)

    super().__init__(
        wavelengths=wavelengths,
        spectrum=spectrum,
        weights=weights,
    )

model(optics, return_wf=False, return_psf=False)

Models the source object through the provided optics.

Parameters:

Name Type Description Default
optics Optics

The optics through which to model the source object.

required
return_wf bool = False

Should the Wavefront object be returned instead of the psf Array?

False
return_psf bool = False

Should the PSF object be returned instead of the psf Array?

False

Returns:

Name Type Description
object (Array, Wavefront, PSF)

if return_wf is False and return_psf is False, returns the psf Array. if return_wf is True and return_psf is False, returns the Wavefront object. if return_wf is False and return_psf is True, returns the PSF object.

Source code in src/dLux/sources.py
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
def model(
    self: Source,
    optics: Optics,
    return_wf: bool = False,
    return_psf: bool = False,
) -> Array:
    """
    Models the source object through the provided optics.

    Parameters
    ----------
    optics : Optics
        The optics through which to model the source object.
    return_wf : bool = False
        Should the Wavefront object be returned instead of the psf Array?
    return_psf : bool = False
        Should the PSF object be returned instead of the psf Array?

    Returns
    -------
    object : Array, Wavefront, PSF
        if `return_wf` is False and `return_psf` is False, returns the psf Array.
        if `return_wf` is True and `return_psf` is False, returns the Wavefront
            object.
        if `return_wf` is False and `return_psf` is True, returns the PSF object.
    """
    # Normalise and get input values
    self = self.normalise()
    positions = dlu.positions_from_sep(
        self.position, self.separation, self.position_angle
    )
    flux = dlu.fluxes_from_contrast(self.mean_flux, self.contrast)
    weights = self.weights * flux[:, None]

    # Return wf case is simple
    prop_fn = lambda position, weight: optics.propagate(
        self.wavelengths, position, weight, return_wf, return_psf
    )
    output = filter_vmap(prop_fn)(positions, weights)

    # Return wf is simple case
    if return_wf:
        return output

    # Return psf just requires constructing object
    if return_psf:
        return PSF(output.data.sum(0), output.pixel_scale.mean())

    # Return array is simple
    return output.sum(0)

ResolvedSource

Bases: PointSource

A single resolved source with a spectrum, position, flux, and distribution array that represents the resolved component.

UML

UML

Attributes:

Name Type Description
position (Array, radians)

The (x, y) on-sky position of this object.

flux (float, photons)

The flux of the object.

distribution Array

The array of intensities representing the resolved source.

spectrum Spectrum

The spectrum of this object, represented by a Spectrum object.

Source code in src/dLux/sources.py
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
class ResolvedSource(PointSource):
    """
    A single resolved source with a spectrum, position, flux, and distribution array
    that represents the resolved component.

    ??? abstract "UML"
        ![UML](../../assets/uml/ResolvedSource.png)

    Attributes
    ----------
    position : Array, radians
        The (x, y) on-sky position of this object.
    flux : float, photons
        The flux of the object.
    distribution : Array
        The array of intensities representing the resolved source.
    spectrum : Spectrum
        The spectrum of this object, represented by a Spectrum object.
    """

    distribution: Array

    def __init__(
        self: Source,
        wavelengths: Array = None,
        position: Array = np.zeros(2),
        flux: float = 1.0,
        distribution: Array = np.ones((3, 3)),
        weights: Array = None,
        spectrum: Spectrum() = None,
    ):
        """
        Parameters
        ----------
        wavelengths : Array, metres
            The array of wavelengths at which the spectrum is defined.
        position : Array, radians = np.zeros(2)
            The (x, y) on-sky position of this object.
        flux : float, photons = 1.
            The flux of the object.
        distribution : Array = np.ones((3, 3))
            The array of intensities representing the resolved source.
        weights : Array = None
            The spectral weights of the object.
        spectrum : Spectrum = None
            The spectrum of this object, represented by a Spectrum object.
        """
        distribution = np.asarray(distribution, dtype=float)
        self.distribution = distribution / distribution.sum()

        if self.distribution.ndim != 2:
            raise ValueError("distribution must be a 2d array.")

        super().__init__(
            position=position,
            flux=flux,
            spectrum=spectrum,
            wavelengths=wavelengths,
            weights=weights,
        )

    def normalise(self: Source) -> Source:
        """
        Method for returning a new source object with a normalised total
        spectrum and source distribution.

        Returns
        -------
        source : Source
            The source object with the normalised spectrum and distribution.
        """
        spectrum = self.spectrum.normalise()
        distribution_floor = np.maximum(self.distribution, 0.0)
        distribution = distribution_floor / distribution_floor.sum()
        return self.set(["spectrum", "distribution"], [spectrum, distribution])

    def model(
        self: Source,
        optics: Optics = None,
        return_wf: bool = False,
        return_psf: bool = False,
    ) -> Array:
        """
        Models the source object through the provided optics.

        Parameters
        ----------
        optics : Optics
            The optics through which to model the source object.
        return_wf : bool = False
            Should the Wavefront object be returned instead of the psf Array?
        return_psf : bool = False
            Should the PSF object be returned instead of the psf Array?

        Returns
        -------
        object : Array, Wavefront, PSF
            if `return_wf` is False and `return_psf` is False, returns the psf Array.
            if `return_wf` is True and `return_psf` is False, returns the Wavefront
                object.
            if `return_wf` is False and `return_psf` is True, returns the PSF object.
        """
        if return_wf and return_psf:
            raise ValueError(
                "return_wf and return_psf cannot both be True. "
                "Please choose one."
            )
        # Normalise and get parameters
        self = self.normalise()
        weights = self.weights * self.flux

        # Note we always return wf here so we can convolve each wavelength
        # individually if a chromatic wavefront output is required.
        wf = optics.propagate(
            self.wavelengths, self.position, weights, return_wf=True
        )

        # Returning wf is a special case
        if return_wf:
            conv_fn = lambda psf: convolve(psf, self.distribution, mode="same")
            return wf.set("amplitude", vmap(conv_fn)(wf.psf) ** 0.5)

        # Return psf object
        conv_psf = convolve(wf.psf.sum(0), self.distribution, mode="same")
        if return_psf:
            return PSF(conv_psf, wf.pixel_scale.mean())

        # Return array psf
        return conv_psf

__init__(wavelengths=None, position=np.zeros(2), flux=1.0, distribution=np.ones((3, 3)), weights=None, spectrum=None)

Parameters:

Name Type Description Default
wavelengths (Array, metres)

The array of wavelengths at which the spectrum is defined.

None
position Array, radians = np.zeros(2)

The (x, y) on-sky position of this object.

zeros(2)
flux float, photons = 1.

The flux of the object.

1.0
distribution Array = np.ones((3, 3))

The array of intensities representing the resolved source.

ones((3, 3))
weights Array = None

The spectral weights of the object.

None
spectrum Spectrum = None

The spectrum of this object, represented by a Spectrum object.

None
Source code in src/dLux/sources.py
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
def __init__(
    self: Source,
    wavelengths: Array = None,
    position: Array = np.zeros(2),
    flux: float = 1.0,
    distribution: Array = np.ones((3, 3)),
    weights: Array = None,
    spectrum: Spectrum() = None,
):
    """
    Parameters
    ----------
    wavelengths : Array, metres
        The array of wavelengths at which the spectrum is defined.
    position : Array, radians = np.zeros(2)
        The (x, y) on-sky position of this object.
    flux : float, photons = 1.
        The flux of the object.
    distribution : Array = np.ones((3, 3))
        The array of intensities representing the resolved source.
    weights : Array = None
        The spectral weights of the object.
    spectrum : Spectrum = None
        The spectrum of this object, represented by a Spectrum object.
    """
    distribution = np.asarray(distribution, dtype=float)
    self.distribution = distribution / distribution.sum()

    if self.distribution.ndim != 2:
        raise ValueError("distribution must be a 2d array.")

    super().__init__(
        position=position,
        flux=flux,
        spectrum=spectrum,
        wavelengths=wavelengths,
        weights=weights,
    )

model(optics=None, return_wf=False, return_psf=False)

Models the source object through the provided optics.

Parameters:

Name Type Description Default
optics Optics

The optics through which to model the source object.

None
return_wf bool = False

Should the Wavefront object be returned instead of the psf Array?

False
return_psf bool = False

Should the PSF object be returned instead of the psf Array?

False

Returns:

Name Type Description
object (Array, Wavefront, PSF)

if return_wf is False and return_psf is False, returns the psf Array. if return_wf is True and return_psf is False, returns the Wavefront object. if return_wf is False and return_psf is True, returns the PSF object.

Source code in src/dLux/sources.py
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
def model(
    self: Source,
    optics: Optics = None,
    return_wf: bool = False,
    return_psf: bool = False,
) -> Array:
    """
    Models the source object through the provided optics.

    Parameters
    ----------
    optics : Optics
        The optics through which to model the source object.
    return_wf : bool = False
        Should the Wavefront object be returned instead of the psf Array?
    return_psf : bool = False
        Should the PSF object be returned instead of the psf Array?

    Returns
    -------
    object : Array, Wavefront, PSF
        if `return_wf` is False and `return_psf` is False, returns the psf Array.
        if `return_wf` is True and `return_psf` is False, returns the Wavefront
            object.
        if `return_wf` is False and `return_psf` is True, returns the PSF object.
    """
    if return_wf and return_psf:
        raise ValueError(
            "return_wf and return_psf cannot both be True. "
            "Please choose one."
        )
    # Normalise and get parameters
    self = self.normalise()
    weights = self.weights * self.flux

    # Note we always return wf here so we can convolve each wavelength
    # individually if a chromatic wavefront output is required.
    wf = optics.propagate(
        self.wavelengths, self.position, weights, return_wf=True
    )

    # Returning wf is a special case
    if return_wf:
        conv_fn = lambda psf: convolve(psf, self.distribution, mode="same")
        return wf.set("amplitude", vmap(conv_fn)(wf.psf) ** 0.5)

    # Return psf object
    conv_psf = convolve(wf.psf.sum(0), self.distribution, mode="same")
    if return_psf:
        return PSF(conv_psf, wf.pixel_scale.mean())

    # Return array psf
    return conv_psf

normalise()

Method for returning a new source object with a normalised total spectrum and source distribution.

Returns:

Name Type Description
source Source

The source object with the normalised spectrum and distribution.

Source code in src/dLux/sources.py
367
368
369
370
371
372
373
374
375
376
377
378
379
380
def normalise(self: Source) -> Source:
    """
    Method for returning a new source object with a normalised total
    spectrum and source distribution.

    Returns
    -------
    source : Source
        The source object with the normalised spectrum and distribution.
    """
    spectrum = self.spectrum.normalise()
    distribution_floor = np.maximum(self.distribution, 0.0)
    distribution = distribution_floor / distribution_floor.sum()
    return self.set(["spectrum", "distribution"], [spectrum, distribution])

PointResolvedSource

Bases: ResolvedSource

A class for modelling a point source and a resolved source that is defined relative to the point source. An example would be an unresolved star with a resolved dust shell or debris disk. These two objects share the same spectra but have their flux defined by flux (the mean flux) and the flux ratio (contrast) between the point source and resolved distribution. The resolved component is defined by an array of intensities that represent the resolved distribution.

UML

UML

Attributes:

Name Type Description
position (Array, radians)

The (x, y) on-sky position of this object.

flux (float, photons)

The mean flux of the point and resolved source.

distribution Array

The array of intensities representing the resolved source.

contrast float

The contrast ratio between the point source and the resolved source.

spectrum Spectrum

The spectrum of this object, represented by a Spectrum object.

Source code in src/dLux/sources.py
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
class PointResolvedSource(ResolvedSource):
    """
    A class for modelling a point source and a resolved source that is defined
    relative to the point source. An example would be an unresolved star with
    a resolved dust shell or debris disk. These two objects share the same
    spectra but have their flux defined by flux (the mean flux) and the flux
    ratio (contrast) between the point source and resolved distribution. The
    resolved component is defined by an array of intensities that represent
    the resolved distribution.

    ??? abstract "UML"
        ![UML](../../assets/uml/PointResolvedSource.png)

    Attributes
    ----------
    position : Array, radians
        The (x, y) on-sky position of this object.
    flux : float, photons
        The mean flux of the point and resolved source.
    distribution : Array
        The array of intensities representing the resolved source.
    contrast : float
        The contrast ratio between the point source and the resolved source.
    spectrum : Spectrum
        The spectrum of this object, represented by a Spectrum object.
    """

    contrast: float

    def __init__(
        self: Source,
        wavelengths: Array = None,
        position: Array = np.zeros(2),
        flux: float = 1.0,
        distribution: Array = np.ones((3, 3)),
        contrast: float = 1.0,
        weights: Array = None,
        spectrum: Spectrum() = None,
    ) -> Source:
        """
        Parameters
        ----------
        wavelengths : Array, metres = None
            The array of wavelengths at which the spectrum is defined.
        position : Array, radians = np.zeros(2)
            The (x, y) on-sky position of this object.
        flux : float, photons = 1.
            The mean flux of the point and resolved source.
        distribution : Array = np.ones((3, 3))
            The array of intensities representing the resolved source.
        contrast : float = 1.
            The contrast ratio between the point source and the resolved source.
        weights : Array = None
            The spectral weights of the object.
        spectrum : Spectrum = None
            The spectrum of this object, represented by a Spectrum object.
        """
        wavelengths = np.asarray(wavelengths, dtype=float)
        if weights is None:
            weights = np.ones((2, len(wavelengths)))

        self.contrast = float(contrast)

        super().__init__(
            wavelengths=wavelengths,
            position=position,
            flux=flux,
            distribution=distribution,
            spectrum=spectrum,
            weights=weights,
            # contrast=contrast,
        )

    def model(
        self: Source,
        optics: Optics,
        return_wf: bool = False,
        return_psf: bool = False,
    ) -> Array:
        """
        Models the source object through the provided optics.

        Parameters
        ----------
        optics : Optics
            The optics through which to model the source object.
        return_wf : bool = False
            Should the Wavefront object be returned instead of the psf Array?
        return_psf : bool = False
            Should the PSF object be returned instead of the psf Array?

        Returns
        -------
        object : Array, Wavefront, PSF
            if `return_wf` is False and `return_psf` is False, returns the psf Array.
            if `return_wf` is True and `return_psf` is False, returns the Wavefront
                object.
            if `return_wf` is False and `return_psf` is True, returns the PSF object.
        """
        if return_wf and return_psf:
            raise ValueError(
                "return_wf and return_psf cannot both be True. "
                "Please choose one."
            )
        # Normalise and get parameters
        self = self.normalise()
        flux = dlu.fluxes_from_contrast(self.flux, self.contrast)
        weights = self.weights * flux[:, None]

        # Note we always return wf here so we can convolve each wavelength
        # individually if a chromatic wavefront output is required. We also
        # Can not propagate the weights since they have different values
        # for the point and resolved source.
        wf = optics.propagate(self.wavelengths, self.position, return_wf=True)

        # Returning wf is a special case, we need to convolve each psf with
        # the distribution, and them re-combine them into a vectorised wf
        if return_wf:
            # Perform convolution
            conv_fn = lambda psf: convolve(psf, self.distribution, mode="same")
            conv_wf = wf.set("amplitude", vmap(conv_fn)(wf.psf) ** 0.5)

            # Stack leaves manually, this is a bit of a hack to get around
            # string leaf errors from tree_map, and to avoid
            # flattening/unflattening with partition and combine
            stack_leaves = lambda x, y: np.stack([x, y], axis=0)
            amplitudes = stack_leaves(wf.amplitude, conv_wf.amplitude)
            phases = stack_leaves(wf.phase, conv_wf.phase)
            pixel_scales = stack_leaves(wf.pixel_scale, conv_wf.pixel_scale)
            wavelengths = stack_leaves(wf.wavelength, conv_wf.wavelength)

            # Combine into single wf and finally apply weights
            combined_wf = wf.set(
                ["wavelength", "amplitude", "phase", "pixel_scale"],
                [wavelengths, amplitudes, phases, pixel_scales],
            )
            return combined_wf.multiply("amplitude", weights[:, :, None, None])

        # Create singe array psf object
        point_psf = (np.expand_dims(weights[0], (1, 2)) * wf.psf).sum(0)
        resolved_psf = (np.expand_dims(weights[1], (1, 2)) * wf.psf).sum(0)
        conv_psf = convolve(resolved_psf, self.distribution, mode="same")
        psf = point_psf + conv_psf
        if return_psf:
            return PSF(psf, wf.pixel_scale.mean())

        # Return array psf
        return psf

__init__(wavelengths=None, position=np.zeros(2), flux=1.0, distribution=np.ones((3, 3)), contrast=1.0, weights=None, spectrum=None)

Parameters:

Name Type Description Default
wavelengths Array, metres = None

The array of wavelengths at which the spectrum is defined.

None
position Array, radians = np.zeros(2)

The (x, y) on-sky position of this object.

zeros(2)
flux float, photons = 1.

The mean flux of the point and resolved source.

1.0
distribution Array = np.ones((3, 3))

The array of intensities representing the resolved source.

ones((3, 3))
contrast float = 1.

The contrast ratio between the point source and the resolved source.

1.0
weights Array = None

The spectral weights of the object.

None
spectrum Spectrum = None

The spectrum of this object, represented by a Spectrum object.

None
Source code in src/dLux/sources.py
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
def __init__(
    self: Source,
    wavelengths: Array = None,
    position: Array = np.zeros(2),
    flux: float = 1.0,
    distribution: Array = np.ones((3, 3)),
    contrast: float = 1.0,
    weights: Array = None,
    spectrum: Spectrum() = None,
) -> Source:
    """
    Parameters
    ----------
    wavelengths : Array, metres = None
        The array of wavelengths at which the spectrum is defined.
    position : Array, radians = np.zeros(2)
        The (x, y) on-sky position of this object.
    flux : float, photons = 1.
        The mean flux of the point and resolved source.
    distribution : Array = np.ones((3, 3))
        The array of intensities representing the resolved source.
    contrast : float = 1.
        The contrast ratio between the point source and the resolved source.
    weights : Array = None
        The spectral weights of the object.
    spectrum : Spectrum = None
        The spectrum of this object, represented by a Spectrum object.
    """
    wavelengths = np.asarray(wavelengths, dtype=float)
    if weights is None:
        weights = np.ones((2, len(wavelengths)))

    self.contrast = float(contrast)

    super().__init__(
        wavelengths=wavelengths,
        position=position,
        flux=flux,
        distribution=distribution,
        spectrum=spectrum,
        weights=weights,
        # contrast=contrast,
    )

model(optics, return_wf=False, return_psf=False)

Models the source object through the provided optics.

Parameters:

Name Type Description Default
optics Optics

The optics through which to model the source object.

required
return_wf bool = False

Should the Wavefront object be returned instead of the psf Array?

False
return_psf bool = False

Should the PSF object be returned instead of the psf Array?

False

Returns:

Name Type Description
object (Array, Wavefront, PSF)

if return_wf is False and return_psf is False, returns the psf Array. if return_wf is True and return_psf is False, returns the Wavefront object. if return_wf is False and return_psf is True, returns the PSF object.

Source code in src/dLux/sources.py
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
def model(
    self: Source,
    optics: Optics,
    return_wf: bool = False,
    return_psf: bool = False,
) -> Array:
    """
    Models the source object through the provided optics.

    Parameters
    ----------
    optics : Optics
        The optics through which to model the source object.
    return_wf : bool = False
        Should the Wavefront object be returned instead of the psf Array?
    return_psf : bool = False
        Should the PSF object be returned instead of the psf Array?

    Returns
    -------
    object : Array, Wavefront, PSF
        if `return_wf` is False and `return_psf` is False, returns the psf Array.
        if `return_wf` is True and `return_psf` is False, returns the Wavefront
            object.
        if `return_wf` is False and `return_psf` is True, returns the PSF object.
    """
    if return_wf and return_psf:
        raise ValueError(
            "return_wf and return_psf cannot both be True. "
            "Please choose one."
        )
    # Normalise and get parameters
    self = self.normalise()
    flux = dlu.fluxes_from_contrast(self.flux, self.contrast)
    weights = self.weights * flux[:, None]

    # Note we always return wf here so we can convolve each wavelength
    # individually if a chromatic wavefront output is required. We also
    # Can not propagate the weights since they have different values
    # for the point and resolved source.
    wf = optics.propagate(self.wavelengths, self.position, return_wf=True)

    # Returning wf is a special case, we need to convolve each psf with
    # the distribution, and them re-combine them into a vectorised wf
    if return_wf:
        # Perform convolution
        conv_fn = lambda psf: convolve(psf, self.distribution, mode="same")
        conv_wf = wf.set("amplitude", vmap(conv_fn)(wf.psf) ** 0.5)

        # Stack leaves manually, this is a bit of a hack to get around
        # string leaf errors from tree_map, and to avoid
        # flattening/unflattening with partition and combine
        stack_leaves = lambda x, y: np.stack([x, y], axis=0)
        amplitudes = stack_leaves(wf.amplitude, conv_wf.amplitude)
        phases = stack_leaves(wf.phase, conv_wf.phase)
        pixel_scales = stack_leaves(wf.pixel_scale, conv_wf.pixel_scale)
        wavelengths = stack_leaves(wf.wavelength, conv_wf.wavelength)

        # Combine into single wf and finally apply weights
        combined_wf = wf.set(
            ["wavelength", "amplitude", "phase", "pixel_scale"],
            [wavelengths, amplitudes, phases, pixel_scales],
        )
        return combined_wf.multiply("amplitude", weights[:, :, None, None])

    # Create singe array psf object
    point_psf = (np.expand_dims(weights[0], (1, 2)) * wf.psf).sum(0)
    resolved_psf = (np.expand_dims(weights[1], (1, 2)) * wf.psf).sum(0)
    conv_psf = convolve(resolved_psf, self.distribution, mode="same")
    psf = point_psf + conv_psf
    if return_psf:
        return PSF(psf, wf.pixel_scale.mean())

    # Return array psf
    return psf

Scene

Bases: BaseSource

A source object that holds a set of sources that are model simultaneously.

UML

UML

Attributes:

Name Type Description
sources dict

A dictionary of source objects to model simultaneously.

Source code in src/dLux/sources.py
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
class Scene(BaseSource):
    """
    A source object that holds a set of sources that are model simultaneously.

    ??? abstract "UML"
        ![UML](../../assets/uml/Scene.png)

    Attributes
    ----------
    sources : dict
        A dictionary of source objects to model simultaneously.
    """

    sources: dict

    def __init__(self: Scene, sources: list[Source]):
        """
        Parameters
        ----------
        sources : list[Source]
            A list of source objects to model simultaneously.
        """
        super().__init__()
        if isinstance(sources, (BaseSource, tuple)):
            sources = [sources]
        self.sources = dlu.list2dictionary(sources, False, BaseSource)

    def normalise(self: Scene) -> Scene:
        """
        Method for returning a new scene with normalised source objects.

        Returns
        -------
        scene : Scene
            The normalised scene object.
        """
        is_source = lambda leaf: isinstance(leaf, BaseSource)
        norm_fn = lambda source: source.normalise()
        sources = tree_map(norm_fn, self.sources, is_leaf=is_source)
        return self.set("sources", sources)

    def __getattr__(self: Source, key: str) -> Any:
        """
        Raises the individual sources via their keys.

        Parameters
        ----------
        key : str
            The key of the item to be searched for in the sub-dictionaries.

        Returns
        -------
        item : object
            The item corresponding to the supplied key in the sub-dictionaries.
        """
        if key in self.sources.keys():
            return self.sources[key]
        raise AttributeError(
            f"{self.__class__.__name__} has no attribute " f"{key}."
        )

    def model(
        self: Scene,
        optics: Optics(),
        return_wf: bool = False,
        return_psf: bool = False,
    ) -> Array:
        """
        Models the source object through the provided optics.

        Parameters
        ----------
        optics : Optics
            The optics through which to model the source object.
        return_wf : bool = False
            Should the Wavefront object be returned instead of the psf Array?
        return_psf : bool = False
            Should the PSF object be returned instead of the psf Array?

        Returns
        -------
        object : Array, Wavefront, PSF
            if `return_wf` is False and `return_psf` is False, returns the psf Array.
            if `return_wf` is True and `return_psf` is False, returns the Wavefront
                object.
            if `return_wf` is False and `return_psf` is True, returns the PSF object.
        """
        self = self.normalise()

        # Define leaf_fn and map across sources
        leaf_fn = lambda leaf: isinstance(leaf, BaseSource)
        output = tree_map(
            lambda s: s.model(optics, return_wf, return_psf),
            self.sources,
            is_leaf=leaf_fn,
        )

        # Return wf case is simple
        if return_wf:
            return output

        # Return psf case requires mapping across the psf outputs
        if return_psf:
            # Define mapping function
            leaf_fn = lambda leaf: isinstance(leaf, PSF)
            get_psfs = lambda psf: psf.data.sum(tuple(range(psf.ndim)))
            get_pscales = lambda psf: psf.pixel_scale.mean()

            # Get values and return PSF
            psf = dlu.map2array(get_psfs, output, leaf_fn).sum(0)
            pixel_scale = dlu.map2array(get_pscales, output, leaf_fn).mean()
            return PSF(psf, pixel_scale)

        # Return array is simple
        return dlu.map2array(lambda x: x, output).sum(0)

__getattr__(key)

Raises the individual sources via their keys.

Parameters:

Name Type Description Default
key str

The key of the item to be searched for in the sub-dictionaries.

required

Returns:

Name Type Description
item object

The item corresponding to the supplied key in the sub-dictionaries.

Source code in src/dLux/sources.py
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
def __getattr__(self: Source, key: str) -> Any:
    """
    Raises the individual sources via their keys.

    Parameters
    ----------
    key : str
        The key of the item to be searched for in the sub-dictionaries.

    Returns
    -------
    item : object
        The item corresponding to the supplied key in the sub-dictionaries.
    """
    if key in self.sources.keys():
        return self.sources[key]
    raise AttributeError(
        f"{self.__class__.__name__} has no attribute " f"{key}."
    )

__init__(sources)

Parameters:

Name Type Description Default
sources list[Source]

A list of source objects to model simultaneously.

required
Source code in src/dLux/sources.py
737
738
739
740
741
742
743
744
745
746
747
def __init__(self: Scene, sources: list[Source]):
    """
    Parameters
    ----------
    sources : list[Source]
        A list of source objects to model simultaneously.
    """
    super().__init__()
    if isinstance(sources, (BaseSource, tuple)):
        sources = [sources]
    self.sources = dlu.list2dictionary(sources, False, BaseSource)

model(optics, return_wf=False, return_psf=False)

Models the source object through the provided optics.

Parameters:

Name Type Description Default
optics Optics

The optics through which to model the source object.

required
return_wf bool = False

Should the Wavefront object be returned instead of the psf Array?

False
return_psf bool = False

Should the PSF object be returned instead of the psf Array?

False

Returns:

Name Type Description
object (Array, Wavefront, PSF)

if return_wf is False and return_psf is False, returns the psf Array. if return_wf is True and return_psf is False, returns the Wavefront object. if return_wf is False and return_psf is True, returns the PSF object.

Source code in src/dLux/sources.py
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
def model(
    self: Scene,
    optics: Optics(),
    return_wf: bool = False,
    return_psf: bool = False,
) -> Array:
    """
    Models the source object through the provided optics.

    Parameters
    ----------
    optics : Optics
        The optics through which to model the source object.
    return_wf : bool = False
        Should the Wavefront object be returned instead of the psf Array?
    return_psf : bool = False
        Should the PSF object be returned instead of the psf Array?

    Returns
    -------
    object : Array, Wavefront, PSF
        if `return_wf` is False and `return_psf` is False, returns the psf Array.
        if `return_wf` is True and `return_psf` is False, returns the Wavefront
            object.
        if `return_wf` is False and `return_psf` is True, returns the PSF object.
    """
    self = self.normalise()

    # Define leaf_fn and map across sources
    leaf_fn = lambda leaf: isinstance(leaf, BaseSource)
    output = tree_map(
        lambda s: s.model(optics, return_wf, return_psf),
        self.sources,
        is_leaf=leaf_fn,
    )

    # Return wf case is simple
    if return_wf:
        return output

    # Return psf case requires mapping across the psf outputs
    if return_psf:
        # Define mapping function
        leaf_fn = lambda leaf: isinstance(leaf, PSF)
        get_psfs = lambda psf: psf.data.sum(tuple(range(psf.ndim)))
        get_pscales = lambda psf: psf.pixel_scale.mean()

        # Get values and return PSF
        psf = dlu.map2array(get_psfs, output, leaf_fn).sum(0)
        pixel_scale = dlu.map2array(get_pscales, output, leaf_fn).mean()
        return PSF(psf, pixel_scale)

    # Return array is simple
    return dlu.map2array(lambda x: x, output).sum(0)

normalise()

Method for returning a new scene with normalised source objects.

Returns:

Name Type Description
scene Scene

The normalised scene object.

Source code in src/dLux/sources.py
749
750
751
752
753
754
755
756
757
758
759
760
761
def normalise(self: Scene) -> Scene:
    """
    Method for returning a new scene with normalised source objects.

    Returns
    -------
    scene : Scene
        The normalised scene object.
    """
    is_source = lambda leaf: isinstance(leaf, BaseSource)
    norm_fn = lambda source: source.normalise()
    sources = tree_map(norm_fn, self.sources, is_leaf=is_source)
    return self.set("sources", sources)