Utilities¶
load_mask_params¶
danish.utils.load_mask_params ¶
Load mask parameters from a YAML file in the datadir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of the YAML file containing the mask parameters. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing the mask parameters. |
Source code in danish/utils.py
hexapolar¶
danish.utils.hexapolar ¶
Generate hexapolar grid of points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outer
|
float
|
Outer radius of hexapolar grid. |
1.0
|
inner
|
float
|
Inner radius of hexapolar grid. |
0.0
|
nrad
|
int
|
Number of radii on which create points. |
5
|
naz
|
int
|
Approximate number of azimuthal angles uniformly spaced along the outermost ring. Each ring is constrained to have a multiple of kfold azimuths, so the realized value may be slightly different than the input value here. Inner rings will have fewer azimuths in proportion to their radius, but will still be constrained to a multiple of kfold. (If the innermost ring has radius 0, then exactly 1 point, with azimuth undefined, will be used on that "ring".) Default: None, which means to scale the number of azimuths to the number of radii such that radii and azimuths are approximately equally spaced. |
None
|
kfold
|
int
|
Each ring will have a multiple of this many azimuths. Default: 6. |
6
|
rth
|
bool
|
If True, return r, theta instead of x, y. |
False
|
Returns:
| Type | Description |
|---|---|
x, y : ndarray
|
Hexapolar grid. |
Source code in danish/utils.py
gq_points¶
danish.utils.gq_points ¶
Deterministic weighted point set whose moments match a 2D Gaussian.
Builds concentric rings of equally-spaced points whose radii and per-ring weights are set by quadrature on the radial variable.
When rmax is None (the default), Gauss-Laguerre quadrature is
used on s = r²/2, placing nodes over the full [0, ∞) range.
All moments E[x^a y^b] of the target Gaussian are reproduced
exactly through total degree
D = min(naz - 1, 4 * nrad - 2)
For the default nrad=2, naz=6 (12 points) this gives D = 5,
i.e. all moments through 5th order are exact.
When rmax is given, Gauss-Legendre quadrature is used on the
radial CDF interval [0, u_max] where u_max = 1 - exp(-rmax²/2),
so that all rings lie within rmax sigma. The small amount of
probability mass beyond rmax is discarded and the weights are
renormalized to sum to 1. This places nodes more densely in the
interior and is better suited for UKF-style applications where
many rings are desired without reaching far into the tails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nrad
|
int
|
Number of concentric rings (default 2). |
2
|
naz
|
int
|
Approximate number of azimuthal angles uniformly spaced along the outermost ring. Each ring is constrained to have a multiple of kfold azimuths, so the realized value may be slightly different than the input value here. Inner rings will have fewer azimuths in proportion to their radius, but will still be constrained to a multiple of kfold. |
None
|
kfold
|
int
|
Each ring will have a multiple of this many azimuths. Default: 6. |
6
|
cov
|
(2, 2) array_like or None
|
Target covariance matrix. Defaults to the 2x2 identity (standard normal). For a general covariance the standard-normal points are linearly transformed via the Cholesky factor. |
None
|
center
|
bool
|
If True, prepend a point at the origin with weight zero. (The Gauss-Laguerre rule always assigns zero weight to r = 0 because the radial density r·exp(-r²/2) vanishes there, but a centre point can still be useful as a structural reference.) |
False
|
rmax
|
float or None
|
Maximum radius (in units of sigma) for the outermost ring. When set, Gauss-Legendre quadrature on the radial CDF is used instead of Gauss-Laguerre, keeping all points within rmax. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
x, y : ndarray, shape ``(N,)``
|
Sample positions, where |
|
w |
ndarray, shape ``(N,)``
|
Non-negative weights summing to 1. |
Source code in danish/utils.py
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 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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |