aasensio / hazel2

Hazel v2.0: synthesis and inversion of Stokes profiles caused by the joint action of atomic level polarization and the Hanle and Zeeman effects
https://aasensio.github.io/hazel2/index.html
MIT License
21 stars 6 forks source link

import hazel #2

Closed reza35 closed 6 years ago

reza35 commented 6 years ago

should I do anything regarding the SIR code to get things working? I had no warning in installation but cannot import hazel:

(rpy3) reza@debian:/data/hazel2$ ipython Python 3.4.5 | packaged by conda-forge | (default, Sep 8 2016, 14:22:44) Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details.

In [1]: import hazel

ImportError Traceback (most recent call last)

in () ----> 1 import hazel /data/hazel2/hazel/__init__.py in () ----> 1 from .atmosphere import * 2 from .model import * 3 from .configuration import * 4 from .spectrum import * 5 from .multiprocess import * /data/hazel2/hazel/atmosphere.py in () 3 import os 4 from hazel.util import i0_allen, fvoigt ----> 5 from hazel.codes import hazel_code, sir_code 6 from hazel.hsra import hsra_continuum 7 from hazel.io import Generic_hazel_file, Generic_SIR_file, Generic_parametric_file /data/hazel2/hazel/codes/__init__.py in () ----> 1 from .sir_code import * 2 from .hazel_code import * ImportError: No module named 'hazel.codes.sir_code'
aasensio commented 6 years ago

Can you try to remove the build directory and try python setup.py install again? I'll remove the build directory from github later.

reza35 commented 6 years ago

I cloned it again. now setup.py is located in src/ and when I go there and run python setup.py install, I get an error message like this: ... gfortran -c -ffree-line-length-none -fPIC -O3 -fno-automatic -ffast-math -funroll-loops -Dpython -cpp hazel_py.f90 running install running build running build_ext cythoning pyhazel.pyx to pyhazel.c error: [Errno 2] No such file or directory: '/scratch/reza/hazel2/hazel/src/pyhazel.pyx'

aasensio commented 6 years ago

That's odd. There shouldn't be any setup.py on src/. Can you pull again the repository and check that this is indeed the case?

reza35 commented 6 years ago

I did a git clone of the latest version, then setup.py install, and it worked fine. In a new terminal, I started ipython, and basically executed the example in https://aasensio.github.io/hazel2/basic.html page, and it created a nice plot.

The only comment: in the Readme file in the main branch, under "Programmatically", the example contains "j" which should not be there, simply replace it with something like this:

mod.atmospheres['ch1'].set_parameters([10.0,20.0,100.0,1.0,0.0,8.0,1.0,0.0,1.0])

aasensio commented 6 years ago

Fixed.

avsukhorukov commented 6 years ago

I'm having exactly the same problem as Reza reported at the beginning with the "ImportError: No module named 'hazel.codes.sir_code'" message. I use Python 3.5.2, GCC 5.4.0 on Ubuntu 16.04.4 x86_64. The build log for "python3 setup.py install" has no errors and is here.

aasensio commented 6 years ago

Is this the first you install hazel2? If not, could you have a look at /usr/local/lib/python3.5/dist-packagesand check that there is not a previous version of hazel (should be called either hazelinv or hazel). I had a problem registering hazel at pip and I had to change the name of the package to hazelinv.

avsukhorukov commented 6 years ago

Yes, this is the 1st time I install hazel2. I tried building it in several different ways by completely cleaning the repository and the contents of /usr/local/lib/python3.5/dist-packages/hazel*.

First. The problem is gone once I make the development version (python3 setup.py develop). I can build the default version on top (python3 setup.py install) or even clean the repository and the contents of /usr/.../dist-packages/hazel* and build the default version and it will work. The test four-panel case from "Basic usage - Programmatically" works.

Second. If I make a fresh clone of the repository and try to build the default version again, it throws me the same problem as I have reported before. There is something between install and develop that really makes the difference.

Third. Taking an advantage of the moment, could you fix the following things in the documentation?

Installation - Requirements:

Basic usage - Programmatically:

UPD: I've forgotten to mention that I'm installing the code from source. I'm not using pip/conda/any environments.

aasensio commented 6 years ago

Are you trying to import hazel from the installation directory? If this is the case, this might be the cause why you are having problems with the ImportError: No module named 'hazel.codes.sir_code' error. Try to change directory and see if it works.

Additionally, if you install using python setup.py develop, you can uninstall the package for using later python setup.py install by using python setup.py develop --uninstall (or editing the easy-install.pth file in the /usr/.../dist-packages/ directory).

I've also updated the documentation. I'm waiting for the code to be slightly more stable to upload it to pip and conda.

avsukhorukov commented 6 years ago

Just in case if somebody encounters the same issue and none of the above suggestions work, here is how I got round the problem. For some reason, installing the development version and then the normal one on top of it works:

mariaritamurabito commented 3 years ago

Hi, I have the problem with "import hazel" too. I'm following these suggestions, removing build directory, recloning and reinstalling but it has no effect. I tried to import from the hazel2 directory (the installation directory) and I have this error: Python 3.6.12 |Anaconda, Inc.| (default, Sep 8 2020, 23:10:56) Type 'copyright', 'credits' or 'license' for more information IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import hazel

ModuleNotFoundError Traceback (most recent call last)

in ----> 1 import hazel ~/hazel2/hazel/__init__.py in 2 __author__ = "Andres Asensio Ramos" 3 ----> 4 from .atmosphere import * 5 from .model import * 6 from .configuration import * ~/hazel2/hazel/atmosphere.py in 3 import os 4 from hazel.util import i0_allen, fvoigt ----> 5 from hazel.codes import hazel_code, sir_code 6 from hazel.hsra import hsra_continuum 7 from hazel.io import Generic_hazel_file, Generic_SIR_file, Generic_parametric_file ~/hazel2/hazel/codes/__init__.py in ----> 1 from .sir_code import * 2 from .hazel_code import * ModuleNotFoundError: No module named 'hazel.codes.sir_code' If I do the command outside the installation directory the error change: ImportError: /home/solare/anaconda3/envs/hazel_env/lib/python3.6/site-packages/hazel-2018.9.22-py3.6-linux-x86_64.egg/hazel/codes/sir_code.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZGVdN8v_expf I checked if in /usr/local/lib/python3.5/dist-packages there is something. And no.
aasensio commented 3 years ago

Solved for the moment. Pulled the latest version of the code, updated conda, reinstalled all packages and it works.