Skip to content

Detectors

LayeredDetector

Bases: BaseDetector

Applies a series of detector layers to some input psf.

UML

UML

Attributes:

Name Type Description
layers OrderedDict

A series of DetectorLayer transformations to apply to the input psf.

Source code in src/dLux/detectors.py
 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
 58
 59
 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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
class LayeredDetector(BaseDetector):
    """
    Applies a series of detector layers to some input psf.

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

    Attributes
    ----------
    layers: OrderedDict
        A series of `DetectorLayer` transformations to apply to the input psf.
    """

    layers: OrderedDict

    def __init__(self: LayeredDetector, layers: list[DetectorLayer, tuple]):
        """
        Parameters
        ----------
        layers : list[DetectorLayer, tuple]
            A list of DetectorLayer objects to apply to the input psf. List entries
            can be tuples of (key, layer) to specify a key, else the key is taken as
            the class name of the layer.
        """
        self.layers = dlu.list2dictionary(layers, True, DetectorLayer)
        super().__init__()

    def __getattr__(self: LayeredDetector, key: str) -> object:
        """
        Raises the individual layers via their keys.

        Parameters
        ----------
        key : str
            The key of the item to be searched for in the layers dictionary.

        Returns
        -------
        item : object
            The item corresponding to the supplied key in the layers
            dictionary.
        """
        if key in self.layers.keys():
            return self.layers[key]
        else:
            raise AttributeError(
                "'{}' object has no attribute '{}'".format(type(self), key)
            )

    def model(
        self: LayeredDetector, psf: PSF, return_psf: bool = False
    ) -> Array:
        """
        Applied the detector layers to the input psf.

        Parameters
        ----------
        psf : PSF
            The input psf to be transformed.

        Returns
        -------
        psf : PSF
            The output psf after being transformed by the detector layers.
        """
        for key, layer in self.layers.items():
            psf = layer.apply(psf)
        if return_psf:
            return psf
        return psf.data

    def insert_layer(
        self: LayeredDetector, layer: Union[DetectorLayer, tuple], index: int
    ) -> LayeredDetector:
        """
        Inserts a layer into the layers dictionary at a specified index. This function
        calls the list2dictionary function to ensure all keys remain unique. Note that
        this can result in some keys being modified if they are duplicates. The input
        'layer' can be a tuple of (key, layer) to specify a key, else the key is taken
        as the class name of the layer.

        Parameters
        ----------
        layer : Any
            The layer to be inserted.
        index : int
            The index at which to insert the layer.

        Returns
        -------
        detector : LayeredDetector
            The updated detector.
        """
        return self.set(
            "layers",
            dlu.insert_layer(self.layers, layer, index, DetectorLayer),
        )

    def remove_layer(self: LayeredDetector, key: str) -> LayeredDetector:
        """
        Removes a layer from the layers dictionary, specified by its key.

        Parameters
        ----------
        key : str
            The key of the layer to be removed.

        Returns
        -------
        detector : LayeredDetector
            The updated detector.
        """
        return self.set("layers", dlu.remove_layer(self.layers, key))

__getattr__(key)

Raises the individual layers via their keys.

Parameters:

Name Type Description Default
key str

The key of the item to be searched for in the layers dictionary.

required

Returns:

Name Type Description
item object

The item corresponding to the supplied key in the layers dictionary.

Source code in src/dLux/detectors.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def __getattr__(self: LayeredDetector, key: str) -> object:
    """
    Raises the individual layers via their keys.

    Parameters
    ----------
    key : str
        The key of the item to be searched for in the layers dictionary.

    Returns
    -------
    item : object
        The item corresponding to the supplied key in the layers
        dictionary.
    """
    if key in self.layers.keys():
        return self.layers[key]
    else:
        raise AttributeError(
            "'{}' object has no attribute '{}'".format(type(self), key)
        )

__init__(layers)

Parameters:

Name Type Description Default
layers list[DetectorLayer, tuple]

A list of DetectorLayer objects to apply to the input psf. List entries can be tuples of (key, layer) to specify a key, else the key is taken as the class name of the layer.

required
Source code in src/dLux/detectors.py
37
38
39
40
41
42
43
44
45
46
47
def __init__(self: LayeredDetector, layers: list[DetectorLayer, tuple]):
    """
    Parameters
    ----------
    layers : list[DetectorLayer, tuple]
        A list of DetectorLayer objects to apply to the input psf. List entries
        can be tuples of (key, layer) to specify a key, else the key is taken as
        the class name of the layer.
    """
    self.layers = dlu.list2dictionary(layers, True, DetectorLayer)
    super().__init__()

insert_layer(layer, index)

Inserts a layer into the layers dictionary at a specified index. This function calls the list2dictionary function to ensure all keys remain unique. Note that this can result in some keys being modified if they are duplicates. The input 'layer' can be a tuple of (key, layer) to specify a key, else the key is taken as the class name of the layer.

Parameters:

Name Type Description Default
layer Any

The layer to be inserted.

required
index int

The index at which to insert the layer.

required

Returns:

Name Type Description
detector LayeredDetector

The updated detector.

Source code in src/dLux/detectors.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def insert_layer(
    self: LayeredDetector, layer: Union[DetectorLayer, tuple], index: int
) -> LayeredDetector:
    """
    Inserts a layer into the layers dictionary at a specified index. This function
    calls the list2dictionary function to ensure all keys remain unique. Note that
    this can result in some keys being modified if they are duplicates. The input
    'layer' can be a tuple of (key, layer) to specify a key, else the key is taken
    as the class name of the layer.

    Parameters
    ----------
    layer : Any
        The layer to be inserted.
    index : int
        The index at which to insert the layer.

    Returns
    -------
    detector : LayeredDetector
        The updated detector.
    """
    return self.set(
        "layers",
        dlu.insert_layer(self.layers, layer, index, DetectorLayer),
    )

model(psf, return_psf=False)

Applied the detector layers to the input psf.

Parameters:

Name Type Description Default
psf PSF

The input psf to be transformed.

required

Returns:

Name Type Description
psf PSF

The output psf after being transformed by the detector layers.

Source code in src/dLux/detectors.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def model(
    self: LayeredDetector, psf: PSF, return_psf: bool = False
) -> Array:
    """
    Applied the detector layers to the input psf.

    Parameters
    ----------
    psf : PSF
        The input psf to be transformed.

    Returns
    -------
    psf : PSF
        The output psf after being transformed by the detector layers.
    """
    for key, layer in self.layers.items():
        psf = layer.apply(psf)
    if return_psf:
        return psf
    return psf.data

remove_layer(key)

Removes a layer from the layers dictionary, specified by its key.

Parameters:

Name Type Description Default
key str

The key of the layer to be removed.

required

Returns:

Name Type Description
detector LayeredDetector

The updated detector.

Source code in src/dLux/detectors.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def remove_layer(self: LayeredDetector, key: str) -> LayeredDetector:
    """
    Removes a layer from the layers dictionary, specified by its key.

    Parameters
    ----------
    key : str
        The key of the layer to be removed.

    Returns
    -------
    detector : LayeredDetector
        The updated detector.
    """
    return self.set("layers", dlu.remove_layer(self.layers, key))