hpparvi / PyTransit

Fast and easy exoplanet transit light curve modelling.
GNU General Public License v2.0
99 stars 23 forks source link

ImportError No module named gimenez #14

Closed odemangeon closed 8 years ago

odemangeon commented 8 years ago

I am working on Mac OS X 10.11.2 (El Capitan). I just tried to install pytransit using the command provided in GitHub: python setup.py config_fc --fcompiler=gnu95 --opt="-Ofast" --f90flags="-cpp -fopenmp -march=native -mno-avx" build python setup.py install --user

Everything goes well (warnings but no error). But when in python, I try import pytransit I get the following error message: ImportError: No module named 'gimenez'. (see details in the .txt file attached).

ErrorReportpytransit 20160119.txt

odemangeon commented 8 years ago

I figured it out. This comes from relative imports. For example, for the issue reported above, in pytransit/init.py, you have

from gimenez import Gimenez

If I turned it into

from .gimenez import Gimenez

It solves the problem.

There is a couple of import to change like that here and there and pytransit import without errors. Should I fork those changes ?

odemangeon commented 8 years ago

I tried the code with the following example

import numpy as np
from pytransit import MandelAgol

t = np.linspace(0.8,1.2,500)
k, t0, p, a, i, e, w = 0.1, 1.01, 4, 8, 0.48*np.pi, 0.2, 0.5*np.pi
u = [0.25,0.10]

m = MandelAgol()
f = m.evaluate(t, k, u, t0, p, a, i, e, w)

and I found another issue:

/Users/Oliv/anaconda/lib/python3.4/site-packages/pytransit/tm.py in _calculate_z(self, t, t0, p, a, i, e, w, interpolate_z)
     107                 z = of.z_eccentric_ps3(self._time, t0, p, a, i, e, w, nthreads=self.nthr)
     108             else:
 --> 109                 z = of.z_eccentric_newton(self._time, t0, p, a, i, e, w, nthreads=self.nthr)
     110
     111         return z

TypeError: Required argument 'nth' (pos 8) not found

I solved it slightly modifying the code as below

if interpolate_z:
            z = of.z_eccentric_ip(self._time, t0, p, a, i, e, w, nth=self.nthr, update=True)
        else:
            if fabs(e) < 0.01:
                z = of.z_circular(self._time, t0, p, a, i, nth=self.nthr)
                if self.eclipse:
                    z *= -1.
            elif fabs(e) < 0.2:
                z = of.z_eccentric_ps3(self._time, t0, p, a, i, e, w, nth=self.nthr)
            else:
                z = of.z_eccentric_newton(self._time, t0, p, a, i, e, w, nth=self.nthr)

So same question: Should I fork those changes ?

hpparvi commented 8 years ago

Thanks, I've fixed now the issue with the nthreads vs. nth. This was something I introduced a day or two ago when changing the Fortran routines but forgetting to fix the Python code calling them...

To be honest, I haven't tested the code with Python 3 at all yet, which explains the problem with relative imports. I'm now doing some final bug hunting and cleanup before a v1.0 release, and I'll be happy to merge in any fixes that help with Python 3 compatibility.

hpparvi commented 8 years ago

I've fixed the Python 3 compatibility issues, and the code should now work fine both with Python 2 and 3.