Open jrackham-mo opened 6 months ago
I think the problem here is really the logic of what callbacks are for + what order they happen in. It's complicated because most constraints get applied after the callback, but certain special cases get "shortcut" to apply to the load process before the callback. ( specifically name constraints to speedup um files loading, and netcdf loading ) See : https://github.com/SciTools/iris/issues/3944
So does this mean that using a callback to validate the data being loaded is a bad idea? Rather than "validate during load", should we doing an approach of "load then validate"?
So does this mean that using a callback to validate the data being loaded is a bad idea? Rather than "validate during load", should we doing an approach of "load then validate"?
Well I guess it depends what you're trying to achieve. The load callback sits in the "middle" of the load process, and is there principally to capture metadata changes to a "raw" cube at a point where its context in the original sourcefile is still available, and before raw cubes are merged and constrained. As it is described in the User Guide. ( Except for the "constraint shortcutting" just described that is 🤔 )
So maybe it isn't really appropriate for this purpose. What was the original thinking, why you do it this way ?
What was the original thinking, why you do it this way ?
For our work on UG-ANTS, we want to validate that people are loading cubes with meshes for the applications that should be working with UGrid data, and that there is no mesh for applications that should be working with regular grid data.
I'd like the validation to be on load or at worst immediately after load: it gives us a chance to give a clear error message (a message saying "loading wrong type of data" is more useful than a message saying "tried to access a mesh but couldn't find it" - the first is definitely a load problem; the second could be a problem in subsequent processing), and it gives the error message before any expensive or time consuming processing has occurred.
A callback seemed a good way to ensure the load and the validation were "simultaneous" (I think it may have been yourself that suggested a callback?), but it's starting to look like the combination of callback and constraint is cryptic enough that we may want to go "load then validate" rather than "validate during load".
This has been worked on, but should remain open until #6014 can be implemented.
After #6122 is complete: we should investigate how the new 'correct' subsetting of meshes affects this issue. I have added this to the task-list in #6120.
🐛 Bug Report
When applying a constraint on a
MeshCoord
and a callback which checks the loaded cube has a mesh, the callback is not applied on the returned cube.How To Reproduce
Steps to reproduce the behaviour:
MeshCoord
) and pass the custom callback.MeshCoord
s have been converted toAuxCoord
s as expected, but no exception was raised.Expected behaviour
I expected an exception to have been raised by the custom callback function, since the returned cube has no mesh.
Reproducible example
Output:
Environment