LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
Functions | Variables
lsst.scarlet.lite.utils Namespace Reference

Functions

np.ndarray integrated_gaussian_value (np.ndarray x, float sigma)
 
np.ndarray integrated_circular_gaussian (np.ndarray|None x=None, np.ndarray|None y=None, float sigma=0.8)
 
 get_circle_mask (int diameter, npt.DTypeLike dtype=np.float64)
 
 is_attribute_safe_to_transfer (name, value)
 
 continue_class (cls)
 

Variables

 ScalarLike = bool | int | float | complex
 
tuple ScalarTypes = (bool, int, float, complex)
 
 sqrt2 = np.sqrt(2)
 
 sqrt_pi = np.sqrt(np.pi)
 
 INTRINSIC_SPECIAL_ATTRIBUTES
 

Function Documentation

◆ continue_class()

lsst.scarlet.lite.utils.continue_class ( cls)
Re-open the decorated class, adding any new definitions into the
original.
For example:
.. code-block:: python
    class Foo:
        pass
    @continueClass
    class Foo:
        def run(self):
            return None
is equivalent to:
.. code-block:: python
    class Foo:
        def run(self):
            return None
.. warning::
    Python's built-in `super` function does not behave properly in classes
    decorated with `continue_class`.  Base class methods must be invoked
    directly using their explicit types instead.

This is copied directly from lsst.utils. If any additional functions are
used from that repo we should remove this function and make lsst.utils
a dependency. But for now, it is easier to copy this single wrapper
than to include lsst.utils and all of its dependencies.

Definition at line 161 of file utils.py.

161def continue_class(cls):
162 """Re-open the decorated class, adding any new definitions into the
163 original.
164 For example:
165 .. code-block:: python
166 class Foo:
167 pass
168 @continueClass
169 class Foo:
170 def run(self):
171 return None
172 is equivalent to:
173 .. code-block:: python
174 class Foo:
175 def run(self):
176 return None
177 .. warning::
178 Python's built-in `super` function does not behave properly in classes
179 decorated with `continue_class`. Base class methods must be invoked
180 directly using their explicit types instead.
181
182 This is copied directly from lsst.utils. If any additional functions are
183 used from that repo we should remove this function and make lsst.utils
184 a dependency. But for now, it is easier to copy this single wrapper
185 than to include lsst.utils and all of its dependencies.
186 """
187 orig = getattr(sys.modules[cls.__module__], cls.__name__)
188 for name in dir(cls):
189 # Common descriptors like classmethod and staticmethod can only be
190 # accessed without invoking their magic if we use __dict__; if we use
191 # getattr on those we'll get e.g. a bound method instance on the dummy
192 # class rather than a classmethod instance we can put on the target
193 # class.
194 attr = cls.__dict__.get(name, None) or getattr(cls, name)
195 if is_attribute_safe_to_transfer(name, attr):
196 setattr(orig, name, attr)
197 return orig

◆ get_circle_mask()

lsst.scarlet.lite.utils.get_circle_mask ( int diameter,
npt.DTypeLike dtype = np.float64 )
Get a boolean image of a circle

Parameters
----------
diameter:
    The diameter of the circle and width
    of the image.
dtype:
    The `dtype` of the image.

Returns
-------
circle:
    A boolean array with ones for the pixels with centers
    inside of the circle and zeros
    outside of the circle.

Definition at line 97 of file utils.py.

97def get_circle_mask(diameter: int, dtype: npt.DTypeLike = np.float64):
98 """Get a boolean image of a circle
99
100 Parameters
101 ----------
102 diameter:
103 The diameter of the circle and width
104 of the image.
105 dtype:
106 The `dtype` of the image.
107
108 Returns
109 -------
110 circle:
111 A boolean array with ones for the pixels with centers
112 inside of the circle and zeros
113 outside of the circle.
114 """
115 c = (diameter - 1) / 2
116 # The center of the circle and its radius are
117 # off by half a pixel for circles with
118 # even numbered diameter
119 if diameter % 2 == 0:
120 radius = diameter / 2
121 else:
122 radius = c
123 x = np.arange(diameter)
124 x, y = np.meshgrid(x, x)
125 r = np.sqrt((x - c) ** 2 + (y - c) ** 2)
126
127 circle = np.ones((diameter, diameter), dtype=dtype)
128 circle[r > radius] = 0
129 return circle
130
131

◆ integrated_circular_gaussian()

np.ndarray lsst.scarlet.lite.utils.integrated_circular_gaussian ( np.ndarray | None x = None,
np.ndarray | None y = None,
float sigma = 0.8 )
Create a circular Gaussian that is integrated over pixels

This is typically used for the model PSF,
working well with the default parameters.

Parameters
----------
x, y:
    The x,y-coordinates to evaluate the integrated Gaussian.
    If `X` and `Y` are `None` then they will both be given the
    default value `numpy.arange(-7, 8)`, resulting in a
    `15x15` centered image.
sigma:
    The standard deviation of the Gaussian.

Returns
-------
image:
    A Gaussian function integrated over `X` and `Y`.

Definition at line 57 of file utils.py.

59) -> np.ndarray:
60 """Create a circular Gaussian that is integrated over pixels
61
62 This is typically used for the model PSF,
63 working well with the default parameters.
64
65 Parameters
66 ----------
67 x, y:
68 The x,y-coordinates to evaluate the integrated Gaussian.
69 If `X` and `Y` are `None` then they will both be given the
70 default value `numpy.arange(-7, 8)`, resulting in a
71 `15x15` centered image.
72 sigma:
73 The standard deviation of the Gaussian.
74
75 Returns
76 -------
77 image:
78 A Gaussian function integrated over `X` and `Y`.
79 """
80 if x is None:
81 if y is None:
82 x = np.arange(-7, 8)
83 y = x
84 else:
85 raise ValueError(
86 f"Either X and Y must be specified, or neither must be specified, got {x=} and {y=}"
87 )
88 elif y is None:
89 raise ValueError(f"Either X and Y must be specified, or neither must be specified, got {x=} and {y=}")
90
91 _x = integrated_gaussian_value(np.abs(x), sigma)[None, :]
92 _y = integrated_gaussian_value(np.abs(y), sigma)[:, None]
93 result = _x * _y
94 return result / np.sum(result)
95
96

◆ integrated_gaussian_value()

np.ndarray lsst.scarlet.lite.utils.integrated_gaussian_value ( np.ndarray x,
float sigma )
A Gaussian function evaluated at `x`

Parameters
----------
x:
    The coordinates to evaluate the integrated Gaussian
    (ie. the centers of pixels).
sigma:
    The standard deviation of the Gaussian.

Returns
-------
gaussian:
    A Gaussian function integrated over `x`

Definition at line 36 of file utils.py.

36def integrated_gaussian_value(x: np.ndarray, sigma: float) -> np.ndarray:
37 """A Gaussian function evaluated at `x`
38
39 Parameters
40 ----------
41 x:
42 The coordinates to evaluate the integrated Gaussian
43 (ie. the centers of pixels).
44 sigma:
45 The standard deviation of the Gaussian.
46
47 Returns
48 -------
49 gaussian:
50 A Gaussian function integrated over `x`
51 """
52 lhs = erfc((x - 0.5) / (sqrt2 * sigma))
53 rhs = erfc((x + 0.5) / (sqrt2 * sigma))
54 return sqrt_pi * 0.5 * sigma * (lhs - rhs)
55
56

◆ is_attribute_safe_to_transfer()

lsst.scarlet.lite.utils.is_attribute_safe_to_transfer ( name,
value )
Return True if an attribute is safe to monkeypatch-transfer to another
class.
This rejects special methods that are defined automatically for all
classes, leaving only those explicitly defined in a class decorated by
`continueClass` or registered with an instance of `TemplateMeta`.

Definition at line 147 of file utils.py.

147def is_attribute_safe_to_transfer(name, value):
148 """Return True if an attribute is safe to monkeypatch-transfer to another
149 class.
150 This rejects special methods that are defined automatically for all
151 classes, leaving only those explicitly defined in a class decorated by
152 `continueClass` or registered with an instance of `TemplateMeta`.
153 """
154 if name.startswith("__") and (
155 value is getattr(object, name, None) or name in INTRINSIC_SPECIAL_ATTRIBUTES
156 ):
157 return False
158 return True
159
160

Variable Documentation

◆ INTRINSIC_SPECIAL_ATTRIBUTES

lsst.scarlet.lite.utils.INTRINSIC_SPECIAL_ATTRIBUTES
Initial value:
1= frozenset(
2 (
3 "__qualname__",
4 "__module__",
5 "__metaclass__",
6 "__dict__",
7 "__weakref__",
8 "__class__",
9 "__subclasshook__",
10 "__name__",
11 "__doc__",
12 )
13)

Definition at line 132 of file utils.py.

◆ ScalarLike

lsst.scarlet.lite.utils.ScalarLike = bool | int | float | complex

Definition at line 28 of file utils.py.

◆ ScalarTypes

tuple lsst.scarlet.lite.utils.ScalarTypes = (bool, int, float, complex)

Definition at line 29 of file utils.py.

◆ sqrt2

lsst.scarlet.lite.utils.sqrt2 = np.sqrt(2)

Definition at line 32 of file utils.py.

◆ sqrt_pi

lsst.scarlet.lite.utils.sqrt_pi = np.sqrt(np.pi)

Definition at line 33 of file utils.py.