feat: #1030 - Add GasData conversion utilities from_species() and to_species()#1036
Merged
Gorkowski merged 2 commits intouncscode:mainfrom Feb 3, 2026
Merged
Conversation
Add from_species() and to_species() functions for converting between GasSpecies and GasData containers: - from_species(): Converts GasSpecies to GasData with batch dimension support, transforming concentration from kg/m³ to molecules/m³ - to_species(): Converts GasData back to GasSpecies for a single box, requiring vapor pressure strategies since GasData is data-only Key features: - Handle both single and multi-species conversions - Support n_boxes replication in from_species() - Validate strategy count and box_index in to_species() - Error on mixed partitioning (GasSpecies requires uniform) Includes 13 comprehensive tests covering: - Single/multi-species conversions - Unit conversion verification - Box index selection - Error handling for mismatched inputs - Round-trip data preservation Closes uncscode#1030 ADW-ID: 1955660d
- Fixed line length violations (E501) in error messages - Fixed mypy type errors for names variable type inference - Extracted f-string expressions to local variables for line length This commit fixes validation gaps found in issue uncscode#1030. Closes uncscode#1030 ADW-ID: 1955660d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Target Branch:
mainFixes #1030 | Workflow:
1955660dSummary
Adds bidirectional conversion utilities between the existing
GasSpeciesclass and the newGasDatacontainer. This enables gradual migration from the behavior-richGasSpeciesto the data-onlyGasDatarepresentation, supporting multi-box CFD simulations while maintaining backward compatibility.The key challenge addressed is unit conversion:
GasSpeciesstores concentration in kg/m³ whileGasDatauses molecules/m³, requiring Avogadro's number for conversion.What Changed
New Components
particula/gas/gas_data.py- Addedfrom_species()andto_species()conversion functions (~175 LOC)Modified Components
particula/gas/__init__.py- Exportedfrom_speciesandto_speciesin__all__Tests Added/Updated
particula/gas/tests/gas_data_test.py- Added 13 comprehensive test cases across 3 test classes:TestFromSpecies(4 tests): single/multi-species conversion, n_boxes replication, unit conversion verificationTestToSpecies(6 tests): single/multi-species conversion, box_index selection, error handling for strategy mismatch, out-of-range box_index, and mixed partitioningTestRoundTrip(3 tests): single/multi-species round-trip preservation, different partitioning valuesHow It Works
The conversion utilities bridge the gap between GasSpecies (with vapor pressure strategies) and GasData (data-only):
from_species(species, n_boxes=1):to_species(data, vapor_pressure_strategies, box_index=0):Implementation Notes
to_species()raisesValueErrorfor mixed partitioning becauseGasSpecies.append()requires uniform partitioning across all species+=operator to build multi-species GasSpecies, matching existing API patternsTesting