Skip to content

Commit 6681fca

Browse files
author
jngaravitoc
committed
update tests to match basis refactor and minor edits
1 parent a531225 commit 6681fca

File tree

7 files changed

+47
-77
lines changed

7 files changed

+47
-77
lines changed

EXPtools/__init__.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
# Allow direct access to these submodules/classes from the package
2-
from .basis_builder.profiles import Profiles
3-
from .basis_builder.basis_utils import make_basis, make_config, make_Dfit
4-
from .basis_builder.makemodel import make_model
5-
from .ios.ios import exp_coefficients
1+
# Re-export selected submodules and utilities at the package level
2+
from .basis.profiles import Profiles
3+
from .basis.basis_utils import load_basis, make_basis, write_config
4+
from .basis.makemodel import make_model
5+
#from .ios.ios import exp_coefficients
66
from .utils.halo import ICHernquist
7-
from .utils import write_basis, load_basis
87
from .visuals import Grid3D
9-
# Explicitly declare public API
8+
9+
# Declare the public API
1010
__all__ = [
11-
"Profiles",
12-
"makebasis",
13-
"write_table",
14-
"make_config",
15-
"exp_coefficients",
16-
"makemodel",
17-
"ICHernquist"
18-
]
11+
"Profiles",
12+
"make_basis",
13+
"write_config",
14+
"make_Dfit",
15+
"make_model",
16+
"exp_coefficients",
17+
"ICHernquist",
18+
"load_basis",
19+
"Grid3D",
20+
]
1921

EXPtools/utils/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
from . import coefficients
33
from . import indexing
44
from . import units
5-
from .basis import load_basis, write_basis

