Skip to content

write_restart_file/write_partial_restart_file validate directions axis against number_of_frequencies, not number_of_directions #12

Description

@cgrudz

Summary

Both write_restart_file and write_partial_restart_file in src/roguewave/wavewatch3/io.py validate the spectra array's directions axis (shape[2]) against parent_restart_file.number_of_frequencies instead of number_of_directions:

Impact

For any grid where number_of_frequencies != number_of_directions, writing a valid spectra array of the correct shape raises a spurious ValueError. Conversely, if a future change ever produced a genuinely wrong-shaped directions axis that happened to equal the frequency count, this check would silently pass instead of catching it.

Why this was never caught

tests/restart_files/'s fixture restart file has number_of_frequencies == number_of_directions == 36 (see test_number_of_directions/test_number_of_frequencies in test_restart_file.py), so shape[2] != number_of_frequencies and shape[2] != number_of_directions are indistinguishable for that fixture. Neither test_io.py's write_partial_restart_file/reassemble_restart_file_from_parts tests nor anything else in the suite exercises a grid with unequal counts.

Real-world reproduction

Sofar's own esm-run-scripts/preprocess_waves/setup/containerized/grid.sh defines grid configs with frequency_bins=50, direction_bins=36 — writing a restart against one of these would trip this bug today.

Suggested fix

Change shape[2] != parent_restart_file.number_of_frequencies to shape[2] != parent_restart_file.number_of_directions in both functions, and add a test fixture (or a second synthetic grid) with n_freq != n_dir so this class of bug can't hide again.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions