From 28fedf92fa4a29a55b792a2ed7db8e42dfaa35ad Mon Sep 17 00:00:00 2001 From: Jeff Curtis Date: Wed, 9 Sep 2026 20:24:42 -0500 Subject: [PATCH 1/3] fix length of particle source array --- src/aero_particle.hpp | 2 +- tests/test_aero_particle.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aero_particle.hpp b/src/aero_particle.hpp index 36c21759..14860302 100644 --- a/src/aero_particle.hpp +++ b/src/aero_particle.hpp @@ -222,7 +222,7 @@ struct AeroParticle { } static auto sources(const AeroParticle &self) { - int len = AeroData::__len__(*self.aero_data); + int len = AeroData::n_source(*self.aero_data); auto fn = f_aero_particle_get_component_sources; return pypartmc::get_array_values_set_len(self, fn, len); } diff --git a/tests/test_aero_particle.py b/tests/test_aero_particle.py index 7c65cae6..0350e7c2 100644 --- a/tests/test_aero_particle.py +++ b/tests/test_aero_particle.py @@ -512,7 +512,7 @@ def test_sources(): sources = sut.sources # assert - assert len(sources) == aero_dist.n_mode + assert len(sources) == aero_data.n_source assert isinstance(sources[0], int) @staticmethod From 84e589b7fa697090ecb986bc3c73d5dbd5eb9276 Mon Sep 17 00:00:00 2001 From: Jeff Curtis Date: Wed, 9 Sep 2026 20:50:54 -0500 Subject: [PATCH 2/3] test particle sources against a multi-source aerosol dist --- tests/test_aero_particle.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/test_aero_particle.py b/tests/test_aero_particle.py index 0350e7c2..c15b4f99 100644 --- a/tests/test_aero_particle.py +++ b/tests/test_aero_particle.py @@ -4,6 +4,7 @@ # Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors # #################################################################################################### +import copy import gc import numpy as np @@ -14,6 +15,7 @@ from .test_aero_data import AERO_DATA_CTOR_ARG_MINIMAL from .test_aero_dist import AERO_DIST_CTOR_ARG_MINIMAL +from .test_aero_mode import AERO_MODE_CTOR_LOG_NORMAL from .test_aero_state import AERO_STATE_CTOR_ARG_MINIMAL from .test_env_state import ENV_STATE_CTOR_ARG_MINIMAL @@ -504,16 +506,23 @@ def test_refract_core(): def test_sources(): # arrange aero_data = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL) - aero_dist = ppmc.AeroDist(aero_data, AERO_DIST_CTOR_ARG_MINIMAL) + # two log-normal modes differing only in name (i.e. source) and size + modes = copy.deepcopy(AERO_MODE_CTOR_LOG_NORMAL) + modes["test_mode_2"] = copy.deepcopy(AERO_MODE_CTOR_LOG_NORMAL["test_mode"]) + aero_dist = ppmc.AeroDist(aero_data, [modes]) aero_state = ppmc.AeroState(aero_data, *AERO_STATE_CTOR_ARG_MINIMAL) _ = aero_state.dist_sample(aero_dist, 1.0, 0.0) - sut = aero_state.particle(0) + # act - sources = sut.sources + sources = [ + aero_state.particle(i_part).sources for i_part in range(len(aero_state)) + ] # assert - assert len(sources) == aero_data.n_source - assert isinstance(sources[0], int) + assert aero_data.n_source == len(modes) + assert all(len(src) == aero_data.n_source for src in sources) + assert isinstance(sources[0][0], int) + assert all(sum(src) == 1 for src in sources) @staticmethod def test_get_weighting(): From 5ceb83409ae4a5fdcfa794c17a7d2d518ea3782c Mon Sep 17 00:00:00 2001 From: Jeff Curtis Date: Wed, 9 Sep 2026 21:15:03 -0500 Subject: [PATCH 3/3] improve assertion --- tests/test_aero_particle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_aero_particle.py b/tests/test_aero_particle.py index c15b4f99..372802dd 100644 --- a/tests/test_aero_particle.py +++ b/tests/test_aero_particle.py @@ -506,7 +506,7 @@ def test_refract_core(): def test_sources(): # arrange aero_data = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL) - # two log-normal modes differing only in name (i.e. source) and size + # two log-normal modes differing only in name (i.e. source) modes = copy.deepcopy(AERO_MODE_CTOR_LOG_NORMAL) modes["test_mode_2"] = copy.deepcopy(AERO_MODE_CTOR_LOG_NORMAL["test_mode"]) aero_dist = ppmc.AeroDist(aero_data, [modes]) @@ -519,7 +519,7 @@ def test_sources(): ] # assert - assert aero_data.n_source == len(modes) + assert aero_data.n_source == aero_dist.n_mode assert all(len(src) == aero_data.n_source for src in sources) assert isinstance(sources[0][0], int) assert all(sum(src) == 1 for src in sources)