Map SILAM OPeNDAP variables, add unit conversions, and comprehensive tests for air quality ingest#478
Conversation
- Map to correct SILAM variables: cnc_PM2_5, cnc_PM10, vmr_*_gas - Add unit conversion from kg/m³ to µg/m³ for PM variables - Add VMR to concentration conversion for gas species - Use air_dens for proper gas concentration calculation - All tests passing Co-authored-by: cloneofghosts <10248058+cloneofghosts@users.noreply.github.com>
- Remove redundant silam_variable_mapping dictionary - Rename convert_vmr_to_concentration to convert_mass_mixing_ratio_to_concentration - Remove unused molecular_weight parameter from conversion function - Clarify that SILAM vmr_*_gas variables are mass mixing ratios, not volume mixing ratios - All tests still passing Co-authored-by: cloneofghosts <10248058+cloneofghosts@users.noreply.github.com>
- Add KG_M3_TO_UG_M3 constant for unit conversion factor - Add STANDARD_AIR_DENSITY constant for fallback air density - Update all usages to use named constants - Improves code maintainability and readability - All tests passing Co-authored-by: cloneofghosts <10248058+cloneofghosts@users.noreply.github.com>
|
@copilot Here is the definition for each of the vmr gasses: _FillValue: -1.74483046E9 _FillValue: -1.74483046E9 _FillValue: -1.74483046E9 _FillValue: -1.74483046E9 |
- Fix conversion function: vmr_*_gas are volume mixing ratios (mole/mole), not mass mixing ratios - Add molar mass constants from SILAM metadata (O3: 0.048, NO2: 0.046, SO2: 0.064, CO: 0.028 kg/mole) - Update formula: concentration = VMR * air_density * molar_mass * 1e9 - Update comments to reflect correct units (mole/mole) - All tests passing Co-authored-by: cloneofghosts <10248058+cloneofghosts@users.noreply.github.com>
- Add MOLAR_MASS_AIR constant (0.02897 kg/mole for dry air) - Update formula: concentration = VMR * air_density * (molar_mass_pollutant / molar_mass_air) * 1e9 - Correct physics: VMR is mole_pollutant/mole_air, conversion requires ratio of molar masses - All tests passing Co-authored-by: cloneofghosts <10248058+cloneofghosts@users.noreply.github.com>
You're absolutely right - the metadata confirms these are volume mixing ratios (units: mole/mole), not mass mixing ratios as I initially assumed. I've corrected the conversion formula in commit cbf4ea9: Updated conversion: concentration (µg/m³) = VMR (mole/mole) × air_density (kg/m³) × (molar_mass_pollutant / molar_mass_air) × 1e9Using the molar masses from the SILAM metadata you provided:
All tests passing and conversion is now physically correct. |
|
@copilot Can you add some tests to make sure everything is working properly? Maybe some can include AQI calculations with the other variables to make sure it gives expected values. Can add to the existing AQI tests file. This might be outside the scope of this PR but how does the OPeNDAP download work? I've tried looking at the code and can't figure that part out. |
- Create API/silam_conversion.py module for testable conversion utilities - Add 5 unit tests for VMR to concentration conversion - Add 3 integration tests for AQI calculation with VMR-converted gases - Tests cover: basic conversion, zero values, different gases, arrays, realistic values - Integration tests verify AQI calculations with moderate/high pollutant levels - All 41 tests passing (33 existing + 8 new) Co-authored-by: cloneofghosts <10248058+cloneofghosts@users.noreply.github.com>
I've added comprehensive tests in commit 9acabd1: VMR Conversion Tests (5 tests):
AQI Integration Tests (3 tests):
All 41 tests passing (33 existing + 8 new). Regarding OPeNDAP download: The code uses |
The SILAM ingest was attempting to use generic variable names that don't exist in the actual SILAM OPeNDAP dataset. Updated to use the correct SILAM v6.1 variable names with proper unit conversions and added comprehensive tests to validate the conversion logic.
Variable Mapping
cnc_PM2_5,cnc_PM10(provided in kg/m³, converted to µg/m³)vmr_O3_gas,vmr_NO2_gas,vmr_SO2_gas,vmr_CO_gas(volume mixing ratios in mole/mole)air_dens(kg/m³, used for volume mixing ratio conversions)Unit Conversions
Note: SILAM's
vmr_*_gasvariables are true volume mixing ratios (mole pollutant/mole air) as confirmed by the SILAM metadata (units: mole/mole, silam_amount_unit: mole). The conversion requires both the pollutant's molar mass and air's molar mass (0.02897 kg/mole for dry air).Molar Masses
From SILAM metadata:
Code Quality
API/silam_conversion.pymodule for testable conversion utilitiesTesting
Added comprehensive test coverage (8 new tests, 41 total tests passing):
VMR Conversion Tests (5 unit tests):
AQI Integration Tests (3 tests):
All tests validate that VMR to concentration conversion is mathematically correct and that AQI calculations integrate properly with VMR-converted data.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.