Skip to content

Commit bbe483f

Browse files
committed
Updates to regionprops and resources
1 parent d915269 commit bbe483f

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

boxkit/api/_regionprops.py

+29-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
""" Module with implemenation of measure methods"""
2-
2+
import numpy
33
import itertools
44
import skimage.measure as skimage_measure
55

@@ -53,22 +53,37 @@ def skimage_props_blk(block, lsetkey, labelkey):
5353
-------
5454
listprops : list of properties
5555
"""
56-
5756
block[labelkey][:, :, :] = skimage_measure.label(block[lsetkey] >= 0)
5857

59-
listprops = skimage_measure.regionprops(block[labelkey].astype(int))
58+
shape, deltas, corners = [list(), list(), list()]
6059

61-
# proplist = ["area", "centroid", "equivalent_diameter_area"]
62-
# proplist = ["area"]
60+
for idim, nblocks in enumerate([block.nzb, block.nyb, block.nxb]):
61+
if nblocks == 1:
62+
continue
63+
else:
64+
shape.append(nblocks)
65+
deltas.append([block.dz, block.dy, block.dx][idim])
66+
corners.append([block.zmin, block.ymin, block.xmin][idim])
6367

64-
listprops = [
65-
{
66-
"area": props["area"] * block.dx * block.dy * block.dz,
67-
"centroid": props["centroid"],
68-
}
69-
for props in listprops
70-
]
68+
listprops = skimage_measure.regionprops(
69+
numpy.reshape(block[labelkey], shape).astype(int)
70+
)
71+
ndim = len(shape)
7172

72-
# listprops = [{key: props[key] for key in proplist} for props in listprops]
73+
modified_props = list()
74+
for props in listprops:
7375

74-
return listprops
76+
modified_dict = dict()
77+
78+
modified_dict["area"] = props["area"] * numpy.prod(deltas)
79+
modified_dict["centroid"] = [
80+
corners[idim] + deltas[idim] * props["centroid"][idim]
81+
for idim in range(ndim)
82+
]
83+
84+
if ndim == 2:
85+
modified_dict["perimeter"] = props["perimeter"] * deltas[0]
86+
87+
modified_props.append(modified_dict)
88+
89+
return modified_props

boxkit/library/_data.py

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Data(_DataBase): # pylint: disable=too-many-instance-attributes
4848
'remotefile': sftp remote file default (None),
4949
'variables' : dictionary of variables default ({}),
5050
'storage' : ('numpy', 'zarr', 'dask', 'pyarrow')
51+
'time' : float variable to store time
5152
"""
5253

5354
type_ = "default"
@@ -68,6 +69,7 @@ def __init__(self, **attributes):
6869
self.variables = {}
6970
self.dtype = {}
7071
self.varlist = []
72+
self.time = 0.0
7173

7274
self._set_attributes(attributes)
7375
self._set_data()

boxkit/library/_dataset.py

+5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ def dtype(self):
135135
"""dtype"""
136136
return self._data.dtype
137137

138+
@property
139+
def time(self):
140+
"""time"""
141+
return self._data.time
142+
138143
def addvar(self, varkey, dtype=float):
139144
"""addvar"""
140145
self._data.addvar(varkey, dtype)

boxkit/options.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
ZARR=None
44
DASK=None
55
SERVER=None
6-
TESTING=None
6+
TESTING=1

boxkit/resources/read/_flash.py

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def read_flash(
6161
"inputfile": inputfile,
6262
"remotefile": remotefile,
6363
"variables": variables,
64+
"time": inputfile["real scalars"][0][1],
6465
}
6566

6667
get_blk_attributes.nthreads = nthreads

0 commit comments

Comments
 (0)