Skip to content

refactor: Move units support into package extensions, add DynamicQuantities backend - #65

Draft
icweaver wants to merge 2 commits into
mainfrom
units
Draft

icweaver wants to merge 2 commits into
mainfrom
units

Conversation

@icweaver

@icweaver icweaver commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

NOT READY FOR REVIEW

The numeric core is now units-free. Unitful and DynamicQuantities support live in package extensions that load with using Unitful / using DynamicQuantities.

Core

  • Unitful and DynamicQuantities are now weakdeps; PhysicalConstants and UnitfulAstro are dropped.
  • Physical constants are the CODATA2018 / SI-2019 exact values in SI units, defined once in core; both extensions build their unitful constants from
    them.
  • Backend hooks (_ustrip, _velocity_ratio, _spectral_axis_factor) have unitless defaults and are specialized per extension. A plain Real
    velocity is still read as km/s, and a unitless axis is still treated as wavelength.
  • Unitless blackbody is computed in plain floats (last-digit change in its doctest output).

SpectrumBaseUnitfulExt

  • spectrum constructors for Quantity axes (wavelength, frequency, energy, including BinnedSpectrum), ustrip(spec), unit(spec),
    blackbody(::Quantity...).
  • Redshift factors chosen by dispatch on the axis type: Length stretches, Frequency/Energy compress.
  • uconvert conversions of the spectral axis and flux density, powered by UnitfulEquivalences.

SpectrumBaseDynamicQuantitiesExt

  • Same constructors, redshift/doppler_shift and blackbody support, plus ustrip(spec) and dimension(spec) (DynamicQuantities has no unit
    objects).
  • DynamicQuantities doesn't encode dimension in the type, so dimension checks and redshift factors inspect the axis value. @inferred redshift/doppler_shift still hold.

Docs and tests

  • Documenter pulls docstrings from the extension modules; new "DynamicQuantities helpers" section.
  • New test/ext/dynamicquantities.jl; doctests now also cover extension docstrings.

Caveats and follow-ups

  • Unitful isn't optional in practice yet: DustExtinction (a hard dependency) loads Unitful, so the Unitful extension is always active. Truly
    optional Unitful needs DustExtinction to become optional too.
  • UnitfulEquivalences stays a hard dependency so uconvert works with only using Unitful. The alternative is a separate ["Unitful", "UnitfulEquivalences"] extension, at the cost of requiring using UnitfulEquivalences.
  • No uconvert equivalent for DynamicQuantities yet; it needs its own E = hν = hc/λ and F_ν = F_λ λ²/c implementation.

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.40506% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.69%. Comparing base (ed81082) to head (d821e2c).

Files with missing lines Patch % Lines
ext/SpectrumBaseDynamicQuantitiesExt.jl 83.33% 5 Missing ⚠️
ext/SpectrumBaseUnitfulExt.jl 97.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #65      +/-   ##
==========================================
- Coverage   96.05%   94.69%   -1.36%     
==========================================
  Files          11       12       +1     
  Lines         228      264      +36     
==========================================
+ Hits          219      250      +31     
- Misses          9       14       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant