Skip to content

Conversation

@andycasey
Copy link
Owner

@andycasey andycasey commented Feb 2, 2026

Summary

Comprehensive improvements to luminare including CLI, tests, bug fixes, and documentation.

Changes

🖥️ CLI Commands

luminare train

Train models from HDF5 spectral grids with extensive control options:

luminare train grid.h5 model.pkl --n-components 128

Grid Control:

  • -s/--slice DIM=VAL: Fix dimension at value/index
  • -b/--bounds DIM=MIN:MAX: Restrict dimension range
  • --valid-only: Only valid (finite, positive) spectra
  • --require-converged: Only converged spectra
  • --flip DIM: Reverse dimension order
  • --list-dims: Inspect grid structure

luminare predict

Generate spectra from parameters:

luminare predict model.pkl -p Teff=5500 -p logg=4.0 --plot

luminare fit

Fit parameters to observed spectra:

luminare fit model.pkl spectrum.fits -o results.json --plot

luminare info

Inspect trained models with label ranges and metadata.

🧪 Test Suite (95 tests)

  • test_nmf.py: Convergence, non-negativity, loss functions
  • test_fourier.py: Round-trip, basis evaluation, Gram diagonal
  • test_scalers.py: Transform/inverse transform
  • test_continuum.py: Design matrix, initial theta
  • test_emulator.py: Integration tests

🐛 Bug Fixes

  1. gram_diagonal mask bug: Reshape 1D mask to N-D grid for proper axis computation
  2. Type hint errors: jnp.array is a function, use Optional[jnp.ndarray]
  3. Missing imports: Added typing imports
  4. Dependencies: Added jaxopt, equinox to requirements

📚 Documentation

  • Expanded README with usage examples
  • Added docs/training.md, docs/fitting.md, docs/api.md
  • Full CLI reference

🔧 Other

  • Updated pyproject.toml metadata
  • Added .pre-commit-config.yaml
  • Added .gitignore

Testing

cd luminare
uv sync --python 3.12
uv pip install pytest
.venv/bin/pytest tests/ -v
# 95 passed

- luminare train: Train NMF model from spectral grid
- luminare predict: Generate spectrum from parameters
- luminare fit: Fit parameters to observed spectrum
- luminare info: Inspect model metadata

Also:
- Updated pyproject.toml with proper metadata and entry point
- Expanded README with usage examples
- Added click and optimistix dependencies
- Bumped version to 0.1.5
@coveralls
Copy link

coveralls commented Feb 2, 2026

Pull Request Test Coverage Report for Build 21591372365

Details

  • 44 of 541 (8.13%) changed or added relevant lines in 8 files are covered.
  • 11 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+33.2%) to 33.191%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/luminare/utils.py 0 1 0.0%
src/luminare/initial.py 0 6 0.0%
src/luminare/fourier.py 12 29 41.38%
src/luminare/emulator.py 6 25 24.0%
src/luminare/cli.py 0 454 0.0%
Files with Coverage Reduction New Missed Lines %
src/luminare/utils.py 1 12.0%
src/luminare/emulator.py 3 35.62%
src/luminare/fourier.py 3 72.82%
src/luminare/initial.py 4 16.67%
Totals Coverage Status
Change from base Build 18310530654: 33.2%
Covered Lines: 311
Relevant Lines: 937

💛 - Coveralls

Andy Casey added 11 commits February 2, 2026 23:56
New options for controlling the training grid:
- --slice/-s: Fix dimension at value or index (e.g., -s Teff=5000 or -s Teff=5)
- --bounds/-b: Restrict dimension range (e.g., -b logg=3.0:5.0)
- --valid-only: Only use spectra with finite, positive flux
- --require-converged: Only use converged spectra (if flag exists)
- --flip: Reverse dimension order (e.g., --flip Teff)
- --list-dims: Show available dimensions and exit
- --spectra-key: Override auto-detection of spectra dataset

Also improved:
- Auto-detect n_modes if not specified (~half grid points, min 3)
- Auto-detect parameter dimensions from HDF5 structure
- Save stellar_label_names and ranges in model for downstream use
- Better validation of n_modes vs grid dimensions
- More informative progress output
- Fix gram_diagonal mask dimension bug: reshape 1D mask to N-D grid
- Fix type hint errors: jnp.array is a function, use Optional[jnp.ndarray]
- Add missing typing imports (Optional, Tuple)
- Add jaxopt and equinox to dependencies

All 95 tests now pass.
- Add separate lint job with ruff check and format verification
- Enable uv dependency caching for faster builds
- Consolidate Python matrix to 3.11 and 3.12
- Switch to Codecov for coverage reporting
- Add publish.yml for PyPI publishing on version tags
- Update README badge to use Codecov
- Test all help commands
- Test info command with model file
- Test option parsing (slice, bounds)
- Test error handling for missing files

Total: 108 tests passing
- Add test_utils.py: Tests for air_to_vacuum and parse_marcs_photosphere_path
- Add test_initial.py: Tests for estimate_vsini function
- Add test_integration.py: Integration tests for create_stellar_spectrum_model
- Expand test_emulator.py: Tests for convolved_flux, StellarSpectrumModel class
- Expand test_fourier.py: Edge cases, matdiag, hvag_inverse, gram_diagonal with mask

Coverage improved from 33% to 64%:
- utils.py: 12% -> 100%
- fourier.py: 73% -> 100%
- emulator.py: 36% -> 85%
- continuum.py: 100%
- scalers.py: 100%
- nmf.py: 97%

Total: 185 tests passing
- Replace bare except with except Exception in cli.py
- Add noqa: E402 comments for intentional late imports in tests
- Remove unused imports (Tuple, reduce, pytest, random, numpy)
- Remove unused local variables in test functions
- Apply ruff format to all files
- Add comprehensive CLI tests for train command (slice, bounds, valid-only,
  require-converged, flip, pixel-subsampling, precision options)
- Add tests for nmf_weights_and_coefficients function in initial.py (98% coverage)
- Add tests for create_stellar_spectrum_model in emulator.py (96% coverage)
- Add tests for continuum model, wavelength interpolation, air/vacuum conversion
- Fix GPU detection error in CLI train command (handle missing GPU backend)

Test coverage improvements:
- cli.py: 36% -> 71%
- emulator.py: 85% -> 96%
- initial.py: 44% -> 98%
- Overall: 64% -> 85%
- Add tests for predict command: basic usage, CSV output, FITS output,
  models without wavelength or label names, empty/partial params
- Add tests for fit command: CSV and FITS spectrum input, various
  continuum region configurations, models without label names
- Add tests for FITS file variants: 2D arrays, missing ivar, HDU index 3,
  invalid structures
- Add edge case tests for both commands

Coverage increased from 71% to 90% for cli.py module.

Uses mocking to avoid expensive JAX computations in tests.
@andycasey andycasey merged commit 7bbacbb into main Feb 2, 2026
0 of 6 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.

2 participants