Skip to content

Commit 806dbf8

Browse files
authored
Py3 (#159)
* py3 fixes * fibermap now Table not numpy array * update .travis.yml and changes.rst prior to py3 PR * update .travis.yml for py3.5 tests * astropy 1.2.1 for tests * let travis astropy 1.2.1 pick numpy version * use default scipy version * travis tests with specsim v0.5
1 parent c79c3ad commit 806dbf8

11 files changed

+39
-29
lines changed

.travis.yml

+18-11
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ env:
3838
# The following versions are the 'default' for tests, unless
3939
# overidden underneath. They are defined here in order to save having
4040
# to repeat them for all configurations.
41-
- NUMPY_VERSION=1.10
42-
- SCIPY_VERSION=0.16
43-
- ASTROPY_VERSION=1.1.1
41+
# - NUMPY_VERSION=1.10
42+
# - SCIPY_VERSION=0.16
43+
- ASTROPY_VERSION=1.2.1
4444
# - SPHINX_VERSION=1.3
45-
- DESIUTIL_VERSION=1.6.0
45+
- DESIUTIL_VERSION=1.8.0
4646
- DESIMODEL_VERSION=0.4.5
4747
- DESIMODEL_DATA=branches/test-0.4.5
4848
- DESISIM_TESTDATA_VERSION=0.3.2
49-
- SPECLITE_VERSION=0.4
50-
- SPECSIM_VERSION=v0.4
51-
- SPECTER_VERSION=0.5.0
52-
- DESISPEC_VERSION=0.8.0
53-
- DESITARGET_VERSION=0.5.0
49+
- SPECLITE_VERSION=0.5
50+
- SPECSIM_VERSION=v0.5
51+
- SPECTER_VERSION=0.6.0
52+
- DESISPEC_VERSION=0.10.0
53+
- DESITARGET_VERSION=0.6.1
5454
# - DESIMODEL_VERSION=trunk
5555
- DESI_LOGLEVEL=DEBUG
5656
- MAIN_CMD='python setup.py'
@@ -70,6 +70,7 @@ env:
7070
- DEBUG=False
7171
matrix:
7272
- PYTHON_VERSION=2.7 SETUP_CMD='egg_info'
73+
- PYTHON_VERSION=3.5 SETUP_CMD='egg_info'
7374

7475
matrix:
7576
# Don't wait for allowed failures.
@@ -96,9 +97,15 @@ matrix:
9697
- os: linux
9798
env: PYTHON_VERSION=2.7 SETUP_CMD='bdist_egg'
9899

99-
# Try all python versions with the latest numpy
100+
# Try multiple python versions with the latest numpy
100101
- os: linux
101-
env: PYTHON_VERSION=2.7 SETUP_CMD='test --coverage'
102+
env: PYTHON_VERSION=2.7 SETUP_CMD='test'
103+
CONDA_DEPENDENCIES=$CONDA_ALL_DEPENDENCIES
104+
PIP_DEPENDENCIES=$PIP_ALL_DEPENDENCIES
105+
DESIHUB_PIP_DEPENDENCIES=$DESIHUB_PIP_ALL_DEPENDENCIES
106+
107+
- os: linux
108+
env: PYTHON_VERSION=3.5 SETUP_CMD='test --coverage'
102109
CONDA_DEPENDENCIES=$CONDA_ALL_DEPENDENCIES
103110
PIP_DEPENDENCIES=$PIP_ALL_DEPENDENCIES
104111
DESIHUB_PIP_DEPENDENCIES=$DESIHUB_PIP_ALL_DEPENDENCIES

doc/changes.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
desisim change log
33
==================
44

5-
0.13.2 (unreleased)
5+
0.14.0 (unreleased)
66
-------------------
77

8-
* no changes yet
8+
* updates for python 3.5
99

1010
0.13.1 (2016-08-18)
1111
-------------------

py/desisim/io.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ def read_cosmics(filename, expid=1, shape=None, jitter=True):
515515
iixy = np.s_[ny:2*ny, nx:2*nx]
516516
mean, median, std = sigma_clipped_stats(pix[iixy], sigma=3, iters=5)
517517
meta['RDNOISE4'] = std
518-
518+
fx.close()
519+
519520
return Image(pix, ivar, mask, meta=meta)
520521

521522
#-------------------------------------------------------------------------
@@ -727,7 +728,7 @@ def empty_metatable(nmodel=1, objtype='ELG', add_SNeIa=None):
727728
from astropy.table import Table, Column
728729

729730
meta = Table()
730-
meta.add_column(Column(name='OBJTYPE', length=nmodel, dtype='S10'))
731+
meta.add_column(Column(name='OBJTYPE', length=nmodel, dtype=(str, 10)))
731732
meta.add_column(Column(name='TEMPLATEID', length=nmodel, dtype='i4',
732733
data=np.zeros(nmodel)-1))
733734
meta.add_column(Column(name='SEED', length=nmodel, dtype='int64',

py/desisim/obs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def specter_objtype(desitype):
311311
if len(unknown_types) > 0:
312312
raise ValueError('Unknown input objtypes {}'.format(unknown_types))
313313

314-
results = np.zeros(len(intype), dtype='S8')
314+
results = np.zeros(len(intype), dtype=(str, 8))
315315
for objtype in desi2specter:
316316
ii = (intype == objtype)
317317
results[ii] = desi2specter[objtype]
@@ -354,7 +354,7 @@ def get_next_tileid(program='DARK'):
354354

355355
tiles = table.vstack([tiles, brighttiles])
356356

357-
program_col = table.Column(name='PROGRAM', length=len(tiles), dtype='S6')
357+
program_col = table.Column(name='PROGRAM', length=len(tiles), dtype=(str, 6))
358358
tiles.add_column(program_col)
359359
tiles['PROGRAM'][tiles['PASS'] <= 3] = 'DARK'
360360
tiles['PROGRAM'][tiles['PASS'] == 4] = 'GRAY'

py/desisim/quickcat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def quickcat(tilefiles, targets, truth, zcat=None, perfect=False):
122122
if 'BRICKNAME' in truth.dtype.names:
123123
newzcat['BRICKNAME'] = truth['BRICKNAME']
124124
else:
125-
newzcat['BRICKNAME'] = np.zeros(len(truth), dtype='S8')
125+
newzcat['BRICKNAME'] = np.zeros(len(truth), dtype=(str, 8))
126126

127127
#- Copy TRUEZ -> Z so that we can add errors without altering original
128128
newzcat['Z'] = truth['TRUEZ'].copy()

py/desisim/scripts/quickbrick.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def main(args):
141141
# Initialize the output truth table.
142142
truth = dict()
143143
meta = Table()
144-
truth['OBJTYPE'] = np.zeros(args.nspec, dtype='S10')
144+
truth['OBJTYPE'] = np.zeros(args.nspec, dtype=(str, 10))
145145
truth['FLUX'] = np.zeros((args.nspec, npix))
146146
truth['WAVE'] = wave
147147
jj = list()
@@ -225,11 +225,11 @@ def main(args):
225225
meta = meta_new
226226

227227
# Add TARGETID and the true OBJTYPE to the metadata table.
228-
meta.add_column(Column(true_objtype, dtype='S10', name='TRUE_OBJTYPE'))
228+
meta.add_column(Column(true_objtype, dtype=(str, 10), name='TRUE_OBJTYPE'))
229229
meta.add_column(Column(targetids, name='TARGETID'))
230230

231231
# Now add fixed-up OBJTYPE to the template meta table
232-
meta.add_column(Column(true_objtype, dtype='S10', name='OBJTYPE'))
232+
meta.add_column(Column(true_objtype, dtype=(str, 10), name='OBJTYPE'))
233233

234234
# Rename REDSHIFT -> TRUEZ anticipating later table joins with zbest.Z
235235
meta.rename_column('REDSHIFT', 'TRUEZ')

py/desisim/scripts/quickgen.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def main(args=None):
7979
if args.fibermap:
8080

8181
print("Reading fibermap file %s"%(args.fibermap))
82-
fibermap,hdr=read_fibermap(args.fibermap, header=True)
82+
fibermap=read_fibermap(args.fibermap)
8383
objtype=fibermap['OBJTYPE'].copy()
8484
#need to replace STD and MWS_STAR object types with STAR and BGS object types with LRG since quicksim expects star instead of std or mws_star and LRG instead of BGS
8585
stdindx=np.where(objtype=='STD') # match STD with STAR
@@ -88,8 +88,8 @@ def main(args=None):
8888
objtype[stdindx]='STAR'
8989
objtype[mwsindx]='STAR'
9090
objtype[bgsindx]='LRG'
91-
NIGHT=hdr['NIGHT']
92-
EXPID=hdr['EXPID']
91+
NIGHT=fibermap.meta['NIGHT']
92+
EXPID=fibermap.meta['EXPID']
9393

9494

9595
else:

py/desisim/targets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def get_targets(nspec, flavor, tileid=None, seed=None, specmin=0):
288288

289289
truth = dict()
290290
truth['FLUX'] = np.zeros( (nspec, len(wave)) )
291-
truth['OBJTYPE'] = np.zeros(nspec, dtype='S10')
291+
truth['OBJTYPE'] = np.zeros(nspec, dtype=(str, 10))
292292
##- Note: unlike other elements, first index of WAVE isn't spectrum index
293293
truth['WAVE'] = wave
294294

@@ -395,7 +395,7 @@ def get_targets(nspec, flavor, tileid=None, seed=None, specmin=0):
395395
fibermap['POSITIONER'] = fiberpos['POSITIONER'][specmin:specmin+nspec]
396396
fibermap['SPECTROID'] = fiberpos['SPECTROGRAPH'][specmin:specmin+nspec]
397397
fibermap['TARGETID'] = np.random.randint(sys.maxsize, size=nspec)
398-
fibermap['TARGETCAT'] = np.zeros(nspec, dtype='|S20')
398+
fibermap['TARGETCAT'] = np.zeros(nspec, dtype=(str, 20))
399399
fibermap['LAMBDAREF'] = np.ones(nspec, dtype=np.float32)*5400
400400
fibermap['RA_TARGET'] = ra
401401
fibermap['DEC_TARGET'] = dec

py/desisim/templates.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ def make_star_templates(self, nmodel=100, vrad_meansig=(0.0, 200.0),
11791179
# Shuffle the basis templates and then split them into ~equal chunks, so
11801180
# we can speed up the calculations below.
11811181
chunksize = np.min((nbase, 50))
1182-
nchunk = long(np.ceil(nbase / chunksize))
1182+
nchunk = int(np.ceil(nbase / chunksize))
11831183

11841184
alltemplateid = np.tile(np.arange(nbase), (nmodel, 1))
11851185
for tempid in alltemplateid:

py/desisim/test/test_quickcat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def setUpClass(cls):
1919
truth = Table()
2020
truth['TARGETID'] = np.random.randint(0,2**60, size=n)
2121
truth['TRUEZ'] = np.random.uniform(0, 1.5, size=n)
22-
truth['TRUETYPE'] = np.zeros(n, dtype='S10')
22+
truth['TRUETYPE'] = np.zeros(n, dtype=(str, 10))
2323
ii = (targets['DESI_TARGET'] == 1); truth['TRUETYPE'][ii] = 'GALAXY'
2424
ii = (targets['DESI_TARGET'] == 2); truth['TRUETYPE'][ii] = 'GALAXY'
2525
ii = (targets['DESI_TARGET'] == 4); truth['TRUETYPE'][ii] = 'QSO'

py/desisim/test/test_templates.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ def test_input_meta(self):
129129
badkeys = list()
130130
for key in meta1.colnames:
131131
if key in ('DECAM_FLUX', 'WISE_FLUX', 'OIIFLUX', 'HBETAFLUX'):
132-
if not np.allclose(meta1[key], meta2[key]):
132+
#- not sure why the tolerances aren't closer
133+
if not np.allclose(meta1[key], meta2[key], atol=5e-5):
133134
print(meta1['OBJTYPE'][0], key, meta1[key], meta2[key])
134135
badkeys.append(key)
135136
else:
136137
if not np.all(meta1[key] == meta2[key]):
137138
badkeys.append(key)
139+
138140
self.assertEqual(len(badkeys), 0, 'mismatch for spectral type {} in keys {}'.format(meta1['OBJTYPE'][0], badkeys))
139141
self.assertTrue(np.allclose(flux1, flux2))
140142
self.assertTrue(np.all(wave1 == wave2))

0 commit comments

Comments
 (0)