Utilities functions¶
This module contains the utilities functions strictly related to the computation, and input/output.
ProcessTimeSamples
¶
Bases: object
This class precomputes quantities needed during the analysis once the input file have been read.
During its initialization, a private member function :func:initializeweights
is called to precompute arrays needed for the explicit implementation of :class:BlockDiagonalPreconditionerLO
and :class:BlockDiagonalLO
.
Moreover it masks all the unobserved or pathological pixels which won't be taken into account,
via the functions :func:repixelization
and :func:flagging_samples
.
.. note::
This the reason why the value ``npix`` has to be updated after the removal
of the pathological pixels.
Parameters
npix
: {int} total number of pixels that could be observed;pixs
: {array} list of pixels observed in the time domain;pol
: {int,[defaultpol=1
]} process an intensity only (pol=1
), polarization onlypol=2
and intensity+polarization map (pol=3
);phi
: {array, [defaultNone
]} array with polarization angles (needed ifpol=3,2
);w
: {array, [defaultNone
]} array with noise weights , :math:w_t= N^{-1} _{tt}
, computed by :func:BlockLO.build_blocks
. If it is not set :func:ProcessTimeSamples.initializeweights
assumes it to be a :func:numpy.ones
array;obspix
:{array} Map from the internal pixelization to an external one, i.e. HEALPIX, it has to be modified when pathological pixels are not taken into account; Default is :func:numpy.arange(npix)
;threshold_cond
: {float} set the condition number threshold to mask bad conditioned pixels (it's used in polarization cases). Default is set to 1.e3.
Source code in brahmap/utilities/process_ces.py
8 9 10 11 12 13 14 15 16 17 18 19 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 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 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 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 263 264 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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
|
flagging_samples()
¶
Flags the time samples related to bad pixels to -1.
Source code in brahmap/utilities/process_ces.py
initializeweights(phi, w)
¶
Pre-compute the quantitities needed for the implementation of :math:(A^T A)
and to masks bad pixels.
Parameters
counts
: how many times a given pixel is observed in the timestream;mask
: mask either unobserved (counts=0
) or bad constrained pixels (see thepol=3,2
following cases) ;-
If
pol=2
: the matrix :math:(A^T A)
is symmetric and block-diagonal, each block can be written as :.. csv-table::
":math:`\sum_t cos^2 2 \phi_t`", ":math:`\sum_t sin 2\phi_t cos 2 \phi_t`" ":math:`\sum_t sin2 \phi_t cos 2 \phi_t`", ":math:`\sum_t sin^2 2 \phi_t`"
the determinant, the trace are therefore needed to compute the eigenvalues of each block via the formula:
.. math:: \lambda_{min,max}= Tr(M)/2 \pm \sqrt{Tr^2(M)/4 - det(M)}
being :math:
M
a2x2
matrix. The eigenvalues are needed to define the mask of bad constrained pixels whose condition number is :math:\gg 1
. -
If
pol=3
*: each block of the matrix :math:(A^T A)
is a3 x 3
matrix:.. csv-table::
":math:`n_{hits}`", ":math:`\sum_t cos 2 \phi_t`", ":math:`\sum_t sin 2 \phi_t`" ":math:`\sum_t cos 2 \phi_t`", ":math:`\sum_t cos^2 2 \phi_t`", ":math:`\sum_t sin 2\phi_t cos 2 \phi_t`" ":math:`\sum_t sin 2 \phi_t`", ":math:`\sum_t sin2 \phi_t cos 2 \phi_t`", ":math:`\sum_t sin^2 2 \phi_t`"
We then define the mask of bad constrained pixels by both considering the condition number similarly as in the
pol=2
case and the pixels whose count is :math:\geq 3
.
Source code in brahmap/utilities/process_ces.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
|
repixelization()
¶
Performs pixel reordering by excluding all the unbserved or pathological pixels.
Source code in brahmap/utilities/process_ces.py
bash_colors
¶
This class contains the necessary definitions to print to bash screen with colors. Sometimes it can be useful...
Source code in brahmap/utilities/utilities_functions.py
angles_gen(theta0, n, sample_freq=200.0, whwp_freq=2.5)
¶
Generate polarization angle given the sample frequency of the instrument,
the frequency of HWP and the size n
of the timestream.
Source code in brahmap/utilities/utilities_functions.py
filter_warnings(wfilter)
¶
wfilter: {string} - "ignore": never print matching warnings; - "always": always print matching warnings
is_sorted(seq)
¶
noise_val(nb, bandwidth=1)
¶
Generate elements to fill the noise covariance
matrix with a random ditribution :math:N_{tt}= < n_t n_t >
.
Parameters
nb
: {int} number of noise stationary intervals, i.e. number of blocks in N_tt'.-
bandwidth
: {int} the width of the diagonal band,e.g. :bandwidth=1
define the first up and low diagonal termsbandwidth=2
2 off diagonal terms.
Returns
t
: {list of arrays }shape=(nb,bandwidth)
diag
: {list },size = nb
diagonal values of each block .
Source code in brahmap/utilities/utilities_functions.py
output_profile(pr)
¶
Output of the profiling with :func:profile_run
.
Parameter
pr
: instance returned by :func:profile_run
Source code in brahmap/utilities/utilities_functions.py
pairs_gen(nrows, ncols)
¶
Generate random int
numbers to fill the pointing matrix for observed pixels.
Implemented even for polarization runs.
Source code in brahmap/utilities/utilities_functions.py
profile_run()
¶
subscan_resize(data, subscan)
¶
Resize a tod-size array by considering only the subscan intervals.
Source code in brahmap/utilities/utilities_functions.py
system_setup(nt, npix, nb)
¶
Setup the linear system
Returns
d
:{array} ant
array of random numbers;pairs
: {array } the non-null indices of the pointing matrix;- phi :{array}
angles if
pol=3
- t,diag : {outputs of :func:
noise_val
} noise values to construct the noise covariance matrix
Source code in brahmap/utilities/utilities_functions.py
lbs_process_timesamples(nside, pointings, pol_angles, pol_idx=3, w=None, threshold_cond=1000.0, obspix=None, galactic_coords=True)
¶
This function accepts the pointing and polarization angle arrays from litebird_sim
, rotates them from elliptic to galactic coordinate system, generates the pixel indices of the pointings and then passes them to :func:ProcessTimeSamples
.
Args:
nside
(int): nside for the output mappointings
(np.ndarray): An array of detector pointings of shape (nsamp, 2)pol_angles
(np.ndarray): A 1-d array of polarization anglepol_idx
(int): Type of map-making to use. Defaults to 3.w
(np.ndarray): array with noise weights , :math:w_t= N^{-1} _{tt}
, computed by :func:BlockLO.build_blocks
. If it is not set :func:ProcessTimeSamples.initializeweights
assumes it to be a :func:numpy.ones
array. Defaults to None.threshold_cond
(float): Sets the condition number threshold to mask bad conditioned pixels (it's used in polarization cases). Defaults to 1.e3.obspix
(np.ndarray): Map from the internal pixelization to an external one, i.e. HEALPIX, it has to be modified when pathological pixels are not taken into account. It not set, it is assumed to be `numpy.arange(npix). Defaults to None.galactic_coords
(bool, optional): Say yes if you want your result in galactic coordinates. Defaults to True.
Returns:
pointings
(np.ndarray): Pointings as pixel indexProcessTimeSamples
: ProcessTimeSamples class