EXPtools/utils/halo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def triaxial(self, axis_ratios, rot_angle,
4343
axis_ratios : list
4444
List of principal axis ratios in the following order: [a, b, c]
4545
axis will be computes as x/a, y/b, z/c
46-
rot_angle : float
46+
rot_angle : float
4747
Angle at which the halo is going to be rotated in degrees
4848
rot_axis : str
4949
Rotation axis it could be: 'x', 'y', 'z'

EXPtools/visuals/visualize.py

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def find_field(basis, coefficients, time=0, xyz=(0, 0, 0), property='dens',
146146
else:
147147
raise ValueError("Invalid property specified. Possible values are 'dens', 'pot', and 'force'.")
148148

149-
def spherical_avg_prop(basis, coefficients, time=0, radius=np.linspace(0.1, 600, 100), property='dens'):
149+
def spherical_avg_prop(grid, basis, coefficients, time=0, radius=np.linspace(0.1, 600, 100), property='dens'):
150150
"""
151151
Computes the spherically averaged value of the specified property of the field over the given radii.
152152
@@ -174,53 +174,15 @@ def spherical_avg_prop(basis, coefficients, time=0, radius=np.linspace(0.1, 600,
174174
ValueError:
175175
If the property argument is not 'dens', 'pot', or 'force'.
176176
"""
177+
Grid3D()
178+
fields = pyEXP.field.FieldGenerator(times, mesh)
179+
points = field.points(basis, coefs)
180+
181+
return radius, profile
177182

178-
coefficients.set_coefs(coefficients.getCoefStruct(time))
179-
field = [find_field(basis, np.hstack([[rad], [0], [0]]), property=property, include_monopole=True) for rad in radius]
180-
181-
if property == 'force':
182-
return np.vstack(field), radius
183-
184-
return np.array(field), radius
185-
186-
187-
def make_grid(gridtype, gridspecs, rgrid, representation='cartesian'):
188-
"""
189-
Make a variety of grids in different coordinate representations
190183

191-
Parameters
192-
----------
193-
gridtype:
194-
npoints:
195-
rgrid:
196-
representation:
197184

198185

199-
Returns:
200-
--------
201-
coordinates
202-
203-
"""
204-
205-
if gridtype == 'spherical':
206-
arcostheta = np.linspace(-1, 1, gridspecs['theta_bins'])
207-
phi = np.linspace(0, 2*np.pi, gridspecs['phi_bins'])
208-
theta_mesh, phi_mesh = np.meshgrid(np.arccos(arcostheta), phi)
209-
210-
if representation == 'cartesian':
211-
x = rgrid * np.sin(theta_mesh) * np.cos(phi_mesh)
212-
y = rgrid * np.sin(theta_mesh) * np.sin(phi_mesh)
213-
z = rgrid * np.cos(theta_mesh)
214-
## TODO: fix this return to allow the user to chose what to return
215-
return np.array([x, y, z]), theta_mesh, phi_mesh
216-
217-
elif representation == 'spherical':
218-
return np.array([theta_mesh, phi_mesh])
219-
220-
else:
221-
print('gridtype {} not implemented'.format(gridtype))
222-
return 0
223-
224186
def return_fields_in_grid(basis, coefficients, times=[0],
225187
projection='3D', proj_plane=0,
226188
grid_lim=300, npoints=150,):

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "EXPtools"
7-
version = "0.2.1"
7+
version = "0.2.2"
88
authors = [
99
{ name="Nico Garavito-Camargo", email="ngaravito@flatironinstitute.org" },
1010
{ name="Arpit Arora", email="arora125@sas.upenn.edu"},
1111
]
1212

1313
description = "Library to analyze and visualize basis function expansions using pyEXP"
1414
readme = "README.md"
15-
requires-python = ">=3.8"
15+
requires-python = ">=3.10"
1616
keywords = ["astronomy", "dynamics"]
1717
classifiers = [
1818
"Programming Language :: Python :: 3",

tests/test_basis_utils.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import tempfile
33
import os
44
import yaml
5-
from EXPtools.basis_builder import make_model, make_config, _write_table
5+
from EXPtools.basis import make_model, make_config, write_table
6+
from EXPtools.basis import Profiles
7+
68

79
def test_write_table():
810
# Prepare dummy data
@@ -76,30 +78,35 @@ def test_make_config():
7678
print("✅ All tests passed for make_config")
7779

7880

79-
def test_makemodel():
81+
def test_make_model():
82+
from pathlib import Path
83+
84+
DATA_DIR = Path(__file__).parent / "data"
8085
# Create simple synthetic density profile
81-
radius = np.logspace(-1, 1, 5) # 5 points from 0.1 to 10
82-
density = 1.0 / radius**2 # rho ~ r^-2 (common in astrophysics)
86+
TEST_PLUMMER = "test_plummer_halo.txt"
87+
test_data = os.join(DATA_DIR, TEST_PLUMMER)
88+
R_plummer, D_plummer, M_plummer, P_plummer = np.loadtxt(test_data, skiprows=3, unpack=True)
89+
90+
radius = np.logspace(-2, 2.5, 300) #
91+
halo_model = Profiles(radius, scale_radius=10)
92+
density = Profiles.plummer_density()
8393

8494
Mtotal = 10.0 # desired total mass
8595

8696
# Run model generation
87-
r_scaled, d_scaled, m_scaled, p_scaled = make_model(radius, density, Mtotal, verbose=False)
88-
97+
r_scaled, d_scaled, m_scaled, p_scaled = make_model(radius, density, Mtotal,
98+
physical_units=True, verbose=False)
8999
# Assertions
90-
assert r_scaled.shape == radius.shape
91-
assert d_scaled.shape == density.shape
92-
assert m_scaled.shape == radius.shape
93-
assert p_scaled.shape == radius.shape
100+
assert r_scaled == R_plummer
101+
assert d_scaled == D_plummer
102+
assert m_scaled == M_plummer
103+
assert p_scaled == P_plummer
94104

95105
assert np.all(np.isfinite(r_scaled))
96106
assert np.all(np.isfinite(d_scaled))
97107
assert np.all(np.isfinite(m_scaled))
98108
assert np.all(np.isfinite(p_scaled))
99109

100-
assert np.all(r_scaled > 0)
101-
assert np.all(d_scaled > 0)
102-
assert np.all(m_scaled > 0)
103110

104111
# Check mass conservation approximately
105112
np.testing.assert_allclose(m_scaled[-1], Mtotal, rtol=1e-2)

tests/test_profiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from EXPtools.basis_builder import profiles
2+
from EXPtools.basis import profiles
33

44
# Test output of functions
55
# Test document test functions

0 commit comments

Comments
 (0)