forked from sunilgandhilab/brainquant3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·245 lines (226 loc) · 9.76 KB
/
setup.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Set this to True to enable building extensions using Cython.
# Set it to False to build extensions from the C file (that was previously created using Cython).
# Set it to 'auto' to build with Cython if available, otherwise
# from the C file.
import os
import sys
import numpy
import shutil
import tarfile
import urllib.request as request
import ssl
from glob import glob
from pathlib import Path
from setuptools import find_packages
from setuptools.command.install import install as _install
from distutils.core import setup
from distutils.extension import Extension
from bq3d._version import __version__
if sys.platform not in ['linux', 'darwin']:
raise EnvironmentError(f'Platform {sys.platform} not supported.')
if sys.platform == 'linux':
try:
from pip._internal.main import main
except:
try:
from pip._internal import main
except:
from pip import main
opencv_libs = '.lib-linux'
elastix_URL = 'elastix-5.0.0-linux.tar.bz2'
ilastik_URL = 'ilastik-1.3.3-Linux-noGurobi.tar.bz2'
elif sys.platform == 'darwin':
from pip._internal import main
opencv_libs = '.lib-osx'
elastix_URL = 'elastix-5.0.0-mac.tar.gz'
ilastik_URL = 'ilastik-1.3.3post2-OSX-noGurobi.tar.bz2'
USE_CYTHON = 'False'
if USE_CYTHON:
try:
from Cython.Distutils import build_ext
from Cython.Build import cythonize
except ImportError:
if USE_CYTHON == 'auto':
USE_CYTHON = False
else:
raise
cmdclass = {}
ext_modules = []
if USE_CYTHON:
ext_modules += cythonize([
Extension("bq3d.analysis._voxelization",
sources=["bq3d/analysis/_voxelization.pyx"],
include_dirs=[numpy.get_include()]
),
Extension("bq3d.image_filters.filters._background_subtraction",
sources=["bq3d/image_filters/filters/_background_subtraction.pyx"]
),
Extension("bq3d.image_filters.filters.helpers.array_manipulations",
sources=["bq3d/image_filters/filters/helpers/array_manipulations.pyx"]
),
Extension("bq3d.image_filters.filters.label._connect",
sources=["bq3d/image_filters/filters/label/_connect.pyx"],
language="c++",
include_dirs=[numpy.get_include(), "include"],
extra_link_args=[os.path.join(f'bq3d/{opencv_libs}', f) for f in os.listdir(
f'bq3d/{opencv_libs}')],
runtime_library_dirs=[f'$ORIGIN/../../../{opencv_libs}']
),
Extension("bq3d.image_filters.filters.label._threshold",
sources=["bq3d/image_filters/filters/label/_threshold.pyx"],
include_dirs=[numpy.get_include()],
language="c++"
),
Extension("bq3d.image_filters.filters.label._filter",
sources=["bq3d/image_filters/filters/label/_filter.pyx"],
include_dirs=[numpy.get_include()],
language="c++"
),
Extension("bq3d.image_filters.filters.label._overlap",
sources=["bq3d/image_filters/filters/label/_overlap.pyx"],
include_dirs=[numpy.get_include()],
language="c++"
),
Extension("bq3d.image_filters.filters.label.watershed._watershed",
sources=["bq3d/image_filters/filters/label/watershed/_watershed.pyx"],
include_dirs=[numpy.get_include()],
language="c++"
),
Extension("bq3d.image_filters.filters.helpers._nonzero_coords",
sources=["bq3d/image_filters/filters/helpers/_nonzero_coords.pyx"],
include_dirs=[numpy.get_include()],
language='c++'
),
Extension("bq3d.image_filters.filters._standardize",
sources=["bq3d/image_filters/filters/_standardize.pyx"],
include_dirs=[numpy.get_include()],
language='c++'
)
])
cmdclass['build_ext'] = build_ext
else:
ext_modules += [
Extension("bq3d.analysis._voxelization",
sources=["bq3d/analysis/_voxelization.c"],
include_dirs=[numpy.get_include()]
),
Extension("bq3d.image_filters.filters._background_subtraction",
sources=["bq3d/image_filters/filters/_background_subtraction.c"]
),
Extension("bq3d.image_filters.filters.helpers.array_manipulations",
sources=["bq3d/image_filters/filters/helpers/array_manipulations.c"]
),
Extension("bq3d.image_filters.filters.label._connect",
sources=["bq3d/image_filters/filters/label/_connect.cpp"],
language="c++",
include_dirs=[numpy.get_include(), "include"],
extra_link_args=[os.path.join(f'bq3d/{opencv_libs}', f) for f in os.listdir(
f'bq3d/{opencv_libs}')],
runtime_library_dirs=[f'$ORIGIN/../../../{opencv_libs}']
),
Extension("bq3d.image_filters.filters.label._threshold",
sources=["bq3d/image_filters/filters/label/_threshold.cpp"],
include_dirs=[numpy.get_include()],
language="c++"
),
Extension("bq3d.image_filters.filters.label._filter",
sources=["bq3d/image_filters/filters/label/_filter.cpp"],
include_dirs=[numpy.get_include()],
language="c++"
),
Extension("bq3d.image_filters.filters.label._overlap",
sources=["bq3d/image_filters/filters/label/_overlap.cpp"],
include_dirs=[numpy.get_include()],
language="c++"
),
Extension("bq3d.image_filters.filters.label.watershed._watershed",
sources=["bq3d/image_filters/filters/label/watershed/_watershed.cpp"],
include_dirs=[numpy.get_include()],
language="c++"
),
Extension("bq3d.image_filters.filters.helpers._nonzero_coords",
sources=["bq3d/image_filters/filters/helpers/_nonzero_coords.cpp"],
include_dirs=[numpy.get_include()],
language='c++'
),
Extension("bq3d.image_filters.filters._standardize",
sources=["bq3d/image_filters/filters/_standardize.cpp"],
include_dirs=[numpy.get_include()],
language='c++'
)
]
class install(_install):
def run(self):
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
# download external programs required by package to install directory.
cwd = os.getcwd()
matches = glob(os.path.join(cwd, 'build/lib.*'))
build_dir = cwd if len(matches) == 0 else matches[0]
dest = Path(build_dir) / 'bq3d/.external'
print('installing elastix')
url = 'https://glams.bio.uci.edu/' + elastix_URL
tmp = Path(url).name
sink = dest / 'elastix-5.0.0'
with request.urlopen(url, context=ctx) as response, open(tmp, 'wb') as out_file:
shutil.copyfileobj(response, out_file)
try:
tar = tarfile.open(tmp, "r:bz2") # Linux
except:
tar = tarfile.open(tmp, "r:gz") # MacOS
tar.extractall(sink)
tar.close()
print('installing ilastik')
url = 'https://glams.bio.uci.edu/' + ilastik_URL
tmp = Path(url).name
sink = dest / 'ilastik-1.3.3'
with request.urlopen(url, context=ctx) as response, open(tmp, 'wb') as out_file:
shutil.copyfileobj(response, out_file)
tar = tarfile.open(tmp, "r:bz2")
tar.extractall(sink)
tar.close()
# Install ANTsPy
print('installing ants')
if sys.platform == 'linux':
try:
main(['install', '--user', "https://github.com/ANTsX/ANTsPy/releases/download/v0.1.4/antspy-0.1.4-cp36-cp36m-linux_x86_64.whl"])
except:
main(['install', '--user', "https://github.com/ANTsX/ANTsPy/releases/download/v0.2.0/antspyx-0.2.0-cp37-cp37m-linux_x86_64.whl"])
if sys.platform == 'darwin':
try:
main(['install', '--user', "https://github.com/ANTsX/ANTsPy/releases/download/Weekly/antspy-0.1.4-cp36-cp36m-macosx_10_7_x86_64.whl"])
except:
main(['install', '--user', "https://github.com/ANTsX/ANTsPy/releases/download/v0.1.8/antspyx-0.1.8-cp37-cp37m-macosx_10_14_x86_64.whl"])
_install.run(self)
cmdclass['install'] = install
setup(
name= 'brainquant3d',
version= __version__,
description= 'Tools for tera-voxel image analysis.',
author= 'Ricardo Azevedo, Jack Zeitoun',
author_email= '[email protected], [email protected]',
maintainer= 'Ricardo Azevedo',
maintainer_email= '[email protected]',
url= 'https://github.com/ricardo-re-azevedo/brainquant3d',
license= 'BY-NC-SA 4.0',
cmdclass= cmdclass,
packages= find_packages(),
install_requires=[
'numpy',
'pyyaml',
'scipy',
'opencv-python',
'tifffile',
'scikit-image',
'pandas',
'h5py',
'vtk',
'anytree',
'webcolors', # required for antspy
'plotly' # required for antspy
],
include_package_data=True,
ext_modules=ext_modules,
keywords='tera voxel teravoxel image analysis biology'
)