-
Notifications
You must be signed in to change notification settings - Fork 59
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
1 parent
640ecb2
commit d49e20a
Showing
27 changed files
with
572 additions
and
102 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
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,80 @@ | ||
import zipfile | ||
from pathlib import Path | ||
from urllib.parse import urlparse | ||
from urllib.request import url2pathname | ||
from zipfile import ZipFile | ||
|
||
from compliance_checker.protocols import netcdf | ||
|
||
# | ||
|
||
|
||
def is_zarr(url): | ||
""" """ | ||
|
||
if netcdf.is_netcdf(url): | ||
return False | ||
|
||
if ".zarr" in url: | ||
return True | ||
|
||
if urlparse(url).scheme in ("https", "s3", "file"): | ||
return True | ||
|
||
if zipfile.is_zipfile(url): | ||
if ".zmetadata" in ZipFile(url).namelist(): | ||
return True | ||
|
||
if Path(url).is_dir(): | ||
if (Path(url) / ".zmetadata").exists(): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def as_zarr(url): | ||
""" | ||
Transform pointers to zarr datasets to valid nczarr urls, as described in | ||
https://www.unidata.ucar.edu/blogs/developer/entry/overview-of-zarr-support-in\n | ||
url: str or Path to valid zarr dataset\n | ||
Distinct from is_cdl etc in that it will return the appropriate URI \n\n | ||
Not tested on Windows paths at the moment, as NCZarr is not supported in Windows\n | ||
A valid Zarr dataset could be provided in any of the following forms:\n | ||
"http://s3.amazonaws.com/bucket/dataset.zarr"\n | ||
"http://s3.amazonaws.com/bucket/dataset.zarr"#mode=nczarr,s3\n | ||
"/home/path/to/dataset.zarr"\n | ||
Path('/home/path/to/dataset.zarr')\n | ||
"file:///home/path/to/dataset.zarr"\n | ||
"file:///home/path/to/dataset.randomExt#mode=nczarr,file" | ||
"file:///home/path/to/dataset.zarr#mode=nczarr,zip" | ||
""" | ||
|
||
pr = urlparse(str(url)) | ||
|
||
if "mode=nczarr" in pr.fragment: | ||
if pr.netloc: | ||
return str(url) # already valid nczarr url | ||
elif pr.scheme == "file": | ||
return str(url) # already valid nczarr url | ||
|
||
zarr_url = Path( | ||
url2pathname(pr.path), | ||
).resolve() # url2pathname necessary to avoid urlparse bug in windows | ||
|
||
if pr.netloc: | ||
mode = "s3" | ||
elif zipfile.is_zipfile(zarr_url): | ||
mode = "zip" | ||
elif zarr_url.is_dir(): | ||
mode = "file" | ||
else: | ||
raise ValueError( | ||
f"Could not identify {url},\nif #mode=nczarr,zarr, please pass this explicitly\nValid url options are described here\nhttps://www.unidata.ucar.edu/blogs/developer/entry/overview-of-zarr-support-in", | ||
) | ||
|
||
url_base = url if mode == "s3" else zarr_url.as_uri() | ||
|
||
zarr_url = f"{url_base}#mode=nczarr,{mode}" | ||
return zarr_url | ||
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 @@ | ||
{} |
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,3 @@ | ||
{ | ||
"zarr_format": 2 | ||
} |
169 changes: 169 additions & 0 deletions
169
compliance_checker/tests/data/trajectory.zarr/.zmetadata
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,169 @@ | ||
{ | ||
"metadata": { | ||
".zattrs": {}, | ||
".zgroup": { | ||
"zarr_format": 2 | ||
}, | ||
"lat/.zarray": { | ||
"chunks": [ | ||
2, | ||
3 | ||
], | ||
"compressor": { | ||
"blocksize": 0, | ||
"clevel": 5, | ||
"cname": "lz4", | ||
"id": "blosc", | ||
"shuffle": 1 | ||
}, | ||
"dtype": "<f4", | ||
"fill_value": "NaN", | ||
"filters": null, | ||
"order": "C", | ||
"shape": [ | ||
2, | ||
3 | ||
], | ||
"zarr_format": 2 | ||
}, | ||
"lat/.zattrs": { | ||
"_ARRAY_DIMENSIONS": [ | ||
"trajectory", | ||
"obs" | ||
], | ||
"axis": "Y", | ||
"long_name": "Latitude", | ||
"standard_name": "latitude", | ||
"units": "degrees_north" | ||
}, | ||
"lon/.zarray": { | ||
"chunks": [ | ||
2, | ||
3 | ||
], | ||
"compressor": { | ||
"blocksize": 0, | ||
"clevel": 5, | ||
"cname": "lz4", | ||
"id": "blosc", | ||
"shuffle": 1 | ||
}, | ||
"dtype": "<f4", | ||
"fill_value": "NaN", | ||
"filters": null, | ||
"order": "C", | ||
"shape": [ | ||
2, | ||
3 | ||
], | ||
"zarr_format": 2 | ||
}, | ||
"lon/.zattrs": { | ||
"_ARRAY_DIMENSIONS": [ | ||
"trajectory", | ||
"obs" | ||
], | ||
"axis": "X", | ||
"long_name": "Longitude", | ||
"standard_name": "longitude", | ||
"units": "degrees_east" | ||
}, | ||
"temperature/.zarray": { | ||
"chunks": [ | ||
2, | ||
3, | ||
5 | ||
], | ||
"compressor": { | ||
"blocksize": 0, | ||
"clevel": 5, | ||
"cname": "lz4", | ||
"id": "blosc", | ||
"shuffle": 1 | ||
}, | ||
"dtype": "<f4", | ||
"fill_value": "NaN", | ||
"filters": null, | ||
"order": "C", | ||
"shape": [ | ||
2, | ||
3, | ||
5 | ||
], | ||
"zarr_format": 2 | ||
}, | ||
"temperature/.zattrs": { | ||
"_ARRAY_DIMENSIONS": [ | ||
"trajectory", | ||
"obs", | ||
"z" | ||
], | ||
"coordinates": "time lat lon z", | ||
"long_name": "Seawater Temperature", | ||
"standard_name": "sea_water_temperature", | ||
"units": "deg_C" | ||
}, | ||
"time/.zarray": { | ||
"chunks": [ | ||
2, | ||
3 | ||
], | ||
"compressor": { | ||
"blocksize": 0, | ||
"clevel": 5, | ||
"cname": "lz4", | ||
"id": "blosc", | ||
"shuffle": 1 | ||
}, | ||
"dtype": "<f8", | ||
"fill_value": "NaN", | ||
"filters": null, | ||
"order": "C", | ||
"shape": [ | ||
2, | ||
3 | ||
], | ||
"zarr_format": 2 | ||
}, | ||
"time/.zattrs": { | ||
"_ARRAY_DIMENSIONS": [ | ||
"trajectory", | ||
"obs" | ||
], | ||
"axis": "T", | ||
"long_name": "Time", | ||
"standard_name": "time", | ||
"units": "seconds since 1970-01-01T00:00:00Z" | ||
}, | ||
"z/.zarray": { | ||
"chunks": [ | ||
5 | ||
], | ||
"compressor": { | ||
"blocksize": 0, | ||
"clevel": 5, | ||
"cname": "lz4", | ||
"id": "blosc", | ||
"shuffle": 1 | ||
}, | ||
"dtype": "<f4", | ||
"fill_value": "NaN", | ||
"filters": null, | ||
"order": "C", | ||
"shape": [ | ||
5 | ||
], | ||
"zarr_format": 2 | ||
}, | ||
"z/.zattrs": { | ||
"_ARRAY_DIMENSIONS": [ | ||
"z" | ||
], | ||
"long_name": "Depth below surface", | ||
"positive": "down", | ||
"standard_name": "depth", | ||
"units": "m" | ||
} | ||
}, | ||
"zarr_consolidated_format": 1 | ||
} |
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,22 @@ | ||
{ | ||
"chunks": [ | ||
2, | ||
3 | ||
], | ||
"compressor": { | ||
"blocksize": 0, | ||
"clevel": 5, | ||
"cname": "lz4", | ||
"id": "blosc", | ||
"shuffle": 1 | ||
}, | ||
"dtype": "<f4", | ||
"fill_value": "NaN", | ||
"filters": null, | ||
"order": "C", | ||
"shape": [ | ||
2, | ||
3 | ||
], | ||
"zarr_format": 2 | ||
} |
Oops, something went wrong.