Opt-in array-backed loading for !include netCDF resources#4
Open
bjarketol wants to merge 1 commit into
Open
Conversation
Keep included netCDF data as numpy arrays instead of nested Python lists,
avoiding a ~4-28x memory blow-up for large resources:
- load_yaml/_get_YAML/_ds2yml gain an nc_data option ("list" default,
"array" keeps numpy arrays); nc_data propagates into nested includes
- _fmt is made ndarray-safe (the elementwise "!= {}" filter broke on arrays)
- validate() gains array_data=True for structure-only validation: arrays are
replaced by [] so jsonschema checks keys/dims without materialising or
iterating the bulk data
- tests for array round-trip equivalence and structure-only validation
Default behaviour (lists, full validation) is unchanged; both are opt-in.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in way to keep
!included netCDF resources as numpy arrays instead of nested Python lists, avoiding a large memory blow-up for big resources (e.g. per-turbine time series).load_yaml(..., nc_data="array")keeps included netCDF data as numpy arrays.nc_datais threaded through_get_YAML/_ds2ymland propagates into nested includes. Default ("list") is unchanged._fmtis made ndarray-safe (the elementwise!= {}filter raised on arrays).validate(..., array_data=True)adds structure-only validation for array-backed inputs: arrays are replaced by[]so jsonschema validates keys/dimswithout materialising or iterating the bulk data (jsonschema cannot accept ndarrays, and iterating large arrays isO(N)).Why
_ds2ymlcurrently callsxr.Dataset.to_dict(), which turns array data into nested Python lists — roughly 4–28× the numpy footprint (Python float objects vs packedfloat64). For large time-series resources this dominates load memory.Measured on a 16 MB
wind_resource.nc:nc_data="list"(default)nc_data="array"→ ~4× lower peak, with no change to default behaviour.
Compatibility
Both additions are opt-in; the default dict-of-lists representation and full validation are untouched, so existing consumers are unaffected. Includes tests for array round-trip equivalence and structure-only validation.
🤖 Generated with Claude Code