-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile_stuff.py
60 lines (41 loc) · 1.76 KB
/
profile_stuff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# import multiprocessing
# try:
# multiprocessing.set_start_method('forkserver')
# except:
# pass
import h5py
import numpy as np
from skimage.util import apply_parallel
from skimage import filters
from memory_profiler import profile
import dask.array as da
@profile
def run_apply_parallel(imagepath, chunks, mode='h5py-direct'):
sigma = 3
if mode == 'h5py-direct':
print('Running gaussing filter on h5py array using dask.')
with h5py.File(imagepath, 'r') as f:
image = f['data']
result = apply_parallel(filters.gaussian, image, chunks, extra_arguments=(sigma, ), depth=sigma)
elif mode == 'numpy-array':
print('Running gaussing filter on numpy array using dask.')
with h5py.File(imagepath, 'r') as f:
image = f['data'][:]
result = apply_parallel(filters.gaussian, image, chunks, extra_arguments=(sigma, ), depth=sigma)
return result
@profile
def run_map_overlap(func, imagepath, chunks, overlap, mode='h5py-direct', extra_arguments=(), extra_keywords={}):
boundary='periodic'
def wrapped_func(arr):
return func(arr, *extra_arguments, **extra_keywords)
if mode == 'h5py-direct':
print('Running gaussing filter on h5py array using dask.')
with h5py.File(imagepath, 'r') as f:
darr = da.from_array(f['data'], chunks=chunks)
result = darr.map_overlap(wrapped_func, overlap, boundary=boundary).compute()
elif mode == 'numpy-array':
print('Running gaussing filter on numpy array using dask.')
with h5py.File(imagepath, 'r') as f:
darr = da.from_array(f['data'][:], chunks=chunks)
result = darr.map_overlap(wrapped_func, overlap, boundary=boundary).compute()
return result