Skip to content

models

Model primitives and Amigo model subclasses used for resolved sources.

Full API

Models and Amigo model subclasses used for resolved sources.

This module implements resolved-source models for both image plane fitting and interferometric data (DISCO).

ResolvedAmigoModel ¤

Bases: _AmigoModel, _BaseResolvedModel

Amigo model specialised for resolved (image-plane) sources.

This class composes the internal _AmigoModel parameter initialisation behaviour with the _BaseResolvedModel helpers for retrieving a resolved-source distribution. It is the primary model used in the examples to represent a resolved astronomical source for use with the amigo fitting machinery.

Parameters:

Name Type Description Default
exposures sequence

Sequence of exposure / fit objects describing each observation.

required
optics

Amigo-style objects used to build the forward model (see amigo documentation for expected types).

required
detector

Amigo-style objects used to build the forward model (see amigo documentation for expected types).

required
ramp_model

Amigo-style objects used to build the forward model (see amigo documentation for expected types).

required
read

Amigo-style objects used to build the forward model (see amigo documentation for expected types).

required
state mapping

Optional calibration state used to override optics/detector/ramp initial values.

required
rotate bool

If True (default) apply exposure rotation to distributions.

True
source_oversample int

Oversampling factor for source-plane operations. When setting an oversampling factor > 1, the optics model must be initialised with an oversample to match (e.g. 3 times source_oversample).

1
param_initers dict

Parameter initialiser values forwarded to exposure initialisation.

None
Source code in src/dorito/models.py
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
class ResolvedAmigoModel(_AmigoModel, _BaseResolvedModel):
    """Amigo model specialised for resolved (image-plane) sources.

    This class composes the internal `_AmigoModel` parameter initialisation
    behaviour with the `_BaseResolvedModel` helpers for retrieving a
    resolved-source distribution. It is the primary model used in the
    examples to represent a resolved astronomical source for use with the
    amigo fitting machinery.

    Parameters
    ----------
    exposures : sequence
        Sequence of exposure / fit objects describing each observation.
    optics, detector, ramp_model, read
        Amigo-style objects used to build the forward model (see amigo
        documentation for expected types).
    state : mapping, optional
        Optional calibration state used to override optics/detector/ramp
        initial values.
    rotate : bool, optional
        If True (default) apply exposure rotation to distributions.
    source_oversample : int, optional
        Oversampling factor for source-plane operations. When setting an
        oversampling factor > 1, the optics model must be initialised
        with an oversample to match (e.g. 3 times source_oversample).
    param_initers : dict, optional
        Parameter initialiser values forwarded to exposure initialisation.
    """

    source_oversample: int = 1

    def __init__(
        self,
        exposures,
        optics,
        detector,
        ramp_model,
        read,
        state,
        rotate: bool = True,
        source_oversample=1,
        param_initers: dict = None,
    ):
        self.rotate = rotate
        self.source_oversample = source_oversample

        super().__init__(exposures, optics, detector, ramp_model, read, state, param_initers)

TransformedResolvedModel ¤

Bases: ResolvedAmigoModel

Resolved model that stores and operates in a compact image basis.

This class wraps a provided ImageBasis object and stores the source distribution as basis coefficients. When initialising, if a distribution is provided in param_initers it is converted to basis coefficients and stored under the coeffs initialiser key.

Parameters:

Name Type Description Default
basis ImageBasis

Basis object providing to_basis / from_basis conversions.

required
window Array

Optional multiplicative window applied to reconstructed images.

None
source_oversample int

Oversampling factor for source-plane operations.

1
param_initers dict

Parameter initialisers; accepts a distribution entry which will be converted to coeffs via the supplied basis.

