foscat 3.8.0__py3-none-any.whl → 3.9.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,86 +551,85 @@ 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))
618
- if len(i_im.shape) == 1: # nopol
619
- ft_im = self.comp_tf(
620
- self.backend.bk_gather(l_im, idx), nside, realfft=True
621
+ ft_im = self.comp_tf(
622
+ self.backend.bk_gather(l_im, idx, axis=1), nside, realfft=True
623
+ )
624
+ if map2 is not None:
625
+ ft_im2 = self.comp_tf(
626
+ self.backend.bk_gather(l_map2, idx, axis=1), nside, realfft=True
621
627
  )
622
- if map2 is not None:
623
- ft_im2 = self.comp_tf(
624
- self.backend.bk_gather(l_map2, idx), nside, realfft=True
625
- )
626
628
  else:
627
629
  ft_im = self.comp_tf(l_im, nside, realfft=True)
628
630
  if map2 is not None:
629
631
  ft_im2 = self.comp_tf(l_map2, nside, realfft=True)
630
-
632
+
631
633
  lth = self.ring_th(nside)
632
634
 
633
635
  co_th = np.cos(lth)
@@ -635,84 +637,104 @@ class alm:
635
637
  lmax = 3 * nside - 1
636
638
 
637
639
  cl2 = None
638
- cl2_L1 = None
639
- dt2 = 0
640
- dt3 = 0
641
- dt4 = 0
640
+
642
641
  if not doT: # polarize case
643
642
 
644
643
  self.init_Ys(spin, nside)
645
-
644
+
646
645
  if len(i_im.shape) == 2:
647
- l_im = i_im[None,:,:]
646
+ l_im = i_im[None, :, :]
648
647
  if map2 is not None:
649
- l_map2 = i_map2[None,:,:]
648
+ l_map2 = i_map2[None, :, :]
650
649
  no_input_column = True
651
- N_image=1
650
+ N_image = 1
652
651
  else:
653
652
  l_im = i_im
654
653
  if map2 is not None:
655
654
  l_map2 = i_map2
656
- N_image=i_im.shape[0]
655
+ N_image = i_im.shape[0]
657
656
 
658
657
  if nest:
659
658
  idx = hp.ring2nest(nside, np.arange(12 * nside**2))
660
- l_Q = self.backend.bk_gather(l_im[:,int(do_all_pol)], idx)
661
- l_U = self.backend.bk_gather(l_im[:,1 + int(do_all_pol)], idx)
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)
662
661
  ft_im_Pp = self.comp_tf(self.backend.bk_complex(l_Q, l_U), nside)
663
662
  ft_im_Pm = self.comp_tf(self.backend.bk_complex(l_Q, -l_U), nside)
664
663
  if map2 is not None:
665
- l_Q = self.backend.bk_gather(l_map2[:,int(do_all_pol)], idx)
666
- l_U = self.backend.bk_gather(l_map2[:,1 + int(do_all_pol)], idx)
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
+ )
667
670
  ft_im2_Pp = self.comp_tf(self.backend.bk_complex(l_Q, l_U), nside)
668
671
  ft_im2_Pm = self.comp_tf(self.backend.bk_complex(l_Q, -l_U), nside)
669
672
  else:
670
673
  ft_im_Pp = self.comp_tf(
671
- 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,
672
678
  )
673
679
  ft_im_Pm = self.comp_tf(
674
- 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,
675
684
  )
676
685
  if map2 is not None:
677
686
  ft_im2_Pp = self.comp_tf(
678
- 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
+ ),
679
690
  nside,
680
691
  )
681
692
  ft_im2_Pm = self.comp_tf(
682
693
  self.backend.bk_complex(
683
- l_map2[:,int(doT)], -l_map2[:,1 + int(do_all_pol)]
694
+ l_map2[:, int(doT)], -l_map2[:, 1 + int(do_all_pol)]
684
695
  ),
685
696
  nside,
686
697
  )
687
-
688
- l_cl=[]
698
+
699
+ l_cl = []
689
700
  for m in range(lmax + 1):
690
701
 
691
702
  plm = self.backend.bk_cast(
692
- self.compute_legendre_m(co_th, m, 3 * nside - 1, nside) / (
693
- 12 * nside**2
694
- )
695
- )
703
+ self.compute_legendre_m(co_th, m, 3 * nside - 1, nside)
704
+ / (12 * nside**2)
705
+ )
696
706
 
697
707
  if doT or do_all_pol:
698
- 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
+ )
699
711
 
700
712
  if map2 is not None:
701
- 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
+ )
702
716
  else:
703
717
  tmp2 = tmp
704
718
 
705
719
  if not doT: # polarize case
706
720
  plmp = self.Yp[spin, nside][m]
707
721
  plmm = self.Ym[spin, nside][m]
708
- tmpp = self.backend.bk_reduce_sum(plmp[None,:,:] * ft_im_Pp[:,None, :,m], 2)
709
- 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
+ )
710
728
  almE = -(tmpp + tmpm) / 2.0
711
729
  almB = (tmpp - tmpm) / (2j)
712
730
 
713
731
  if map2 is not None:
714
- tmpp2 = self.backend.bk_reduce_sum(plmp[None,:,:] * ft_im2_Pp[:,None,:, m], 2)
715
- 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
+ )
716
738
 
717
739
  almE2 = -(tmpp2 + tmpm2) / 2.0
718
740
  almB2 = (tmpp2 - tmpm2) / (2j)
@@ -721,39 +743,33 @@ class alm:
721
743
  almB2 = almB
722
744
 
723
745
  if do_all_pol:
724
- tmpTT = self.backend.bk_real(
725
- (tmp * self.backend.bk_conjugate(tmp2))
726
- )
727
- tmpTE = self.backend.bk_real(
728
- (tmp * self.backend.bk_conjugate(almE2))
729
- )
746
+ tmpTT = self.backend.bk_real(tmp * self.backend.bk_conjugate(tmp2))
747
+ tmpTE = self.backend.bk_real(tmp * self.backend.bk_conjugate(almE2))
730
748
  tmpTB = -self.backend.bk_real(
731
- (tmp * self.backend.bk_conjugate(almB2))
749
+ tmp * self.backend.bk_conjugate(almB2)
732
750
  )
733
751
 
734
- tmpEE = self.backend.bk_real((almE * self.backend.bk_conjugate(almE2)))
735
- tmpBB = self.backend.bk_real((almB * self.backend.bk_conjugate(almB2)))
736
- 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))
737
755
 
738
756
  if map2 is not None:
739
757
  tmpEB = (
740
758
  tmpEB
741
- - self.backend.bk_real(
742
- (almE2 * self.backend.bk_conjugate(almB))
743
- )
759
+ - self.backend.bk_real(almE2 * self.backend.bk_conjugate(almB))
744
760
  ) / 2
745
761
 
746
762
  if do_all_pol:
747
763
  tmpTE = (
748
764
  tmpTE
749
765
  + self.backend.bk_real(
750
- (tmp2 * self.backend.bk_conjugate(almE))
766
+ tmp2 * self.backend.bk_conjugate(almE)
751
767
  )
752
768
  ) / 2
753
769
  tmpTB = (
754
770
  tmpTB
755
771
  - self.backend.bk_real(
756
- (tmp2 * self.backend.bk_conjugate(almB))
772
+ tmp2 * self.backend.bk_conjugate(almB)
757
773
  )
758
774
  ) / 2
759
775
 
@@ -769,57 +785,57 @@ class alm:
769
785
  l_cl.append(tmpEE)
770
786
  l_cl.append(tmpBB)
771
787
  l_cl.append(tmpEB)
772
-
788
+
773
789
  else:
774
790
  offset_tensor = self.backend.bk_zeros(
775
- (N_image,m), dtype=self.backend.all_bk_type
791
+ (N_image, m), dtype=self.backend.all_bk_type
776
792
  )
777
793
  if do_all_pol:
778
794
  l_cl.append(offset_tensor)
779
- l_cl.append(2*tmpTT)
795
+ l_cl.append(2 * tmpTT)
780
796
  l_cl.append(offset_tensor)
781
- l_cl.append(2*tmpEE)
797
+ l_cl.append(2 * tmpEE)
782
798
  l_cl.append(offset_tensor)
783
- l_cl.append(2*tmpBB)
799
+ l_cl.append(2 * tmpBB)
784
800
  l_cl.append(offset_tensor)
785
- l_cl.append(2*tmpTE)
801
+ l_cl.append(2 * tmpTE)
786
802
  l_cl.append(offset_tensor)
787
- l_cl.append(2*tmpEB)
803
+ l_cl.append(2 * tmpEB)
788
804
  l_cl.append(offset_tensor)
789
- l_cl.append(2*tmpTB)
805
+ l_cl.append(2 * tmpTB)
790
806
  else:
791
807
  l_cl.append(offset_tensor)
792
- l_cl.append(2*tmpEE)
808
+ l_cl.append(2 * tmpEE)
793
809
  l_cl.append(offset_tensor)
794
- l_cl.append(2*tmpBB)
810
+ l_cl.append(2 * tmpBB)
795
811
  l_cl.append(offset_tensor)
796
- l_cl.append(2*tmpEB)
812
+ l_cl.append(2 * tmpEB)
797
813
  else:
798
- tmp = self.backend.bk_real((tmp * self.backend.bk_conjugate(tmp2)))
814
+ tmp = self.backend.bk_real(tmp * self.backend.bk_conjugate(tmp2))
799
815
  if m == 0:
800
816
  l_cl.append(tmp)
801
817
  else:
802
818
  offset_tensor = self.backend.bk_zeros(
803
- (N_image,m), dtype=self.backend.all_bk_type
819
+ (N_image, m), dtype=self.backend.all_bk_type
804
820
  )
805
821
  l_cl.append(offset_tensor)
806
- l_cl.append(2*tmp)
807
-
808
- l_cl=self.backend.bk_concat(l_cl,1)
809
-
822
+ l_cl.append(2 * tmp)
823
+
824
+ l_cl = self.backend.bk_concat(l_cl, 1)
825
+
810
826
  if doT:
811
- cl2 = self.backend.bk_reshape(l_cl,[N_image,lmax+1,lmax+1])
812
- 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)
813
829
  else:
814
830
  if do_all_pol:
815
- 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])
816
832
  else:
817
- cl2 = self.backend.bk_reshape(l_cl,[N_image,lmax+1,3,lmax+1])
818
- cl2 = self.backend.bk_reduce_sum(cl2,1)
819
-
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
+
820
836
  if no_input_column:
821
- cl2=cl2[0]
822
-
837
+ cl2 = cl2[0]
838
+
823
839
  cl2_l1 = self.backend.bk_L1(cl2)
824
840
 
825
841
  return cl2, cl2_l1
@@ -827,7 +843,7 @@ class alm:
827
843
  def map2alm(self, im, nest=False):
828
844
  nside = int(np.sqrt(im.shape[0] // 12))
829
845
 
830
- ph = self.shift_ph(nside)
846
+ # ph = self.shift_ph(nside)
831
847
 
832
848
  if nest:
833
849
  idx = hp.ring2nest(nside, np.arange(12 * nside**2))
@@ -892,7 +908,7 @@ class alm:
892
908
  return self.backend.bk_reshape(
893
909
  self.backend.bk_concat(ft_im, 0), [lmax + 1, 4 * nside - 1]
894
910
  )
895
-
911
+ """
896
912
  if nest:
897
913
  idx = hp.ring2nest(nside, np.arange(12 * nside**2))
898
914
  ft_im = self.comp_tf(
@@ -918,6 +934,7 @@ class alm:
918
934
  alm = self.backend.bk_concat([alm, tmp], axis=0)
919
935
 
920
936
  return o_map
937
+ """
921
938
 
922
939
  def map2alm_spin(self, im_Q, im_U, spin=2, nest=False):
923
940
 
@@ -926,9 +943,9 @@ class alm:
926
943
 
927
944
  nside = int(np.sqrt(im_Q.shape[0] // 12))
928
945
 
929
- lth = self.ring_th(nside)
946
+ # lth = self.ring_th(nside)
930
947
 
931
- co_th = np.cos(lth)
948
+ # co_th = np.cos(lth)
932
949
 
933
950
  if nest:
934
951
  idx = hp.ring2nest(nside, np.arange(12 * nside**2))
@@ -942,7 +959,7 @@ class alm:
942
959
 
943
960
  lmax = 3 * nside - 1
944
961
 
945
- alm = None
962
+ # alm = None
946
963
  for m in range(lmax + 1):
947
964
  # not yet debug use spherical
948
965
  # plmp1,plmm1=self.compute_legendre_spin2_m(co_th,si_th,m,3*nside-1)