Skip to content

base

Interfaces and helpers for fitting beam models to maps.

Beam-fitting functions follow the fit_{MODEL}_map naming convention and the FitMap interface defined below. See individual fitting functions for details of each beam model.

FitMap

Bases: Protocol

Source code in lat_beams/fitting/map/base.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class FitMap(Protocol):
    def __call__(
        self,
        imap: Float[ndmap, "ny nx"],
        ivar: Float[ndmap, "ny nx"],
        posmap: Float[ndmap, "2 ny nx"],
        guess: AxisManager,
        map_units: str = "pW",
        **kwargs: object,
    ) -> tuple[Optional[AxisManager], Optional[Float[ndmap, "ny nx"]]]:
        """Fit a beam model to a map.

        Parameters
        ----------
        imap : Float[ndmap, "ny nx"]
            Input beam map.
        ivar : Float[ndmap, "ny nx"]
            Inverse-variance map for `imap`.
        posmap : Float[ndmap, "2 ny nx"]
            Position map in radians. The first component is `eta` and the
            second is `xi`.
        guess : AxisManager
            Initial parameter values useful for starting the fit. See
            :func:`make_guess` for the standard parameters.
        map_units : str, default: "pW"
            Units of the input map.
        **kwargs : object
            Additional arguments for the specific fitting function.

        Returns
        -------
        fit_params : Optional[AxisManager]
            Fitted model parameters. Returns `None` if the fit fails.
        model : Optional[Float[ndmap, "ny nx"]]
            Model evaluated with the fitted parameters. Returns `None` if
            the fit fails.
        """
        ...

__call__(imap, ivar, posmap, guess, map_units='pW', **kwargs)

Fit a beam model to a map.

Parameters:

Name Type Description Default
imap Float[ndmap, 'ny nx']

Input beam map.

required
ivar Float[ndmap, 'ny nx']

Inverse-variance map for imap.

required
posmap Float[ndmap, '2 ny nx']

Position map in radians. The first component is eta and the second is xi.

required
guess AxisManager

Initial parameter values useful for starting the fit. See :func:make_guess for the standard parameters.

required
map_units str

Units of the input map.

"pW"
**kwargs object

Additional arguments for the specific fitting function.

{}

Returns:

Name Type Description
fit_params Optional[AxisManager]

Fitted model parameters. Returns None if the fit fails.

model Optional[Float[ndmap, 'ny nx']]

Model evaluated with the fitted parameters. Returns None if the fit fails.

Source code in lat_beams/fitting/map/base.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def __call__(
    self,
    imap: Float[ndmap, "ny nx"],
    ivar: Float[ndmap, "ny nx"],
    posmap: Float[ndmap, "2 ny nx"],
    guess: AxisManager,
    map_units: str = "pW",
    **kwargs: object,
) -> tuple[Optional[AxisManager], Optional[Float[ndmap, "ny nx"]]]:
    """Fit a beam model to a map.

    Parameters
    ----------
    imap : Float[ndmap, "ny nx"]
        Input beam map.
    ivar : Float[ndmap, "ny nx"]
        Inverse-variance map for `imap`.
    posmap : Float[ndmap, "2 ny nx"]
        Position map in radians. The first component is `eta` and the
        second is `xi`.
    guess : AxisManager
        Initial parameter values useful for starting the fit. See
        :func:`make_guess` for the standard parameters.
    map_units : str, default: "pW"
        Units of the input map.
    **kwargs : object
        Additional arguments for the specific fitting function.

    Returns
    -------
    fit_params : Optional[AxisManager]
        Fitted model parameters. Returns `None` if the fit fails.
    model : Optional[Float[ndmap, "ny nx"]]
        Model evaluated with the fitted parameters. Returns `None` if
        the fit fails.
    """
    ...

make_guess(amp=1, fwhm_xi=2 / 60, fwhm_eta=2 / 60, xi0=0, eta0=0, phi=0, off=0)

Make an initial beam-fitting parameter guess.

Parameters:

Name Type Description Default
amp float

Initial beam amplitude.

1
fwhm_xi float

Initial FWHM in xi.

2 / 60
fwhm_eta float

Initial FWHM in eta.

2 / 60
xi0 float

Initial beam center in xi.

0
eta0 float

Initial beam center in eta.

0
phi float

Initial beam rotation angle.

0
off float

Initial DC offset.

0

Returns:

Name Type Description
guess AxisManager

AxisManager containing the initial parameters. All values are scalar and positional parameters are in radians.

Source code in lat_beams/fitting/map/base.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def make_guess(
    amp: float = 1,
    fwhm_xi: float = 2 / 60,
    fwhm_eta: float = 2 / 60,
    xi0: float = 0,
    eta0: float = 0,
    phi: float = 0,
    off: float = 0,
) -> AxisManager:
    """Make an initial beam-fitting parameter guess.

    Parameters
    ----------
    amp : float, default: 1
        Initial beam amplitude.
    fwhm_xi : float, default: 2 / 60
        Initial FWHM in `xi`.
    fwhm_eta : float, default: 2 / 60
        Initial FWHM in `eta`.
    xi0 : float, default: 0
        Initial beam center in `xi`.
    eta0 : float, default: 0
        Initial beam center in `eta`.
    phi : float, default: 0
        Initial beam rotation angle.
    off : float, default: 0
        Initial DC offset.

    Returns
    -------
    guess : AxisManager
        `AxisManager` containing the initial parameters. All values are scalar
        and positional parameters are in radians.
    """
    guess_dict = locals()
    guess = AxisManager()
    for n, v in guess_dict.items():
        guess.wrap(n, v)
    return guess