keflavich / pyradex

Python interface to RADEX
BSD 3-Clause "New" or "Revised" License
18 stars 12 forks source link

datapath IndexError #17

Closed astro313 closed 6 years ago

astro313 commented 6 years ago

Hi Adam,

I installed pyradex on my Mac OSX without a problem but I couldn't run pyradex.Radex().

I am using python 2.7.12 on Mac OSX 10.11.6 (El Capitan). Here's the error message:

In [1]: run simple_co.py
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/Users/admin/Research/Radex/pyradex/examples/simple_co.py in <module>()
      2 import pylab as pl
      3 
----> 4 R = pyradex.Radex(column=1e16)
      5 R.maxiter=1000
      6 #print R.radex.impex.molfile,R.molpath

/Users/admin/anaconda/lib/python2.7/site-packages/pyradex/core.pyc in __init__(self, collider_densities, density, total_density, temperature, species, column, column_per_bin, tbackground, deltav, abundance, datapath, escapeProbGeom, outfile, logfile, debug, mu, source_area)
    286 
    287         if datapath is not None:
--> 288             self.datapath = datapath
    289             if self.datapath != os.path.expanduser(datapath):
    290                 raise ValueError("Data path %s was not successfully stored;"

/Users/admin/anaconda/lib/python2.7/site-packages/pyradex/core.pyc in datapath(self, radat)
    644             self.radex.setup.radat[:] = np.bytes_([""] * len(self.radex.setup.radat))
    645         else:
--> 646             self.radex.setup.radat[:] = ""
    647         # there is dangerous magic here: radat needs to be interpreted as an array,
    648         # but you can't make it an array of characters easily...

IndexError: too many indices for array

In [5]: import os

In [6]: os.getenv('RADEX_DATAPATH') 
Out[6]: '/Users/admin/Research/Radex/pyradex'

I looked at pyradex/core.py and found

        # there is dangerous magic here: radat needs to be interpreted as an array,
        # but you can't make it an array of characters easily...

not sure if this may be relevant?

Thanks, Daisy

keflavich commented 6 years ago

I think this has to do with changes to numpy, and therefore it may be a real bug. However... I can't reproduce this error locally. Are you on the master version of pyradex? What version of numpy are you using?

astro313 commented 6 years ago

Yes I am on master branch. I am using numpy 1.13.1. Which version should I try running pyradex?

keflavich commented 6 years ago

I'm not sure. I'm on numpy 1.12. I tried both py2 and py3 with no error. Maybe this is a np 1.13 issue?

astro313 commented 6 years ago

I tried numpy 1.12.0 and 1.12.1 but both versions gave me ImportError on import pyradex


*---------------------------------------------------------------------------*

*RuntimeError**                              Traceback (most recent call
last)*

*RuntimeError**: module compiled against API version 0xb but this version
of numpy is 0xa*

*---------------------------------------------------------------------------*

*ImportError**                               Traceback (most recent call
last)*

*----> 1* *import** pyradex*

*/Users/admin/anaconda/lib/python2.7/site-packages/pyradex/__init__.py** in
**<module>**()*

*      5* *from* *.* *import** utils*

*      6* *from* *.* *import** despotic_interface*

*----> 7* *from* *.* *import** radex*

*      8* *from* *.* *import** synthspec*

*/Users/admin/anaconda/lib/python2.7/site-packages/pyradex/radex/__init__.py**
in **<module>**()*

*----> 1* *from* *.* *import** radex*

*ImportError**: numpy.core.multiarray failed to import*

I ended up re-installing pyradex with python setup.py install_radex install_myradex build install instead of python setup.py install_radex install_myradex install. It's working now with numpy 1.12.1.

Thanks!

yxlinaqua commented 6 years ago

Hi,

I met with a problem similar to this, " File "/home/cham/anaconda2/lib/python2.7/site-packages/pyradex/base_class.py", line 127, in species self.molpath = os.path.join(self.datapath,species+'.dat')

File "/home/cham/anaconda2/lib/python2.7/site-packages/pyradex/core.py", line 614, in molpath self.radex.impex.molfile[:] = ""

IndexError: too many indices for array"

I tried to solve it following the suggestions here but it didn't work. I'll try with py3 first now.

yxlinaqua commented 6 years ago

py3 works fine. Thanks!