Skip to content

Make Mono.d_spacing conditionally required per XDI/1.0 spec - #6

Merged
AAAlvesJr merged 1 commit into
AAAlvesJr:mainfrom
smrgeoinfo:conditional-mono-d-spacing
Jul 25, 2026
Merged

Make Mono.d_spacing conditionally required per XDI/1.0 spec#6
AAAlvesJr merged 1 commit into
AAAlvesJr:mainfrom
smrgeoinfo:conditional-mono-d-spacing

Conversation

@smrgeoinfo

Copy link
Copy Markdown
Contributor

Summary

The XDI/1.0 specification requires Mono.d_spacing only when the abscissa (Column.1) is monochromator angle or encoder step count — the mono d-spacing is needed only to convert those units into energy:

The Mono.d_spacing header field must be specified if the abscissa is conveyed as monochromator angle.

The current schema requires Mono.d_spacing unconditionally, which produces spurious errors on the many XDI files whose abscissa is energy or wavelength (where d_spacing is optional).

Fix

  • Remove the unconditional "required": ["d_spacing"] from the mono subschema.
  • Add a top-level allOf conditional that requires mono.d_spacing only when column.1 matches ^(angle|encoder)(\s|$).

Tests

  • test_missing_mono (whose fixture has Column.1: energy) is replaced with test_mono_dspacing_not_required_for_energy_abscissa to reflect the corrected semantics.
  • test_WriteToFile / test_WriteToFileTwo: invalid_data setup now also switches the abscissa to angle deg so removing d_spacing still triggers the mono error path.
  • New tests/test_MonoDspacingConditional.py covers three cases:
    • angle abscissa, no d_spacing → mono error
    • angle abscissa, with d_spacing → no mono error
    • energy abscissa, no d_spacing → no mono error
  • New fixtures: tests/missing_dspacing_angle.xdi, tests/valid_angle_dspacing.xdi.

Test plan

  • python -m pytest tests/ — 26/27 pass on this branch. The one remaining failure (test_WrongFields::test_invalid_column) is pre-existing on main (unrelated to this change).
  • Manually confirmed with a real-world energy-abscissa file that previously errored on mono.d_spacing: after the fix, no mono error is raised; when the same file's abscissa is edited to angle deg, the mono error correctly fires.

Context

Encountered while integrating xdi_validator into a CDIF-XAS metadata pipeline against a corpus of ~100 real-world XDI files from Diamond Light Source beamline B18 (all energy abscissa). Every file was being flagged as invalid solely on the unconditional Mono.d_spacing requirement, which the XDI/1.0 spec does not actually mandate for energy abscissae.

The XDI/1.0 specification requires Mono.d_spacing only when the
abscissa (Column.1) is monochromator angle or encoder step count,
since d_spacing is needed to convert those units to energy:

    "The Mono.d_spacing header field must be specified if the abscissa
    is conveyed as monochromator angle."

    -- specification/spec.md (XraySpectroscopy/XAS-Data-Interchange)

The schema previously required Mono.d_spacing unconditionally, causing
spurious errors on the many XDI files whose abscissa is energy or
wavelength (where d_spacing is optional).

Fix:
  * Remove the unconditional `required: ["d_spacing"]` from the
    `mono` subschema.
  * Add a top-level `allOf` conditional that requires
    `mono.d_spacing` only when `column.1` matches
    `^(angle|encoder)(\s|$)`.

Tests:
  * Existing `test_missing_mono` (fixture has energy abscissa) is
    replaced with `test_mono_dspacing_not_required_for_energy_abscissa`
    to reflect the corrected semantics.
  * `test_WriteToFile` / `test_WriteToFileTwo`: their `invalid_data`
    setup now also swaps the abscissa to `angle deg` so removing
    d_spacing still triggers the mono error path.
  * New `test_MonoDspacingConditional.py` with three cases:
      - angle abscissa, no d_spacing  -> mono error
      - angle abscissa, with d_spacing -> no mono error
      - energy abscissa, no d_spacing  -> no mono error
  * New fixtures `missing_dspacing_angle.xdi` and
    `valid_angle_dspacing.xdi`.
@AAAlvesJr

Copy link
Copy Markdown
Owner

Dear @smrgeoinfo, thank you very much for this important contribution. Just reviewed your PR and everything seems fine for me. I will merge it now and prepare a new release to make the changes promptly available for the other users.

@AAAlvesJr
AAAlvesJr merged commit 6dfe294 into AAAlvesJr:main Jul 25, 2026
2 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