-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,56 @@ | ||
def cleanPath: . | sub("^\\.(?<x>.*)\\/.+"; "\(.x)"; "g"); | ||
|
||
def containsExactString($query): reduce .[] as $i (false; . or ($i == $query)); | ||
|
||
def hasAllKeys($queryKeys): keys as $keys | | ||
reduce ($queryKeys | .[] ) as $k (true; . and ( $keys | containsExactString($k))); | ||
|
||
def inExact($arr): reduce ($arr | .[]) as $v ([., false]; [.[0], .[1] or ($v == .[0])]) | .[1]; | ||
|
||
def zarrArrayKeys: ["zarr_format", "shape", "chunks", "dtype", "compressor", "fill_value", "order", | ||
"dimension_separator", "filters"]; | ||
|
||
def zarrGroupKeys: ["zarr_format"]; | ||
|
||
def isZarrArray: type == "object" and hasAllKeys( zarrArrayKeys ); | ||
|
||
def zarrArrayObj: zarrArrayKeys as $za | with_entries(select(.key | inExact( $za ))); | ||
|
||
def zarrArrayAttrs: zarrArrayKeys as $za | with_entries(select(.key | inExact( $za ) | not)); | ||
|
||
def zarrGroupObj: { "zarr_format" : .zarr_format }; | ||
|
||
def zarrGroupAttrs: zarrGroupKeys as $zg | with_entries(select(.key | inExact( $zg ) | not)); | ||
|
||
def zarrAttrs: . as $obj | | ||
if ($obj | isZarrArray) then | ||
{ | ||
".zarray" : ($obj | zarrArrayObj), | ||
".zattrs" : ($obj | zarrArrayAttrs) | ||
} | ||
else | ||
{ | ||
".zgroup" : ($obj | zarrGroupObj), | ||
".zattrs" : ($obj | zarrGroupAttrs) | ||
} | ||
end; | ||
|
||
def hasAttributes: type == "object" and has("attributes"); | ||
|
||
def zomTreePath: ltrimstr( "/") | split("/") | map_values( ["members", . ] ) | flatten; | ||
|
||
def zomAdd( $path; $attrs; $suffix ): | ||
($path | zomTreePath | . + $suffix) as $p | | ||
getpath( $p ) as $currentAttrs | | ||
setpath( $p; $currentAttrs + $attrs ); | ||
|
||
def zomAddFiles: | ||
reduce inputs as $i ({}; | ||
input_filename as $f | | ||
($f | cleanPath) as $p | | ||
if ($f | endswith(".zattrs")) then | ||
zomAdd( ($p | cleanPath); $i; ["attributes"] ) | ||
else | ||
zomAdd( ($p | cleanPath); $i; [] ) | ||
end); | ||
|