-
Notifications
You must be signed in to change notification settings - Fork 7
Support JWST and Roman #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dc40329
feat: extensions/tags fallback
icweaver 56a8c33
feat: checksum validation flag
icweaver 0d425a0
feat: autodetect block or frame layout for Lz4 compression (needed fo…
icweaver a821211
Merge branch 'main' into strict
icweaver e012b21
feat: add Lz4 block writing for python asdf compat
icweaver e5b6bd4
refactor: rename layout --> lz4_layout
icweaver c305d7a
Merge branch 'main' into strict
icweaver c2af315
Merge branch 'main' into strict
icweaver c67bc14
test: update
icweaver 4e591e7
Merge branch 'main' into strict
icweaver e9a377d
test: update
icweaver ab17e30
test: added some
icweaver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| function write_asdf(dir, body) | ||
| path = joinpath(dir, "temp.asdf") | ||
| open(path, "w") do io | ||
| print(io, | ||
| """ | ||
| #ASDF 1.0.0 | ||
| #ASDF_STANDARD 1.2.0 | ||
| # This is an ASDF file <https://asdf-standard.readthedocs.io/> | ||
| %YAML 1.1 | ||
| %TAG ! tag:stsci.edu:asdf/ | ||
| --- | ||
| !core/asdf-1.1.0 | ||
| $(body) | ||
| ... | ||
| """ | ||
| ) | ||
| end | ||
| return path | ||
| end | ||
|
|
||
| load_tag(tag; kwargs...) = mktempdir() do dir | ||
| path = write_asdf(dir, tag) | ||
| af = ASDF.load_file(path; kwargs...) | ||
| end | ||
|
|
||
| @testset "unknown mapping" begin | ||
| tag_unknown_mapping = """ | ||
| known_key: hello | ||
| custom_obj: !<tag:example.org:mylib/widget-1.0.0> | ||
| width: 42 | ||
| height: 7 | ||
| """ | ||
|
|
||
| # The default `extensions = false` case | ||
| @test_throws Exception load_tag(tag_unknown_mapping; extensions = false) | ||
| @test_throws Exception load_tag(tag_unknown_sequence; extensions = false) | ||
| @test_throws Exception load_tag(tag_unknown_scalar; extensions = false) | ||
|
|
||
| # Should fall back to an `AbstractDict` | ||
| af = load_tag(tag_unknown_mapping; extensions = true) | ||
| obj = af.metadata["custom_obj"] | ||
| @test obj isa AbstractDict | ||
| @test obj["width"] == 42 | ||
| @test obj["height"] == 7 | ||
|
|
||
| # Known key still parsed as normal | ||
| @test af.metadata["known_key"] == "hello" | ||
|
|
||
| # And loading the file multiple times does not mutate any shared/global state | ||
| af1 = load_tag(tag_unknown_mapping; extensions = true) | ||
| af2 = load_tag(tag_unknown_mapping; extensions = true) | ||
| @test af1.metadata["custom_obj"]["width"] == af2.metadata["custom_obj"]["width"] | ||
| end | ||
|
|
||
| @testset "unknown sequence" begin | ||
| tag_unknown_sequence = """ | ||
| known_key: hello | ||
| custom_list: !<tag:example.org:mylib/series-1.0.0> | ||
| - alpha | ||
| - beta | ||
| - gamma | ||
| """ | ||
|
|
||
| # Should fall back to an `AbstractVector` | ||
| af = load_tag(tag_unknown_sequence; extensions = true) | ||
| list = af.metadata["custom_list"] | ||
|
|
||
| @test list isa AbstractVector | ||
| @test length(list) == 3 | ||
| @test list[1] == "alpha" | ||
| @test list[2] == "beta" | ||
| @test list[3] == "gamma" | ||
|
|
||
| end | ||
|
|
||
| @testset "unknown scalar" begin | ||
| tag_unknown_scalar = """ | ||
| known_key: hello | ||
| custom_value: !<tag:example.org:mylib/quantity-1.0.0> 3.14 | ||
| """ | ||
|
|
||
| # Should fall back to an `AbstractString` | ||
| af = load_tag(tag_unknown_scalar; extensions = true) | ||
| value = af.metadata["custom_value"] | ||
|
|
||
| @test value isa AbstractString | ||
| @test value == "3.14" | ||
| end | ||
|
|
||
| @testset "unknown all" begin | ||
| tag_unknown_all = """ | ||
| known_key: hello | ||
| mapping_node: !<tag:example.org:mylib/widget-1.0.0> | ||
| width: 42 | ||
| height: 7 | ||
| sequence_node: !<tag:example.org:mylib/series-1.0.0> | ||
| - alpha | ||
| - beta | ||
| scalar_node: !<tag:example.org:mylib/quantity-1.0.0> 3.14 | ||
| """ | ||
|
|
||
| # Fallbacks should also work if all unknowns are present in the same file. | ||
| af = load_tag(tag_unknown_all; extensions = true) | ||
| md = af.metadata | ||
|
|
||
| # Mapping branch | ||
| @test md["mapping_node"] isa AbstractDict | ||
| @test md["mapping_node"]["width"] == 42 | ||
|
|
||
| # Sequence branch | ||
| @test md["sequence_node"] isa AbstractVector | ||
| @test md["sequence_node"][1] == "alpha" | ||
|
|
||
| # Scalar branch | ||
| @test md["scalar_node"] isa AbstractString | ||
| @test md["scalar_node"] == "3.14" | ||
|
|
||
| # Known key unaffected | ||
| @test md["known_key"] == "hello" | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also produce the block layout? Should we? Can Python handle the frame layout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reminding me, will add that in. Looks like they can, but as a plug-in https://github.com/asdf-format/asdf-compression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in e012b21
There is a
layoutoption forNDArrayWrappernow to flip between frame and block. Does that seem like a reasonable place to control things? I guess it doesn't really make sense for other compression schemes, so I just set the default layout asdefaultI don't love from a maintainability point of view that there is now a hand-rolled Lz4-specific encode and decode path to accommodate Python's asdf scheme. There's also the matter of compatibility with Lz4 frame support on the Python side, but since that's still an experimental plugin, maybe that can be a problem for future us to deal with.
I am now squarely out of my comfort zone and would gladly accept any suggestions for simplifying things, haha. Thanks again for taking a look!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is only for lz4 then I would call it
lz4_layout, with values:frameand:block. I am sure that other compression schemes will also want to have options in the future, e.g. specifying the compression level.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, just renamed here e5b6bd4