Skip to content

Commit a589db1

Browse files
committed
Checkpoint changes from outflow forcing development
1 parent bbe483f commit a589db1

19 files changed

+323
-41
lines changed

bin/cmd.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CustomCmd:
2323
("with-zarr", None, "With zarr data backend"),
2424
("with-dask", None, "With dask data/parallel backend"),
2525
("with-server", None, "With remote server utilitiy"),
26-
("enable-testing", None, "Enable testing mode"),
26+
("enable-analysis", None, "Enable analysis mode"),
2727
]
2828

2929
def initialize_options(self):
@@ -35,7 +35,7 @@ def initialize_options(self):
3535
self.with_zarr = None # pylint: disable=attribute-defined-outside-init
3636
self.with_dask = None # pylint: disable=attribute-defined-outside-init
3737
self.with_server = None # pylint: disable=attribute-defined-outside-init
38-
self.enable_testing = None # pylint: disable=attribute-defined-outside-init
38+
self.enable_analysis = None # pylint: disable=attribute-defined-outside-init
3939

4040
def finalize_options(self):
4141
"""
@@ -47,7 +47,7 @@ def finalize_options(self):
4747
"with_zarr",
4848
"with_dask",
4949
"with_server",
50-
"enable_testing",
50+
"enable_analysis",
5151
]:
5252
if getattr(self, option) not in [None, 1]:
5353
raise ValueError(f"{option} is a flag")
@@ -101,9 +101,9 @@ def run(self, user):
101101
executable="/bin/bash",
102102
)
103103

104-
if self.enable_testing:
104+
if self.enable_analysis:
105105
subprocess.run(
106-
f"{sys.executable} -m pip install -r requirements/testing.txt {with_user}",
106+
f"{sys.executable} -m pip install -r requirements/analysis.txt {with_user}",
107107
shell=True,
108108
check=True,
109109
executable="/bin/bash",
@@ -116,7 +116,7 @@ def run(self, user):
116116
optfile.write(f"ZARR={self.with_zarr}\n")
117117
optfile.write(f"DASK={self.with_dask}\n")
118118
optfile.write(f"SERVER={self.with_server}\n")
119-
optfile.write(f"TESTING={self.enable_testing}\n")
119+
optfile.write(f"ANALYSIS={self.enable_analysis}\n")
120120

121121

122122
# replaces the default build command for setup.py

boxkit/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from .api import *
44
from . import library
5-
from . import options
65
from . import resources
6+
from . import options
77

88
if options.CBOX:
99
from . import cbox

boxkit/api/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
from ._resfilter import resfilter
1111
from ._mean import mean_temporal
1212

13-
if options.TESTING:
13+
if options.ANALYSIS:
1414
from ._regionprops import regionprops

boxkit/api/_create.py

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def create_dataset(storage=None, **attributes):
2929
nxb=1,
3030
nyb=1,
3131
nzb=1,
32+
xguard=0,
33+
yguard=0,
34+
zguard=0,
3235
nblockx=1,
3336
nblocky=1,
3437
nblockz=1,
@@ -46,6 +49,9 @@ def create_dataset(storage=None, **attributes):
4649
"nxb": int(self.nxb),
4750
"nyb": int(self.nyb),
4851
"nzb": int(self.nzb),
52+
"xguard": int(self.xguard),
53+
"yguard": int(self.yguard),
54+
"zguard": int(self.zguard),
4955
}
5056

5157
data = library.Data(storage=storage, **data_attributes)

boxkit/api/_mergeblocks.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def mergeblocks(
5454
nxb=nblockx * dataset.nxb,
5555
nyb=nblocky * dataset.nyb,
5656
nzb=nblockz * dataset.nzb,
57+
xguard=0 if dataset.nxb == 1 else 1,
58+
yguard=0 if dataset.nyb == 1 else 1,
59+
zguard=0 if dataset.nzb == 1 else 1,
5760
xmin=dataset.xmin,
5861
ymin=dataset.ymin,
5962
zmin=dataset.zmin,
@@ -113,7 +116,17 @@ def map_blk_to_merged_dset(blk_sorted, merged_dataset, varlist):
113116
for varkey in varlist:
114117
for block in merged_dataset.blocklist:
115118
block[varkey][
116-
blk_sorted.nzb * kloc : blk_sorted.nzb * (kloc + 1),
117-
blk_sorted.nyb * jloc : blk_sorted.nyb * (jloc + 1),
118-
blk_sorted.nxb * iloc : blk_sorted.nxb * (iloc + 1),
119-
] = blk_sorted[varkey][:, :, :]
119+
blk_sorted.nzb * kloc
120+
+ block.zguard : blk_sorted.nzb * (kloc + 1)
121+
+ block.zguard,
122+
blk_sorted.nyb * jloc
123+
+ block.yguard : blk_sorted.nyb * (jloc + 1)
124+
+ block.yguard,
125+
blk_sorted.nxb * iloc
126+
+ block.xguard : blk_sorted.nxb * (iloc + 1)
127+
+ block.xguard,
128+
] = blk_sorted[varkey][
129+
blk_sorted.zguard : blk_sorted.nzb + blk_sorted.zguard,
130+
blk_sorted.yguard : blk_sorted.nyb + blk_sorted.yguard,
131+
blk_sorted.xguard : blk_sorted.nxb + blk_sorted.xguard,
132+
]

boxkit/api/_read.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ def read_dataset(
4646
4747
"""
4848
if not source:
49-
source = "test-sample"
49+
source = "sample"
5050

