Skip to content

Commit 31afcb1

Browse files
authored
protect users from going oob with tile sizes (#140)
* protect users from going oob with tile sizes * fixing size of tile protection and test
1 parent 4b255ff commit 31afcb1

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/silvimetric/resources/storage.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,28 @@ def create(config: StorageConfig, ctx: tiledb.Ctx = None):
8787
(config.root.maxy - config.root.miny) / float(config.resolution)
8888
)
8989

90+
# protect user from out of bounds errors
91+
xsize = min(config.xsize, xi+1)
92+
ysize = min(config.ysize, yi+1)
93+
if xsize < config.xsize:
94+
config.log.warning(f'X Tile size lowered to {xsize}')
95+
if ysize < config.ysize:
96+
config.log.warning(f'Y Tile size lowered to {ysize}')
97+
config.xsize = xsize
98+
config.ysize = ysize
99+
90100
dim_row = tiledb.Dim(
91101
name='X',
92102
domain=(0, xi),
93103
dtype=np.uint64,
94-
tile=config.xsize,
104+
tile=xsize,
95105
filters=tiledb.FilterList([tiledb.ZstdFilter()]),
96106
)
97107
dim_col = tiledb.Dim(
98108
name='Y',
99109
domain=(0, yi),
100110
dtype=np.uint64,
101-
tile=config.ysize,
111+
tile=ysize,
102112
filters=tiledb.FilterList([tiledb.ZstdFilter()]),
103113
)
104114
domain = tiledb.Domain(dim_row, dim_col)

tests/test_storage.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pytest
44
import os
55
import copy
6-
import datetime
76

87
from silvimetric import (
98
Storage,
@@ -93,6 +92,39 @@ def test_metric_dependencies(
9392

9493
ms[0].dependencies = []
9594

95+
def test_oob_storage(
96+
self,
97+
tmp_path_factory,
98+
metrics,
99+
crs,
100+
resolution,
101+
attrs,
102+
bounds,
103+
):
104+
ms = copy.deepcopy(metrics)
105+
path = tmp_path_factory.mktemp('test_tdb')
106+
p = os.path.abspath(path)
107+
108+
sc = StorageConfig(
109+
tdb_dir=p,
110+
crs=crs,
111+
resolution=resolution,
112+
attrs=attrs,
113+
metrics=ms,
114+
root=bounds,
115+
xsize=1000,
116+
ysize=1000
117+
)
118+
119+
s = Storage.create(sc)
120+
a = s.open('r')
121+
122+
assert a.schema.domain.dim('X').tile == 12
123+
assert s.config.xsize == 12
124+
assert a.schema.domain.dim('Y').tile == 12
125+
assert s.config.ysize == 12
126+
127+
96128
def test_metrics(self, storage: Storage):
97129
m_list = storage.get_metrics()
98130
a_list = storage.get_attributes()

0 commit comments

Comments
 (0)