Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in plotting module #35

Closed
FilippoOggionni opened this issue Jan 11, 2022 · 10 comments
Closed

Error in plotting module #35

FilippoOggionni opened this issue Jan 11, 2022 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@FilippoOggionni
Copy link
Member

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).

@FilippoOggionni FilippoOggionni added the bug Something isn't working label Jan 11, 2022
@FilippoOggionni FilippoOggionni self-assigned this Jan 11, 2022
@FilippoOggionni
Copy link
Member Author

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).

@FilippoOggionni
Copy link
Member Author

Build is finished but the plotting module on the API reference is still empty... 🤔

@gaffarelj
Copy link
Member

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.

@FilippoOggionni
Copy link
Member Author

FilippoOggionni commented Jan 12, 2022

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.

@gaffarelj
Copy link
Member

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.

@gaffarelj
Copy link
Member

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'

@gaffarelj
Copy link
Member

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.

@FilippoOggionni
Copy link
Member Author

Can you try to implement it please? @gaffarelj

@gaffarelj
Copy link
Member

I can take a look at it when I have time yes.

@gaffarelj
Copy link
Member

gaffarelj commented Jan 12, 2022

The plotting API docs are now live.

I fixed this with 51f6d1b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants