foscat 2025.9.1__py3-none-any.whl → 2025.9.4__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/BkTorch.py +160 -93
- foscat/FoCUS.py +80 -267
- foscat/HOrientedConvol.py +233 -250
- foscat/HealBili.py +12 -8
- foscat/Plot.py +1112 -142
- foscat/SphericalStencil.py +1346 -0
- foscat/UNET.py +21 -7
- foscat/healpix_unet_torch.py +656 -171
- foscat/scat_cov.py +2 -0
- {foscat-2025.9.1.dist-info → foscat-2025.9.4.dist-info}/METADATA +1 -1
- {foscat-2025.9.1.dist-info → foscat-2025.9.4.dist-info}/RECORD +14 -13
- {foscat-2025.9.1.dist-info → foscat-2025.9.4.dist-info}/WHEEL +0 -0
- {foscat-2025.9.1.dist-info → foscat-2025.9.4.dist-info}/licenses/LICENSE +0 -0
- {foscat-2025.9.1.dist-info → foscat-2025.9.4.dist-info}/top_level.txt +0 -0
foscat/FoCUS.py
CHANGED
|
@@ -6,7 +6,7 @@ import numpy as np
|
|
|
6
6
|
import foscat.HealSpline as HS
|
|
7
7
|
from scipy.interpolate import griddata
|
|
8
8
|
|
|
9
|
-
TMPFILE_VERSION = "
|
|
9
|
+
TMPFILE_VERSION = "V9_0"
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class FoCUS:
|
|
@@ -36,7 +36,7 @@ class FoCUS:
|
|
|
36
36
|
mpi_rank=0
|
|
37
37
|
):
|
|
38
38
|
|
|
39
|
-
self.__version__ = "2025.09.
|
|
39
|
+
self.__version__ = "2025.09.4"
|
|
40
40
|
# P00 coeff for normalization for scat_cov
|
|
41
41
|
self.TMPFILE_VERSION = TMPFILE_VERSION
|
|
42
42
|
self.P1_dic = None
|
|
@@ -123,6 +123,7 @@ class FoCUS:
|
|
|
123
123
|
silent=self.silent,
|
|
124
124
|
)
|
|
125
125
|
elif BACKEND == "tensorflow":
|
|
126
|
+
'''
|
|
126
127
|
from foscat.BkTensorflow import BkTensorflow
|
|
127
128
|
|
|
128
129
|
self.backend = BkTensorflow(
|
|
@@ -131,7 +132,10 @@ class FoCUS:
|
|
|
131
132
|
gpupos=gpupos,
|
|
132
133
|
silent=self.silent,
|
|
133
134
|
)
|
|
135
|
+
'''
|
|
136
|
+
raise 'TENSORFLOW BACKEND Not anymore maintained'
|
|
134
137
|
else:
|
|
138
|
+
'''
|
|
135
139
|
from foscat.BkNumpy import BkNumpy
|
|
136
140
|
|
|
137
141
|
self.backend = BkNumpy(
|
|
@@ -140,6 +144,8 @@ class FoCUS:
|
|
|
140
144
|
gpupos=gpupos,
|
|
141
145
|
silent=self.silent,
|
|
142
146
|
)
|
|
147
|
+
'''
|
|
148
|
+
raise 'NUMPY BACKEND Not anymore maintained'
|
|
143
149
|
|
|
144
150
|
self.all_bk_type = self.backend.all_bk_type
|
|
145
151
|
self.all_cbk_type = self.backend.all_cbk_type
|
|
@@ -648,7 +654,7 @@ class FoCUS:
|
|
|
648
654
|
return rim
|
|
649
655
|
|
|
650
656
|
# --------------------------------------------------------
|
|
651
|
-
def ud_grade_2(self, im, axis=0, cell_ids=None, nside=None):
|
|
657
|
+
def ud_grade_2(self, im, axis=0, cell_ids=None, nside=None,max_poll=False):
|
|
652
658
|
|
|
653
659
|
if self.use_2D:
|
|
654
660
|
ishape = list(im.shape)
|
|
@@ -711,12 +717,21 @@ class FoCUS:
|
|
|
711
717
|
|
|
712
718
|
else:
|
|
713
719
|
shape = list(im.shape)
|
|
714
|
-
if
|
|
715
|
-
|
|
716
|
-
|
|
720
|
+
if max_poll:
|
|
721
|
+
if cell_ids is not None:
|
|
722
|
+
sim, new_cell_ids = self.backend.binned_mean(im, cell_ids,reduce='max')
|
|
723
|
+
return sim, new_cell_ids
|
|
717
724
|
|
|
718
|
-
|
|
719
|
-
|
|
725
|
+
return self.backend.bk_reduce_max(
|
|
726
|
+
self.backend.bk_reshape(im, shape[0:-1]+[shape[-1]//4,4]), axis=-1
|
|
727
|
+
),None
|
|
728
|
+
else:
|
|
729
|
+
if cell_ids is not None:
|
|
730
|
+
sim, new_cell_ids = self.backend.binned_mean(im, cell_ids,reduce='mean')
|
|
731
|
+
return sim, new_cell_ids
|
|
732
|
+
|
|
733
|
+
return self.backend.bk_reduce_mean(
|
|
734
|
+
self.backend.bk_reshape(im, shape[0:-1]+[shape[-1]//4,4]), axis=-1
|
|
720
735
|
),None
|
|
721
736
|
|
|
722
737
|
# --------------------------------------------------------
|
|
@@ -725,6 +740,7 @@ class FoCUS:
|
|
|
725
740
|
nouty=None,
|
|
726
741
|
cell_ids=None,
|
|
727
742
|
o_cell_ids=None,
|
|
743
|
+
force_init_index=False,
|
|
728
744
|
nside=None):
|
|
729
745
|
|
|
730
746
|
ishape = list(im.shape)
|
|
@@ -806,7 +822,7 @@ class FoCUS:
|
|
|
806
822
|
else:
|
|
807
823
|
lout = nside
|
|
808
824
|
|
|
809
|
-
if (lout,nout) not in self.pix_interp_val:
|
|
825
|
+
if (lout,nout) not in self.pix_interp_val or force_init_index:
|
|
810
826
|
if not self.silent:
|
|
811
827
|
print("compute lout nout", lout, nout)
|
|
812
828
|
if cell_ids is None:
|
|
@@ -837,7 +853,7 @@ class FoCUS:
|
|
|
837
853
|
|
|
838
854
|
self.pix_interp_val[(lout,nout)] = 1
|
|
839
855
|
self.weight_interp_val[(lout,nout)] = self.backend.bk_SparseTensor(
|
|
840
|
-
self.backend.bk_constant(indice),
|
|
856
|
+
self.backend.bk_constant(indice.T),
|
|
841
857
|
self.backend.bk_constant(self.backend.bk_cast(w)),
|
|
842
858
|
dense_shape=[i_npix,o_cell_ids.shape[0]],
|
|
843
859
|
)
|
|
@@ -848,12 +864,9 @@ class FoCUS:
|
|
|
848
864
|
o_cell_ids=np.tile(cell_ids,ratio)*ratio+np.repeat(np.arange(ratio),cell_ids.shape[0])
|
|
849
865
|
i_npix=cell_ids.shape[0]
|
|
850
866
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
#sp = HS.heal_spline(level,gamma=2.0)
|
|
854
|
-
|
|
867
|
+
|
|
855
868
|
th, ph = hp.pix2ang(
|
|
856
|
-
nout, o_cell_ids, nest=True
|
|
869
|
+
nout, self.backend.to_numpy(o_cell_ids), nest=True
|
|
857
870
|
)
|
|
858
871
|
|
|
859
872
|
all_idx,www=hp.get_interp_weights(lout,th,ph,nest=True)
|
|
@@ -866,7 +879,7 @@ class FoCUS:
|
|
|
866
879
|
sorter = np.argsort(hidx)
|
|
867
880
|
|
|
868
881
|
index=sorter[np.searchsorted(hidx,
|
|
869
|
-
cell_ids,
|
|
882
|
+
self.backend.to_numpy(cell_ids),
|
|
870
883
|
sorter=sorter)]
|
|
871
884
|
|
|
872
885
|
mask = -np.ones([hidx.shape[0]])
|
|
@@ -892,7 +905,7 @@ class FoCUS:
|
|
|
892
905
|
|
|
893
906
|
self.pix_interp_val[(lout,nout)] = 1
|
|
894
907
|
self.weight_interp_val[(lout,nout)] = self.backend.bk_SparseTensor(
|
|
895
|
-
self.backend.bk_constant(indice),
|
|
908
|
+
self.backend.bk_constant(indice.T),
|
|
896
909
|
self.backend.bk_constant(self.backend.bk_cast(w)),
|
|
897
910
|
dense_shape=[i_npix,o_cell_ids.shape[0]],
|
|
898
911
|
)
|
|
@@ -1317,19 +1330,10 @@ class FoCUS:
|
|
|
1317
1330
|
nside,
|
|
1318
1331
|
)
|
|
1319
1332
|
)
|
|
1320
|
-
|
|
1321
|
-
'''
|
|
1322
|
-
nn=self.NORIENT*12*nside**2
|
|
1323
|
-
idxEB=np.concatenate([tmp,tmp,tmp,tmp],0)
|
|
1324
|
-
idxEB[tmp.shape[0]:2*tmp.shape[0],0]+=12*nside**2
|
|
1325
|
-
idxEB[3*tmp.shape[0]:,0]+=12*nside**2
|
|
1326
|
-
idxEB[2*tmp.shape[0]:,1]+=nn
|
|
1327
|
-
|
|
1328
|
-
tmpEB=np.zeros([tmpw.shape[0]*4],dtype='complex')
|
|
1329
|
-
'''
|
|
1333
|
+
|
|
1330
1334
|
import foscat.HOrientedConvol as hs
|
|
1331
1335
|
|
|
1332
|
-
hconvol=hs.HOrientedConvol(nside,
|
|
1336
|
+
hconvol=hs.HOrientedConvol(nside,4*self.KERNELSZ+1,cell_ids=cell_ids)
|
|
1333
1337
|
|
|
1334
1338
|
if cell_ids is None:
|
|
1335
1339
|
l_cell_ids=np.arange(12*nside**2)
|
|
@@ -1432,23 +1436,6 @@ class FoCUS:
|
|
|
1432
1436
|
for k in range(self.NORIENT):
|
|
1433
1437
|
indice_1_0[(4*k+2)*ndata:(4*k+4)*ndata]+=self.NORIENT*l_cell_ids.shape[0]
|
|
1434
1438
|
indice_1_0[(4*k)*ndata:(4*k+4)*ndata]+=k*l_cell_ids.shape[0]
|
|
1435
|
-
'''
|
|
1436
|
-
import matplotlib.pyplot as plt
|
|
1437
|
-
plt.figure()
|
|
1438
|
-
plt.subplot(2,2,1)
|
|
1439
|
-
plt.plot(indice_1_0)
|
|
1440
|
-
plt.subplot(2,2,2)
|
|
1441
|
-
plt.plot(indice_1_1)
|
|
1442
|
-
plt.subplot(2,2,3)
|
|
1443
|
-
plt.plot(wav.real)
|
|
1444
|
-
plt.subplot(2,2,4)
|
|
1445
|
-
plt.plot(abs(wav))
|
|
1446
|
-
|
|
1447
|
-
iarg=np.argsort(indice_1_0)
|
|
1448
|
-
indice_1_1=indice_1_1[iarg]
|
|
1449
|
-
indice_1_0=indice_1_0[iarg]
|
|
1450
|
-
wav=wav[iarg]
|
|
1451
|
-
'''
|
|
1452
1439
|
|
|
1453
1440
|
indice=np.concatenate([indice_1_1[:,None],indice_1_0[:,None]],1)
|
|
1454
1441
|
|
|
@@ -1457,52 +1444,9 @@ class FoCUS:
|
|
|
1457
1444
|
indice_2_1[3*ndata:4*ndata]+=l_cell_ids.shape[0]
|
|
1458
1445
|
indice_2_0=np.tile(np.repeat(np.arange(l_cell_ids.shape[0]),nvalid),4)
|
|
1459
1446
|
indice_2_0[2*ndata:]+=l_cell_ids.shape[0]
|
|
1460
|
-
'''
|
|
1461
|
-
plt.figure()
|
|
1462
|
-
plt.subplot(2,2,1)
|
|
1463
|
-
plt.plot(indice_2_0)
|
|
1464
|
-
plt.subplot(2,2,2)
|
|
1465
|
-
plt.plot(indice_2_1)
|
|
1466
|
-
plt.subplot(2,2,3)
|
|
1467
|
-
plt.plot(wav.real)
|
|
1468
|
-
plt.subplot(2,2,4)
|
|
1469
|
-
plt.plot(wwav)
|
|
1470
1447
|
|
|
1471
|
-
iarg=np.argsort(indice_2_0)
|
|
1472
|
-
indice_2_1=indice_2_1[iarg]
|
|
1473
|
-
indice_2_0=indice_2_0[iarg]
|
|
1474
|
-
wwav=wwav[iarg]
|
|
1475
|
-
'''
|
|
1476
1448
|
indice2=np.concatenate([indice_2_1[:,None],indice_2_0[:,None]],1)
|
|
1477
1449
|
|
|
1478
|
-
'''
|
|
1479
|
-
for k in range(self.NORIENT*12*nside**2):
|
|
1480
|
-
if k%(nside**2)==0:
|
|
1481
|
-
print('Init index 1/2 spin=%d Please wait %d done against %d nside=%d kernel=%d'%(spin,k//(nside**2),
|
|
1482
|
-
self.NORIENT*12,
|
|
1483
|
-
nside,
|
|
1484
|
-
self.KERNELSZ))
|
|
1485
|
-
idx=np.where(tmp[:,1]==k)[0]
|
|
1486
|
-
|
|
1487
|
-
im=np.zeros([12*nside**2])
|
|
1488
|
-
im[tmp[idx,0]]=tmpw[idx].real
|
|
1489
|
-
almR=hp.map2alm(hp.reorder(im,n2r=True))
|
|
1490
|
-
im[tmp[idx,0]]=tmpw[idx].imag
|
|
1491
|
-
almI=hp.map2alm(hp.reorder(im,n2r=True))
|
|
1492
|
-
|
|
1493
|
-
i,q,u=hp.alm2map_spin([almR,almR*0,0*almR],nside,spin,3*nside-1)
|
|
1494
|
-
i2,q2,u2=hp.alm2map_spin([almI,0*almI,0*almI],nside,spin,3*nside-1)
|
|
1495
|
-
|
|
1496
|
-
tmpEB[idx]=hp.reorder(i,r2n=True)[tmp[idx,0]]+1J*hp.reorder(i2,r2n=True)[tmp[idx,0]]
|
|
1497
|
-
tmpEB[idx+tmp.shape[0]]=hp.reorder(q,r2n=True)[tmp[idx,0]]+1J*hp.reorder(q2,r2n=True)[tmp[idx,0]]
|
|
1498
|
-
|
|
1499
|
-
i,q,u=hp.alm2map_spin([0*almR,almR,0*almR],nside,spin,3*nside-1)
|
|
1500
|
-
i2,q2,u2=hp.alm2map_spin([0*almI,almI,0*almI],nside,spin,3*nside-1)
|
|
1501
|
-
|
|
1502
|
-
tmpEB[idx+2*tmp.shape[0]]=hp.reorder(i,r2n=True)[tmp[idx,0]]+1J*hp.reorder(i2,r2n=True)[tmp[idx,0]]
|
|
1503
|
-
tmpEB[idx+3*tmp.shape[0]]=hp.reorder(q,r2n=True)[tmp[idx,0]]+1J*hp.reorder(q2,r2n=True)[tmp[idx,0]]
|
|
1504
|
-
|
|
1505
|
-
'''
|
|
1506
1450
|
self.save_index("%s/FOSCAT_%s_W%d_%d_%d_PIDX-SPIN%d.fst"% (self.TEMPLATE_PATH,
|
|
1507
1451
|
self.TMPFILE_VERSION,
|
|
1508
1452
|
self.KERNELSZ**2,
|
|
@@ -1510,7 +1454,7 @@ class FoCUS:
|
|
|
1510
1454
|
nside,
|
|
1511
1455
|
spin
|
|
1512
1456
|
),
|
|
1513
|
-
indice
|
|
1457
|
+
indice.T
|
|
1514
1458
|
)
|
|
1515
1459
|
self.save_index("%s/FOSCAT_%s_W%d_%d_%d_WAVE-SPIN%d.fst"% (self.TEMPLATE_PATH,
|
|
1516
1460
|
self.TMPFILE_VERSION,
|
|
@@ -1521,49 +1465,6 @@ class FoCUS:
|
|
|
1521
1465
|
),
|
|
1522
1466
|
wav
|
|
1523
1467
|
)
|
|
1524
|
-
'''
|
|
1525
|
-
tmp = self.read_index(
|
|
1526
|
-
"%s/FOSCAT_%s_W%d_%d_%d_PIDX2-SPIN0.fst"
|
|
1527
|
-
% (
|
|
1528
|
-
self.TEMPLATE_PATH,
|
|
1529
|
-
TMPFILE_VERSION,
|
|
1530
|
-
l_kernel**2,
|
|
1531
|
-
self.NORIENT,
|
|
1532
|
-
nside
|
|
1533
|
-
)
|
|
1534
|
-
)
|
|
1535
|
-
|
|
1536
|
-
tmpw = self.read_index("%s/FOSCAT_%s_W%d_%d_%d_SMOO-SPIN0.fst"% (
|
|
1537
|
-
self.TEMPLATE_PATH,
|
|
1538
|
-
self.TMPFILE_VERSION,
|
|
1539
|
-
self.KERNELSZ**2,
|
|
1540
|
-
self.NORIENT,
|
|
1541
|
-
nside,
|
|
1542
|
-
)
|
|
1543
|
-
)
|
|
1544
|
-
for k in range(12*nside**2):
|
|
1545
|
-
if k%(nside**2)==0:
|
|
1546
|
-
print('Init index 2/2 spin=%d Please wait %d done against %d nside=%d kernel=%d'%(spin,k//(nside**2),
|
|
1547
|
-
12,
|
|
1548
|
-
nside,
|
|
1549
|
-
self.KERNELSZ))
|
|
1550
|
-
idx=np.where(tmp[:,1]==k)[0]
|
|
1551
|
-
|
|
1552
|
-
im=np.zeros([12*nside**2])
|
|
1553
|
-
im[tmp[idx,0]]=tmpw[idx]
|
|
1554
|
-
almR=hp.map2alm(hp.reorder(im,n2r=True))
|
|
1555
|
-
|
|
1556
|
-
i,q,u=hp.alm2map_spin([almR,almR*0,0*almR],nside,spin,3*nside-1)
|
|
1557
|
-
|
|
1558
|
-
tmpEB[idx]=hp.reorder(i,r2n=True)[tmp[idx,0]]
|
|
1559
|
-
tmpEB[idx+tmp.shape[0]]=hp.reorder(q,r2n=True)[tmp[idx,0]]
|
|
1560
|
-
|
|
1561
|
-
i,q,u=hp.alm2map_spin([0*almR,almR,0*almR],nside,spin,3*nside-1)
|
|
1562
|
-
|
|
1563
|
-
tmpEB[idx+2*tmp.shape[0]]=hp.reorder(i,r2n=True)[tmp[idx,0]]
|
|
1564
|
-
tmpEB[idx+3*tmp.shape[0]]=hp.reorder(q,r2n=True)[tmp[idx,0]]
|
|
1565
|
-
|
|
1566
|
-
'''
|
|
1567
1468
|
self.save_index("%s/FOSCAT_%s_W%d_%d_%d_PIDX2-SPIN%d.fst"% (self.TEMPLATE_PATH,
|
|
1568
1469
|
self.TMPFILE_VERSION,
|
|
1569
1470
|
self.KERNELSZ**2,
|
|
@@ -1571,7 +1472,7 @@ class FoCUS:
|
|
|
1571
1472
|
nside,
|
|
1572
1473
|
spin
|
|
1573
1474
|
),
|
|
1574
|
-
indice2
|
|
1475
|
+
indice2.T
|
|
1575
1476
|
)
|
|
1576
1477
|
self.save_index("%s/FOSCAT_%s_W%d_%d_%d_SMOO-SPIN%d.fst"% (self.TEMPLATE_PATH,
|
|
1577
1478
|
self.TMPFILE_VERSION,
|
|
@@ -1584,7 +1485,6 @@ class FoCUS:
|
|
|
1584
1485
|
)
|
|
1585
1486
|
|
|
1586
1487
|
else:
|
|
1587
|
-
'''
|
|
1588
1488
|
if l_kernel == 5:
|
|
1589
1489
|
pw = 0.5
|
|
1590
1490
|
pw2 = 0.5
|
|
@@ -1599,145 +1499,55 @@ class FoCUS:
|
|
|
1599
1499
|
pw = 0.5
|
|
1600
1500
|
pw2 = 0.25
|
|
1601
1501
|
threshold = 4e-5
|
|
1602
|
-
|
|
1603
|
-
import foscat.
|
|
1604
|
-
|
|
1605
|
-
hconvol=hs.HOrientedConvol(nside,l_kernel,cell_ids=cell_ids)
|
|
1606
|
-
|
|
1607
|
-
orientations=np.pi*np.arange(self.NORIENT)/self.NORIENT
|
|
1608
|
-
|
|
1609
|
-
wav,indice,wwav,indice2=hconvol.make_wavelet_matrix(orientations,
|
|
1610
|
-
polar=True,
|
|
1611
|
-
return_index=True,
|
|
1612
|
-
return_smooth=True)
|
|
1502
|
+
|
|
1503
|
+
import foscat.SphericalStencil as hs
|
|
1504
|
+
import torch
|
|
1613
1505
|
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
if not isinstance(cell_ids, np.ndarray):
|
|
1617
|
-
cell_ids = self.backend.to_numpy(cell_ids)
|
|
1618
|
-
th, ph = hp.pix2ang(nside, cell_ids, nest=True)
|
|
1619
|
-
x, y, z = hp.pix2vec(nside, cell_ids, nest=True)
|
|
1620
|
-
|
|
1621
|
-
t, p = hp.pix2ang(nside, cell_ids, nest=True)
|
|
1622
|
-
phi = [p[k] / np.pi * 180 for k in range(ncell)]
|
|
1623
|
-
thi = [t[k] / np.pi * 180 for k in range(ncell)]
|
|
1624
|
-
|
|
1625
|
-
indice2 = np.zeros([ncell * 64, 2], dtype="int")
|
|
1626
|
-
indice = np.zeros([ncell * 64 * self.NORIENT, 2], dtype="int")
|
|
1627
|
-
wav = np.zeros([ncell * 64 * self.NORIENT], dtype="complex")
|
|
1628
|
-
wwav = np.zeros([ncell * 64 * self.NORIENT], dtype="float")
|
|
1629
|
-
|
|
1506
|
+
if cell_ids is None:
|
|
1507
|
+
l_cell_ids=np.arange(12*nside**2)
|
|
1630
1508
|
else:
|
|
1509
|
+
l_cell_ids=cell_ids
|
|
1631
1510
|
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
t, p = hp.pix2ang(nside, np.arange(12 * nside * nside), nest=True)
|
|
1636
|
-
phi = [p[k] / np.pi * 180 for k in range(12 * nside * nside)]
|
|
1637
|
-
thi = [t[k] / np.pi * 180 for k in range(12 * nside * nside)]
|
|
1638
|
-
|
|
1639
|
-
indice2 = np.zeros([12 * nside * nside * 64, 2],
|
|
1640
|
-
dtype="int")
|
|
1511
|
+
if isinstance(l_cell_ids,torch.Tensor):
|
|
1512
|
+
l_cell_ids=self.backend.to_numpy(l_cell_ids)
|
|
1641
1513
|
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
if iii % (nside * nside) == nside * nside - 1:
|
|
1660
|
-
if not self.silent:
|
|
1661
|
-
print(
|
|
1662
|
-
"Pre-compute nside=%6d %.2f%%"
|
|
1663
|
-
% (nside, 100 * iii / (12 * nside * nside))
|
|
1664
|
-
)
|
|
1665
|
-
|
|
1666
|
-
if cell_ids is not None:
|
|
1667
|
-
hidx = np.where(
|
|
1668
|
-
(x - x[iii]) ** 2 + (y - y[iii]) ** 2 + (z - z[iii]) ** 2
|
|
1669
|
-
< (2 * np.pi / nside) ** 2
|
|
1670
|
-
)[0]
|
|
1671
|
-
else:
|
|
1672
|
-
hidx = hp.query_disc(
|
|
1673
|
-
nside,
|
|
1674
|
-
[x[iii], y[iii], z[iii]],
|
|
1675
|
-
2 * np.pi / nside,
|
|
1676
|
-
nest=True,
|
|
1677
|
-
)
|
|
1678
|
-
|
|
1679
|
-
R = hp.Rotator(rot=[phi[iii], -thi[iii]], eulertype="ZYZ")
|
|
1680
|
-
|
|
1681
|
-
t2, p2 = R(th[hidx], ph[hidx])
|
|
1682
|
-
|
|
1683
|
-
vec2 = hp.ang2vec(t2, p2)
|
|
1684
|
-
|
|
1685
|
-
x2 = vec2[:, 0]
|
|
1686
|
-
y2 = vec2[:, 1]
|
|
1687
|
-
z2 = vec2[:, 2]
|
|
1688
|
-
|
|
1689
|
-
ww = np.exp(
|
|
1690
|
-
-pw2
|
|
1691
|
-
* ((nside) ** 2)
|
|
1692
|
-
* ((x2) ** 2 + (y2) ** 2 + (z2 - 1.0) ** 2)
|
|
1693
|
-
)
|
|
1694
|
-
idx = np.where((ww**2) > threshold)[0]
|
|
1695
|
-
nval2 = len(idx)
|
|
1696
|
-
indice2[iv2 : iv2 + nval2, 1] = iii
|
|
1697
|
-
indice2[iv2 : iv2 + nval2, 0] = hidx[idx]
|
|
1698
|
-
wwav[iv2 : iv2 + nval2] = ww[idx] / np.sum(ww[idx])
|
|
1699
|
-
iv2 += nval2
|
|
1700
|
-
|
|
1701
|
-
for l_rotation in range(self.NORIENT):
|
|
1702
|
-
|
|
1703
|
-
angle = (
|
|
1704
|
-
l_rotation / 4.0 * np.pi
|
|
1705
|
-
- phi[iii] / 180.0 * np.pi * (z[hidx] > 0)
|
|
1706
|
-
- (180.0 - phi[iii]) / 180.0 * np.pi * (z[hidx] < 0)
|
|
1707
|
-
)
|
|
1708
|
-
|
|
1709
|
-
# posi=2*(0.5-(z[hidx]<0))
|
|
1710
|
-
|
|
1711
|
-
axes = y2 * np.cos(angle) - x2 * np.sin(angle)
|
|
1712
|
-
wresr = ww * np.cos(pw * axes * (nside) * np.pi)
|
|
1713
|
-
wresi = ww * np.sin(pw * axes * (nside) * np.pi)
|
|
1714
|
-
|
|
1715
|
-
vnorm = wresr * wresr + wresi * wresi
|
|
1716
|
-
idx = np.where(vnorm > threshold)[0]
|
|
1717
|
-
|
|
1718
|
-
nval = len(idx)
|
|
1719
|
-
indice[iv : iv + nval, 1] = iii + l_rotation * ncell
|
|
1720
|
-
indice[iv : iv + nval, 0] = hidx[idx]
|
|
1721
|
-
# print([hidx[k] for k in idx])
|
|
1722
|
-
# print(hp.query_disc(nside, [x[iii],y[iii],z[iii]], np.pi/nside,nest=True))
|
|
1723
|
-
normr = np.mean(wresr[idx])
|
|
1724
|
-
normi = np.mean(wresi[idx])
|
|
1725
|
-
|
|
1726
|
-
val = wresr[idx] - normr + 1j * (wresi[idx] - normi)
|
|
1727
|
-
r = abs(val).sum()
|
|
1728
|
-
|
|
1729
|
-
if r > 0:
|
|
1730
|
-
val = val / r
|
|
1514
|
+
hconvol=hs.SphericalStencil(nside,
|
|
1515
|
+
l_kernel,
|
|
1516
|
+
cell_ids=l_cell_ids,
|
|
1517
|
+
n_gauges=self.NORIENT,
|
|
1518
|
+
gauge_type='cosmo')
|
|
1519
|
+
|
|
1520
|
+
xx=np.tile(np.arange(self.KERNELSZ)-self.KERNELSZ//2,self.KERNELSZ).reshape(self.KERNELSZ*self.KERNELSZ)
|
|
1521
|
+
|
|
1522
|
+
wwr=hconvol.to_tensor((np.exp(-pw2*(xx**2+(xx.T)**2))*np.cos(pw*xx*np.pi)).reshape(1,1,self.KERNELSZ*self.KERNELSZ))
|
|
1523
|
+
wwr-=wwr.mean()
|
|
1524
|
+
wwi=hconvol.to_tensor((np.exp(-pw2*(xx**2+(xx.T)**2))*np.sin(pw*xx*np.pi)).reshape(1,1,self.KERNELSZ*self.KERNELSZ))
|
|
1525
|
+
wwi-=wwi.mean()
|
|
1526
|
+
wwr/=(abs(wwr+1J*wwi)).sum()
|
|
1527
|
+
wwi/=(abs(wwr+1J*wwi)).sum()
|
|
1528
|
+
|
|
1529
|
+
wavr,indice,mshape=hconvol.make_matrix(wwr)
|
|
1530
|
+
wavi,indice,mshape=hconvol.make_matrix(wwi)
|
|
1731
1531
|
|
|
1732
|
-
|
|
1733
|
-
|
|
1532
|
+
wav=hconvol.to_numpy(wavr)+1J*hconvol.to_numpy(wavi)
|
|
1533
|
+
indice=hconvol.to_numpy(indice)
|
|
1734
1534
|
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1535
|
+
|
|
1536
|
+
hconvol=hs.SphericalStencil(nside,
|
|
1537
|
+
l_kernel,
|
|
1538
|
+
cell_ids=l_cell_ids,
|
|
1539
|
+
n_gauges=1,
|
|
1540
|
+
gauge_type='cosmo')
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
ww=hconvol.to_tensor((np.exp(-pw2*(xx**2+(xx.T)**2))).reshape(1,1,self.KERNELSZ*self.KERNELSZ))
|
|
1544
|
+
ww/=ww.sum()
|
|
1545
|
+
|
|
1546
|
+
wwav,indice2,mshape=hconvol.make_matrix(ww)
|
|
1740
1547
|
|
|
1548
|
+
wwav=hconvol.to_numpy(wwav)
|
|
1549
|
+
indice2=hconvol.to_numpy(indice2)
|
|
1550
|
+
|
|
1741
1551
|
if cell_ids is None:
|
|
1742
1552
|
if not self.silent:
|
|
1743
1553
|
print(
|
|
@@ -1795,6 +1605,7 @@ class FoCUS:
|
|
|
1795
1605
|
),
|
|
1796
1606
|
wwav,
|
|
1797
1607
|
)
|
|
1608
|
+
|
|
1798
1609
|
if self.use_2D:
|
|
1799
1610
|
if l_kernel**2 == 9:
|
|
1800
1611
|
if self.rank == 0:
|
|
@@ -1879,7 +1690,7 @@ class FoCUS:
|
|
|
1879
1690
|
spin,
|
|
1880
1691
|
)
|
|
1881
1692
|
)
|
|
1882
|
-
|
|
1693
|
+
'''
|
|
1883
1694
|
if cell_ids is not None:
|
|
1884
1695
|
idx_map=-np.ones([12*nside**2],dtype='int32')
|
|
1885
1696
|
lcell_ids=cell_ids
|
|
@@ -1931,6 +1742,7 @@ class FoCUS:
|
|
|
1931
1742
|
ww=np.bincount(tmp[:,1],weights=np.sqrt(wr*wr+wi*wi))
|
|
1932
1743
|
wr/=ww[tmp[:,1]]
|
|
1933
1744
|
wi/=ww[tmp[:,1]]
|
|
1745
|
+
'''
|
|
1934
1746
|
|
|
1935
1747
|
else:
|
|
1936
1748
|
tmp = indice
|
|
@@ -1941,6 +1753,7 @@ class FoCUS:
|
|
|
1941
1753
|
|
|
1942
1754
|
|
|
1943
1755
|
if spin==0:
|
|
1756
|
+
|
|
1944
1757
|
wr = self.backend.bk_SparseTensor(
|
|
1945
1758
|
self.backend.bk_constant(tmp),
|
|
1946
1759
|
self.backend.bk_constant(self.backend.bk_cast(wr)),
|