forked from JWST-MIRI/MiriTE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
308 lines (280 loc) · 12 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/env python
"""
Setup file for installing the MiriTE software
:History:
11 May 2017: Major new setup.py script based on ez_setup.py, using
the mirisim setup.py as a template and copying code
from the package defsetup.py scripts.
12 May 2017: MIRI software divided into 4 parts: MiriTools, MiriPipeline,
MiriSimulators and MiriCalibration.
14 Jul 2017: Unpack the 470 micron version of the cosmic ray libraries.
27 Jul 2017: Require Python 2.7
13 Sep 2017: MiriCalibration and MiriPipeline packages separated.
15 Jan 2018: MiriTools and MiriSimulators levels removed from package.
22 Jan 2018: Removed empty mirimsim simulator package.
25 Jan 2018: Added missing url metadata.
27 Apr 2018: Require Python 3.5.
22 May 2018: Added README and LICENCE.
04 Jun 2018: Added warning if MIRICLE environment is not activated.
10 Aug 2018: Removed datamodel scripts which are no longer relevant.
08 Oct 2018: Added convert_mrs_resolution script.
11 Oct 2018: Added append_lrs_photom script.
12 Oct 2018: Added cdp_remove_junk script.
07 Oct 2019: Require Python 3.6. Corrected bug in the checking of
conda_prefix.
@author: MIRI Software Team
"""
import io
import os
import re
import sys
import zipfile
import numpy
try:
from setuptools import Extension
# from distutils.core import Extension
from Cython.Distutils import build_ext
except ImportError:
build_ext = None
try:
from setuptools import setup
except ImportError:
from .ez_setup import use_setuptools
use_setuptools()
from setuptools import setup
def read(*names, **kwargs):
with io.open(
os.path.join(os.path.dirname(__file__), *names),
encoding=kwargs.get("encoding", "utf8")
) as fp:
return fp.read()
def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
def get_conda_prefix():
import os
if 'CONDA_PREFIX' in list(os.environ.keys()):
conda_prefix = str(os.environ['CONDA_PREFIX'])
else:
conda_prefix = ''
return conda_prefix
# Test the command arguments given with this script.
# Only unzip data files when building or installing, not when
# cleaning. If a "clean" is requested on its own, the previously
# unzipped files are deleted.
if len(sys.argv[0]) > 0:
argv = sys.argv
if ("build" in argv) or ("install" in argv):
zipflag = True
cleanflag = False
else:
zipflag = False
cleanflag = ("clean" in argv)
if "--quiet" in argv:
verbose = False
else:
verbose = True
conda_prefix = get_conda_prefix()
if verbose:
print("CONDA_PREFIX is", conda_prefix)
# ------------------------------------------------------------------
# Unzip the data files contained in the simulators data directories.
#
# The simulator detector data files are found relative to the
# directory containing this Python script.
(this_dir, this_file) = os.path.split(__file__)
cr_data_path = os.path.join(this_dir, "simulators/data/cosmic_rays")
if not os.path.isdir(cr_data_path):
strg = "Cosmic ray data directory %s not found" % cr_data_path
raise EnvironmentError(strg)
detector_data_path = os.path.join(this_dir, "simulators/data/detector")
if not os.path.isdir(detector_data_path):
strg = "Detector data directory %s not found" % detector_data_path
raise EnvironmentError(strg)
scasim_data_path = os.path.join(this_dir, "simulators/scasim/data")
if not os.path.isdir(scasim_data_path):
strg = "SCASIM data directory %s not found" % scasim_data_path
raise EnvironmentError(strg)
# Unpack the 470 micron version of the cosmic ray library (which has better track lengths)
fziplist0 = [zipfile.ZipFile(os.path.join(cr_data_path,'CRs_SiAs_470.zip'),'r')]
# fziplist0 = [zipfile.ZipFile(os.path.join(cr_data_path,'CRs_SiAs_35.zip'),'r')]
fziplist1 = [zipfile.ZipFile(os.path.join(detector_data_path,'bad_pixelsIM.zip'),'r'),
zipfile.ZipFile(os.path.join(detector_data_path,'bad_pixelsLW.zip'),'r'),
zipfile.ZipFile(os.path.join(detector_data_path,'bad_pixelsSW.zip'),'r'),
zipfile.ZipFile(os.path.join(detector_data_path,'dark_mapIM.zip'),'r'),
zipfile.ZipFile(os.path.join(detector_data_path,'dark_mapLW.zip'),'r'),
zipfile.ZipFile(os.path.join(detector_data_path,'dark_mapSW.zip'),'r')]
fziplist2 = [zipfile.ZipFile(os.path.join(scasim_data_path,'SCATestHorseHead1024.zip'),'r')]
if zipflag:
# Unpack the cosmic ray files
for fzip in fziplist0:
for name in fzip.namelist():
fullname = os.path.join(cr_data_path, name)
if not os.path.isfile(fullname):
if verbose:
print( "Unzipping \'%s\'" % fullname )
data = fzip.read(name)
temp = open(fullname, "wb")
temp.write(data)
temp.close()
else:
if verbose:
print( "\'%s\' already exists" % fullname )
fzip.close()
# Unpack the detector files
for fzip in fziplist1:
for name in fzip.namelist():
fullname = os.path.join(detector_data_path, name)
if not os.path.isfile(fullname):
if verbose:
print( "Unzipping \'%s\'" % fullname )
data = fzip.read(name)
temp = open(fullname, "wb")
temp.write(data)
temp.close()
else:
if verbose:
print( "\'%s\' already exists" % fullname )
fzip.close()
# Unpack the SCASIM files
for fzip in fziplist2:
for name in fzip.namelist():
fullname = os.path.join(scasim_data_path, name)
if not os.path.isfile(fullname):
if verbose:
print( "Unzipping \'%s\'" % fullname )
data = fzip.read(name)
temp = open(fullname, "wb")
temp.write(data)
temp.close()
else:
if verbose:
print( "\'%s\' already exists" % fullname )
fzip.close()
elif cleanflag:
# Clean up the cosmic ray files
for fzip in fziplist0:
for name in fzip.namelist():
fullname = os.path.join(cr_data_path, name)
if os.path.isfile(fullname):
if verbose:
print( "Deleting \'%s\'" % fullname )
try:
os.remove(fullname)
except Exception:
pass
# Clean up the detector files
for fzip in fziplist1:
for name in fzip.namelist():
fullname = os.path.join(detector_data_path, name)
if os.path.isfile(fullname):
if verbose:
print( "Deleting \'%s\'" % fullname )
try:
os.remove(fullname)
except Exception:
pass
# Clean up the SCASIM files
for fzip in fziplist2:
for name in fzip.namelist():
fullname = os.path.join(scasim_data_path, name)
if os.path.isfile(fullname):
if verbose:
print( "Deleting \'%s\'" % fullname )
try:
os.remove(fullname)
except Exception:
pass
entry_points = dict(asdf_extensions=['miri_datamodel = miri.datamodels.miri_extension:MIRIExtension'])
# ------------------------------------------------------------------
setup(
name="miri",
version=find_version("__init__.py"),
description="MIRI tools, data models and simulator software",
url="https://github.com/JWST-MIRI/MiriTE",
author="MIRI European Consortium",
author_email="[email protected]",
license="See LICENCE file",
platforms=["Linux", "Mac OS X"],
python_requires='>=3.6',
packages=['miri',
'miri.tools', 'miri.tools.tests',
'miri.datamodels', 'miri.datamodels.tests',
'miri.simulators', 'miri.simulators.tests',
'miri.simulators.scasim', 'miri.simulators.scasim.tests',
'miri.apt_parser',
],
package_dir={
'miri': '',
'miri.tools': 'tools/',
'miri.tools.tests': 'tools/tests',
'miri.datamodels': 'datamodels/',
'miri.datamodels.tests': 'datamodels/tests',
'miri.simulators': 'simulators/',
'miri.simulators.tests': 'simulators/tests',
'miri.simulators.scasim': 'simulators/scasim',
'miri.simulators.scasim.tests': 'simulators/scasim/tests',
'miri.apt_parser':'apt_parser',
},
package_data={'miri.tools': ['data/__init__.py'],
'miri.datamodels': ['schemas/*.yaml', 'data/*.fits',
'data/*.txt', 'data/__init__.py'],
'miri.simulators': ['schemas/*.yaml', 'data/*.fits',
'data/*.txt', 'data/__init__.py',
'data/amplifiers/*.fits',
'data/amplifiers/*.txt',
'data/detector/*.fits',
'data/detector/*.txt',
'data/cosmic_rays/*.fits',
'data/cosmic_rays/*.txt',
'data/filters/*.fits',
'data/filters/*.txt'],
'miri.simulators.scasim': ['data/SCATestInput80x64.fits',
'data/SCATestHorseHead1024.fits',
'data/__init__.py'],
},
scripts=['miri_installation_check.py',
'datamodels/scripts/append_lrs_photom.py',
'datamodels/scripts/cdp_add_filter_band.py',
'datamodels/scripts/cdp_add_history.py',
'datamodels/scripts/cdp_add_subarray.py',
'datamodels/scripts/cdp_correct_band.py',
'datamodels/scripts/cdp_correct_wildcard.py',
'datamodels/scripts/cdp_get_doc.py',
'datamodels/scripts/cdp_print.py',
'datamodels/scripts/cdp_reduce_dark.py',
'datamodels/scripts/cdp_remove_junk.py',
'datamodels/scripts/cdp_verify.py',
'datamodels/scripts/convert_fits_to_asdf.py',
'datamodels/scripts/convert_mrs_resolution.py',
'datamodels/scripts/convert_slope_data.py',
'datamodels/scripts/find_me_another.py',
'datamodels/scripts/dqflags_examples.py',
'datamodels/scripts/multicdp_band.csh',
'datamodels/scripts/multicdp_filter_band.csh',
'datamodels/scripts/multicdp_remove_junk.csh',
'datamodels/scripts/multicdp_subarray.csh',
'datamodels/scripts/multicdp_verify.py',
'datamodels/scripts/multicdp_wildcard.csh',
'simulators/scasim/scripts/make_bad_pixel_mask.py',
'simulators/scasim/scripts/make_fringe_map.py',
'simulators/scasim/scripts/make_sca_calibration.py',
'simulators/scasim/scripts/make_sca_file.py',
'simulators/scasim/scripts/convert_exposure_data.py',
'simulators/scasim/scripts/detector_latency_test.py',
'simulators/scasim/scripts/plot_exposure_data.py',
'simulators/scasim/scripts/scasim.py',
],
data_files=[('', ['LICENCE', 'README'])],
entry_points=entry_points,
)
if not cleanflag:
if not ('/envs' in conda_prefix):
print("\n*** WARNING: MIRI software installed into the root environment! ***")
print("If you didn't want to do this, remove the above package from site-packages, execute")
print("\n\tsource activate <name-of-miricle-environment>")
print("\nand try again.")