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

PorkChopPlotter failed to make plots with example #1623

Open
athulpg007 opened this issue Apr 5, 2023 · 3 comments
Open

PorkChopPlotter failed to make plots with example #1623

athulpg007 opened this issue Apr 5, 2023 · 3 comments

Comments

@athulpg007
Copy link

athulpg007 commented Apr 5, 2023

馃悶 Problem

Hello poliastro community, I tried to run the following example to generate a porkchop plot.

from astropy import units as u

from poliastro.bodies import Earth, Mars
from poliastro.plotting.porkchop import PorkchopPlotter
from poliastro.util import time_range

launch_span = time_range(start="2005-04-30", end="2005-10-07")
arrival_span = time_range(start="2005-11-16", end="2006-12-21")

porkchop_plot = PorkchopPlotter(Earth, Mars, launch_span, arrival_span)
dv_dpt, dv_arr, c3dpt, c3arr, tof = porkchop_plot.porkchop()

and encountered the following error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[10], line 2
      1 porkchop_plot = PorkchopPlotter(Earth, Mars, launch_span, arrival_span)
----> 2 dv_dpt, dv_arr, c3dpt, c3arr, tof = porkchop_plot.porkchop()

File ~/Documents/poliastro/venv/lib/python3.10/site-packages/poliastro/plotting/porkchop.py:204, in PorkchopPlotter.porkchop(self)
    198     fig = self.ax.figure
    200 c3_levels = np.linspace(
    201     0, self.max_c3.to_value(u.km**2 / u.s**2), 30
    202 )
--> 204 c = self.ax.contourf(
    205     [D.to_datetime() for D in self.launch_span],
    206     [A.to_datetime() for A in self.arrival_span],
    207     c3_launch,
    208     c3_levels,
    209 )
    211 line = self.ax.contour(
    212     [D.to_datetime() for D in self.launch_span],
    213     [A.to_datetime() for A in self.arrival_span],
   (...)
    217     linestyles="solid",
    218 )
    220 cbar = fig.colorbar(c)

File ~/Documents/poliastro/venv/lib/python3.10/site-packages/matplotlib/__init__.py:1442, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
   1439 @functools.wraps(func)
   1440 def inner(ax, *args, data=None, **kwargs):
   1441     if data is None:
-> 1442         return func(ax, *map(sanitize_sequence, args), **kwargs)
   1444     bound = new_sig.bind(ax, *args, **kwargs)
   1445     auto_label = (bound.arguments.get(label_namer)
   1446                   or bound.kwargs.get(label_namer))

File ~/Documents/poliastro/venv/lib/python3.10/site-packages/matplotlib/axes/_axes.py:6467, in Axes.contourf(self, *args, **kwargs)
   6458 """
   6459 Plot filled contours.
   6460 
   (...)
   6464 %(contour_doc)s
   6465 """
   6466 kwargs['filled'] = True
-> 6467 contours = mcontour.QuadContourSet(self, *args, **kwargs)
   6468 self._request_autoscale_view()
   6469 return contours

File ~/Documents/poliastro/venv/lib/python3.10/site-packages/matplotlib/contour.py:769, in ContourSet.__init__(self, ax, levels, filled, linewidths, linestyles, hatches, alpha, origin, extent, cmap, colors, norm, vmin, vmax, extend, antialiased, nchunk, locator, transform, negative_linestyles, *args, **kwargs)
    765 if self.negative_linestyles is None:
    766     self.negative_linestyles = \
    767         mpl.rcParams['contour.negative_linestyle']
--> 769 kwargs = self._process_args(*args, **kwargs)
    770 self._process_levels()
    772 self._extend_min = self.extend in ['min', 'both']

File ~/Documents/poliastro/venv/lib/python3.10/site-packages/matplotlib/contour.py:1411, in QuadContourSet._process_args(self, corner_mask, algorithm, *args, **kwargs)
   1408         corner_mask = mpl.rcParams['contour.corner_mask']
   1409 self._corner_mask = corner_mask
-> 1411 x, y, z = self._contour_args(args, kwargs)
   1413 contour_generator = contourpy.contour_generator(
   1414     x, y, z, name=self._algorithm, corner_mask=self._corner_mask,
   1415     line_type=contourpy.LineType.SeparateCode,
   1416     fill_type=contourpy.FillType.OuterCode,
   1417     chunk_size=self.nchunk)
   1419 t = self.get_transform()

File ~/Documents/poliastro/venv/lib/python3.10/site-packages/matplotlib/contour.py:1453, in QuadContourSet._contour_args(self, args, kwargs)
   1451 else:
   1452     raise _api.nargs_error(fn, takes="from 1 to 4", given=nargs)
-> 1453 z = ma.masked_invalid(z, copy=False)
   1454 self.zmax = float(z.max())
   1455 self.zmin = float(z.min())

File ~/Documents/poliastro/venv/lib/python3.10/site-packages/numpy/ma/core.py:2361, in masked_invalid(a, copy)
   2359 mask = getattr(a, '_mask', None)
   2360 if mask is not None:
-> 2361     condition = ~(np.isfinite(getdata(a)))
   2362     if mask is not nomask:
   2363         condition |= mask

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

馃枼 Please paste the output of following commands

  • system information
Ubuntu 22.04.2 LTS
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0]
  • pip freeze
aiofiles==22.1.0
aiosqlite==0.18.0
anyio==3.6.2
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
astropy==5.2.2
astroquery==0.4.6
asttokens==2.2.1
attrs==22.2.0
Babel==2.12.1
backcall==0.2.0
beautifulsoup4==4.12.0
bleach==6.0.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.1.0
comm==0.1.3
contourpy==1.0.7
cryptography==40.0.1
cycler==0.11.0
debugpy==1.6.6
decorator==5.1.1
defusedxml==0.7.1
executing==1.2.0
fastjsonschema==2.16.3
fonttools==4.39.3
fqdn==1.5.1
html5lib==1.1
idna==3.4
importlib-metadata==6.1.0
ipykernel==6.22.0
ipython==8.12.0
ipython-genutils==0.2.0
isoduration==20.11.0
jaraco.classes==3.2.3
jedi==0.18.2
jeepney==0.8.0
Jinja2==3.1.2
jplephem==2.18
json5==0.9.11
jsonpointer==2.3
jsonschema==4.17.3
jupyter-events==0.6.3
jupyter-ydoc==0.2.3
jupyter_client==8.1.0
jupyter_core==5.3.0
jupyter_server==2.5.0
jupyter_server_fileid==0.8.0
jupyter_server_terminals==0.4.4
jupyter_server_ydoc==0.8.0
jupyterlab==3.6.3
jupyterlab-pygments==0.2.2
jupyterlab_server==2.22.0
keyring==23.13.1
kiwisolver==1.4.4
llvmlite==0.39.1
MarkupSafe==2.1.2
matplotlib==3.7.1
matplotlib-inline==0.1.6
mistune==2.0.5
more-itertools==9.1.0
nbclassic==0.5.5
nbclient==0.7.3
nbconvert==7.3.0
nbformat==5.8.0
nest-asyncio==1.5.6
notebook==6.5.3
notebook_shim==0.2.2
numba==0.56.4
numpy==1.23.5
packaging==23.0
pandas==2.0.0
pandocfilters==1.5.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.5.0
platformdirs==3.2.0
plotly==5.14.0
poliastro==0.17.0
prometheus-client==0.16.0
prompt-toolkit==3.0.38
psutil==5.9.4
ptyprocess==0.7.0
pure-eval==0.2.2
pycparser==2.21
pyerfa==2.0.0.3
Pygments==2.14.0
pyparsing==3.0.9
pyrsistent==0.19.3
python-dateutil==2.8.2
python-json-logger==2.0.7
pytz==2023.3
pyvo==1.4.1
PyYAML==6.0
pyzmq==25.0.2
requests==2.28.2
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
scipy==1.10.1
SecretStorage==3.3.3
Send2Trash==1.8.0
six==1.16.0
sniffio==1.3.0
soupsieve==2.4
stack-data==0.6.2
tenacity==8.2.2
terminado==0.17.1
tinycss2==1.2.1
tomli==2.0.1
tornado==6.2
traitlets==5.9.0
tzdata==2023.3
uri-template==1.2.0
urllib3==1.26.15
wcwidth==0.2.6
webcolors==1.13
webencodings==0.5.1
websocket-client==1.5.1
y-py==0.5.9
ypy-websocket==0.8.2
zipp==3.15.0

I appreciate if someone could tell me if I missed anything, or if this is a bug.

Thanks for all the great work you do.

# Paste your output here:
# Paste your output here:

馃挕 Possible solutions

馃搵 Steps to solve the problem

  • Comment below about what you've started working on.
  • Add, commit, push your changes
  • Submit a pull request and add this in comments - Addresses #<put issue number here>
  • Ask for a review in comments section of pull request
  • Celebrate your contribution to this project 馃帀
@jorgepiloto
Copy link
Member

Thanks for opening this issue, @athulpg007. It looks an issue with the matplotlib version. Imposing:

python -m pip install matplotlib==3.6.3

allows the code to properly execute.

It's been quite a while without a release and I bet 0.17 is probably broken at this point.

@athulpg007
Copy link
Author

Thanks @jorgepiloto. I can confirm the solution works.

@jorgepiloto
Copy link
Member

I am likely to have some time during this weekend to fix this. Let's see if we can perform a patch release on 0.17 to fix this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants