Skip to content

Conversation

@ClementinLeron
Copy link
Collaborator

@ClementinLeron ClementinLeron commented Oct 20, 2025

Description

It extends the time interpolation and scaling capabilities of OpenAirClim to support individual scaling factors per species in the emission inventory.
This allows, for instance, different scaling factors to be applied when using multiple fuel types or accounting for species-specific emission changes.

This improvement addresses the TODO note previously present in apply_scaling:

"TODO: implement scaling for individual species"

Main changes

  • interpolate_time.py
    Updated scale_inv and apply_scaling to handle multiple emission scaling factors (one per species).
  • create_time_evolution.py
    Modified to generate a coherent example including species-dependent scaling.
  • interpolate_time_test.py
    Updated unit tests to reflect the new behavior.

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested?

  • Updated the existing test suite in interpolate_time_test.py to validate per-species scaling.
  • Verified functionality manually using a sample NETCDF4 file with the following structure:
    <class 'netCDF4.Dataset'> root group (NETCDF4 data model, file format HDF5): Title: Time scaling example Convention: CF-XXX Type: scaling dimensions(sizes): time(210), species(5) variables(dimensions): float32 scaling(time, species), int64 time(time), <class 'str'> species(species) groups:

Example
print(file2read.variables['species'][:]) # ['fuel' 'CO2' 'H2O' 'NOx' 'distance']

To reproduce:

  1. Create a NetCDF file with the structure above.
  2. Run OpenAirClim using the same .toml configuration as for the standard scaling example.

Test configuration:

  • Operating system: win32
  • Environment: environment_dev.yaml

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any changed dependencies have been added or removed correctly
  • main branch: I have updated the CHANGELOG
  • main branch: I have updated the version numbering in __about__.py according to the semantic versioning scheme

Clementin Leron added 2 commits October 15, 2025 09:25
implementation scaling for individual species
tests and example updated to match the new scaling function
@liammegill liammegill linked an issue Oct 21, 2025 that may be closed by this pull request
@liammegill liammegill added type: feature Brand new functionality, features, pages, workflows, endpoints etc. module: core Related to the core module labels Oct 21, 2025
@stefan-voelk
Copy link
Collaborator

Thank you very much Clémentin for contributing this code to improve the functionality of OpenAirClim. Before proceeding with the detailed code review, I have some general comments:

  • Please provide the code in a dedicated feature branch within the same repository. The naming convention for the branches is described in the contribution guidelines. In this case, the naming could be something like feature/scaling-multi-species. When the feature branch is in the same repository, it is easier to compare changes than from a forked repository. For long-term developments, we keep the feature branches even after merging into main. This seems like a single development task. Then, we would probably delete the feature branch after having merged into main.
  • Since you are new to our team, read carefully the contribution guidelines for further instructions and relevant documentation on openairclim.org
  • Please update the existing documentation with relevance to the added functionality. There is already a markdown file describing the time evolution. Please update the corresponding paragraphs with reference to the scaling option and briefly explain the added functionality. When the merge into main is finished, openairclim.org is newly built and the updated information in this markdown file is automatically included.

Some remarks on the code provided:

  • create_time_evolution.py I like the approach defining the species as xarray coordinate! Consider updating the attribute section of the output netCDF by adding your name to Author. Please also change Contact for both options, normalization and scaling, to [email protected] which is our new functional Email address users can reach out.
  • The demonstrations and examples provided in the repository do not necessarily be realistic. However, in this case I would adapt the given scaling slightly since the fuel consumption grows by 100%, but the flown distance stays constant. This is not a favorable scenario for the future ;-)
  • Instead of commenting out old code, just remove it unless it is needed for a better understanding. Git will remember all changes made.
  • interpolate_time.py The definition of the list species_order suggests that the order of species matters. However, there is no requirement that the species in the emission inventories or in the time evolution files must meet a certain order. The added functionality should be flexible enough to cope with unordered species and missing species. Consider outputting a warning to the user for missing species.
  • The list species_order = ["fuel", "CO2", "H2O", "NOx", "distance"] is used at several locations within the code. This approach is less sustainable, for example if a new species is added to the OpenAirClim framework. Instead, you could use a global variable ("CONSTANT") defined in the beginning of the module which then has to be updated only once. Alternatively, you can try to program the functionality such that no list species_order is needed at all.

@liammegill liammegill added this to the v0.13.0 milestone Oct 28, 2025
@stefan-voelk stefan-voelk mentioned this pull request Nov 7, 2025
11 tasks
@liammegill liammegill modified the milestones: v0.13.0, v0.14.0 Nov 12, 2025
@stefan-voelk
Copy link
Collaborator

This is a duplicate of Pull Request #99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: core Related to the core module type: feature Brand new functionality, features, pages, workflows, endpoints etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add scaling for each specie

3 participants