Skip to content

Comments

CSV Forcing Provider - enhanced error checking and cleanup#83

Draft
PhilMiller wants to merge 8 commits intodevelopmentfrom
philmiller-csv-forcings-cleanup
Draft

CSV Forcing Provider - enhanced error checking and cleanup#83
PhilMiller wants to merge 8 commits intodevelopmentfrom
philmiller-csv-forcings-cleanup

Conversation

@PhilMiller
Copy link

@PhilMiller PhilMiller commented Nov 19, 2025

The CSV Forcing provider is still in use, particularly for calibration use cases. I identified a number of cases in which it could currently be made to silently return bad data, thus leading to incorrect scientific results. This PR adds guard rails against those cases.

Additions

  • .cpp file for the implementation of class CsvPerFeatureForcingProvider, with contents moved from the header

Changes

  • Store name of forcing file from construction, so that it can be reported in later error messages
  • Use stored file name in place of missing catchment ID variable when reporting errors
  • Tighten checks for bad time inputs and arguments
  • Enforce the limitation of the code that data record durations and request time steps are all exactly one hour
  • Delete dead variables and code
  • Improve const safety and copy-avoidance

Testing

Notes

  • The one-hour timestep and record duration limitations might actually be problematic if used with some sources of forcing data. E.g. GFS data stretches to 3 hour intervals, and long-term forecasts may involve data or steps at 6-hour intervals. This PR does not enable any such uses, but rather ensures that they fail clearly rather than computing nonsensically.

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

@PhilMiller PhilMiller changed the title CSV Forcing Provider cleanup CSV Forcing Provider - enhanced error checking and cleanup Nov 19, 2025
Comment on lines +87 to +88
// XXX There may be callers almost-reasonably relying on being able to request data extending one record_duration() past the end
Logger::logMsgAndThrowError("Requested forcing value runs past the end of the data from CSV file '" + forcing_file_name + "'");
Copy link
Author

Choose a reason for hiding this comment

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

This fails in the unit test currently. Investigating.

@PhilMiller PhilMiller marked this pull request as draft November 24, 2025 18:30
Copy link

@kyle-larkin kyle-larkin left a comment

Choose a reason for hiding this comment

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

This is fine, I think narrowing the time range on the unit tests as a follow on to get this merged would be sufficient.

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