forked from caviere/testing_zipstore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
90 lines (61 loc) · 2.13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import zarr
def open_zipstore_with_zarr(filepath):
try:
with zarr.ZipStore(filepath, mode="r") as store:
root = zarr.open_group(store, mode="r")
# print(root.info)
print("open with zarr:", "OK")
except Exception as e:
print("open with zarr:", e)
def open_zipstore_with_xarray(filepath):
import xarray as xr
try:
with zarr.ZipStore(filepath, mode="r") as store:
ds = xr.open_zarr(store, consolidated=False)
# print(ds.compute())
print("open with xarray:", "OK")
except Exception as e:
print("open with xarray:", e)
def open_zipstore_with_netcdf4(filepath):
# there is no way to open zarr zipstore directly from the netcdf4 library
import netCDF4 as nc
try:
ds = nc.Dataset(filepath, mode="r", format="NCZarr")
ds.close()
print("open with netcdf4:", "OK")
except Exception as e:
print("open with netcdf4:", e)
def open_zipstore_with_h5py(filepath):
import h5py
if h5py.is_hdf5(filepath):
f = h5py.File(filepath, "r")
f.close()
print("open with h5py:", "OK")
else:
print("open with h5py:", "Not a valid HDFS file")
def open_zipstore_with_fsspec(filepath):
import zarr.storage
try:
store = zarr.storage.FSStore(
url=f"zip::file://{filepath}", mode="r"
)
# z = zarr.open(store=store, mode="r")
# print(z.info)
except Exception as e:
print("open with fsspec(zip):", e)
def open_zipstore_with_gdal(filepath):
from osgeo import gdal
# full_filepath = f'ZARR:"{os.path.abspath(filepath)}"'
ds = gdal.OpenEx(f'ZARR:{filepath}', gdal.OF_MULTIDIM_RASTER)
assert ds is not None
def main():
# from url: https://zenodo.org/record/5745520#.Y8qxtBxByV4
filepath = "datasets/ESP0025722.zip"
open_zipstore_with_zarr(filepath)
open_zipstore_with_xarray(filepath)
open_zipstore_with_netcdf4(filepath)
open_zipstore_with_h5py(filepath)
open_zipstore_with_fsspec(filepath)
open_zipstore_with_gdal(filepath)
if __name__ == "__main__":
main()