5151
if not storage:
5252
storage = "numpy-memmap"
5353

54-
data_attributes, block_attributes = resources.read.options[source](
54+
source = getattr(resources, source)
55+
56+
data_attributes, block_attributes = source.read(
5557
filename, server, nthreads, batch, monitor, backend
5658
)
5759

boxkit/api/_regionprops.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def regionprops(dataset, lsetkey, backend="serial", nthreads=1, monitor=False):
2222
labelkey = "bwlabel"
2323
dataset.addvar(labelkey, dtype=int)
2424

25+
normals = ["normx", "normy"]
26+
for norm in normals:
27+
dataset.addvar(norm)
28+
2529
region = api.create_region(dataset)
2630

2731
skimage_props_blk.nthreads = nthreads
@@ -34,6 +38,8 @@ def regionprops(dataset, lsetkey, backend="serial", nthreads=1, monitor=False):
3438
listprops = list(itertools.chain.from_iterable(listprops))
3539

3640
dataset.delvar(labelkey)
41+
for norm in normals:
42+
dataset.delvar(norm)
3743

3844
return listprops
3945

@@ -66,7 +72,14 @@ def skimage_props_blk(block, lsetkey, labelkey):
6672
corners.append([block.zmin, block.ymin, block.xmin][idim])
6773

6874
listprops = skimage_measure.regionprops(
69-
numpy.reshape(block[labelkey], shape).astype(int)
75+
numpy.reshape(
76+
block[labelkey][
77+
block.zguard : block.nzb + block.zguard,
78+
block.yguard : block.nyb + block.yguard,
79+
block.xguard : block.nxb + block.xguard,
80+
],
81+
shape,
82+
).astype(int)
7083
)
7184
ndim = len(shape)
7285

boxkit/library/_block.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def xrange(self, location):
8282
"node": self.__class__.get_node_loc,
8383
}
8484

85-
return range_dict[location](self.xmin, self.xmax, self.dx, self.nxb)
85+
return range_dict[location](
86+
self.xmin, self.xmax, self.dx, self.nxb, self.xguard
87+
)
8688

