Skip to content

Expose the reference-spectrum API on ProcessingContext - #96

Open
birkholz-cubert wants to merge 7 commits into
developfrom
feature/reference-spectrum
Open

Expose the reference-spectrum API on ProcessingContext#96
birkholz-cubert wants to merge 7 commits into
developfrom
feature/reference-spectrum

Conversation

@birkholz-cubert

Copy link
Copy Markdown
Collaborator

What

  • cuvis.ReferenceType gains WhiteSpectrum and TargetSpectrum; has_reference / clear_reference work on them unchanged.
  • ProcessingContext.set_reference becomes polymorphic: the spectrum types take an ImageData carrying wavelengths or a (wavelengths, values) array pair; a white counts spectrum requires effective_bit_depth (1 to 16) and carries integration_time / load_level. Classic types keep the Measurement path; cross-usage is a TypeError before the C layer.
  • New ProcessingContext.get_reference_spectrum(refType) returns the slot as an ImageData (1 x 1 x channels, wavelengths in nm) or None when empty; get_reference stays Measurement-only.
  • Seven tests, including a round trip for both slots and the acceptance check that a flat 100 percent target spectrum leaves the reflectance cube bit-identical.
  • Version 3.5.3.2 to 3.5.3.3, changelog entries per the CONTRIBUTING predicates.

Why

  • The SDK's new white/target reference spectra (reflectance without a white measurement, calibrated target curves) were unreachable from Python.

Pitfalls

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hrw1VcGnJiHXcfeHC8LHus

set_reference becomes polymorphic: the two new ReferenceType members
WhiteSpectrum and TargetSpectrum take spectrum data (an ImageData with
wavelengths, or a (wavelengths, values) pair of arrays) instead of a
Measurement; a white counts spectrum additionally requires
effective_bit_depth and carries integration_time and load_level.
get_reference_spectrum returns either slot as an ImageData, or None
when the slot is empty. has_reference and clear_reference work on the
new members unchanged.

The counts metadata is write-only: the C API stores it but exposes no
getter, so a round trip returns wavelengths and values only.
A flat 50 percent target spectrum halves the reflectance cube; the two
white sources clear each other on set and the counts spectrum drives
the denominator (four times the counts quarter the cube); both spectra
survive a legacy .cu3 save and reload embedded in the file, values and
rounded-nm wavelengths intact.

The flat-100-percent identity check gets one count of tolerance: the
reflectance kernel is parallel and not bit-deterministic between runs.
The CubeExporter is the one component that writes references in their
link forms: with allow_session_file=False it produces a loose .cu3 and
one .cu3sp sidecar per spectrum slot in the Calibration directory,
never embedding a spectrum into the measurement. cuvis_measurement_save
stays the raw legacy dump and is not part of this contract.
full_export=True keeps the processed cube through the export trim.
- target spectrum values are reflectance fractions now, 1.0 = 100 percent
- get_reference_spectrum(WhiteSpectrum) carries effective_bit_depth and
  integration_time attributes, which the flat out-parameter API lost
- behavior tests flipped to fractions; they pass only against an SDK built
  with the fraction convention in reflectivity_on_grid

@manke-cubert manke-cubert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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