Skip to content

Add maps to TUV-x Python constructor#680

Merged
K20shores merged 2 commits intoNCAR:mainfrom
mattldawson:develop-600-tuvx-python-constructor
Nov 19, 2025
Merged

Add maps to TUV-x Python constructor#680
K20shores merged 2 commits intoNCAR:mainfrom
mattldawson:develop-600-tuvx-python-constructor

Conversation

@mattldawson
Copy link
Copy Markdown
Collaborator

This PR adds the ability to pass grid, profile, and radiator maps to the TUV-x constructor in Python.

  • Initially, I tried to use SI units in the Python API, like is done for MICM and CARMA, but for TUV-x this proved to be fairly difficult because of the generic containers (grid, profile, etc.). I recommend using the current TUV-x units for now, and adopting SI units as TUV-x is ported to C++

closes #600

Copilot AI review requested due to automatic review settings November 19, 2025 00:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes the TUV-x Python API by requiring grid, profile, and radiator maps to be passed to the constructor, shifting from a config-only approach to a more flexible host-controlled model. The API now requires explicit solar zenith angle and Earth-Sun distance parameters for each run, removing the previous batch-processing mode.

Key changes:

  • TUV-x constructor now requires GridMap, ProfileMap, and RadiatorMap instances alongside config
  • Run method signature changed to accept solar zenith angle and Earth-Sun distance parameters
  • Removed config-only mode, GetNumberOfSzaSteps(), RunFromConfig(), and related infrastructure
  • Output arrays changed from 3D (sza_steps, layers, rates) to 2D (layers, rates) format

Reviewed Changes

Copilot reviewed 14 out of 17 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
src/tuvx/tuvx.cpp Updated Create and Run methods to accept maps; removed config-only mode logic and helper methods
src/tuvx/tuvx_c_interface.cpp Added dose_rates parameter to RunTuvx function signature
include/musica/tuvx/tuvx.hpp Updated class interface to remove config-only methods and add map parameters
include/musica/tuvx/tuvx_c_interface.hpp Added CreateTuvxFromConfigString with maps; updated function signatures
src/tuvx/interface.F90 Moved and updated internal_create_tuvx_from_config_string to accept maps; removed RunFromConfig and GetNumberOfSzaSteps
fortran/tuvx/tuvx.F90 Updated run_tuvx_c interface to include dose_rates parameter
python/bindings/tuvx/tuvx.cpp Updated Python bindings to pass maps and handle 2D output arrays
python/musica/tuvx/tuvx.py Updated constructor and run method signatures to require maps and runtime parameters
python/musica/__init__.py Added RadiatorMap and Radiator to exports
python/test/integration/test_tuvx.py Added helper functions for creating maps; updated tests for new API
src/test/unit/tuvx/tuvx_run_from_config.cpp Updated test calls to pass nullptr for dose_rates
src/test/data/tuvx/full_from_host/* Added new test data files with NetCDF cross sections and configuration
configs/tuvx/tuv_5_4.json Removed grid and profile definitions (now provided by host)
Comments suppressed due to low confidence (1)

python/test/integration/test_tuvx.py:227

  • The docstring parameter dose_rates: np.ndarray is documented but the method signature for get_dose_rate doesn't show this parameter. This appears to be inconsistent with the actual signature visible in the diff context. Based on other similar methods in the codebase, the dose_rates parameter should be explicitly shown in the method signature documentation.
    radiator_map["hot air balloons"] = hot_air_balloons
    return radiator_map


def test_tuvx_version():
    version = musica.tuvx.version
    assert version is not None
    assert isinstance(version, str)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"type": "base",
"netcdf files": [
{
"file path": "test/data/tuvx/fixed/O2_cross_section.nc"
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration references "test/data/tuvx/fixed/O2_cross_section.nc" but there's an "O2_cross_section.nc" file in the same "full_from_host" directory. This should likely be "test/data/tuvx/full_from_host/O2_cross_section.nc" to reference the local file.

Suggested change
"file path": "test/data/tuvx/fixed/O2_cross_section.nc"
"file path": "test/data/tuvx/full_from_host/O2_cross_section.nc"

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@K20shores K20shores left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me, and I think some of the copilot comments for file paths seem like they could be accepted

@K20shores K20shores merged commit 8d21a92 into NCAR:main Nov 19, 2025
73 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a Python TUV-x constructor for in-code grids, profiles, and radiators

4 participants