steveberardi / starplot

✨ Star charts and maps in Python
https://starplot.dev
MIT License
17 stars 7 forks source link

Error when using Zenithplot with faint stars #27

Closed mrosseel closed 9 months ago

mrosseel commented 9 months ago

When changing the example code to a limiting_magnitude of e.g. 10, the hip_main data is downloaded but then a crash happens. I know it's probably not a good idea to make a zenithplot with mag 10 but wanted to report it anyway.

Env: on a mac, installed homebrew dependencies and starplot itself using poetry - installing shapely from source failed. Testing was done in a jupyter notebook.

Note: the default example did produce a nice plot. Also having trouble with the standard Orion example, maybe it's install related?

from datetime import datetime
from pytz import timezone
from starplot import ZenithPlot
from starplot.styles import PlotStyle, extensions

tz = timezone("America/Los_Angeles")
dt = datetime(2023, 7, 13, 22, 0, tzinfo=tz)  # July 13, 2023 at 10pm PT

p = ZenithPlot(
    lat=33.363484,
    lon=-116.836394,
    dt=dt,
    limiting_magnitude=10,
    style=PlotStyle().extend(
        extensions.BLUE_MEDIUM,
        extensions.ZENITH,
    ),
    resolution=2000,
    adjust_text=True,
)
p.export("01_star_chart.png")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[13], line 9
      6 tz = timezone("America/Los_Angeles")
      7 dt = datetime(2023, 7, 13, 22, 0, tzinfo=tz)  # July 13, 2023 at 10pm PT
----> 9 p = ZenithPlot(
     10     lat=33.363484,
     11     lon=-116.836394,
     12     dt=dt,
     13     limiting_magnitude=10,
     14     style=PlotStyle().extend(
     15         extensions.BLUE_MEDIUM,
     16         extensions.ZENITH,
     17     ),
     18     resolution=2000,
     19     adjust_text=True,
     20 )
     21 p.export("01_star_chart.png")

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/starplot/zenith.py:102, in ZenithPlot.__init__(self, lat, lon, include_info_text, dt, limiting_magnitude, limiting_magnitude_labels, ephemeris, include_planets, style, resolution, hide_colliding_labels, adjust_text, *args, **kwargs)
     99 self._calc_position()
    100 self.project_fn = build_stereographic_projection(self.position)
--> 102 self._init_plot()

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/starplot/zenith.py:322, in ZenithPlot._init_plot(self)
    319 self.ax.axis("off")
    321 self._plot_border()
--> 322 self._plot_stars()
    323 self._plot_constellation_lines()
    324 self._plot_constellation_labels()

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/starplot/zenith.py:174, in ZenithPlot._plot_stars(self)
    172 # Draw stars
    173 if self.style.star.marker.visible:
--> 174     self._plotted_stars = self.ax.scatter(
    175         stardata["x"][bright_stars],
    176         stardata["y"][bright_stars],
    177         sizes,
    178         color=self.style.star.marker.color.as_hex(),
    179         clip_path=self.background_circle,
    180     )
    182 starpos_x = []
    183 starpos_y = []

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/__init__.py:1465, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
   1462 @functools.wraps(func)
   1463 def inner(ax, *args, data=None, **kwargs):
   1464     if data is None:
-> 1465         return func(ax, *map(sanitize_sequence, args), **kwargs)
   1467     bound = new_sig.bind(ax, *args, **kwargs)
   1468     auto_label = (bound.arguments.get(label_namer)
   1469                   or bound.kwargs.get(label_namer))

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/axes/_axes.py:4661, in Axes.scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, plotnonfinite, **kwargs)
   4657 s = np.ma.ravel(s)
   4658 if (len(s) not in (1, x.size) or
   4659         (not np.issubdtype(s.dtype, np.floating) and
   4660          not np.issubdtype(s.dtype, np.integer))):
-> 4661     raise ValueError(
   4662         "s must be a scalar, "
   4663         "or float array-like with the same size as x and y")
   4665 # get the original edgecolor the user passed before we normalize
   4666 orig_edgecolor = edgecolors

ValueError: s must be a scalar, or float array-like with the same size as x and y
steveberardi commented 9 months ago

@mrosseel thanks for reporting this, I was able to reproduce the issue. It looks like starplot is calculating the size of a star marker in a format that matplotlib doesn't like. I'll do some more digging and fix this in an upcoming release :)

What issue are you running into with the Orion map plot? Feel free to open another GH issue, and I'll try to help!

Thanks again!

Steve

mrosseel commented 9 months ago

thx for the quick response, I've added #28 for the Orion issue

steveberardi commented 9 months ago

@mrosseel just fixed this in the latest release -- let me know if you still get that error, thanks!