Skip to content
Snippets Groups Projects
Commit 0bb9aeca authored by Ray Garcia's avatar Ray Garcia :scream_cat:
Browse files

X10 speedup from parameterized slicing with slice() objects

previously had been using double swapaxis with axis=0 slice
parent 896fa26d
No related branches found
No related tags found
No related merge requests found
......@@ -637,8 +637,8 @@ def main():
help="number of tiles in X dimension")
parser.add_argument('-p', '--pixels', type=int, default=2000,
help="max number of pixels in any direction, for tile counts not specified")
parser.add_argument('-P', '--parallel', type=int, default=0,
help="max number of processors to use, default all-available")
parser.add_argument('-P', '--parallel', type=int, default=1,
help="max number of processors to use, default 1; 0 for all-available")
parser.add_argument('-R', '--region', help='region tag to use in filename, e.g. ECONUS')
parser.add_argument('-E', '--environment', default='DT',
help='environment and data type to use in filename, e.g. DT or OR')
......@@ -660,18 +660,22 @@ def main():
environment=args.environment[0], data_type=args.environment[1],
region=args.region, debug=args.debug)
if args.parallel==0:
if args.parallel==1 or len(args.inputs)<=1:
run_all = None
elif args.parallel==0:
multi = mp.Pool()
run_all = multi.map
LOG.info('using {} cores'.format(os.cpu_count()))
elif args.parallel==1:
run_all = map
else:
multi = mp.Pool(args.parallel)
run_all = multi.map
LOG.info('using {} cores'.format(args.parallel))
run_all(cherrychanga, args.inputs)
if run_all:
run_all(cherrychanga, args.inputs)
else:
for inp in args.inputs:
cherrychanga(inp)
return 0
......
......@@ -199,18 +199,23 @@ def slice_yx(seq, n_tiles=(1,1), dimensions=('y', 'x'), path_format=None):
continue
# where y or x dimension is present, swap that axis to 0 and slice
v = V[:]
# v = V # [:]
shape = V.shape
knife = [slice(0, extent) for extent in shape]
if ydo is not None:
v = np.swapaxes(v, 0, ydo) if ydo!=0 else v # there
v = v[iy * nh:(iy + 1) * nh] # slice the section we want
v = np.swapaxes(v, 0, ydo) if ydo!=0 else v # and back again
knife[ydo] = slice(iy * nh, (iy + 1) * nh)
# v = np.swapaxes(v, 0, ydo) if ydo!=0 else v # there
# v = v[iy * nh:(iy + 1) * nh] # slice the section we want
# v = np.swapaxes(v, 0, ydo) if ydo!=0 else v # and back again
if xdo is not None:
v = np.swapaxes(v, 0, xdo) if xdo!=0 else v # there
v = v[ix * nw:(ix + 1) * nw] # slice the section we want
v = np.swapaxes(v, 0, xdo) if xdo!=0 else v # and back again
knife[xdo] = slice(ix * nw, (ix + 1) * nw)
# v = np.swapaxes(v, 0, xdo) if xdo!=0 else v # there
# v = v[ix * nw:(ix + 1) * nw] # slice the section we want
# v = np.swapaxes(v, 0, xdo) if xdo!=0 else v # and back again
yield p, v, d, a
yield p, V[knife], d, a
def nc_write(seq):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment