This PR makes a small update to support astropy 4.x, while still retaining compatibility with astropy 2.x. The current version of simqso + astropy 4.x crashes upon import:
In [1]: import simqso
...
/global/common/software/desi/users/sjbailey/simqso/simqso/hiforest.py in <listcomp>(.0)
27 linelist = fits.getdata(os.path.join(datadir,'all_lin.fits'))
28 Hlines = np.array([i for i in range(linelist.size)
---> 29 if b'HI' in linelist.ION[i]])
30 transitionParams = {}
31 for n,idx in enumerate(Hlines[::-1],start=2):
TypeError: 'in <string>' requires string as left operand, not bytes
@imcgreer after reviewing and merging this PR, could you please make a new simqso tag so that we can use it in our next DESI software release? Thanks.
Background
In astropy 2.x, linelist.ION is a numpy.ndarray object and linelist.ION[0] is numpy.bytes_ thus requiring code like the current if b'HI' in linelist.ION[i]. But inconsistently, linelist['ION'] is a numpy.chararray and linelist['ION'][0] is a str requiring comparisons like if 'HI' in linelist.ION[i] instead (note 'HI' str not b'HI' bytes).
astropy 4.x (or maybe 3.x) made these consistent with both linelist.ION and linelist['ION'] being numpy.chararray objects with individual elements that are str, thus breaking the previous comparison with b'HI'. The syntax that works with both astropy 2.x and 4.x is:
This PR makes a small update to support astropy 4.x, while still retaining compatibility with astropy 2.x. The current version of simqso + astropy 4.x crashes upon import:
@imcgreer after reviewing and merging this PR, could you please make a new simqso tag so that we can use it in our next DESI software release? Thanks.
Background
In astropy 2.x,
linelist.ION
is anumpy.ndarray
object andlinelist.ION[0]
isnumpy.bytes_
thus requiring code like the currentif b'HI' in linelist.ION[i]
. But inconsistently,linelist['ION']
is anumpy.chararray
andlinelist['ION'][0]
is astr
requiring comparisons likeif 'HI' in linelist.ION[i]
instead (note'HI'
str notb'HI'
bytes).astropy 4.x (or maybe 3.x) made these consistent with both
linelist.ION
andlinelist['ION']
beingnumpy.chararray
objects with individual elements that arestr
, thus breaking the previous comparison withb'HI'
. The syntax that works with both astropy 2.x and 4.x is: