|
2 | 2 | #include <xtensor-io/xio_zlib.hpp>
|
3 | 3 | #include <xtensor-io/xio_blosc.hpp>
|
4 | 4 | #include <xtensor-io/ximage.hpp>
|
| 5 | +#include <xtensor-io/xnpz.hpp> |
5 | 6 | #include <xtensor-zarr/xzarr_hierarchy.hpp>
|
6 | 7 |
|
7 | 8 | using namespace xt;
|
8 | 9 |
|
9 |
| -int main() |
| 10 | +int main(int argc, char** argv) |
10 | 11 | {
|
11 |
| - namespace fs = ghc::filesystem; |
12 |
| - const std::string hier_path = "../../../data/xtensor_zarr.zr"; |
13 |
| - fs::remove_all(hier_path); |
14 |
| - fs::create_directory(hier_path); |
15 |
| - const auto img = load_image("../../../data/reference_image.png"); |
16 |
| - |
17 |
| - const auto& s = img.shape(); |
18 |
| - std::vector<size_t> shape; |
19 |
| - std::copy(s.cbegin(), s.cend(), std::back_inserter(shape)); |
20 |
| - std::vector<size_t> chunk_shape = {100, 100, 1}; |
21 |
| - auto h = create_zarr_hierarchy(hier_path, "2"); |
22 |
| - auto g = h.create_group("/"); |
23 |
| - |
24 |
| - // raw |
25 |
| - xzarr_create_array_options<xio_binary_config> raw_options; |
26 |
| - raw_options.fill_value = 0; |
27 |
| - zarray z_raw = h.create_array("/raw", shape, chunk_shape, "|u1", raw_options); |
28 |
| - noalias(z_raw) = img; |
29 |
| - |
30 |
| - // gzip |
31 | 12 | xzarr_register_compressor<xzarr_file_system_store, xio_gzip_config>();
|
32 |
| - xzarr_create_array_options<xio_gzip_config> gzip_options; |
33 |
| - gzip_options.fill_value = 0; |
34 |
| - zarray z_gzip = h.create_array("/gzip", shape, chunk_shape, "|u1", gzip_options); |
35 |
| - noalias(z_gzip) = img; |
36 |
| - |
37 |
| - // zlib |
38 | 13 | xzarr_register_compressor<xzarr_file_system_store, xio_zlib_config>();
|
39 |
| - xzarr_create_array_options<xio_zlib_config> zlib_options; |
40 |
| - zlib_options.fill_value = 0; |
41 |
| - zarray z_zlib = h.create_array("/zlib", shape, chunk_shape, "|u1", zlib_options); |
42 |
| - noalias(z_zlib) = img; |
43 |
| - |
44 |
| - // blosc |
45 | 14 | xzarr_register_compressor<xzarr_file_system_store, xio_blosc_config>();
|
46 |
| - xio_blosc_config blosc_config; |
47 |
| - blosc_config.cname = "lz4"; |
48 |
| - xzarr_create_array_options<xio_blosc_config> blosc_options; |
49 |
| - blosc_options.fill_value = 0; |
50 |
| - blosc_options.compressor = blosc_config; |
51 |
| - auto g_blosc = h.create_group("/blosc/"); |
52 |
| - zarray z_blosc_lz4 = h.create_array("/blosc/lz4", shape, chunk_shape, "|u1", blosc_options); |
53 |
| - noalias(z_blosc_lz4) = img; |
| 15 | + |
| 16 | + if (argc == 1) |
| 17 | + { |
| 18 | + namespace fs = ghc::filesystem; |
| 19 | + std::string hier_path = "../../../data/xtensor_zarr.zr"; |
| 20 | + const auto img = load_image("../../../data/reference_image.png"); |
| 21 | + |
| 22 | + const auto& s = img.shape(); |
| 23 | + std::vector<size_t> shape; |
| 24 | + std::copy(s.cbegin(), s.cend(), std::back_inserter(shape)); |
| 25 | + std::vector<size_t> chunk_shape = {100, 100, 1}; |
| 26 | + |
| 27 | + char zarr_version[2] = "2"; |
| 28 | + const char* data_type = "|u1"; |
| 29 | + |
| 30 | + for (int v = 2; v <= 3; v++) |
| 31 | + { |
| 32 | + if (v == 3) |
| 33 | + { |
| 34 | + hier_path += "3"; |
| 35 | + zarr_version[0] = '3'; |
| 36 | + data_type ++; |
| 37 | + } |
| 38 | + fs::remove_all(hier_path); |
| 39 | + fs::create_directory(hier_path); |
| 40 | + auto h = create_zarr_hierarchy(hier_path.c_str(), zarr_version); |
| 41 | + auto g = h.create_group("/"); |
| 42 | + |
| 43 | + // raw |
| 44 | + xzarr_create_array_options<xio_binary_config> raw_options; |
| 45 | + raw_options.fill_value = 0; |
| 46 | + zarray z_raw = h.create_array("/raw", shape, chunk_shape, data_type, raw_options); |
| 47 | + noalias(z_raw) = img; |
| 48 | + |
| 49 | + // gzip |
| 50 | + xzarr_create_array_options<xio_gzip_config> gzip_options; |
| 51 | + gzip_options.fill_value = 0; |
| 52 | + zarray z_gzip = h.create_array("/gzip", shape, chunk_shape, data_type, gzip_options); |
| 53 | + noalias(z_gzip) = img; |
| 54 | + |
| 55 | + // zlib |
| 56 | + xzarr_create_array_options<xio_zlib_config> zlib_options; |
| 57 | + zlib_options.fill_value = 0; |
| 58 | + zarray z_zlib = h.create_array("/zlib", shape, chunk_shape, data_type, zlib_options); |
| 59 | + noalias(z_zlib) = img; |
| 60 | + |
| 61 | + // blosc |
| 62 | + xio_blosc_config blosc_config; |
| 63 | + blosc_config.cname = "lz4"; |
| 64 | + xzarr_create_array_options<xio_blosc_config> blosc_options; |
| 65 | + blosc_options.fill_value = 0; |
| 66 | + blosc_options.compressor = blosc_config; |
| 67 | + auto g_blosc = h.create_group("/blosc/"); |
| 68 | + zarray z_blosc_lz4 = h.create_array("/blosc/lz4", shape, chunk_shape, data_type, blosc_options); |
| 69 | + noalias(z_blosc_lz4) = img; |
| 70 | + } |
| 71 | + } |
| 72 | + else |
| 73 | + { |
| 74 | + const std::string hier_path = argv[1]; |
| 75 | + std::string ds_name = argv[2]; |
| 76 | + const std::string v3_ext = ".zr3"; |
| 77 | + std::string array_path; |
| 78 | + if (hier_path.compare(hier_path.length() - v3_ext.length(), v3_ext.length(), v3_ext) == 0) |
| 79 | + { |
| 80 | + array_path = hier_path; |
| 81 | + ds_name = "/" + ds_name; |
| 82 | + } |
| 83 | + else |
| 84 | + { |
| 85 | + array_path = hier_path + '/' + ds_name; |
| 86 | + ds_name = ""; |
| 87 | + } |
| 88 | + |
| 89 | + auto h = get_zarr_hierarchy(array_path.c_str()); |
| 90 | + auto z = h.get_array(ds_name); |
| 91 | + auto a = z.get_array<uint8_t>(); |
| 92 | + |
| 93 | + dump_npz("a.npz", "a", a, false, false); |
| 94 | + } |
54 | 95 |
|
55 | 96 | return 0;
|
56 | 97 | }
|
0 commit comments