PyCosmoMMF 0.0.1__tar.gz → 0.0.3__tar.gz

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.
@@ -4,4 +4,3 @@ include *.md
4
4
  include PyCosmoMMF/*.py
5
5
  include PyCosmoMMF/*.npy
6
6
  include MANIFEST.in
7
- include *.pypirc
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCosmoMMF
3
- Version: 0.0.1
3
+ Version: 0.0.3
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
@@ -1,5 +1,5 @@
1
1
  import numpy as np
2
- from numba import njit
2
+ import numba as nb
3
3
 
4
4
  from PyCosmoMMF.filter import *
5
5
  from PyCosmoMMF.hessian import *
@@ -1,5 +1,5 @@
1
1
  import numpy as np
2
- from numba import njit
2
+ import numba as nb
3
3
 
4
4
  def wavevectors3D(dims, box_size=(2*np.pi, 2*np.pi, 2*np.pi)):
5
5
  """
@@ -23,7 +23,7 @@ def wavevectors3D(dims, box_size=(2*np.pi, 2*np.pi, 2*np.pi)):
23
23
  kz = np.fft.fftfreq(dims[2], 1/sample_rate[2]) * (2*np.pi / dims[2])
24
24
  return kx, ky, kz
25
25
 
26
- @njit
26
+ @nb.njit(parallel=True, fastmath=True)
27
27
  def kspace_gaussian_filter(R_S, kv):
28
28
  """
29
29
  create a Gaussian filter in k-space.
@@ -43,13 +43,69 @@ def kspace_gaussian_filter(R_S, kv):
43
43
  kx, ky, kz = kv
44
44
  nx, ny, nz = len(kx), len(ky), len(kz)
45
45
  filter_k = np.zeros((nx, ny, nz))
46
- for ix in range(nx):
46
+ for ix in nb.prange(nx):
47
47
  for iy in range(ny):
48
48
  for iz in range(nz):
49
49
  filter_k[ix, iy, iz] = np.exp(
50
50
  -(kx[ix]**2 + ky[iy]**2 + kz[iz]**2) * R_S**2 / 2)
51
51
  return filter_k
52
52
 
53
+ @nb.njit(parallel=True, fastmath=True)
54
+ def kspace_top_hat_filter(R_S, kv):
55
+ """
56
+ create a top-hat filter in k-space.
57
+
58
+ Parameters
59
+ ----------
60
+ R_S : float
61
+ The smoothing scale.
62
+ kv : tuple
63
+ The wavevectors in each dimension.
64
+
65
+ Returns
66
+ -------
67
+ filter_k : array
68
+ The filter in k-space.
69
+ """
70
+
71
+ kmax = (2 * np.pi) / R_S
72
+
73
+ kx, ky, kz = kv
74
+ nx, ny, nz = len(kx), len(ky), len(kz)
75
+ filter_k = np.zeros((nx, ny, nz))
76
+
77
+ for ix in range(nx):
78
+ for iy in range(ny):
79
+ for iz in range(nz):
80
+ if (np.sqrt(kx[ix]**2 + ky[iy]**2 + kz[iz]**2)) < kmax:
81
+ filter_k[ix, iy, iz] = 1
82
+
83
+ return filter_k
84
+
85
+
86
+ def smooth_top_hat(f, R_S, kv):
87
+ """
88
+ apply a top-hat filter to a field f.
89
+
90
+ Parameters
91
+ ----------
92
+ f : array
93
+ The field to be smoothed.
94
+ R_S : float
95
+ The smoothing scale.
96
+ kv : tuple
97
+ The wavevectors in each dimension.
98
+
99
+ Returns
100
+ -------
101
+ f_Rn : array
102
+ The smoothed field.
103
+ """
104
+ GF = kspace_top_hat_filter(R_S, kv)
105
+ f_Rn = np.real(np.fft.ifftn(GF * np.fft.fftn(f)))
106
+ f_Rn = f_Rn * (np.sum(f) / np.sum(f_Rn))
107
+ return f_Rn
108
+
53
109
  def smooth_gauss(f, R_S, kv):
54
110
  """
55
111
  apply a Gaussian filter to a field f.
@@ -1,5 +1,5 @@
1
1
  import numpy as np
2
- from numba import njit
2
+ import numba as nb
3
3
 
4
4
  def fast_hessian_from_smoothed(f_Rn, R_S, kv):
5
5
  """
@@ -25,13 +25,13 @@ def fast_hessian_from_smoothed(f_Rn, R_S, kv):
25
25
  hessian = np.zeros((dims[0], dims[1], dims[2], 6), dtype=np.complex128)
26
26
  kx, ky, kz = kv[0], kv[1], kv[2]
27
27
 
28
- @njit
28
+ @nb.njit(parallel=True, fastmath=True)
29
29
  def perform_loop(hessian):
30
30
  """
31
31
  This function is a loop that calculates the hessian matrix
32
32
  for each point in the 3D array.
33
33
  """
34
- for x in range(len(kv[0])):
34
+ for x in nb.prange(len(kv[0])):
35
35
  for y in range(len(kv[1])):
36
36
  for z in range(len(kv[2])):
37
37
  # (1,1)
@@ -1,10 +1,10 @@
1
1
  import numpy as np
2
- from numba import njit
2
+ import numba as nb
3
3
 
4
4
  from PyCosmoMMF.filter import *
5
5
  from PyCosmoMMF.hessian import *
6
6
 
7
- @njit
7
+ @nb.njit(parallel=True)
8
8
  def signatures_from_hessian(hessian):
9
9
  """
10
10
  Function to calculate the signatures from a given hessian.
@@ -41,7 +41,7 @@ def signatures_from_hessian(hessian):
41
41
  return 0
42
42
 
43
43
 
44
- for i in range(hsize[0]):
44
+ for i in nb.prange(hsize[0]):
45
45
  for j in range(hsize[1]):
46
46
  for k in range(hsize[2]):
47
47
  hes_slice = np.array([
@@ -97,9 +97,9 @@ def maximum_signature(Rs, field, alg='NEXUSPLUS'):
97
97
  # Calculate signatures at each scale Rn, determine max
98
98
  sigmax = np.ones((nx, ny, nz, 3)) * 0.00001
99
99
 
100
- @njit
100
+ @nb.njit(parallel=True)
101
101
  def perform_loop(sigmax, sigs_Rn, nx, ny, nz):
102
- for ix in range(nx):
102
+ for ix in nb.prange(nx):
103
103
  for iy in range(ny):
104
104
  for iz in range(nz):
105
105
  for sigtype in range(3):
@@ -2,7 +2,7 @@
2
2
  import numpy as np
3
3
  import matplotlib.pyplot as plt
4
4
  from skimage.measure import label
5
- from numba import njit
5
+ import numba as nb
6
6
 
7
7
 
8
8
  def make_the_clusbool(data, max_sigs, verbose, Δ):
@@ -68,9 +68,9 @@ def make_the_clusbool(data, max_sigs, verbose, Δ):
68
68
  volume = np.zeros(total_clusters_detected + 1)
69
69
  signatures = np.zeros(total_clusters_detected + 1)
70
70
 
71
- @njit
71
+ @nb.njit(parallel=True, fastmath=True)
72
72
  def perform_loop(density, volume, signatures, data, max_sigs):
73
- for i in range(nx):
73
+ for i in nb.prange(nx):
74
74
  for j in range(ny):
75
75
  for k in range(nz):
76
76
  if components[i,j,k] != 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCosmoMMF
3
- Version: 0.0.1
3
+ Version: 0.0.3
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
@@ -12,7 +12,7 @@ here = pathlib.Path(__file__).parent.resolve()
12
12
 
13
13
  setup(
14
14
  name='PyCosmoMMF', # Required
15
- version='0.0.1', # Required
15
+ version='0.0.3', # Required
16
16
  description='A package for detecting structures in the Cosmic Web.', # Optional
17
17
  long_description=(here / 'README.md').read_text(encoding='utf-8'), # Optional
18
18
  long_description_content_type='text/markdown', # Optional (see note above)
@@ -57,4 +57,4 @@ setup(
57
57
  'Check out my Website!': 'http://www.james-sunseri.com',
58
58
  'Source': 'https://github.com/James11222/PyCosmoMMF/',
59
59
  }
60
- )
60
+ )
File without changes
File without changes
File without changes
File without changes
File without changes