Migrate particle populations from 0.3.6 to 0.4.0
Start with the units of one particle input in your old study. If it holds
resolved counts, carry those counts into population. If you supply a measured
density to set_number_density, the builder handles the volume conversion.
If you supply raw population yourself, multiply each bin density (m⁻³) or
radius-PDF ordinate (m⁻⁴) by its box’s represented air volume. The result is a count per bin or a population per metre of radius,
respectively. At 1 m³ the conversion factor has a numerical value of one,
so test the conversion at a second volume and compare both number density and
mass by material.
For a measured input, follow the sample calculation below or the input and writer example. To recover a result from an existing analysis file, go directly to Read a 0.3.6 particle history.
Choose the quantity your calculation needs
Section titled “Choose the quantity your calculation needs”Let p be a CPU ParticleData, with B boxes, N bins, resolved slots or
radius nodes, and S materials. Each p.volume[b] is the positive represented
air volume of one box in m³. A particle’s material volume is
sum(mass / material_density) over its materials. A chamber or grid cell has
its own physical air volume, which may differ from the represented sample.
| 0.3.6 input or operation | 0.4.0 expression | Meaning, units and shape |
|---|---|---|
| Construct with raw resolved counts | ParticleData(..., population=counts) or builder set_population(counts) |
Represented number per slot, (B,N). Multiplicities can be fractional. |
| Construct from old discrete bin densities or radius-PDF ordinates | population=density * volume[:, None] for already normalized arrays |
Number per bin, or represented number per metre of radius (m⁻¹), (B,N). Multiply each row by its represented air volume once. |
Write raw amounts through p.concentration[:] |
p.population[:] = amounts |
Writes the existing raw buffer. For an increment expressed per m³ of air, multiply the increment by the row’s volume first. |
| Initialize from a measurement | Builder set_number_density(values, units) or a unit-bearing factory |
Bin or slot density in m⁻³, or radius density in m⁻⁴. |
| Replace a measured CPU sample | p.set_slot_concentration_density(values, volume=new_volume) |
SI density (B,N), or (N,) for one box. Optional scalar or (B,) volume in m³. Omitting volume uses the current volume. |
| Read density at each slot | p.slot_concentration_density |
Detached (B,N), equal to population divided by row volume. Discrete/resolved values are m⁻³. PDF values are m⁻⁴ and need radius quadrature to contribute to a total. |
| Read the total number density | p.number_density |
(B,), m⁻³, summed or integrated by representation. Multiply by p.volume for represented number per box. |
| Read mass by material | p.species_mass_density, p.species_mass_inventory |
(B,S), kg/m³ air and kg per box respectively. Each slot’s p.masses is kg per particle and material. Gas remains gas.concentration in kg/m³ air. |
Throughout 0.4.x, the second positional argument of ParticleData, its
concentration= keyword and writable .concentration property keep their
legacy meaning. They accept resolved counts at any represented volume, and
binned/PDF raw values only when every box has volume exactly 1 m³. A single
non-unit binned row rejects that legacy access for the entire batch. Keep a
reference to p.population to see later in-place writes. A density property
returns a detached result each time you read it.
Import and replace a measured sample
Section titled “Import and replace a measured sample”A discrete bin measured at 2 cm⁻³ contains 500,000 represented particles in
0.25 m³. Import its SI equivalent, 2 × 10⁶ m⁻³, with the base installation.
With Pint installed, replace the density call with
.set_number_density([2.0], "1/cm^3") to use the instrument’s units directly.
import numpy as npfrom particula.particles import ParticleDataBuilder
sample = ( ParticleDataBuilder() .set_distribution_type("discrete") .set_masses(np.array([[[1e-18]]])) .set_density(np.array([1000.0])) .set_number_density([2e6], "1/m^3") .set_volume(0.25) .build())np.testing.assert_equal(sample.population, [[500_000]])A replacement measurement of 400 m⁻³ represents 100 particles in the original sample and 200 in a new sample twice its size. The setter validates both inputs before committing either one. Other holders of the raw arrays see the accepted update.
counts, volumes = sample.population, sample.volumesample.set_slot_concentration_density([400.0])np.testing.assert_equal(counts, [[100.0]])sample.set_slot_concentration_density([400.0], volume=0.5)np.testing.assert_equal(counts, [[200.0]])
with np.testing.assert_raises(ValueError): sample.set_slot_concentration_density([-1.0], volume=1.0)np.testing.assert_equal(counts, [[200.0]])np.testing.assert_equal(volumes, [0.5])Check integration, mass and diameter spectra
Section titled “Check integration, mass and diameter spectra”A change in sample volume should preserve the measured density when the input describes the same air. Suppose two discrete bins or resolved slots contribute 4 and 8 particles m⁻³. They represent 1 and 2 particles in 0.25 m³, or 16 and 32 particles in 4 m³. Dividing each count by its box volume and summing recovers 12 m⁻³ in either box.
For a material budget, multiply each slot’s contribution to number density by its per-particle mass of that material. The sum is the material mass per m³ of air. Multiply by the box’s air volume to recover the material inventory in kg.
The example radius PDF integrates to 9 m⁻³ in either sample. Integrate over its radius grid in metres. The endpoints receive half their adjacent interval and interior nodes receive half the sum of their adjacent intervals. The nodes [1, 2, 4] nm have widths [0.5, 1.5, 1] × 10⁻⁹ m. Multiplying by the prescribed ordinates [2, 4, 2] × 10⁹ m⁻⁴ gives contributions of [1, 6, 2] m⁻³. The two samples therefore represent 2.25 and 36 particles in 0.25 and 4 m³. Apply the same weights to per-particle species masses. The three-representation tutorial runs this calculation with unequal slot masses in two materials.
To compare with an instrument, first establish its diameter definition. For spherical volume-equivalent sizes, diameter D = 2r (and dn/dD = ½ dn/dr at D = 2r). For binned spectra, divide each integrated bin density by Δlog₁₀D to obtain density per decade. Dividing by a linear diameter width instead gives density per metre. Use the original diameter edges when recovering a reported band from per-decade data.
Check the reported diameter band and the particles outside it. Here the 2–8 µm band contains 10 particles m⁻³. The 4 µm class falls in the bin to its right, and the 8 µm class falls in the last bin, which includes its upper edge. Including 1 particle m⁻³ below the band and 5 m⁻³ above it recovers the original 16 m⁻³.
from particula.particles import get_binned_number_spectrum, get_number_per_decade
diameter = np.array([1, 2, 4, 8, 9]) * 1e-6edges = np.array([2, 4, 8]) * 1e-6bins = get_binned_number_spectrum(diameter, [1, 2, 3, 5, 5], edges)per_decade = get_number_per_decade(bins.bin_number_density, edges)band = np.sum(per_decade * np.diff(np.log10(edges)))np.testing.assert_allclose(bins.bin_number_density, [2, 8])np.testing.assert_allclose([band, bins.below_range + band + bins.above_range], [10, 16])Follow the volume through a process
Section titled “Follow the volume through a process”Flushing and expansion can produce identical final densities while leaving different inventories. Start with 100 represented particles and 1 µg of gas in 0.25 m³. At fixed volume, one clean-air half-life removes half of each. Expansion of the original resolved sample to 0.5 m³ retains all 100 particles and the full 1 µg. Both endpoints report 200 particles/m³ and 2 µg gas/m³. Check the represented number and gas kg as well as both densities. The dilution guide runs the fixed-volume CPU and prescribed-volume Warp calculations.
Replacing a particle measurement changes the particle counts. Editing only the particle volume leaves the stored counts and gas density in place. For the same expansion above, such an edit would imply 2 µg of gas in the new volume. Numerical representative-volume scaling has a different purpose. When the resolved slot-exhaustion policy selects it, the sample’s counts and volume scale together, preserving pre-existing particle densities and gas concentration. Ordinary resampling combines or redistributes slot weights at the current volume. Slot-exhaustion policies
- For device calculations, transfer discrete or resolved counts together with
per-box volume.
WarpParticleData.populationholds raw amounts. Import measured densities on the CPU before upload. Native continuous radius PDFs stay on the CPU, and each device process has its own weight requirements. GPU support · Explicit transfers - On parcel export, use the volume at the selected time. For grid transport, multiply sample density by physical cell volume to obtain cell inventory. Parcel and grid budgets
- For optics, sum the product of each cross section (m²) and its integrated number density (m⁻³) to recover the bulk coefficient (m⁻¹). Native particles and measured arrays
Reopen your study
Section titled “Reopen your study”For an archived result, identify what the run saved. An analysis history
lets you check an observable at the recorded times. If it includes raw
populations, use the air volume from that same box and time to recover the
density. If it contains only a derived total, compare that total directly.
Record particle_population and volume together in new studies so you
can reconstruct slot densities later.
To continue the exact trajectory, reopen the checkpoint with the original software, runtime and supported device. To start a new 0.4.0 calculation from the same study, construct its physical state from the migrated inputs and keep the old checkpoint as provenance.
Before replacing a figure, reconstruct one unrounded point from its old inputs, then repeat the calculation with the migrated state at the same time, bin edges and units. Check the tails and each species budget alongside the observable. The study comparisons record the reference data and comparison for individual studies.
Read a 0.3.6 particle history
Section titled “Read a 0.3.6 particle history”Open the archive with load_analysis and check the units before combining
its arrays. The loader returns a schema-2 view of a valid 0.3.6 history and
leaves the file intact. In the returned metadata, package_version and
source_analysis_version identify the original writer and schema.
source_observables describes the original fields, while
metadata["science"]["observables"] gives the units of the returned arrays.
Run the check below from the repository root with Particula installed. All four files use number density as the observable. The resolved file gives you counts and volume to reconstruct it. The discrete and radius-PDF files also include a saved total for comparison. The derived-only file gives you the total directly.
from pathlib import Path
import numpy as npfrom particula.execution.analysis_io import load_analysis
folder = Path("particula/execution/tests/data")for kind, old_unit, new_unit, expected in ( ("resolved", "count", "count", 200.0), ("discrete", "m^-3", "count", 12.0), ("continuous_pdf", "m^-4", "m^-1", 23e-9), ("derived", None, None, 12.0),): data = load_analysis(folder / f"analysis-0.3.6-{kind}.pca") meta, arrays = data.metadata, data.arrays science = meta["science"] assert meta["package_version"] == "0.3.6" assert meta["source_analysis_version"] == 1 and meta["version"] == 2 assert science["observables"]["volume"]["unit"] == "m^3" if new_unit is None: assert "particle_population" not in arrays density = arrays["number_density"] else: assert meta["source_observables"]["particle_concentration"]["unit"] == old_unit assert science["observables"]["particle_population"]["unit"] == new_unit slots = arrays["particle_population"] / arrays["volume"][..., None] if kind == "continuous_pdf": radius = np.array(science["radius_grid_m"]) density = np.sum((slots[..., 1:] + slots[..., :-1]) * np.diff(radius) / 2, axis=-1) else: density = slots.sum(axis=-1) np.testing.assert_allclose(density, [[expected]], atol=0) if "number_density" in arrays: assert science["observables"]["number_density"]["unit"] == "m^-3" np.testing.assert_allclose(density, arrays["number_density"], atol=0)The resolved file’s 100 particles in 0.5 m³ give 200 m⁻³. The derived-only file supplies its total of 12 m⁻³ directly.
The two binned files illustrate why you need the representation as well as the volume. Both store the values [2, 6, 4] at 1 m³. For discrete bins, summing the three contributions gives 12 m⁻³. For a radius PDF, integrating over the [1, 3, 6] nm grid gives 2.3 × 10⁻⁸ m⁻³. The loader requires a volume of 1 m³ for every box and time in these legacy binned files. If it rejects a file, check the represented air volume in the original study.
Related studies
Section titled “Related studies”Explore this topic: State ownership and transfers