From d8302b7f702d7d7e18ecbbd10a5bbb9aafc4bc91 Mon Sep 17 00:00:00 2001 From: hfoote Date: Mon, 16 Dec 2024 15:40:10 -0700 Subject: [PATCH 1/3] spline-smoothed empirical density --- EXPtools/basis_builder/makemodel.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/EXPtools/basis_builder/makemodel.py b/EXPtools/basis_builder/makemodel.py index 9d6aa01..4ff09bf 100644 --- a/EXPtools/basis_builder/makemodel.py +++ b/EXPtools/basis_builder/makemodel.py @@ -1,5 +1,6 @@ import numpy as np import scipy +from scipy.interpolate import interp1d, BSpline, splrep def empirical_density_profile(rbins, pos, mass): """ @@ -30,13 +31,16 @@ def empirical_density_profile(rbins, pos, mass): V_shells = 4/3 * np.pi * (rbins[1:]**3 - rbins[:-1]**3) # Compute density profile - density, _ = np.histogram(r_p, bins=rbins+1, weights=mass) + density, _ = np.histogram(r_p, bins=rbins, weights=mass) density /= V_shells - # Compute bin centers and return profile - #radius = 0.5 * (rbins[1:] + rbins[:-1]) + #compute bin centers and return profile + radius = 0.5 * (rbins[1:] + rbins[:-1]) - return density + tck_s = splrep(radius, np.log10(density), s=0.15) + dens2 = BSpline(*tck_s)(radius) + + return radius, 10**dens2 From 985ee396dc451bafd6514ef2be144b62c0b5d4b9 Mon Sep 17 00:00:00 2001 From: hfoote Date: Mon, 16 Dec 2024 15:43:36 -0700 Subject: [PATCH 2/3] integrating empirical density with makemodel --- EXPtools/basis_builder/makemodel.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/EXPtools/basis_builder/makemodel.py b/EXPtools/basis_builder/makemodel.py index 4ff09bf..cf5f3fc 100644 --- a/EXPtools/basis_builder/makemodel.py +++ b/EXPtools/basis_builder/makemodel.py @@ -146,7 +146,10 @@ def makemodel(func, M, funcargs, rvals = 10.**np.linspace(-2.,4.,2000), pfile='' R = np.nanmax(rvals) # query out the density values - dvals = func(rvals,*funcargs) + if func == empirical_density_profile: + rvals, dvals = func(rvals,*funcargs) + else: + dvals = func(rvals,*funcargs) # make the mass and potential arrays mvals = np.zeros(dvals.size) From c2e74b27b76ca324ccc417f446926a8fc0267cd7 Mon Sep 17 00:00:00 2001 From: hfoote Date: Wed, 22 Jan 2025 16:56:38 -0700 Subject: [PATCH 3/3] fix indexing in remove_terms() --- EXPtools/utils/coefficients.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXPtools/utils/coefficients.py b/EXPtools/utils/coefficients.py index d44ad9d..ee1593d 100644 --- a/EXPtools/utils/coefficients.py +++ b/EXPtools/utils/coefficients.py @@ -18,7 +18,7 @@ def remove_terms(original_coefficients, n, l, m): for i in range(len(l)): lm_idx = int(l[i]*(l[i]+1) / 2) + m[i] print(n[i],l[i],m[i], lm_idx) - try: coefs_matrix[n[i], lm_idx, t] = np.complex128(0) + try: coefs_matrix[lm_idx, n[i], t] = np.complex128(0) except IndexError: continue copy_coeffcients.setMatrix(mat=coefs_matrix[:,:, t], time=t_snaps[t])