Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Uncaught error in plotting #1021

Closed
astrojuanlu opened this issue Sep 20, 2020 · 3 comments · Fixed by #1028
Closed

Uncaught error in plotting #1021

astrojuanlu opened this issue Sep 20, 2020 · 3 comments · Fixed by #1028
Assignees
Labels
good first issue Easy tasks for beginners triaging:bug

Comments

@astrojuanlu
Copy link
Member

astrojuanlu commented Sep 20, 2020

This code:

from poliastro.bodies import Sun
from poliastro.ephem import Ephem
from poliastro.plotting import OrbitPlotter2D

epochs = time_range(..., end=...)  # TBC
earth = Ephem.from_body(Earth, epochs)

plotter = OrbitPlotter2D()

plotter.set_attractor(Sun)
plotter.plot_ephem(earth)

Causes this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-130-a5728741413f> in <module>
      2 
      3 plotter.set_attractor(Sun)
----> 4 plotter.plot_ephem(earth)

~/.pyenv/versions/seminar38/lib/python3.8/site-packages/poliastro/plotting/core.py in plot_ephem(self, ephem, epoch, label, color, trail)
    118 
    119         """
--> 120         super().plot_ephem(ephem, epoch, label=label, color=color, trail=trail)
    121 
    122         if not self._figure._in_batch_mode:

~/.pyenv/versions/seminar38/lib/python3.8/site-packages/poliastro/plotting/_base.py in plot_ephem(self, ephem, epoch, label, color, trail)
    286         # Do not return the result of self._plot
    287         # This behavior might be overriden by subclasses
--> 288         self._plot_ephem(ephem, epoch, label=label, color=color, trail=trail)
    289 
    290 

~/.pyenv/versions/seminar38/lib/python3.8/site-packages/poliastro/plotting/_base.py in _plot_ephem(self, ephem, epoch, label, color, trail)
    200             r0 = None
    201 
--> 202         return self.__add_trajectory(
    203             coordinates, r0, label=str(label), colors=colors, dashed=False
    204         )

~/.pyenv/versions/seminar38/lib/python3.8/site-packages/poliastro/plotting/_base.py in __add_trajectory(self, coordinates, position, label, colors, dashed)
    119         self._trajectories.append(trajectory)
    120 
--> 121         self._redraw_attractor()
    122 
    123         trace_coordinates, trace_position = self.__plot_coordinates_and_position(

~/.pyenv/versions/seminar38/lib/python3.8/site-packages/poliastro/plotting/_base.py in _redraw_attractor(self)
     77         self._clear_attractor()
     78 
---> 79         self._draw_sphere(
     80             self._attractor_radius, color, self._attractor.name,
     81         )

~/.pyenv/versions/seminar38/lib/python3.8/site-packages/poliastro/plotting/core.py in _draw_sphere(self, radius, color, name, center)
    275 
    276     def _draw_sphere(self, radius, color, name, center=[0, 0, 0] * u.km):
--> 277         x_center, y_center = self._project(
    278             center[None]
    279         )  # Indexing trick to add one extra dimension

~/.pyenv/versions/seminar38/lib/python3.8/site-packages/poliastro/plotting/_base.py in _project(self, rr)
    296 
    297     def _project(self, rr):
--> 298         rr_proj = rr - rr.dot(self._frame[2])[:, None] * self._frame[2]
    299         x = rr_proj.dot(self._frame[0])
    300         y = rr_proj.dot(self._frame[1])

TypeError: 'NoneType' object is not subscriptable
@astrojuanlu
Copy link
Member Author

Prospective contributors: StaticOrbitPlotter avoids this uncaught error by doing this:

if self._frame is None:
raise ValueError(
"A frame must be set up first, please use "
"set_orbit_frame(orbit) or plot(orbit)"
)

We should do the same in OrbitPlotter2D, and add a test.

@clacri
Copy link
Contributor

clacri commented Oct 4, 2020

I would like to take care of this issue :) I'm one of the participants of HacktoberfestES and arrived here thanks to @astrojuanlu

@astrojuanlu
Copy link
Member Author

Awesome! All yours @clacri :)

clacri added a commit to clacri/poliastro that referenced this issue Oct 8, 2020
clacri added a commit to clacri/poliastro that referenced this issue Oct 10, 2020
astrojuanlu added a commit that referenced this issue Oct 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy tasks for beginners triaging:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants