Skip to content

Commit 4524240

Browse files
authored
Merge pull request #23 from davidbrochart/local_fs
Overload hierarchy creation with local file system store
2 parents 90d13d9 + 16aa4b1 commit 4524240

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed

examples/explore_hierarchy.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@
146146
"outputs": [],
147147
"source": [
148148
">xcpp14\n",
149-
"xt::xzarr_file_system_store s1(\"test.zr3\");\n",
150-
"auto h1 = xt::get_zarr_hierarchy(s1);"
149+
"auto h1 = xt::get_zarr_hierarchy(\"test.zr3\");"
151150
]
152151
},
153152
{

examples/zarr_v2.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@
191191
"source": [
192192
">xcpp14\n",
193193
"xt::xzarr_register_compressor<xt::xzarr_file_system_store, xt::xio_blosc_config>();\n",
194-
"xt::xzarr_file_system_store s(\"marie_curie.zarr\");\n",
195-
"auto h = xt::get_zarr_hierarchy(s, \"2\");\n",
194+
"auto h = xt::get_zarr_hierarchy(\"marie_curie.zarr\", \"2\");\n",
196195
"auto z = h.get_array(\"\");"
197196
]
198197
},

examples/zarr_v3.ipynb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@
150150
"outputs": [],
151151
"source": [
152152
">xcpp14\n",
153-
"xt::xzarr_file_system_store s1(\"h_zarrita.zr3\");\n",
154-
"auto h1 = xt::get_zarr_hierarchy(s1);\n",
153+
"auto h1 = xt::get_zarr_hierarchy(\"h_zarrita.zr3\");\n",
155154
"xt::zarray z1 = h1.get_array(\"/arthur/dent\");"
156155
]
157156
},
@@ -170,7 +169,7 @@
170169
"source": [
171170
">xcpp14\n",
172171
"auto a1 = z1.get_array<double>();\n",
173-
"std::cout << a1 << std::endl;"
172+
"a1"
174173
]
175174
},
176175
{
@@ -192,8 +191,7 @@
192191
"nlohmann::json attrs = {{\"question\", \"life\"}, {\"answer\", 42}};\n",
193192
"std::size_t pool_size = 1;\n",
194193
"double fill_value = 6.6;\n",
195-
"xt::xzarr_file_system_store s2(\"h_xtensor.zr3\");\n",
196-
"auto h2 = xt::create_zarr_hierarchy(s2);\n",
194+
"auto h2 = xt::create_zarr_hierarchy(\"h_xtensor.zr3\");\n",
197195
"xt::zarray z2 = h2.create_array(\"/arthur/dent\", shape, chunk_shape, \"<f8\", 'C', '/', xt::xio_binary_config(), attrs, pool_size, fill_value);"
198196
]
199197
},
@@ -262,7 +260,7 @@
262260
"auto h3 = xt::get_zarr_hierarchy(s3);\n",
263261
"xt::zarray z3 = h3.get_array(\"/arthur/dent\");\n",
264262
"auto a3 = z3.get_array<int32_t>();\n",
265-
"std::cout << a3 << std::endl;"
263+
"a3"
266264
]
267265
}
268266
],

include/xtensor-zarr/xzarr_hierarchy.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "xzarr_array.hpp"
1717
#include "xzarr_group.hpp"
1818
#include "xzarr_common.hpp"
19+
#include "xzarr_file_system_store.hpp"
1920

2021
namespace xt
2122
{
@@ -50,7 +51,7 @@ namespace xt
5051
nlohmann::json get_nodes(const std::string& path="/");
5152

5253
private:
53-
store_type& m_store;
54+
store_type m_store;
5455
std::string m_zarr_version;
5556
};
5657

@@ -140,6 +141,17 @@ namespace xt
140141
return h;
141142
}
142143

144+
xzarr_hierarchy<xzarr_file_system_store> create_zarr_hierarchy(const char* local_store_path, const std::string& zarr_version = "3")
145+
{
146+
xzarr_file_system_store store(local_store_path);
147+
return create_zarr_hierarchy(store, zarr_version);
148+
}
149+
150+
xzarr_hierarchy<xzarr_file_system_store> create_zarr_hierarchy(const std::string& local_store_path, const std::string& zarr_version = "3")
151+
{
152+
return create_zarr_hierarchy(local_store_path.c_str(), zarr_version);
153+
}
154+
143155
/**
144156
* Accesses a Zarr hierarchy.
145157
* This function returns a ``xzarr_hierarchy`` handler to a hierarchy in a given store.
@@ -176,6 +188,18 @@ namespace xt
176188
xzarr_hierarchy<store_type> h(store, zarr_ver);
177189
return h;
178190
}
191+
192+
xzarr_hierarchy<xzarr_file_system_store> get_zarr_hierarchy(const char* local_store_path, const std::string& zarr_version = "0")
193+
{
194+
xzarr_file_system_store store(local_store_path);
195+
return get_zarr_hierarchy(store, zarr_version);
196+
}
197+
198+
xzarr_hierarchy<xzarr_file_system_store> get_zarr_hierarchy(const std::string& local_store_path, const std::string& zarr_version = "0")
199+
{
200+
return get_zarr_hierarchy(local_store_path.c_str(), zarr_version);
201+
}
202+
179203
}
180204

181205
#endif

test/test_zarr.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ namespace xt
2626
TEST(xzarr_hierarchy, read_v2)
2727
{
2828
xzarr_register_compressor<xzarr_file_system_store, xio_gzip_config>();
29-
xzarr_file_system_store s("h_zarr.zr2");
30-
auto h = get_zarr_hierarchy(s);
29+
auto h = get_zarr_hierarchy("h_zarr.zr2");
3130
zarray z = h.get_array("/arthur/dent");
3231
auto ref = arange(2 * 5).reshape({2, 5});
3332
auto a = z.get_array<double>();
@@ -37,8 +36,7 @@ namespace xt
3736

3837
TEST(xzarr_hierarchy, read_array)
3938
{
40-
xzarr_file_system_store s("h_zarrita.zr3");
41-
auto h = get_zarr_hierarchy(s);
39+
auto h = get_zarr_hierarchy("h_zarrita.zr3");
4240
zarray z = h.get_array("/arthur/dent");
4341
auto ref = arange(2 * 5).reshape({2, 5});
4442
auto a = z.get_array<double>();
@@ -53,8 +51,7 @@ namespace xt
5351
nlohmann::json attrs = {{"question", "life"}, {"answer", 42}};
5452
std::size_t pool_size = 1;
5553
double fill_value = 6.6;
56-
xzarr_file_system_store s("h_xtensor.zr3");
57-
auto h = create_zarr_hierarchy(s);
54+
auto h = create_zarr_hierarchy("h_xtensor.zr3");
5855
zarray z1 = h.create_array("/arthur/dent", shape, chunk_shape, "<f8", 'C', '/', xio_gzip_config(), attrs, pool_size, fill_value);
5956
//xchunked_array_factory<xzarr_file_system_store>::add_dtype<half_float::half>("f2");
6057
//auto a1 = z1.get_array<double>();
@@ -80,8 +77,7 @@ namespace xt
8077

8178
TEST(xzarr_hierarchy, create_group)
8279
{
83-
xzarr_file_system_store store1("h_xtensor.zr3");
84-
auto h1 = get_zarr_hierarchy(store1);
80+
auto h1 = get_zarr_hierarchy("h_xtensor.zr3");
8581
nlohmann::json attrs = {{"heart", "gold"}, {"improbability", "infinite"}};
8682
auto g1 = h1.create_group("/tricia/mcmillan", attrs);
8783
// since "/tricia/mcmillan" is a group, it should not be possible to get it as an array
@@ -90,8 +86,7 @@ namespace xt
9086

9187
TEST(xzarr_hierarchy, create_node)
9288
{
93-
xzarr_file_system_store store1("h_xtensor.zr3");
94-
auto h1 = get_zarr_hierarchy(store1);
89+
auto h1 = get_zarr_hierarchy("h_xtensor.zr3");
9590
h1.create_group("/marvin");
9691
h1["/marvin"].create_group("paranoid");
9792
std::vector<size_t> shape = {5, 5};
@@ -103,8 +98,7 @@ namespace xt
10398

10499
TEST(xzarr_hierarchy, explore)
105100
{
106-
xzarr_file_system_store store1("h_xtensor.zr3");
107-
auto h1 = get_zarr_hierarchy(store1);
101+
auto h1 = get_zarr_hierarchy("h_xtensor.zr3");
108102
std::string children = h1.get_children("/").dump();
109103
std::string ref1 = "{\"arthur\":\"implicit_group\",\"marvin\":\"explicit_group\",\"tricia\":\"implicit_group\"}";
110104
EXPECT_EQ(children, ref1);
@@ -187,8 +181,7 @@ namespace xt
187181
std::size_t pool_size = 1;
188182
double fill_value = 6.6;
189183
std::string zarr_version = "2";
190-
xzarr_file_system_store s("h_xtensor.zr2");
191-
auto h = create_zarr_hierarchy(s, zarr_version);
184+
auto h = create_zarr_hierarchy("h_xtensor.zr2", zarr_version);
192185
zarray z1 = h.create_array("/arthur/dent", shape, chunk_shape, "<f8", 'C', '.', xio_gzip_config(), attrs, pool_size, fill_value);
193186
}
194187
}

0 commit comments

Comments
 (0)