Error in plotting module
FilippoOggionni opened this issue · comments
When doing:
from tudatpy.plotting import plot_miller_ground_track
this error is thrown:
Traceback (most recent call last):
File "/Users/foggionni/Library/Application Support/JetBrains/PyCharm2021.2/scratches/scratch_1.py", line 3, in <module>
from tudatpy.plotting import plot_miller_ground_track
File "/Users/foggionni/opt/miniconda3/envs/revolv-tudatpy/lib/python3.8/site-packages/tudatpy/plotting/__init__.py", line 1, in <module>
from ._ground_track import *
File "/Users/foggionni/opt/miniconda3/envs/revolv-tudatpy/lib/python3.8/site-packages/tudatpy/plotting/_ground_track.py", line 6, in <module>
from mpl_toolkits.basemap import Basemap
ModuleNotFoundError: No module named 'mpl_toolkits.basemap'
This is likely the reason why the API docs for the plotting module are empty (interestingly enough, they do show up when producing the API docs locally - likely because the local system retrieves docstrings directly from the source code instead of tudatpy objects).
I tried locally and by installing the basemap-data-hires
package the error is solved.
Attempting a fix of the online docs by adding such package to the environment.yaml
files (see tudat-team/tudat-bundle@c636ddd and tudat-team/tudat-multidoc@5acd73e).
Build is finished but the plotting
module on the API reference is still empty... 🤔
I just looking into the raw log for the last API docs build (here).
This exception is raised when running the plotting script is run:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/conda/latest/lib/python3.8/site-packages/sphinx/ext/autodoc/importer.py", line 70, in import_module
return importlib.import_module(modname)
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/conda/latest/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/checkouts/latest/build/tudatpy/plotting/__init__.py", line 1, in <module>
from ._ground_track import *
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/checkouts/latest/build/tudatpy/plotting/_ground_track.py", line 3, in <module>
os.environ['PROJ_LIB'] = os.environ['CONDA_PREFIX'] + '/share/proj' # Required fix for Jupyter
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/conda/latest/lib/python3.8/os.py", line 675, in __getitem__
raise KeyError(key) from None
KeyError: 'CONDA_PREFIX'
I believe the error is caused by the fix required for Jupyter. I would advise simply setting a try
and catch
, so that the error is handled in case the CONDA_PREFIX
is unknown in the environment. We could then simply print a warning instead of having the KeyError
triggered.
Thanks for looking into this! I tried the fix you suggested (see 82bb79a), let's see if it works.
Also, I think the util
and plotting
modules were set up quickly by @ggarrett13 (they should be expanded and modified), so we can definitely play around and change stuff.
Perfect 🤞
I have actually started expending util
, by adding compare_results
, pareto_optimums
, and redirect_std
.
For plotting
, I have plans for 3D trajectory plotting and dual y-axis plotting functions.
I see it's still not building. It looks like the fix for Jupyter is actually also needed for the API build:
WARNING: autodoc: failed to import function 'plotting.plot_blue_marble_ground_track' from module 'tudatpy'; the following exception was raised:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/conda/latest/lib/python3.8/site-packages/sphinx/ext/autodoc/importer.py", line 70, in import_module
return importlib.import_module(modname)
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/conda/latest/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/checkouts/latest/build/tudatpy/plotting/__init__.py", line 1, in <module>
from ._ground_track import *
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/checkouts/latest/build/tudatpy/plotting/_ground_track.py", line 10, in <module>
from mpl_toolkits.basemap import Basemap
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/conda/latest/lib/python3.8/site-packages/mpl_toolkits/basemap/__init__.py", line 152, in <module>
pyproj_datadir = os.environ['PROJ_LIB']
File "/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/conda/latest/lib/python3.8/os.py", line 675, in __getitem__
raise KeyError(key) from None
KeyError: 'PROJ_LIB'
The workaround I see would be to set PROJ_LIB=/home/docs/checkouts/readthedocs.org/user_builds/tudatpy/share/proj
(I didn't check, could be something slightly different), when we detect that we are on readthedocs. This could be done by checking the path?
I don't see another solution for now, though there is probably something more elegant to extract the conda path when CONDA_PREFIX
is not set.
Can you try to implement it please? @gaffarelj
I can take a look at it when I have time yes.
The plotting API docs are now live.
I fixed this with 51f6d1b.