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

Uncaught error in plotting #1021

Closed

Description

@astrojuanlu

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

Activity

  1. astrojuanlu commented on Oct 4, 2020

    @astrojuanlu
    MemberAuthor

    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.

  2. clacri commented on Oct 4, 2020

    @clacri
    Contributor

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

  3. astrojuanlu commented on Oct 4, 2020

    @astrojuanlu
    MemberAuthor

    Awesome! All yours @clacri :)

  4. added a commit that references this issue on Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions