|
1 | 1 | import os
|
2 | 2 | import s3fs
|
3 | 3 | import pathlib
|
| 4 | +import pyfive |
4 | 5 | import pytest
|
5 | 6 | import h5netcdf
|
| 7 | +import numpy as np |
6 | 8 |
|
7 | 9 | from tempfile import NamedTemporaryFile
|
8 |
| -from activestorage.active import load_from_s3 |
| 10 | +from activestorage.active import load_from_s3, Active |
9 | 11 |
|
10 | 12 |
|
11 | 13 | # needed by the spoofed s3 filesystem
|
@@ -133,17 +135,29 @@ def test_s3file_with_s3fs(s3fs_s3):
|
133 | 135 | anon=False, version_aware=True, client_kwargs={"endpoint_url": endpoint_uri}
|
134 | 136 | )
|
135 | 137 |
|
136 |
| - # test load by h5netcdf |
| 138 | + # test load by standard h5netcdf |
137 | 139 | with s3.open(os.path.join("MY_BUCKET", file_name), "rb") as f:
|
138 | 140 | print("File path", f.path)
|
139 | 141 | ncfile = h5netcdf.File(f, 'r', invalid_netcdf=True)
|
140 | 142 | print("File loaded from spoof S3 with h5netcdf:", ncfile)
|
141 | 143 | print(ncfile["ta"])
|
142 | 144 | assert "ta" in ncfile
|
143 | 145 |
|
144 |
| - # test Active |
| 146 | + # test active.load_from_s3 |
145 | 147 | storage_options = dict(anon=False, version_aware=True,
|
146 | 148 | client_kwargs={"endpoint_url": endpoint_uri})
|
147 | 149 | with load_from_s3(os.path.join("MY_BUCKET", file_name), storage_options) as ac_file:
|
148 | 150 | print(ac_file)
|
149 | 151 | assert "ta" in ac_file
|
| 152 | + |
| 153 | + # test loading with Pyfive and passing the Dataset to Active |
| 154 | + with s3.open(os.path.join("MY_BUCKET", file_name), "rb") as f: |
| 155 | + print("File path", f.path) |
| 156 | + pie_ds = pyfive.File(f, 'r') |
| 157 | + print("File loaded from spoof S3 with Pyfive:", pie_ds) |
| 158 | + print("Pyfive dataset:", pie_ds["ta"]) |
| 159 | + av = Active(pie_ds["ta"]) |
| 160 | + av._method = "min" |
| 161 | + assert av.method([3,444]) == 3 |
| 162 | + av_slice_min = av[3:5] |
| 163 | + assert av_slice_min == np.array(249.6583, dtype="float32") |
0 commit comments