8789
def yrange(self, location):
8890
"""
@@ -93,7 +95,9 @@ def yrange(self, location):
9395
"node": self.__class__.get_node_loc,
9496
}
9597

96-
return range_dict[location](self.ymin, self.ymax, self.dy, self.nyb)
98+
return range_dict[location](
99+
self.ymin, self.ymax, self.dy, self.nyb, self.yguard
100+
)
97101

98102
def zrange(self, location):
99103
"""
@@ -104,19 +108,29 @@ def zrange(self, location):
104108
"node": self.__class__.get_node_loc,
105109
}
106110

107-
return range_dict[location](self.zmin, self.zmax, self.dz, self.nzb)
111+
return range_dict[location](
112+
self.zmin, self.zmax, self.dz, self.nzb, self.zguard
113+
)
108114

109115
@staticmethod
110-
def get_center_loc(min_val, max_val, delta, num_points):
116+
def get_center_loc(min_val, max_val, delta, num_points, num_guards):
111117
"""Private method for center location"""
112-
return numpy.linspace(min_val + delta / 2, max_val - delta / 2, num_points)
118+
return numpy.linspace(
119+
min_val + delta / 2 - num_guards * delta,
120+
max_val - delta / 2 + num_guards * delta,
121+
num_points + 2 * num_guards,
122+
)
113123

114124
@staticmethod
115125
def get_node_loc(
116-
min_val, max_val, delta, num_points
126+
min_val, max_val, delta, num_points, num_guards
117127
): # pylint: disable=unused-argument
118128
"""Private method for face location"""
119-
return numpy.linspace(min_val, max_val, num_points)
129+
return numpy.linspace(
130+
min_val - num_guards * delta,
131+
max_val + num_guards * delta,
132+
num_points + 2 * num_guards,
133+
)
120134

121135
def _set_attributes(self, attributes):
122136
"""

boxkit/library/_dataset.py

+33
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,39 @@ def halo_exchange( # pylint: disable=too-many-arguments
215215
for varkey in varlist:
216216
halo_exchange_block((block for block in self.blocklist), varkey)
217217

218+
def fill_guard_cells(self, varlist):
219+
"""
220+
Fill guard cells
221+
"""
222+
# Convert single string to a list
223+
if isinstance(varlist, str):
224+
varlist = [varlist]
225+
226+
if len(self.blocklist) > 1:
227+
raise NotImplementedError(
228+
"[boxkit.library.create.Dataset] fill_guard_cells is only implemented for blocklist == 1"
229+
)
230+
231+
for block in self.blocklist:
232+
for var in varlist:
233+
for bnd in range(block.xguard):
234+
block[var][:, :, bnd] = block[var][:, :, block.xguard]
235+
block[var][:, :, bnd + block.nxb + block.xguard] = block[var][
236+
:, :, block.nxb + block.xguard - 1
237+
]
238+
239+
for bnd in range(block.yguard):
240+
block[var][:, bnd, :] = block[var][:, block.yguard, :]
241+
block[var][:, bnd + block.nyb + block.yguard, :] = block[var][
242+
:, block.nyb + block.yguard - 1, :
243+
]
244+
245+
for bnd in range(block.zguard):
246+
block[var][bnd, :, :] = block[var][block.zguard, :, :]
247+
block[var][bnd + block.nzb + block.zguard, :, :] = block[var][
248+
block.nzb + block.zguard - 1, :, :
249+
]
250+
218251

219252
@Action
220253
def halo_exchange_block(block, varkey):

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=1
6+
ANALYSIS=1

boxkit/resources/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
"""Initialize resources"""
2-
from . import read
2+
3+
from . import sample
4+
from . import flash

boxkit/resources/flash/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Initializate flash module"""
2+
3+
from ._read import read
4+
from ... import options
5+
6+
if options.ANALYSIS == 1:
7+
from ._lset import (
8+
bubble_contour_plot,
9+
bubble_normal_vectors,
10+
bubble_shape_measurement,
11+
)

0 commit comments

Comments
 (0)