PyCosmoMMF 0.0.2__py3-none-any.whl → 0.0.7__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.
PyCosmoMMF/__init__.py CHANGED
@@ -6,10 +6,14 @@ from PyCosmoMMF.hessian import *
6
6
  from PyCosmoMMF.tagging import *
7
7
  from PyCosmoMMF.utils import *
8
8
  from PyCosmoMMF.signatures import *
9
-
10
-
11
9
  import pkg_resources
10
+
12
11
  test_field = np.load(pkg_resources.resource_filename(__name__, 'test_density_cube.npy'))
13
12
 
13
+ __version__ = '0.0.5'
14
+
15
+
16
+
17
+
14
18
 
15
19
 
PyCosmoMMF/filter.py CHANGED
@@ -1,5 +1,13 @@
1
1
  import numpy as np
2
2
  import numba as nb
3
+ from PyCosmoMMF.utils import *
4
+
5
+ # if parallel_flag == True:
6
+ # jit_compiler = nb.njit(parallel=True, fastmath=True)
7
+ # else:
8
+ # jit_compiler = nb.njit(fastmath=True)
9
+
10
+ jit_compiler = nb.njit(fastmath=True)
3
11
 
4
12
  def wavevectors3D(dims, box_size=(2*np.pi, 2*np.pi, 2*np.pi)):
5
13
  """
@@ -18,12 +26,12 @@ def wavevectors3D(dims, box_size=(2*np.pi, 2*np.pi, 2*np.pi)):
18
26
  The wavevectors in each dimension.
19
27
  """
20
28
  sample_rate = 2*np.pi * (np.array(dims) / box_size)
21
- kx = np.fft.fftfreq(dims[0], 1/sample_rate[0]) * (2*np.pi / dims[0])
22
- ky = np.fft.fftfreq(dims[1], 1/sample_rate[1]) * (2*np.pi / dims[1])
23
- kz = np.fft.fftfreq(dims[2], 1/sample_rate[2]) * (2*np.pi / dims[2])
29
+ kx = (np.fft.fftfreq(dims[0], 1/sample_rate[0]) * (2*np.pi / dims[0])).astype(np.float32)
30
+ ky = (np.fft.fftfreq(dims[1], 1/sample_rate[1]) * (2*np.pi / dims[1])).astype(np.float32)
31
+ kz = (np.fft.fftfreq(dims[2], 1/sample_rate[2]) * (2*np.pi / dims[2])).astype(np.float32)
24
32
  return kx, ky, kz
25
33
 
26
- @nb.njit(parallel=True, fastmath=True)
34
+ @jit_compiler
27
35
  def kspace_gaussian_filter(R_S, kv):
28
36
  """
29
37
  create a Gaussian filter in k-space.
@@ -42,7 +50,7 @@ def kspace_gaussian_filter(R_S, kv):
42
50
  """
43
51
  kx, ky, kz = kv
44
52
  nx, ny, nz = len(kx), len(ky), len(kz)
45
- filter_k = np.zeros((nx, ny, nz))
53
+ filter_k = np.zeros((nx, ny, nz), dtype=np.float32)
46
54
  for ix in nb.prange(nx):
47
55
  for iy in range(ny):
48
56
  for iz in range(nz):
@@ -50,6 +58,62 @@ def kspace_gaussian_filter(R_S, kv):
50
58
  -(kx[ix]**2 + ky[iy]**2 + kz[iz]**2) * R_S**2 / 2)
51
59
  return filter_k
52
60
 
61
+ @jit_compiler
62
+ def kspace_top_hat_filter(R_S, kv):
63
+ """
64
+ create a top-hat filter in k-space.
65
+
66
+ Parameters
67
+ ----------
68
+ R_S : float
69
+ The smoothing scale.
70
+ kv : tuple
71
+ The wavevectors in each dimension.
72
+
73
+ Returns
74
+ -------
75
+ filter_k : array
76
+ The filter in k-space.
77
+ """
78
+
79
+ kx, ky, kz = kv
80
+ nx, ny, nz = len(kx), len(ky), len(kz)
81
+ filter_k = np.zeros((nx, ny, nz), dtype=np.float32)
82
+
83
+ for ix in nb.prange(nx):
84
+ for iy in range(ny):
85
+ for iz in range(nz):
86
+ k = np.sqrt(kx[ix]**2 + ky[iy]**2 + kz[iz]**2)
87
+ if k == 0.0:
88
+ filter_k[ix, iy, iz] = 1.0
89
+ else:
90
+ filter_k[ix, iy, iz] = 3 * (np.sin(k * R_S) - (k * R_S) * np.cos(k * R_S)) / (k * R_S)**3
91
+
92
+ return filter_k
93
+
94
+ def smooth_top_hat(f, R_S, kv):
95
+ """
96
+ apply a top-hat filter to a field f.
97
+
98
+ Parameters
99
+ ----------
100
+ f : array
101
+ The field to be smoothed.
102
+ R_S : float
103
+ The smoothing scale.
104
+ kv : tuple
105
+ The wavevectors in each dimension.
106
+
107
+ Returns
108
+ -------
109
+ f_Rn : array
110
+ The smoothed field.
111
+ """
112
+ GF = kspace_top_hat_filter(R_S, kv)
113
+ f_Rn = np.real(np.fft.ifftn(GF * np.fft.fftn(f)))
114
+ f_Rn = f_Rn * (np.sum(f) / np.sum(f_Rn))
115
+ return f_Rn.astype(np.float32)
116
+
53
117
  def smooth_gauss(f, R_S, kv):
54
118
  """
55
119
  apply a Gaussian filter to a field f.
@@ -71,7 +135,7 @@ def smooth_gauss(f, R_S, kv):
71
135
  GF = kspace_gaussian_filter(R_S, kv)
72
136
  f_Rn = np.real(np.fft.ifftn(GF * np.fft.fftn(f)))
73
137
  f_Rn = f_Rn * (np.sum(f) / np.sum(f_Rn))
74
- return f_Rn
138
+ return f_Rn.astype(np.float32)
75
139
 
76
140
 
77
141
  def smooth_loggauss(f, R_S, kv):
@@ -114,5 +178,5 @@ def smooth_loggauss(f, R_S, kv):
114
178
  norm = np.sum(f) / np.sum(f_result)
115
179
  f_result *= norm
116
180
 
117
- return f_result
181
+ return f_result.astype(np.float32)
118
182
 
PyCosmoMMF/hessian.py CHANGED
@@ -1,5 +1,13 @@
1
1
  import numpy as np
2
2
  import numba as nb
3
+ from PyCosmoMMF.utils import *
4
+
5
+ # if parallel_flag == True:
6
+ # jit_compiler = nb.njit(parallel=True, fastmath=True)
7
+ # else:
8
+ # jit_compiler = nb.njit(fastmath=True)
9
+
10
+ jit_compiler = nb.njit(fastmath=True)
3
11
 
4
12
  def fast_hessian_from_smoothed(f_Rn, R_S, kv):
5
13
  """
@@ -22,10 +30,10 @@ def fast_hessian_from_smoothed(f_Rn, R_S, kv):
22
30
 
23
31
  f_Rn_hat = np.fft.fftn(f_Rn)
24
32
  dims = f_Rn_hat.shape
25
- hessian = np.zeros((dims[0], dims[1], dims[2], 6), dtype=np.complex128)
33
+ hessian = np.zeros((dims[0], dims[1], dims[2], 6), dtype=np.complex64)
26
34
  kx, ky, kz = kv[0], kv[1], kv[2]
27
35
 
28
- @nb.njit(parallel=True, fastmath=True)
36
+ @jit_compiler
29
37
  def perform_loop(hessian):
30
38
  """
31
39
  This function is a loop that calculates the hessian matrix
PyCosmoMMF/signatures.py CHANGED
@@ -3,8 +3,16 @@ import numba as nb
3
3
 
4
4
  from PyCosmoMMF.filter import *
5
5
  from PyCosmoMMF.hessian import *
6
+ from PyCosmoMMF.utils import *
6
7
 
7
- @nb.njit(parallel=True)
8
+ # if parallel_flag == True:
9
+ # jit_compiler = nb.njit(parallel=True)
10
+ # else:
11
+ # jit_compiler = nb.njit
12
+
13
+ jit_compiler = nb.njit
14
+
15
+ @jit_compiler
8
16
  def signatures_from_hessian(hessian):
9
17
  """
10
18
  Function to calculate the signatures from a given hessian.
@@ -21,7 +29,7 @@ def signatures_from_hessian(hessian):
21
29
  """
22
30
 
23
31
  hsize = hessian.shape[:3]
24
- sigs = np.zeros((hsize[0], hsize[1], hsize[2], 3))
32
+ sigs = np.zeros((hsize[0], hsize[1], hsize[2], 3), dtype=np.float32)
25
33
 
26
34
  #helper functions
27
35
  def θ(x):
@@ -87,17 +95,18 @@ def maximum_signature(Rs, field, alg='NEXUSPLUS'):
87
95
  raise ValueError("alg must be either 'NEXUS' or 'NEXUSPLUS'")
88
96
 
89
97
  nx, ny, nz = field.shape
98
+ eps = 1e-5
90
99
 
91
100
  # Make sure the field has no 0 values
92
- field = field + 0.0001
101
+ field = field + eps
93
102
 
94
103
  # Calculate wave vectors for our field
95
104
  wave_vecs = wavevectors3D((nx, ny, nz))
96
105
 
97
106
  # Calculate signatures at each scale Rn, determine max
98
- sigmax = np.ones((nx, ny, nz, 3)) * 0.00001
107
+ sigmax = np.ones((nx, ny, nz, 3), dtype=np.float32) * eps
99
108
 
100
- @nb.njit(parallel=True)
109
+ @jit_compiler
101
110
  def perform_loop(sigmax, sigs_Rn, nx, ny, nz):
102
111
  for ix in nb.prange(nx):
103
112
  for iy in range(ny):
PyCosmoMMF/tagging.py CHANGED
@@ -3,7 +3,14 @@ import numpy as np
3
3
  import matplotlib.pyplot as plt
4
4
  from skimage.measure import label
5
5
  import numba as nb
6
+ from PyCosmoMMF.utils import *
6
7
 
8
+ # if parallel_flag == True:
9
+ # jit_compiler = nb.njit(parallel=True, fastmath=True)
10
+ # else:
11
+ # jit_compiler = nb.njit(fastmath=True)
12
+
13
+ jit_compiler = nb.njit(fastmath=True)
7
14
 
8
15
  def make_the_clusbool(data, max_sigs, verbose, Δ):
9
16
  """
@@ -68,7 +75,7 @@ def make_the_clusbool(data, max_sigs, verbose, Δ):
68
75
  volume = np.zeros(total_clusters_detected + 1)
69
76
  signatures = np.zeros(total_clusters_detected + 1)
70
77
 
71
- @nb.njit(parallel=True, fastmath=True)
78
+ @jit_compiler
72
79
  def perform_loop(density, volume, signatures, data, max_sigs):
73
80
  for i in nb.prange(nx):
74
81
  for j in range(ny):
@@ -228,7 +235,7 @@ def calc_structure_bools(data, max_sigs, verbose, clusbool=None, Smin=-3, Smax=2
228
235
  S_fil, dM2_fil = calc_mass_change(filament_valid, flat_data_valid, Smin, Smax)
229
236
  ind = np.argmax(dM2_fil)
230
237
  filament_thresh = S_fil[ind]
231
- filbool = (max_sigs[:,:,:,2] > filament_thresh) & (~clusbool)
238
+ filbool = (max_sigs[:,:,:,1] > filament_thresh) & (~clusbool)
232
239
 
233
240
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
234
241
  # Step 3. Create Wall Boolean Filter
PyCosmoMMF/utils.py CHANGED
@@ -1,4 +1,8 @@
1
1
  import numpy as np
2
+ import os
3
+
4
+ #by default we set the parallel flag to False
5
+ # parallel_flag = False
2
6
 
3
7
  def test_print():
4
8
  """
@@ -15,4 +19,4 @@ def shrink(data, new_size):
15
19
  zs = new_size
16
20
  return data.reshape(xs, data.shape[0]//xs,
17
21
  ys, data.shape[1]//ys,
18
- zs, data.shape[2]//zs).sum(axis=1).sum(axis=2).sum(axis=3)
22
+ zs, data.shape[2]//zs).sum(axis=1).sum(axis=2).sum(axis=3)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCosmoMMF
3
- Version: 0.0.2
3
+ Version: 0.0.7
4
4
  Summary: A package for detecting structures in the Cosmic Web.
5
5
  Home-page: https://github.com/James11222/PyCosmoMMF/
6
6
  Author: James Sunseri
@@ -0,0 +1,12 @@
1
+ PyCosmoMMF/__init__.py,sha256=aFzvbdQpInIvDpdwLtCWTMBeqJpe_g4zlgn9eZhyr30,346
2
+ PyCosmoMMF/filter.py,sha256=spC_G2J3U9gtvHRLYe2lwrDrrFHAs6tNbE9b9Ebuszk,4401
3
+ PyCosmoMMF/hessian.py,sha256=v3LsODISHzacrYGZoNOg5q7a5lIN7dPthUYAdfAzAAE,1972
4
+ PyCosmoMMF/signatures.py,sha256=GDr3A2k6AF0iB0YNrZdl--7aw7PwwTDvCKI1n4bMsRs,3704
5
+ PyCosmoMMF/tagging.py,sha256=4xNpGGhBhZueuC1ZW4xD7SqKLnmAa2w0-KPSl4YuDVM,13385
6
+ PyCosmoMMF/test_density_cube.npy,sha256=WGhNAA4ja-NRkChvWXYSWQruuC2AG-zbwow5Wu29XMY,131200
7
+ PyCosmoMMF/utils.py,sha256=evWIDwRRiqXQcy4OrKTxs81l7Ux__RLYzJypO4to5yE,661
8
+ PyCosmoMMF-0.0.7.dist-info/LICENSE,sha256=6WlYpuEFF26eGU-3slIeHSkgBUd6_PnY8bZUi5R489Q,1070
9
+ PyCosmoMMF-0.0.7.dist-info/METADATA,sha256=qipXvpxxWC1b41fZidjszhJlrmor9uMWycqRYckIYgk,7708
10
+ PyCosmoMMF-0.0.7.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
11
+ PyCosmoMMF-0.0.7.dist-info/top_level.txt,sha256=DBkJA2VF3bXlBt5UXANVQAdbTjxrGGa007Y4yAlMYSA,11
12
+ PyCosmoMMF-0.0.7.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- PyCosmoMMF/__init__.py,sha256=sF_p2wszkyoMuR488oBcjxy92HiSe5DH-CiB9Pk6pD8,321
2
- PyCosmoMMF/filter.py,sha256=xhIKm8cWYls7eOIxk6id0yOxrlek_OuwbvzWrxBhdJI,2755
3
- PyCosmoMMF/hessian.py,sha256=PcJ8O8rj00D5-ZCO9AJ3LKeovKYXGaDZtcXFebMpNzE,1788
4
- PyCosmoMMF/signatures.py,sha256=LvFw6frIXH37R6Blm5IeUXsufD6m5jxt6Ui77Mzp7_U,3515
5
- PyCosmoMMF/tagging.py,sha256=gEWg0ZzKr3L595TD44BsgWrZKr6wVxFq8svq7DEKdt4,13201
6
- PyCosmoMMF/test_density_cube.npy,sha256=WGhNAA4ja-NRkChvWXYSWQruuC2AG-zbwow5Wu29XMY,131200
7
- PyCosmoMMF/utils.py,sha256=3RmWJUN_hG3xaW-JjqX2a6YFRjk9No2kzFhnB_Zkg8E,579
8
- PyCosmoMMF-0.0.2.dist-info/LICENSE,sha256=6WlYpuEFF26eGU-3slIeHSkgBUd6_PnY8bZUi5R489Q,1070
9
- PyCosmoMMF-0.0.2.dist-info/METADATA,sha256=HUIS3xxwW9AGY21Nq-g52uLaP3KjntdZ-1oTl1CtCIg,7708
10
- PyCosmoMMF-0.0.2.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
11
- PyCosmoMMF-0.0.2.dist-info/top_level.txt,sha256=DBkJA2VF3bXlBt5UXANVQAdbTjxrGGa007Y4yAlMYSA,11
12
- PyCosmoMMF-0.0.2.dist-info/RECORD,,