Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/amrex_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"from flekspy.util import download_testfile, unit_one\n",
"from flekspy.util.transformations import create_field_transform\n",
"from flekspy.util.gmm import generate_synthetic_gmm_data, compare_gmm_results\n",
"from flekspy.amrex import AMReXParticleData\n",
"from flekspy.amrex import AMReXParticle\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
Expand Down Expand Up @@ -77,7 +77,7 @@
"source": [
"## Using the Native AMReX Particle Loader\n",
"\n",
"For scenarios where you only need to load particle data and the overhead of `yt` is not desired, `flekspy` provides a direct, experimental loader called `AMReXParticleData`. This is much faster than the yt loader with a simple interface."
"For scenarios where you only need to load particle data and the overhead of `yt` is not desired, `flekspy` provides a direct, experimental loader called `AMReXParticle`. This is much faster than the yt loader with a simple interface."
]
},
{
Expand All @@ -87,7 +87,7 @@
"outputs": [],
"source": [
"data_file = \"data/3d_particle_region0_1_t00000002_n00000007_amrex\"\n",
"pd = AMReXParticleData(data_file)\n",
"pd = AMReXParticle(data_file)\n",
"pd"
]
},
Expand Down
2 changes: 1 addition & 1 deletion samples/vdf_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def calculate_histograms(particle_file, regions, var_x, var_y, hist_range, hist_
"""
print(f"Loading particle data from: {particle_file}")
try:
pd = flekspy.amrex.AMReXParticleData(particle_file)
pd = flekspy.amrex.AMReXParticle(particle_file)
except Exception as e:
print(f"Error loading particle data: {e}")
return [], 0.0 # Return empty list and zero max
Expand Down
8 changes: 4 additions & 4 deletions src/flekspy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"YtFLEKSData",
"extract_phase",
"FLEKSTP",
"AMReXParticleData",
"AMReXParticle",
"xr",
]

Expand All @@ -27,7 +27,7 @@ def __getattr__(name):
"YtFLEKSData": "flekspy.yt",
"extract_phase": "flekspy.yt",
"FLEKSTP": "flekspy.tp",
"AMReXParticleData": "flekspy.amrex",
"AMReXParticle": "flekspy.amrex",
"read_idl": "flekspy.idl",
"DerivedAccessor": "flekspy.idl",
"xr": "xarray",
Expand Down Expand Up @@ -95,7 +95,7 @@ def load(
YtFLEKSData = __getattr__("YtFLEKSData")
return YtFLEKSData(filename, readFieldData)
else:
AMReXParticleData = __getattr__("AMReXParticleData")
return AMReXParticleData(filename)
AMReXParticle = __getattr__("AMReXParticle")
return AMReXParticle(filename)
else:
raise Exception("Error: unknown file format!")
4 changes: 2 additions & 2 deletions src/flekspy/amrex/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .particle_data import AMReXParticleData, AMReXParticleHeader
from .particle_data import AMReXParticle, AMReXParticleHeader

__all__ = ["AMReXParticleData", "AMReXParticleHeader"]
__all__ = ["AMReXParticle", "AMReXParticleHeader"]
4 changes: 2 additions & 2 deletions src/flekspy/amrex/particle_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def read_amrex_binary_particle_file(
return idata, rdata


class AMReXParticleData(AMReXPlottingMixin):
class AMReXParticle(AMReXPlottingMixin):
"""
This class provides an interface to the particle data in a plotfile.
Data is loaded lazily upon first access to `idata` or `rdata`.
Expand Down Expand Up @@ -279,7 +279,7 @@ def _parse_particle_h_files(self) -> None:

def __repr__(self) -> str:
repr_str = (
f"AMReXParticleData from {self.output_dir}\n"
f"AMReXParticle from {self.output_dir}\n"
f"Time: {self.time}\n"
f"Dimensions: {self.dim}\n"
f"Domain Dimensions: {self.domain_dimensions}\n"
Expand Down
2 changes: 1 addition & 1 deletion src/flekspy/amrex/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class AMReXPlottingMixin:
"""A mixin class for AMReXParticleData plotting functionalities."""
"""A mixin class for AMReXParticle plotting functionalities."""

_AXIS_LABEL_MAP = {
"velocity_x": r"$v_x$",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_amrex_3d_plots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from unittest.mock import patch
import matplotlib.pyplot as plt
from flekspy.amrex import AMReXParticleData
from flekspy.amrex import AMReXParticle
from pathlib import Path

@pytest.mark.parametrize(
Expand All @@ -18,7 +18,7 @@ def test_3d_plots(setup_test_data, data_file, plot_method_name):
a matplotlib figure and axes.
"""
data_dir = Path(setup_test_data)
ds = AMReXParticleData(data_dir / data_file)
ds = AMReXParticle(data_dir / data_file)
plot_func = getattr(ds, plot_method_name)

with patch("matplotlib.pyplot.show"):
Expand Down
46 changes: 23 additions & 23 deletions tests/test_amrex_loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from flekspy.amrex import AMReXParticleData
from flekspy.amrex import AMReXParticle
from flekspy.amrex.plotting import AMReXPlottingMixin
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -19,7 +19,7 @@ def select_particles_in_region(self, x_range=None, y_range=None, z_range=None):

@pytest.fixture
def mock_amrex_data():
"""Creates a mock AMReXParticleData object for testing."""
"""Creates a mock AMReXParticle object for testing."""
# Mock header
header = MagicMock()
header.real_component_names = ["x", "y", "z", "velocity_x", "velocity_y", "velocity_z", "weight"]
Expand All @@ -37,7 +37,7 @@ def particle_data(setup_test_data):
plotfile_directory = os.path.join(
setup_test_data, "3d_particle_region0_1_t00000002_n00000007_amrex"
)
return AMReXParticleData(plotfile_directory)
return AMReXParticle(plotfile_directory)


@pytest.fixture
Expand Down Expand Up @@ -68,8 +68,8 @@ def mock_plot_components():

@pytest.fixture
def mock_pdata():
"""Provides a mock AMReXParticleData object with alias resolution mocked."""
pdata = MagicMock(spec=AMReXParticleData)
"""Provides a mock AMReXParticle object with alias resolution mocked."""
pdata = MagicMock(spec=AMReXParticle)
pdata._resolve_alias.side_effect = lambda x: x
pdata._get_axis_label.side_effect = lambda x: x
return pdata
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_plot_phase(mock_plot_components, mock_pdata):
"Normalized Weighted Density",
)

result_fig, result_ax = AMReXParticleData.plot_phase(
result_fig, result_ax = AMReXParticle.plot_phase(
mock_pdata,
x_variable="x",
y_variable="vy",
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_plot_phase_with_existing_axes(mock_plot_components, mock_pdata):
"Particle Count",
)

result_fig, result_ax = AMReXParticleData.plot_phase(
result_fig, result_ax = AMReXParticle.plot_phase(
mock_pdata, x_variable="x", y_variable="y", ax=mock_ax
)

Expand All @@ -203,7 +203,7 @@ def test_plot_phase_no_colorbar(mock_plot_components, mock_pdata):
"Particle Count",
)

AMReXParticleData.plot_phase(
AMReXParticle.plot_phase(
mock_pdata, x_variable="x", y_variable="y", add_colorbar=False
)

Expand All @@ -217,7 +217,7 @@ def test_plot_phase_no_particles(mock_plot_components, mock_pdata):
"""
mock_pdata.get_phase_space_density.return_value = None

result = AMReXParticleData.plot_phase(
result = AMReXParticle.plot_phase(
mock_pdata, x_variable="x", y_variable="y", x_range=(0, 1)
)

Expand All @@ -237,7 +237,7 @@ def test_plot_phase_with_hist_range(mock_plot_components, mock_pdata):
)

custom_range = [[0.1, 0.9], [0.2, 0.8]]
AMReXParticleData.plot_phase(
AMReXParticle.plot_phase(
mock_pdata, x_variable="x", y_variable="y", hist_range=custom_range
)

Expand All @@ -259,7 +259,7 @@ def test_plot_phase_log_scale_with_vmin_vmax(mock_plot_components, mock_pdata):
)

with patch("matplotlib.colors.LogNorm") as mock_log_norm:
AMReXParticleData.plot_phase(
AMReXParticle.plot_phase(
mock_pdata, x_variable="x", y_variable="y", log_scale=True, vmin=1, vmax=10
)
mock_log_norm.assert_called_once_with(vmin=1, vmax=10)
Expand Down Expand Up @@ -287,7 +287,7 @@ def test_plot_phase_subplots(mock_pdata):
with patch(
"matplotlib.pyplot.subplots", return_value=(fig_mock, axes_mock)
) as mock_subplots:
result_fig, result_axes = AMReXParticleData.plot_phase_subplots(
result_fig, result_axes = AMReXParticle.plot_phase_subplots(
mock_pdata,
x_variable="x",
y_variable="vy",
Expand Down Expand Up @@ -337,7 +337,7 @@ def test_plot_phase_subplots_empty_region(mock_pdata):
"matplotlib.pyplot.subplots", return_value=(fig_mock, axes_mock)
):
# This should execute without raising a ValueError
AMReXParticleData.plot_phase_subplots(
AMReXParticle.plot_phase_subplots(
mock_pdata,
x_variable="x",
y_variable="vy",
Expand Down Expand Up @@ -421,7 +421,7 @@ def test_plot_phase_with_transform(mock_plot_components, mock_pdata):
def dummy_transform(data):
return data, ["x_new", "y_new"]

AMReXParticleData.plot_phase(
AMReXParticle.plot_phase(
mock_pdata,
x_variable="x_new",
y_variable="y_new",
Expand All @@ -446,7 +446,7 @@ def test_plot_phase_with_kde(mock_plot_components, mock_pdata):
"Weighted Density",
)

AMReXParticleData.plot_phase(
AMReXParticle.plot_phase(
mock_pdata,
x_variable="x",
y_variable="y",
Expand Down Expand Up @@ -488,7 +488,7 @@ def test_plot_phase_with_spatial_transform(mock_plot_components, mock_pdata):
def spatial_transform(data):
return data, ["pos_parallel", "pos_perp"]

AMReXParticleData.plot_phase(
AMReXParticle.plot_phase(
mock_pdata,
x_variable="pos_parallel",
y_variable="pos_perp",
Expand Down Expand Up @@ -521,7 +521,7 @@ def field_aligned_transform(data):
"v_perp1",
]

AMReXParticleData.plot_phase(
AMReXParticle.plot_phase(
mock_pdata,
x_variable="v_parallel",
y_variable="v_perp1",
Expand All @@ -546,7 +546,7 @@ def test_get_phase_space_density_basic(mock_pdata):
np.array([0.0, 1.0]),
np.array([0.0, 1.0]),
)
H, xedges, yedges, cbar_label = AMReXParticleData.get_phase_space_density(
H, xedges, yedges, cbar_label = AMReXParticle.get_phase_space_density(
mock_pdata, x_variable="x", y_variable="y"
)

Expand All @@ -566,7 +566,7 @@ def test_get_phase_space_density_normalized(mock_pdata):
# and get_phase_space_density will use mock_pdata.rdata
mock_pdata.select_particles_in_region.return_value = mock_pdata.rdata

H, _, _, cbar_label = AMReXParticleData.get_phase_space_density(
H, _, _, cbar_label = AMReXParticle.get_phase_space_density(
mock_pdata, x_variable="x", y_variable="y", normalize=True
)

Expand All @@ -590,7 +590,7 @@ def scale_transform(data):
np.array([0.0, 1.0]),
np.array([0.0, 1.0]),
)
AMReXParticleData.get_phase_space_density(
AMReXParticle.get_phase_space_density(
mock_pdata,
x_variable="x_scaled",
y_variable="y_scaled",
Expand Down Expand Up @@ -619,7 +619,7 @@ def test_get_phase_space_density_with_kde(mock_pdata):
mock_kde_instance.return_value = np.random.rand(10 * 10)
mock_gaussian_kde.return_value = mock_kde_instance

_, _, _, cbar_label = AMReXParticleData.get_phase_space_density(
_, _, _, cbar_label = AMReXParticle.get_phase_space_density(
mock_pdata,
x_variable="x",
y_variable="y",
Expand Down Expand Up @@ -651,7 +651,7 @@ def mock_select(x_range=None, y_range=None, z_range=None):

mock_pdata.select_particles_in_region.side_effect = mock_select

H, _, _, _ = AMReXParticleData.get_phase_space_density(
H, _, _, _ = AMReXParticle.get_phase_space_density(
mock_pdata,
x_variable="x",
y_variable="y",
Expand Down Expand Up @@ -689,7 +689,7 @@ def test_plot_phase_with_marginals(mock_plot_components, mock_pdata):
)

with patch("matplotlib.pyplot.figure", return_value=mock_fig):
AMReXParticleData.plot_phase(
AMReXParticle.plot_phase(
mock_pdata, x_variable="x", y_variable="y", marginals=True
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_fleks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_amrex_plot(self, amrex_data_files):

def test_amrex_particle_loader_default(self, setup_test_data):
ds = fs.load(os.path.join(setup_test_data, "3d_particle*amrex"))
assert isinstance(ds, fs.amrex.AMReXParticleData)
assert isinstance(ds, fs.amrex.AMReXParticle)


@pytest.fixture(scope="class")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_gmm_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from unittest.mock import MagicMock

from flekspy.util.gmm import get_gmm_parameters
from flekspy.amrex.particle_data import AMReXParticleData
from flekspy.amrex.particle_data import AMReXParticle


@pytest.fixture
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_get_gmm_temperatures_isotropic(fitted_gmm):
from scipy.constants import m_u, k

# Test with explicit particle_mass in amu
parameters = AMReXParticleData.get_gmm_temperatures(
parameters = AMReXParticle.get_gmm_temperatures(
fitted_gmm, particle_mass=2.0, isotropic=True
)

Expand All @@ -68,7 +68,7 @@ def test_get_gmm_temperatures_isotropic(fitted_gmm):
assert parameters[1]["temperature"] == pytest.approx(expected_temp_2)

# Test with default particle_mass (should be 1.0 amu)
parameters_default = AMReXParticleData.get_gmm_temperatures(
parameters_default = AMReXParticle.get_gmm_temperatures(
fitted_gmm, isotropic=True
)
expected_temp_1_default = 1.0 * m_u * 1.5 / k
Expand All @@ -87,7 +87,7 @@ def test_get_gmm_temperatures_bi_maxwellian(fitted_gmm):
"""
from scipy.constants import m_u, k

parameters = AMReXParticleData.get_gmm_temperatures(
parameters = AMReXParticle.get_gmm_temperatures(
fitted_gmm, particle_mass=2.0, isotropic=False
)

Expand Down