NOAA-ORR-ERD / gridded

A single API for accessing / working with gridded model results on multiple grid types
https://noaa-orr-erd.github.io/gridded/index.html
The Unlicense
64 stars 14 forks source link

Refactor validation of Variable:Grid compatibility #42

Open ChrisBarker-NOAA opened 5 years ago

ChrisBarker-NOAA commented 5 years ago

It is possible to create a either a Grid, Dataset, and Variable independenty and in any order. Which makes it tricky to validate whether they are compatible, e.g.

If a variable has a location n the nodes, then its last dimension should be the same as the number of nodes in the Grid. But that can't be checked until there is both a Grid and a Variable that are connected to each other.

Currently, this is handled by not validating, but rather calling "infer_location" whenever the location is needed, but this is pretty klunky, and requires a robust inferred location -- and if the user (Or input file) specifies a location that is not what would get inferred, it would be better to raise an error, rather then getting something different than what's expected.

So it seems that the validation should happen in the Dataset -- perhaps when the Variable is added to the Dataset. This is a bit tricky as currently Variables are simply in a dict. (this is why the old UGrid code had a add_data method). But we could work around that by making a "validating dict" that validated variables when they were added.