Skip to content

Commit b34ffab

Browse files
author
NGC
authored
Merge pull request #33 from hfoote/coefficient-zeroing-fix
Coefficient zeroing fix
2 parents 9e9aea7 + c2e74b2 commit b34ffab

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

EXPtools/basis_builder/makemodel.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import scipy
3+
from scipy.interpolate import interp1d, BSpline, splrep
34

45
def empirical_density_profile(rbins, pos, mass):
56
"""
@@ -30,13 +31,16 @@ def empirical_density_profile(rbins, pos, mass):
3031
V_shells = 4/3 * np.pi * (rbins[1:]**3 - rbins[:-1]**3)
3132

3233
# Compute density profile
33-
density, _ = np.histogram(r_p, bins=rbins+1, weights=mass)
34+
density, _ = np.histogram(r_p, bins=rbins, weights=mass)
3435
density /= V_shells
3536

36-
# Compute bin centers and return profile
37-
#radius = 0.5 * (rbins[1:] + rbins[:-1])
37+
#compute bin centers and return profile
38+
radius = 0.5 * (rbins[1:] + rbins[:-1])
3839

39-
return density
40+
tck_s = splrep(radius, np.log10(density), s=0.15)
41+
dens2 = BSpline(*tck_s)(radius)
42+
43+
return radius, 10**dens2
4044

4145

4246

@@ -142,7 +146,10 @@ def makemodel(func, M, funcargs, rvals = 10.**np.linspace(-2.,4.,2000), pfile=''
142146
R = np.nanmax(rvals)
143147

144148
# query out the density values
145-
dvals = func(rvals,*funcargs)
149+
if func == empirical_density_profile:
150+
rvals, dvals = func(rvals,*funcargs)
151+
else:
152+
dvals = func(rvals,*funcargs)
146153

147154
# make the mass and potential arrays
148155
mvals = np.zeros(dvals.size)

EXPtools/utils/coefficients.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def remove_terms(original_coefficients, n, l, m):
1818
for i in range(len(l)):
1919
lm_idx = int(l[i]*(l[i]+1) / 2) + m[i]
2020
print(n[i],l[i],m[i], lm_idx)
21-
try: coefs_matrix[n[i], lm_idx, t] = np.complex128(0)
21+
try: coefs_matrix[lm_idx, n[i], t] = np.complex128(0)
2222
except IndexError: continue
2323
copy_coeffcients.setMatrix(mat=coefs_matrix[:,:, t], time=t_snaps[t])
2424

0 commit comments

Comments
 (0)