alphaparrot / ExoPlaSim

Exoplanet Planet Simulator (PlaSim extended for different planet types (including tidally-locked) and evolution on geological timescales--glaciers and carbon cycle)
GNU General Public License v2.0
53 stars 13 forks source link

Import of exoplasim.pyfft #1

Closed maureenjcohen closed 1 year ago

maureenjcohen commented 2 years ago

Added import of pyfft to init

I was getting an error about pyfft not being found from the pyburn readfile function unless I manually imported pyfft first, so I've added an import to init.

alphaparrot commented 2 years ago

Hmm, I think this will actually cause problems--pyfft is a compiled library built from Fortran source (you'll notice there's only pyfft.so and pyfft.f90, and no pyfft.py), and it can only be compiled after ExoPlaSim is installed--requiring that it be imported in the main module will mean that "import exoplasim" will fail on new installations, since the pyfft compilation happens when the compilers are configured, which is when an ExoPlaSim Model object is created for the very first time post-install. This is why even in pyburn, pyfft is only imported inside the functions that need it--pyburn should only check for pyfft's existence at runtime when it is actively required, and therefore likely to already exist.

I'm a bit concerned/confused by the pyfft import error in readfile--you'll notice that at lines 548-551 of pyburn.py, pyfft does get imported in pyburn.readfile.

Possible explanations:

  1. Working within the package directory, rather than letting ExoPlaSim be installed to the currently-used path, and Python getting mad about the 'exoplasim.' prefix when importing pyfft (because it doesn't know it's inside a package).
  2. Using Python 2, and something has broken, probably with f2py (the numpy library that compiles Fortran code into Python-importable linked libraries), meaning pyfft.so isn't being generated, or is broken.
  3. Something else is broken/changed with f2py in a more-recent version of numpy than I tested on, meaning pyfft.so isn't being generated, or is broken.
  4. Something else has gone wrong, possibly (probably) my fault.

Can you report the version of Python you're using, the version of numpy you have installed, whether you're working locally within the package folder structure or installing it to the system/python path (with pip install or python setup.py install), and the exact text of the error message you're getting with the pyfft import?

alphaparrot commented 1 year ago

Closing this because if I remember correctly we resolved this offline, and the PR isn't needed