Repository navigation
Conversation
Applies the given encoding (e.g. {"zlib": True, "complevel": 4}) to
every array in the dataset, so callers no longer need linopy's internal
variable names to compress the file. Explicit `encoding` entries take
precedence.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build cost — v1 vs legacyv1 build peak & time relative to legacy, on this commit — not a comparison against master (that is CodSpeed).
Full table (time + peak, mean)📊 Interactive plots + CSV: download the semantics-report-v1-vs-legacy artifact from this run. Report-only · not a gate · refreshed on every push · obsolete once legacy is dropped. |
Merging this PR will not alter performance
Comparing Footnotes
|
This branch has not been deployed
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.
The linopy model does currently not have an easy way to add compression options to all variables since the name of quite some variables depend on factors like whether they are frozen or MultiIndex'ed.
Thus, this PR adds a simple compression argument to Model.to_netcdf which is applied to the encoding and enabled by default.
Note
The following content was generated by AI.
Add
compressionoption toModel.to_netcdf, on by defaultModel.to_netcdfforwards**kwargstoxarray.Dataset.to_netcdf, but compressing the file required a per-variableencodingkeyed by linopy's internal names (variables-x-labels,constraints-c-…), which callers can't know in advance.This adds a keyword-only
compressionargument, applied to every array in the dataset:compression=Trueapplies{"zlib": True, "complevel": 3}. This also affects the internal writes inremote/ssh.pyandremote/oetc.py..encoding, on the merged dataset that gets written, not on the model's own arrays. As a result:.encoding(e.g.dtype,complevel) win overcompression;encoding=passed to xarray replaces its encoding entirely, as in plain xarray;scipy/netCDF3, in-memory bytes) silently ignore it, so the default never breaks a write. An explicit dict is likewise ignored there.netcdf4andh5netcdfskip compression on those without raising an error.Works for regular and frozen (
CSRConstraint) constraints, whose CSR components are written as plain 1-D arrays. On a 2000-row toy model withzlib/complevel=4, the file shrinks about 5×.Tests
test_model_to_netcdf_compression:encodingentry wins overcompression;assert_model_equal.test_model_to_netcdf_compression_non_numeric_coords: datetime and timedelta coordinates are compressed on variables and frozen constraints, and string coordinates don't break writing or reading back.test_model_to_netcdf_default_compression: the default appliescomplevel=3, andcompression=Falseturns it off.test_model_to_netcdf_compression_keeps_array_encoding: a user-set.encodingon a model array wins, and the model itself isn't modified.test_model_to_netcdf_compression_scipy:scipywrites with both the default and an explicit dict.All pass with
netcdf4, and withh5netcdfinstalled.🤖 Generated with Claude Code