foscat 3.8.2__py3-none-any.whl → 2025.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
foscat/alm.py CHANGED
@@ -1,5 +1,3 @@
1
- import time
2
-
3
1
  import healpy as hp
4
2
  import numpy as np
5
3
 
@@ -98,12 +96,12 @@ class alm:
98
96
  self.ring_ph(nside)
99
97
  x = (-1j * np.arange(3 * nside)).reshape(1, 3 * nside)
100
98
  self.matrix_shift_ph[nside] = self.backend.bk_exp(
101
- self.backend.bk_cast(x * self.lph[nside].reshape(4 * nside - 1, 1))
99
+ self.backend.bk_cast(x * self.lph[nside].reshape(4 * nside - 1, 1))
102
100
  )
103
101
 
104
102
  self.lmax = 3 * nside - 1
105
103
 
106
- ratio_mm = {}
104
+ # ratio_mm = {}
107
105
 
108
106
  for m in range(3 * nside):
109
107
  val = np.zeros([self.lmax - m + 1])
@@ -120,17 +118,17 @@ class alm:
120
118
  aval[1] = 2 * m + 1
121
119
  val[1] = val[0] - 0.5 * self.log(2 * m + 1)
122
120
 
123
- for l in range(m + 2, self.lmax + 1):
124
- aval[l - m] = (2 * l - 1) / (l - m)
125
- bval[l - m] = (l + m - 1) / (l - m)
126
- val[l - m] = (
127
- val[l - m - 1]
128
- + 0.5 * self.log(l - m)
129
- - 0.5 * self.log(l + m)
121
+ for ell in range(m + 2, self.lmax + 1):
122
+ aval[ell - m] = (2 * ell - 1) / (ell - m)
123
+ bval[ell - m] = (ell + m - 1) / (ell - m)
124
+ val[ell - m] = (
125
+ val[ell - m - 1]
126
+ + 0.5 * self.log(ell - m)
127
+ - 0.5 * self.log(ell + m)
130
128
  )
131
129
 
132
- self.A[nside, m] = self.backend.bk_constant((aval))
133
- self.B[nside, m] = self.backend.bk_constant((bval))
130
+ self.A[nside, m] = self.backend.bk_constant(aval)
131
+ self.B[nside, m] = self.backend.bk_constant(bval)
134
132
  self.ratio_mm[nside, m] = self.backend.bk_constant(
135
133
  np.sqrt(4 * np.pi) * np.expand_dims(np.exp(val), 1)
136
134
  )
@@ -167,8 +165,8 @@ class alm:
167
165
  vnorm = 1 / np.expand_dims(
168
166
  np.sqrt(2 * (np.arange(ell_max - m + 1) + m) + 1), 1
169
167
  )
170
- self.Yp[s, nside][m] = self.backend.bk_cast(iplus[idx] * vnorm+0J)
171
- self.Ym[s, nside][m] = self.backend.bk_cast(imoins[idx] * vnorm+0J)
168
+ self.Yp[s, nside][m] = self.backend.bk_cast(iplus[idx] * vnorm + 0j)
169
+ self.Ym[s, nside][m] = self.backend.bk_cast(imoins[idx] * vnorm + 0j)
172
170
 
173
171
  del iplus
174
172
  del imoins
@@ -224,7 +222,7 @@ class alm:
224
222
  result[0] = Pmm
225
223
 
226
224
  if m == lmax:
227
- return result * np.exp(ratio) * np.sqrt(4 * np.pi)+0J
225
+ return result * np.exp(ratio) * np.sqrt(4 * np.pi) + 0j
228
226
 
229
227
  # Étape 2 : Calcul de P_{l+1, m}(x)
230
228
  result[1] = x * (2 * m + 1) * result[0]
@@ -232,20 +230,23 @@ class alm:
232
230
  ratio[1, 0] = ratio[0, 0] - 0.5 * self.log(2 * m + 1)
233
231
 
234
232
  # Étape 3 : Récurence pour l > m + 1
235
- for l in range(m + 2, lmax + 1):
236
- result[l - m] = (
237
- (2 * l - 1) * x * result[l - m - 1] - (l + m - 1) * result[l - m - 2]
238
- ) / (l - m)
239
- ratio[l - m, 0] = (
240
- 0.5 * self.log(l - m) - 0.5 * self.log(l + m) + ratio[l - m - 1, 0]
233
+ for ell in range(m + 2, lmax + 1):
234
+ result[ell - m] = (
235
+ (2 * ell - 1) * x * result[ell - m - 1]
236
+ - (ell + m - 1) * result[ell - m - 2]
237
+ ) / (ell - m)
238
+ ratio[ell - m, 0] = (
239
+ 0.5 * self.log(ell - m)
240
+ - 0.5 * self.log(ell + m)
241
+ + ratio[ell - m - 1, 0]
241
242
  )
242
- if np.max(abs(result[l - m])) > self._limit_range:
243
- result[l - m - 1] *= self._limit_range
244
- result[l - m] *= self._limit_range
245
- ratio[l - m - 1, 0] += self._log_limit_range
246
- ratio[l - m, 0] += self._log_limit_range
243
+ if np.max(abs(result[ell - m])) > self._limit_range:
244
+ result[ell - m - 1] *= self._limit_range
245
+ result[ell - m] *= self._limit_range
246
+ ratio[ell - m - 1, 0] += self._log_limit_range
247
+ ratio[ell - m, 0] += self._log_limit_range
247
248
 
248
- return result * np.exp(ratio) * np.sqrt(4 * np.pi)+0J
249
+ return result * np.exp(ratio) * np.sqrt(4 * np.pi) + 0j
249
250
 
250
251
  # Calcul des P_{lm}(x) pour tout l inclus dans [m,lmax]
251
252
  def compute_legendre_m_old2(self, x, m, lmax, nside):
@@ -265,10 +266,10 @@ class alm:
265
266
  result[1] = x * self.A[nside, m][1] * result[0]
266
267
 
267
268
  # Étape 3 : Récurence pour l > m + 1
268
- for l in range(m + 2, lmax + 1):
269
- result[l - m] = (
270
- self.A[nside, m][l - m] * x * result[l - m - 1]
271
- - self.B[nside, m][l - m] * result[l - m - 2]
269
+ for ell in range(m + 2, lmax + 1):
270
+ result[ell - m] = (
271
+ self.A[nside, m][ell - m] * x * result[ell - m - 1]
272
+ - self.B[nside, m][ell - m] * result[ell - m - 2]
272
273
  )
273
274
  result = self.backend.bk_reshape(
274
275
  self.backend.bk_concat([result[k] for k in range(lmax + 1 - m)], axis=0),
@@ -367,19 +368,19 @@ class alm:
367
368
  ratio[2, 0] = ratio[1, 0] - self.log(2 * m + 1) / 2
368
369
 
369
370
  # Étape 3 : Récurence pour l > m + 1
370
- for l in range(m + 2, lmax + 1):
371
- result[l - m + 1] = (
372
- (2 * l - 1) * co_th * result[l - m]
373
- - (l + m - 1) * result[l - m - 1]
374
- ) / (l - m)
375
- ratio[l - m + 1, 0] = (self.log(l - m) - self.log(l + m)) / 2 + ratio[
376
- l - m, 0
377
- ]
378
- if np.max(abs(result[l - m + 1])) > self._limit_range:
379
- result[l - m] *= self._limit_range
380
- result[l - m + 1] *= self._limit_range
381
- ratio[l - m, 0] += self._log_limit_range
382
- ratio[l - m + 1, 0] += self._log_limit_range
371
+ for ell in range(m + 2, lmax + 1):
372
+ result[ell - m + 1] = (
373
+ (2 * ell - 1) * co_th * result[ell - m]
374
+ - (ell + m - 1) * result[ell - m - 1]
375
+ ) / (ell - m)
376
+ ratio[ell - m + 1, 0] = (
377
+ self.log(ell - m) - self.log(ell + m)
378
+ ) / 2 + ratio[ell - m, 0]
379
+ if np.max(abs(result[ell - m + 1])) > self._limit_range:
380
+ result[ell - m] *= self._limit_range
381
+ result[ell - m + 1] *= self._limit_range
382
+ ratio[ell - m, 0] += self._log_limit_range
383
+ ratio[ell - m + 1, 0] += self._log_limit_range
383
384
 
384
385
  ylm = result * np.exp(ratio)
385
386
  ylm[1:] *= (
@@ -396,8 +397,8 @@ class alm:
396
397
  ) + ell * (ell - 1) * cot_th * cot_th
397
398
  b = 2 * m * (ell - 1) * cot_th / si_th
398
399
  w = np.zeros([lmax + 1 - m, 1])
399
- l = ell[ell > 1]
400
- w[ell > 1] = np.sqrt(1 / ((l + 2) * (l + 1) * (l) * (l - 1)))
400
+ l_ell = ell[ell > 1]
401
+ w[ell > 1] = np.sqrt(1 / ((l_ell + 2) * (l_ell + 1) * (l_ell) * (l_ell - 1)))
401
402
  w = w.reshape(lmax + 1 - m, 1)
402
403
 
403
404
  alpha_plus = w * (a + b)
@@ -418,13 +419,13 @@ class alm:
418
419
  r = self.backend.bk_rfft(val)
419
420
  if axis == 0:
420
421
  r_inv = self.backend.bk_reverse(
421
- self.backend.bk_conjugate(r[...,1:-1]), axis=-1
422
+ self.backend.bk_conjugate(r[..., 1:-1]), axis=-1
422
423
  )
423
424
  else:
424
425
  r_inv = self.backend.bk_reverse(
425
426
  self.backend.bk_conjugate(r[..., 1:-1]), axis=-1
426
427
  )
427
- return self.backend.bk_concat([r, r_inv], axis=axis+1)
428
+ return self.backend.bk_concat([r, r_inv], axis=axis + 1)
428
429
 
429
430
  def irfft2fft(self, val, N, axis=0):
430
431
  if axis == 0:
@@ -433,9 +434,9 @@ class alm:
433
434
  return self.backend.bk_irfft(val[:, 0 : N // 2 + 1])
434
435
 
435
436
  def comp_tf(self, im, nside, realfft=False):
436
-
437
- #im is [Nimage,12*nside**2]
438
-
437
+
438
+ # im is [Nimage,12*nside**2]
439
+
439
440
  self.shift_ph(nside)
440
441
  n = 0
441
442
 
@@ -444,9 +445,9 @@ class alm:
444
445
  N = 4 * (k + 1)
445
446
 
446
447
  if realfft:
447
- tmp = self.rfft2fft(im[:,n : n + N])
448
+ tmp = self.rfft2fft(im[:, n : n + N])
448
449
  else:
449
- tmp = self.backend.bk_fft(im[:,n : n + N])
450
+ tmp = self.backend.bk_fft(im[:, n : n + N])
450
451
 
451
452
  l_n = tmp.shape[1]
452
453
 
@@ -454,43 +455,45 @@ class alm:
454
455
  repeat_n = 3 * nside // l_n + 1
455
456
  tmp = self.backend.bk_tile(tmp, repeat_n, axis=1)
456
457
 
457
- ft_im.append(tmp[:,None,0 : 3 * nside])
458
+ ft_im.append(tmp[:, None, 0 : 3 * nside])
458
459
 
459
460
  n += N
460
461
 
461
462
  N = 4 * nside * (2 * nside + 1)
462
- v = self.backend.bk_reshape(im[:,n : n + N], [im.shape[0],2 * nside + 1, 4 * nside])
463
+ v = self.backend.bk_reshape(
464
+ im[:, n : n + N], [im.shape[0], 2 * nside + 1, 4 * nside]
465
+ )
463
466
  if realfft:
464
467
  v_fft = self.rfft2fft(v, axis=1)[:, :, : 3 * nside]
465
468
  else:
466
469
  v_fft = self.backend.bk_fft(v)[:, :, : 3 * nside]
467
470
 
468
471
  n += N
469
-
472
+
470
473
  ft_im.append(v_fft)
471
-
474
+
472
475
  if nside > 1:
473
476
  for k in range(nside - 1):
474
477
  N = 4 * (nside - 1 - k)
475
478
 
476
479
  if realfft:
477
- tmp = self.rfft2fft(im[:,n : n + N])
480
+ tmp = self.rfft2fft(im[:, n : n + N])
478
481
  else:
479
- tmp = self.backend.bk_fft(im[:,n : n + N])
482
+ tmp = self.backend.bk_fft(im[:, n : n + N])
480
483
 
481
484
  l_n = tmp.shape[1]
482
485
 
483
486
  if l_n < 3 * nside + 1:
484
487
  repeat_n = 3 * nside // l_n + 1
485
488
  tmp = self.backend.bk_tile(tmp, repeat_n, axis=1)
486
-
487
- ft_im.append(tmp[:,None,0 : 3 * nside])
489
+
490
+ ft_im.append(tmp[:, None, 0 : 3 * nside])
488
491
  n += N
489
-
492
+
490
493
  return (
491
- self.backend.bk_concat(ft_im, axis=1)
492
- * self.matrix_shift_ph[nside][None,:,:]
493
- )
494
+ self.backend.bk_concat(ft_im, axis=1)
495
+ * self.matrix_shift_ph[nside][None, :, :]
496
+ )
494
497
 
495
498
  def icomp_tf(self, i_im, nside, realfft=False):
496
499
 
@@ -548,70 +551,70 @@ class alm:
548
551
  else:
549
552
  return result
550
553
 
551
- def anafast(self, im, map2=None, nest=False, spin=2,axes=0):
554
+ def anafast(self, im, map2=None, nest=False, spin=2, axes=0):
552
555
  """The `anafast` function computes the L1 and L2 norm power spectra.
553
556
 
554
- Currently, it is not optimized for single-pass computation due to the relatively inefficient computation of \(Y_{lm}\).
557
+ Currently, it is not optimized for single-pass computation due to the relatively inefficient computation of (Y_{lm}).
555
558
  Nonetheless, it utilizes TensorFlow and can be integrated into gradient computations.
556
559
 
557
560
  Input:
558
- - `im`: a vector of size \([12 \times \text{Nside}^2]\) for scalar data, or of size \([2, 12 \times \text{Nside}^2]\) for Q,U polar data,
559
- or of size \([3, 12 \times \text{Nside}^2]\) for I,Q,U polar data.
560
- - `map2` (optional): a vector of size \([12 \times \text{Nside}^2]\) for scalar data, or of size
561
- \([3, 12 \times \text{Nside}^2]\) for polar data. If provided, cross power spectra will be computed.
561
+ - `im`: a vector of size ([12 \times \text{Nside}^2]) for scalar data, or of size ([2, 12 \times \text{Nside}^2]) for Q,U polar data,
562
+ or of size ([3, 12 \times \text{Nside}^2]) for I,Q,U polar data.
563
+ - `map2` (optional): a vector of size ([12 \times \text{Nside}^2]) for scalar data, or of size
564
+ ([3, 12 \times \text{Nside}^2]) for polar data. If provided, cross power spectra will be computed.
562
565
  - `nest=True`: alters the ordering of the input maps.
563
566
  - `spin=2` for 1/2 spin data as Q and U. Spin=1 for seep fields
564
567
 
565
568
  Output:
566
- -A tensor of size \([l_{\text{max}} \times (l_{\text{max}}-1)]\) formatted as \([6, \ldots]\),
569
+ -A tensor of size ([l_{\text{max}} \times (l_{\text{max}}-1)) formatted as ([6, ldots]),
567
570
  ordered as TT, EE, BB, TE, EB.TBanafast function computes L1 and L2 norm powerspctra.
568
571
 
569
572
  """
570
573
  no_input_column = False
571
-
574
+
572
575
  i_im = self.backend.bk_cast(im)
573
576
  if map2 is not None:
574
577
  i_map2 = self.backend.bk_cast(map2)
575
578
 
576
579
  doT = True
577
-
578
- if len(i_im.shape)-axes == 1: # nopol
580
+
581
+ if len(i_im.shape) - axes == 1: # nopol
579
582
  nside = int(np.sqrt(i_im.shape[axes] // 12))
580
583
  else:
581
- if len(i_im.shape)-axes == 2:
584
+ if len(i_im.shape) - axes == 2:
582
585
  doT = False
583
- nside = int(np.sqrt(i_im.shape[axes+1] // 12))
584
- do_all_pol=False
585
- if i_im.shape[axes]==3:
586
- do_all_pol=True
587
-
586
+ nside = int(np.sqrt(i_im.shape[axes + 1] // 12))
587
+ do_all_pol = False
588
+ if i_im.shape[axes] == 3:
589
+ do_all_pol = True
590
+
588
591
  self.shift_ph(nside)
589
592
 
590
593
  if doT or do_all_pol:
591
- if len(i_im.shape) == 1 + int(do_all_pol):# no pol if 1 all pol if 2
594
+ if len(i_im.shape) == 1 + int(do_all_pol): # no pol if 1 all pol if 2
592
595
  if do_all_pol:
593
- l_im = i_im[None,0,...]
596
+ l_im = i_im[None, 0, ...]
594
597
  if map2 is not None:
595
- l_map2 = i_map2[None,0,...]
598
+ l_map2 = i_map2[None, 0, ...]
596
599
  else:
597
- l_im = i_im[None,...]
600
+ l_im = i_im[None, ...]
598
601
  if map2 is not None:
599
- l_map2 = i_map2[None,...]
602
+ l_map2 = i_map2[None, ...]
600
603
  no_input_column = True
601
- N_image=1
602
-
603
- else:
604
+ N_image = 1
605
+
606
+ else:
604
607
  if do_all_pol:
605
- l_im = i_im[:,0]
608
+ l_im = i_im[:, 0]
606
609
  if map2 is not None:
607
- l_map2 = i_map2[:,0]
608
- N_image=i_im.shape[0]
609
-
610
+ l_map2 = i_map2[:, 0]
611
+ N_image = i_im.shape[0]
612
+
610
613
  else:
611
614
  l_im = i_im
612
615
  if map2 is not None:
613
616
  l_map2 = i_map2
614
- N_image=i_im.shape[0]
617
+ N_image = i_im.shape[0]
615
618
 
616
619
  if nest:
617
620
  idx = hp.ring2nest(nside, np.arange(12 * nside**2))
@@ -626,7 +629,7 @@ class alm:
626
629
  ft_im = self.comp_tf(l_im, nside, realfft=True)
627
630
  if map2 is not None:
628
631
  ft_im2 = self.comp_tf(l_map2, nside, realfft=True)
629
-
632
+
630
633
  lth = self.ring_th(nside)
631
634
 
632
635
  co_th = np.cos(lth)
@@ -634,84 +637,104 @@ class alm:
634
637
  lmax = 3 * nside - 1
635
638
 
636
639
  cl2 = None
637
- cl2_L1 = None
638
- dt2 = 0
639
- dt3 = 0
640
- dt4 = 0
640
+
641
641
  if not doT: # polarize case
642
642
 
643
643
  self.init_Ys(spin, nside)
644
-
644
+
645
645
  if len(i_im.shape) == 2:
646
- l_im = i_im[None,:,:]
646
+ l_im = i_im[None, :, :]
647
647
  if map2 is not None:
648
- l_map2 = i_map2[None,:,:]
648
+ l_map2 = i_map2[None, :, :]
649
649
  no_input_column = True
650
- N_image=1
650
+ N_image = 1
651
651
  else:
652
652
  l_im = i_im
653
653
  if map2 is not None:
654
654
  l_map2 = i_map2
655
- N_image=i_im.shape[0]
655
+ N_image = i_im.shape[0]
656
656
 
657
657
  if nest:
658
658
  idx = hp.ring2nest(nside, np.arange(12 * nside**2))
659
- l_Q = self.backend.bk_gather(l_im[:,int(do_all_pol)], idx,axis=1)
660
- l_U = self.backend.bk_gather(l_im[:,1 + int(do_all_pol)], idx,axis=1)
659
+ l_Q = self.backend.bk_gather(l_im[:, int(do_all_pol)], idx, axis=1)
660
+ l_U = self.backend.bk_gather(l_im[:, 1 + int(do_all_pol)], idx, axis=1)
661
661
  ft_im_Pp = self.comp_tf(self.backend.bk_complex(l_Q, l_U), nside)
662
662
  ft_im_Pm = self.comp_tf(self.backend.bk_complex(l_Q, -l_U), nside)
663
663
  if map2 is not None:
664
- l_Q = self.backend.bk_gather(l_map2[:,int(do_all_pol)], idx,axis=1)
665
- l_U = self.backend.bk_gather(l_map2[:,1 + int(do_all_pol)], idx,axis=1)
664
+ l_Q = self.backend.bk_gather(
665
+ l_map2[:, int(do_all_pol)], idx, axis=1
666
+ )
667
+ l_U = self.backend.bk_gather(
668
+ l_map2[:, 1 + int(do_all_pol)], idx, axis=1
669
+ )
666
670
  ft_im2_Pp = self.comp_tf(self.backend.bk_complex(l_Q, l_U), nside)
667
671
  ft_im2_Pm = self.comp_tf(self.backend.bk_complex(l_Q, -l_U), nside)
668
672
  else:
669
673
  ft_im_Pp = self.comp_tf(
670
- self.backend.bk_complex(l_im[:,int(do_all_pol)], l_im[:,1 + int(do_all_pol)]), nside
674
+ self.backend.bk_complex(
675
+ l_im[:, int(do_all_pol)], l_im[:, 1 + int(do_all_pol)]
676
+ ),
677
+ nside,
671
678
  )
672
679
  ft_im_Pm = self.comp_tf(
673
- self.backend.bk_complex(l_im[:,int(do_all_pol)], -l_im[:,1 + int(do_all_pol)]), nside
680
+ self.backend.bk_complex(
681
+ l_im[:, int(do_all_pol)], -l_im[:, 1 + int(do_all_pol)]
682
+ ),
683
+ nside,
674
684
  )
675
685
  if map2 is not None:
676
686
  ft_im2_Pp = self.comp_tf(
677
- self.backend.bk_complex(l_map2[:,int(do_all_pol)], l_map2[:,1 + int(do_all_pol)]),
687
+ self.backend.bk_complex(
688
+ l_map2[:, int(do_all_pol)], l_map2[:, 1 + int(do_all_pol)]
689
+ ),
678
690
  nside,
679
691
  )
680
692
  ft_im2_Pm = self.comp_tf(
681
693
  self.backend.bk_complex(
682
- l_map2[:,int(doT)], -l_map2[:,1 + int(do_all_pol)]
694
+ l_map2[:, int(doT)], -l_map2[:, 1 + int(do_all_pol)]
683
695
  ),
684
696
  nside,
685
697
  )
686
-
687
- l_cl=[]
698
+
699
+ l_cl = []
688
700
  for m in range(lmax + 1):
689
701
 
690
702
  plm = self.backend.bk_cast(
691
- self.compute_legendre_m(co_th, m, 3 * nside - 1, nside) / (
692
- 12 * nside**2
693
- )
694
- )
703
+ self.compute_legendre_m(co_th, m, 3 * nside - 1, nside)
704
+ / (12 * nside**2)
705
+ )
695
706
 
696
707
  if doT or do_all_pol:
697
- tmp = self.backend.bk_reduce_sum(plm[None,:,:] * ft_im[:,None,:, m], 2)
708
+ tmp = self.backend.bk_reduce_sum(
709
+ plm[None, :, :] * ft_im[:, None, :, m], 2
710
+ )
698
711
 
699
712
  if map2 is not None:
700
- tmp2 = self.backend.bk_reduce_sum(plm[None,:,:] * ft_im2[:,None, :, m], 2)
713
+ tmp2 = self.backend.bk_reduce_sum(
714
+ plm[None, :, :] * ft_im2[:, None, :, m], 2
715
+ )
701
716
  else:
702
717
  tmp2 = tmp
703
718
 
704
719
  if not doT: # polarize case
705
720
  plmp = self.Yp[spin, nside][m]
706
721
  plmm = self.Ym[spin, nside][m]
707
- tmpp = self.backend.bk_reduce_sum(plmp[None,:,:] * ft_im_Pp[:,None, :,m], 2)
708
- tmpm = self.backend.bk_reduce_sum(plmm[None,:,:] * ft_im_Pm[:,None, :,m], 2)
722
+ tmpp = self.backend.bk_reduce_sum(
723
+ plmp[None, :, :] * ft_im_Pp[:, None, :, m], 2
724
+ )
725
+ tmpm = self.backend.bk_reduce_sum(
726
+ plmm[None, :, :] * ft_im_Pm[:, None, :, m], 2
727
+ )
709
728
  almE = -(tmpp + tmpm) / 2.0
710
729
  almB = (tmpp - tmpm) / (2j)
711
730
 
712
731
  if map2 is not None:
713
- tmpp2 = self.backend.bk_reduce_sum(plmp[None,:,:] * ft_im2_Pp[:,None,:, m], 2)
714
- tmpm2 = self.backend.bk_reduce_sum(plmm[None,:,:] * ft_im2_Pm[:,None,:, m], 2)
732
+ tmpp2 = self.backend.bk_reduce_sum(
733
+ plmp[None, :, :] * ft_im2_Pp[:, None, :, m], 2
734
+ )
735
+ tmpm2 = self.backend.bk_reduce_sum(
736
+ plmm[None, :, :] * ft_im2_Pm[:, None, :, m], 2
737
+ )
715
738
 
716
739
  almE2 = -(tmpp2 + tmpm2) / 2.0
717
740
  almB2 = (tmpp2 - tmpm2) / (2j)
@@ -720,39 +743,33 @@ class alm:
720
743
  almB2 = almB
721
744
 
722
745
  if do_all_pol:
723
- tmpTT = self.backend.bk_real(
724
- (tmp * self.backend.bk_conjugate(tmp2))
725
- )
726
- tmpTE = self.backend.bk_real(
727
- (tmp * self.backend.bk_conjugate(almE2))
728
- )
746
+ tmpTT = self.backend.bk_real(tmp * self.backend.bk_conjugate(tmp2))
747
+ tmpTE = self.backend.bk_real(tmp * self.backend.bk_conjugate(almE2))
729
748
  tmpTB = -self.backend.bk_real(
730
- (tmp * self.backend.bk_conjugate(almB2))
749
+ tmp * self.backend.bk_conjugate(almB2)
731
750
  )
732
751
 
733
- tmpEE = self.backend.bk_real((almE * self.backend.bk_conjugate(almE2)))
734
- tmpBB = self.backend.bk_real((almB * self.backend.bk_conjugate(almB2)))
735
- tmpEB = -self.backend.bk_real((almE * self.backend.bk_conjugate(almB2)))
752
+ tmpEE = self.backend.bk_real(almE * self.backend.bk_conjugate(almE2))
753
+ tmpBB = self.backend.bk_real(almB * self.backend.bk_conjugate(almB2))
754
+ tmpEB = -self.backend.bk_real(almE * self.backend.bk_conjugate(almB2))
736
755
 
737
756
  if map2 is not None:
738
757
  tmpEB = (
739
758
  tmpEB
740
- - self.backend.bk_real(
741
- (almE2 * self.backend.bk_conjugate(almB))
742
- )
759
+ - self.backend.bk_real(almE2 * self.backend.bk_conjugate(almB))
743
760
  ) / 2
744
761
 
745
762
  if do_all_pol:
746
763
  tmpTE = (
747
764
  tmpTE
748
765
  + self.backend.bk_real(
749
- (tmp2 * self.backend.bk_conjugate(almE))
766
+ tmp2 * self.backend.bk_conjugate(almE)
750
767
  )
751
768
  ) / 2
752
769
  tmpTB = (
753
770
  tmpTB
754
771
  - self.backend.bk_real(
755
- (tmp2 * self.backend.bk_conjugate(almB))
772
+ tmp2 * self.backend.bk_conjugate(almB)
756
773
  )
757
774
  ) / 2
758
775
 
@@ -768,57 +785,57 @@ class alm:
768
785
  l_cl.append(tmpEE)
769
786
  l_cl.append(tmpBB)
770
787
  l_cl.append(tmpEB)
771
-
788
+
772
789
  else:
773
790
  offset_tensor = self.backend.bk_zeros(
774
- (N_image,m), dtype=self.backend.all_bk_type
791
+ (N_image, m), dtype=self.backend.all_bk_type
775
792
  )
776
793
  if do_all_pol:
777
794
  l_cl.append(offset_tensor)
778
- l_cl.append(2*tmpTT)
795
+ l_cl.append(2 * tmpTT)
779
796
  l_cl.append(offset_tensor)
780
- l_cl.append(2*tmpEE)
797
+ l_cl.append(2 * tmpEE)
781
798
  l_cl.append(offset_tensor)
782
- l_cl.append(2*tmpBB)
799
+ l_cl.append(2 * tmpBB)
783
800
  l_cl.append(offset_tensor)
784
- l_cl.append(2*tmpTE)
801
+ l_cl.append(2 * tmpTE)
785
802
  l_cl.append(offset_tensor)
786
- l_cl.append(2*tmpEB)
803
+ l_cl.append(2 * tmpEB)
787
804
  l_cl.append(offset_tensor)
788
- l_cl.append(2*tmpTB)
805
+ l_cl.append(2 * tmpTB)
789
806
  else:
790
807
  l_cl.append(offset_tensor)
791
- l_cl.append(2*tmpEE)
808
+ l_cl.append(2 * tmpEE)
792
809
  l_cl.append(offset_tensor)
793
- l_cl.append(2*tmpBB)
810
+ l_cl.append(2 * tmpBB)
794
811
  l_cl.append(offset_tensor)
795
- l_cl.append(2*tmpEB)
812
+ l_cl.append(2 * tmpEB)
796
813
  else:
797
- tmp = self.backend.bk_real((tmp * self.backend.bk_conjugate(tmp2)))
814
+ tmp = self.backend.bk_real(tmp * self.backend.bk_conjugate(tmp2))
798
815
  if m == 0:
799
816
  l_cl.append(tmp)
800
817
  else:
801
818
  offset_tensor = self.backend.bk_zeros(
802
- (N_image,m), dtype=self.backend.all_bk_type
819
+ (N_image, m), dtype=self.backend.all_bk_type
803
820
  )
804
821
  l_cl.append(offset_tensor)
805
- l_cl.append(2*tmp)
806
-
807
- l_cl=self.backend.bk_concat(l_cl,1)
808
-
822
+ l_cl.append(2 * tmp)
823
+
824
+ l_cl = self.backend.bk_concat(l_cl, 1)
825
+
809
826
  if doT:
810
- cl2 = self.backend.bk_reshape(l_cl,[N_image,lmax+1,lmax+1])
811
- cl2 = self.backend.bk_reduce_sum(cl2,1)
827
+ cl2 = self.backend.bk_reshape(l_cl, [N_image, lmax + 1, lmax + 1])
828
+ cl2 = self.backend.bk_reduce_sum(cl2, 1)
812
829
  else:
813
830
  if do_all_pol:
814
- cl2 = self.backend.bk_reshape(l_cl,[N_image,lmax+1,6,lmax+1])
831
+ cl2 = self.backend.bk_reshape(l_cl, [N_image, lmax + 1, 6, lmax + 1])
815
832
  else:
816
- cl2 = self.backend.bk_reshape(l_cl,[N_image,lmax+1,3,lmax+1])
817
- cl2 = self.backend.bk_reduce_sum(cl2,1)
818
-
833
+ cl2 = self.backend.bk_reshape(l_cl, [N_image, lmax + 1, 3, lmax + 1])
834
+ cl2 = self.backend.bk_reduce_sum(cl2, 1)
835
+
819
836
  if no_input_column:
820
- cl2=cl2[0]
821
-
837
+ cl2 = cl2[0]
838
+
822
839
  cl2_l1 = self.backend.bk_L1(cl2)
823
840
 
824
841
  return cl2, cl2_l1
@@ -826,7 +843,7 @@ class alm:
826
843
  def map2alm(self, im, nest=False):
827
844
  nside = int(np.sqrt(im.shape[0] // 12))
828
845
 
829
- ph = self.shift_ph(nside)
846
+ # ph = self.shift_ph(nside)
830
847
 
831
848
  if nest:
832
849
  idx = hp.ring2nest(nside, np.arange(12 * nside**2))
@@ -891,7 +908,7 @@ class alm:
891
908
  return self.backend.bk_reshape(
892
909
  self.backend.bk_concat(ft_im, 0), [lmax + 1, 4 * nside - 1]
893
910
  )
894
-
911
+ """
895
912
  if nest:
896
913
  idx = hp.ring2nest(nside, np.arange(12 * nside**2))
897
914
  ft_im = self.comp_tf(
@@ -917,6 +934,7 @@ class alm:
917
934
  alm = self.backend.bk_concat([alm, tmp], axis=0)
918
935
 
919
936
  return o_map
937
+ """
920
938
 
921
939
  def map2alm_spin(self, im_Q, im_U, spin=2, nest=False):
922
940
 
@@ -925,9 +943,9 @@ class alm:
925
943
 
926
944
  nside = int(np.sqrt(im_Q.shape[0] // 12))
927
945
 
928
- lth = self.ring_th(nside)
946
+ # lth = self.ring_th(nside)
929
947
 
930
- co_th = np.cos(lth)
948
+ # co_th = np.cos(lth)
931
949
 
932
950
  if nest:
933
951
  idx = hp.ring2nest(nside, np.arange(12 * nside**2))
@@ -941,7 +959,7 @@ class alm:
941
959
 
942
960
  lmax = 3 * nside - 1
943
961
 
944
- alm = None
962
+ # alm = None
945
963
  for m in range(lmax + 1):
946
964
  # not yet debug use spherical
947
965
  # plmp1,plmm1=self.compute_legendre_spin2_m(co_th,si_th,m,3*nside-1)