{}
Source code in src/dorito/models.py
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
194
195
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
class TransformedResolvedModel(ResolvedAmigoModel):
    """Resolved model that stores and operates in a compact image basis.

    This class wraps a provided ``ImageBasis`` object and stores the
    source distribution as basis coefficients. When initialising, if a
    ``distribution`` is provided in ``param_initers`` it is converted to
    basis coefficients and stored under the ``coeffs`` initialiser key.

    Parameters
    ----------
    basis : ImageBasis
        Basis object providing ``to_basis`` / ``from_basis`` conversions.
    window : Array, optional
        Optional multiplicative window applied to reconstructed images.
    source_oversample : int, optional
        Oversampling factor for source-plane operations.
    param_initers : dict, optional
        Parameter initialisers; accepts a ``distribution`` entry which will
        be converted to ``coeffs`` via the supplied ``basis``.
    """

    basis: None
    window: Array

    def __init__(
        self,
        exposures,
        optics,
        detector,
        ramp_model,
        read,
        basis: ImageBasis,
        state,
        source_oversample=1,
        window: Array = None,
        param_initers: dict = {},
        rotate: bool = True,
    ):

        # This seems to fix some recompile issues
        def fn(x):
            if isinstance(x, Array):
                if "i" in x.dtype.str:
                    return x
                return np.array(x, dtype=float)
            return x

        self.basis = jtu.map(lambda x: fn(x), basis)
        self.window = window

        if "distribution" in param_initers.keys():
            init_log_dist = np.log10(param_initers["distribution"])
            init_coeffs = self.basis.to_basis(init_log_dist)
            param_initers["coeffs"] = init_coeffs
            del param_initers["distribution"]

        super().__init__(
            exposures,
            optics,
            detector,
            ramp_model,
            read,
            state,
            rotate,
            source_oversample,
            param_initers,
        )

    def get_distribution(
        self,
        exposure,
        rotate: bool = None,
        exponentiate=True,
        window=True,
    ):

        coeffs = self.params["log_dist"][exposure.get_key("log_dist")]

        # exponentiation
        if exponentiate:
            distribution = 10 ** self.basis.from_basis(coeffs)
        else:
            distribution = self.basis.from_basis(coeffs)

        # windowing
        if self.window is not None and window:
            distribution *= self.window

        # rotation
        if rotate is None:
            rotate = self.rotate
        if rotate:
            distribution = exposure.rotate(distribution)

        return distribution

ResolvedDiscoModel ¤

Bases: _BaseResolvedModel

Resolved-source model container for DISCO / interferometric fits.

This lightweight container holds parameters required to transform an image-plane distribution into the complex visibilities used by the DISCO-style fitting code. The constructor collects per-oi parameters by calling each oi.initialise_params(self, distribution) and assembling a parameter mapping compatible with the rest of the amigo pipeline.

Parameters:

Name Type Description Default
ois list

List of OI-like exposure objects providing initialise_params and other data accessors used during fitting.

required
distribution Array

Initial image-plane distribution used to derive initial parameters.

required
uv_npixels int

Number of pixels in the output u/v plane used for transforms.

required
uv_pscale float

Pixel scale in the u/v plane.

required
oversample float

Image-plane oversampling factor used by the model (default: 1.0).

1.0
psf_pixel_scale float

PSF pixel scale in arcseconds per pixel (default chosen for examples).

0.065524085
rotate bool

If True, model-dirty images and transforms will be rotated by the exposure parallactic angle when requested.

True

Attributes:

Name Type Description
pscale_in float

Property returning the image-plane pixel scale in radians per pixel.

Source code in src/dorito/models.py
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
304
305
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
class ResolvedDiscoModel(_BaseResolvedModel):
    """Resolved-source model container for DISCO / interferometric fits.

    This lightweight container holds parameters required to transform an
    image-plane distribution into the complex visibilities used by the
    DISCO-style fitting code. The constructor collects per-oi parameters by
    calling each `oi.initialise_params(self, distribution)` and assembling a
    parameter mapping compatible with the rest of the amigo pipeline.

    Parameters
    ----------
    ois : list
        List of OI-like exposure objects providing `initialise_params` and
        other data accessors used during fitting.
    distribution : Array
        Initial image-plane distribution used to derive initial parameters.
    uv_npixels : int
        Number of pixels in the output u/v plane used for transforms.
    uv_pscale : float
        Pixel scale in the u/v plane.
    oversample : float, optional
        Image-plane oversampling factor used by the model (default: 1.0).
    psf_pixel_scale : float, optional
        PSF pixel scale in arcseconds per pixel (default chosen for examples).
    rotate : bool, optional
        If True, model-dirty images and transforms will be rotated by the
        exposure parallactic angle when requested.

    Attributes
    ----------
    pscale_in : float
        Property returning the image-plane pixel scale in radians per pixel.
    """

    uv_npixels: int
    uv_pscale: float
    oversample: float
    psf_pixel_scale: float

    def __init__(
        self,
        ois: list,
        distribution: Array,
        uv_npixels: int,
        uv_pscale: float,
        oversample: float = 1.0,
        psf_pixel_scale: float = 0.065524085,  # arcsec/pixel
        rotate: bool = True,
    ):

        self.uv_npixels = uv_npixels
        self.oversample = oversample
        self.uv_pscale = uv_pscale
        self.psf_pixel_scale = psf_pixel_scale
        self.rotate = rotate

        params = {}
        for oi in ois:
            param_dict = oi.initialise_params(self, distribution)
            for param, (key, value) in param_dict.items():
                if param not in params.keys():
                    params[param] = {}
                params[param][key] = value

        super().__init__(params)

    @property
    def pscale_in(self):
        """
        The pixel scale of the image plane, in radians per pixel.
        """
        return dlu.arcsec2rad(self.psf_pixel_scale / self.oversample)

pscale_in property ¤

The pixel scale of the image plane, in radians per pixel.