steveberardi / starplot

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

Orion example is failing #28

Closed mrosseel closed 1 year ago

mrosseel commented 1 year ago

For the standard orion example:

from starplot import MapPlot, Projection, SkyObject
from starplot.styles import PlotStyle, extensions

style = PlotStyle().extend(
    extensions.BLUE_LIGHT,
    extensions.MAP,
    {
        "bayer_labels": {
            "font_name": "GFS Didot",  # use a better font for Greek letters
            "font_size": 7,
            "font_alpha": 0.9,
        },
    },
)
style.star.label.font_size = 11

p = MapPlot(
    projection=Projection.MERCATOR,
    ra_min=3.6,
    ra_max=7.8,
    dec_min=-16,
    dec_max=23.6,
    limiting_magnitude=7.2,
    style=style,
    resolution=3600,
)
p.plot_object(
    SkyObject(
        name="M42",
        ra=5.58333,
        dec=-4.61,
        style={
            "marker": {
                "size": 10,
                "symbol": "s",
                "fill": "full",
                "color": "#ff6868",
                "alpha": 1,
                "zorder": 4096,
            },
            "label": {
                "font_size": 10,
                "font_weight": "bold",
                "font_color": "darkred",
                "zorder": 4096,
            },
        },
    )
)
p.export("03_map_orion.png", padding=0.5)

this is the error i'm getting, might be some version mismatch:


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[14], line 17
      4 style = PlotStyle().extend(
      5     extensions.BLUE_LIGHT,
      6     extensions.MAP,
   (...)
     13     },
     14 )
     15 style.star.label.font_size = 11
---> 17 p = MapPlot(
     18     projection=Projection.MERCATOR,
     19     ra_min=3.6,
     20     ra_max=7.8,
     21     dec_min=-16,
     22     dec_max=23.6,
     23     limiting_magnitude=7.2,
     24     style=style,
     25     resolution=3600,
     26 )
     27 p.plot_object(
     28     SkyObject(
     29         name="M42",
   (...)
     48     )
     49 )
     50 p.export("03_map_orion.png", padding=0.5)

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/starplot/map.py:110, in MapPlot.__init__(self, projection, ra_min, ra_max, dec_min, dec_max, dt, limiting_magnitude, limiting_magnitude_labels, include_planets, ephemeris, style, resolution, hide_colliding_labels, adjust_text, *args, **kwargs)
    108 self.dec_min = dec_min
    109 self.dec_max = dec_max
--> 110 self._init_plot()

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/starplot/map.py:417, in MapPlot._init_plot(self)
    415 self._plot_gridlines()
    416 self._plot_constellation_lines()
--> 417 self._plot_constellation_borders()
    418 self._plot_constellation_labels()
    419 self._plot_milky_way()

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/starplot/map.py:165, in MapPlot._plot_constellation_borders(self)
    163     return
    164 constellation_borders = gpd.read_file(DataFiles.CONSTELLATION_BORDERS)
--> 165 constellation_borders.plot(
    166     ax=self.ax,
    167     **self.style.constellation_borders.matplot_kwargs(
    168         size_multiplier=self._size_multiplier
    169     ),
    170     **self._plot_kwargs(),
    171 )

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/geopandas/plotting.py:979, in GeoplotAccessor.__call__(self, *args, **kwargs)
    977 kind = kwargs.pop("kind", "geo")
    978 if kind == "geo":
--> 979     return plot_dataframe(data, *args, **kwargs)
    980 if kind in self._pandas_kinds:
    981     # Access pandas plots
    982     return PlotAccessor(data)(kind=kind, **kwargs)

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/geopandas/plotting.py:716, in plot_dataframe(df, column, cmap, color, ax, cax, categorical, legend, scheme, k, vmin, vmax, markersize, figsize, legend_kwds, categories, classification_kwds, missing_kwds, aspect, **style_kwds)
    713     markersize = df[markersize].values
    715 if column is None:
--> 716     return plot_series(
    717         df.geometry,
    718         cmap=cmap,
    719         color=color,
    720         ax=ax,
    721         figsize=figsize,
    722         markersize=markersize,
    723         aspect=aspect,
    724         **style_kwds,
    725     )
    727 # To accept pd.Series and np.arrays as column
    728 if isinstance(column, (np.ndarray, pd.Series)):

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/geopandas/plotting.py:480, in plot_series(s, cmap, color, ax, figsize, aspect, **style_kwds)
    477     values_ = values[line_idx] if cmap else None
    478     color_ = expl_color[line_idx] if color_given else color
--> 480     _plot_linestring_collection(
    481         ax, lines, values_, color=color_, cmap=cmap, **style_kwds
    482     )
    484 # plot all Points in the same collection
    485 points = expl_series[point_idx]

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/geopandas/plotting.py:242, in _plot_linestring_collection(ax, geoms, values, color, cmap, vmin, vmax, **kwargs)
    239 _expand_kwargs(kwargs, multiindex)
    241 segments = [np.array(linestring.coords)[:, :2] for linestring in geoms]
--> 242 collection = LineCollection(segments, **kwargs)
    244 if values is not None:
    245     collection.set_array(np.asarray(values))

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/collections.py:1438, in LineCollection.__init__(self, segments, zorder, **kwargs)
   1436 # Unfortunately, mplot3d needs this explicit setting of 'facecolors'.
   1437 kwargs.setdefault('facecolors', 'none')
-> 1438 super().__init__(
   1439     zorder=zorder,
   1440     **kwargs)
   1441 self.set_segments(segments)

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/collections.py:203, in Collection.__init__(self, edgecolors, facecolors, linewidths, linestyles, capstyle, joinstyle, antialiaseds, offsets, offset_transform, norm, cmap, pickradius, hatch, urls, zorder, **kwargs)
    200 self._offset_transform = offset_transform
    202 self._path_effects = None
--> 203 self._internal_update(kwargs)
    204 self._paths = None

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/artist.py:1219, in Artist._internal_update(self, kwargs)
   1212 def _internal_update(self, kwargs):
   1213     """
   1214     Update artist properties without prenormalizing them, but generating
   1215     errors as if calling `set`.
   1216 
   1217     The lack of prenormalization is to maintain backcompatibility.
   1218     """
-> 1219     return self._update_props(
   1220         kwargs, "{cls.__name__}.set() got an unexpected keyword argument "
   1221         "{prop_name!r}")

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/artist.py:1195, in Artist._update_props(self, props, errfmt)
   1192             if not callable(func):
   1193                 raise AttributeError(
   1194                     errfmt.format(cls=type(self), prop_name=k))
-> 1195             ret.append(func(v))
   1196 if ret:
   1197     self.pchanged()

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/collections.py:618, in Collection.set_linestyle(self, ls)
    592 """
    593 Set the linestyle(s) for the collection.
    594 
   (...)
    615     complete description.
    616 """
    617 try:
--> 618     dashes = [mlines._get_dash_pattern(ls)]
    619 except ValueError:
    620     try:

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/lines.py:45, in _get_dash_pattern(style)
     43 elif style in ['dashed', 'dashdot', 'dotted']:
     44     offset = 0
---> 45     dashes = tuple(mpl.rcParams[f'lines.{style}_pattern'])
     46 #
     47 elif isinstance(style, tuple):

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/__init__.py:762, in RcParams.__getitem__(self, key)
    759         from matplotlib import pyplot as plt
    760         plt.switch_backend(rcsetup._auto_backend_sentinel)
--> 762 return self._get(key)

File ~/Library/Caches/pypoetry/virtualenvs/py-asterisms-TlaOFCju-py3.11/lib/python3.11/site-packages/matplotlib/__init__.py:709, in RcParams._get(self, key)
    690 def _get(self, key):
    691     """
    692     Directly read data bypassing deprecation, backend and validation
    693     logic.
   (...)
    707     :meta public:
    708     """
--> 709     return dict.__getitem__(self, key)

KeyError: 'lines.LineStyleEnum.DASHED_pattern'
steveberardi commented 1 year ago

hmmm, what version of matplotlib is installed in that virtual env?

mrosseel commented 1 year ago
adjusttext                0.8          Iteratively adjust text position in ...
annotated-types           0.5.0        Reusable constraint types to use wit...
anyio                     4.0.0        High level compatibility layer for m...
appnope                   0.1.3        Disable App Nap on macOS >= 10.9
argon2-cffi               23.1.0       Argon2 for Python
argon2-cffi-bindings      21.2.0       Low-level CFFI bindings for Argon2
arrow                     1.2.3        Better dates & times for Python
asttokens                 2.4.0        Annotate AST trees with source code ...
async-lru                 2.0.4        Simple LRU cache for asyncio
attrs                     23.1.0       Classes Without Boilerplate
babel                     2.12.1       Internationalization utilities
backcall                  0.2.0        Specifications for callback function...
beautifulsoup4            4.12.2       Screen-scraping library
bleach                    6.0.0        An easy safelist-based HTML-sanitizi...
cartopy                   0.22.0       A Python library for cartographic vi...
certifi                   2023.7.22    Python package for providing Mozilla...
cffi                      1.15.1       Foreign Function Interface for Pytho...
charset-normalizer        3.2.0        The Real First Universal Charset Det...
click                     8.1.7        Composable command line interface to...
click-plugins             1.1.1        An extension module for click to ena...
cligj                     0.7.2        Click params for commmand line inter...
comm                      0.1.4        Jupyter Python Comm implementation, ...
contourpy                 1.1.1        Python library for calculating conto...
cycler                    0.11.0       Composable style cycles
debugpy                   1.8.0        An implementation of the Debug Adapt...
decorator                 5.1.1        Decorators for Humans
defusedxml                0.7.1        XML bomb protection for Python stdli...
executing                 1.2.0        Get the currently executing AST node...
fastjsonschema            2.18.0       Fastest Python implementation of JSO...
filelock                  3.12.4       A platform independent file lock.
fiona                     1.9.4.post1  Fiona reads and writes spatial data ...
fonttools                 4.42.1       Tools to manipulate font files
fqdn                      1.5.1        Validates fully-qualified domain nam...
geopandas                 0.14.0       Geographic pandas extensions
idna                      3.4          Internationalized Domain Names in Ap...
ipykernel                 6.25.2       IPython Kernel for Jupyter
ipython                   8.15.0       IPython: Productive Interactive Comp...
ipython-genutils          0.2.0        Vestigial utilities from IPython
ipywidgets                8.1.1        Jupyter interactive widgets
isoduration               20.11.0      Operations with ISO 8601 durations
jedi                      0.19.0       An autocompletion tool for Python th...
jinja2                    3.1.2        A very fast and expressive template ...
jplephem                  2.19         Use a JPL ephemeris to predict plane...
json5                     0.9.14       A Python implementation of the JSON5...
jsonpointer               2.4          Identify specific nodes in a JSON do...
jsonschema                4.19.1       An implementation of JSON Schema val...
jsonschema-specifications 2023.7.1     The JSON Schema meta-schemas and voc...
jupyter                   1.0.0        Jupyter metapackage. Install all the...
jupyter-client            8.3.1        Jupyter protocol implementation and ...
jupyter-console           6.6.3        Jupyter terminal console
jupyter-core              5.3.1        Jupyter core package. A base package...
jupyter-events            0.7.0        Jupyter Event System library
jupyter-lsp               2.2.0        Multi-Language Server WebSocket prox...
jupyter-server            2.7.3        The backend—i.e. core services, APIs...
jupyter-server-terminals  0.4.4        A Jupyter Server Extension Providing...
jupyterlab                4.0.6        JupyterLab computational environment
jupyterlab-pygments       0.2.2        Pygments theme using JupyterLab CSS ...
jupyterlab-server         2.25.0       A set of server components for Jupyt...
jupyterlab-widgets        3.0.9        Jupyter interactive widgets for Jupy...
kiwisolver                1.4.5        A fast implementation of the Cassowa...
markupsafe                2.1.3        Safely add untrusted strings to HTML...
matplotlib                3.8.0        Python plotting package
matplotlib-inline         0.1.6        Inline Matplotlib backend for Jupyter
mistune                   3.0.1        A sane and fast Markdown parser with...
mpmath                    1.3.0        Python library for arbitrary-precisi...
nbclient                  0.8.0        A client library for executing noteb...
nbconvert                 7.8.0        Converting Jupyter Notebooks
nbformat                  5.9.2        The Jupyter Notebook format
nest-asyncio              1.5.8        Patch asyncio to allow nested event ...
networkx                  3.1          Python package for creating and mani...
notebook                  7.0.4        Jupyter Notebook - A web-based noteb...
notebook-shim             0.2.3        A shim layer for notebook traits and...
numpy                     1.25.2       Fundamental package for array comput...
overrides                 7.4.0        A decorator to automatically detect ...
packaging                 23.1         Core utilities for Python packages
pandas                    2.1.1        Powerful data structures for data an...
pandocfilters             1.5.0        Utilities for writing pandoc filters...
parso                     0.8.3        A Python Parser
pexpect                   4.8.0        Pexpect allows easy control of inter...
pickleshare               0.7.5        Tiny 'shelve'-like database with con...
pillow                    10.0.1       Python Imaging Library (Fork)
platformdirs              3.10.0       A small Python package for determini...
polars                    0.19.3       Blazingly fast DataFrame library
prometheus-client         0.17.1       Python client for the Prometheus mon...
prompt-toolkit            3.0.39       Library for building powerful intera...
psutil                    5.9.5        Cross-platform lib for process and s...
ptyprocess                0.7.0        Run a subprocess in a pseudo terminal
pure-eval                 0.2.2        Safely evaluate AST nodes without si...
pycparser                 2.21         C parser in Python
pydantic                  2.4.2        Data validation using Python type hints
pydantic-core             2.10.1       
pygments                  2.16.1       Pygments is a syntax highlighting pa...
pyongc                    1.0.2        Python interface to OpenNGC database...
pyparsing                 3.1.1        pyparsing module - Classes and metho...
pyproj                    3.6.1        Python interface to PROJ (cartograph...
pyshp                     2.3.1        Pure Python read/write support for E...
python-dateutil           2.8.2        Extensions to the standard Python da...
python-json-logger        2.0.7        A python library adding a json log f...
pytz                      2023.3.post1 World timezone definitions, modern a...
pyyaml                    6.0.1        YAML parser and emitter for Python
pyzmq                     25.1.1       Python bindings for 0MQ
qtconsole                 5.4.4        Jupyter Qt console
qtpy                      2.4.0        Provides an abstraction layer on top...
referencing               0.30.2       JSON Referencing + Python
requests                  2.31.0       Python HTTP for Humans.
rfc3339-validator         0.1.4        A pure python RFC3339 validator
rfc3986-validator         0.1.1        Pure python rfc3986 validator
rpds-py                   0.10.3       Python bindings to Rust's persistent...
send2trash                1.8.2        Send file to trash natively under Ma...
setuptools                68.2.2       Easily download, build, install, upg...
setuptools-scm            8.0.3        the blessed package to manage your v...
sgp4                      2.22         Track Earth satellites given TLE dat...
shapely                   2.0.1        Manipulation and analysis of geometr...
six                       1.16.0       Python 2 and 3 compatibility utilities
skyfield                  1.46         Elegant astronomy for Python
sniffio                   1.3.0        Sniff out which async library your c...
soupsieve                 2.5          A modern CSS selector implementation...
stack-data                0.6.2        Extract data from python stack frame...
starplot                  0.3.1        Star charts and maps
sympy                     1.12         Computer algebra system (CAS) in Python
terminado                 0.17.1       Tornado websocket backend for the Xt...
tinycss2                  1.2.1        A tiny CSS parser
torch                     2.0.1        Tensors and Dynamic neural networks ...
tornado                   6.3.3        Tornado is a Python web framework an...
tqdm                      4.66.1       Fast, Extensible Progress Meter
traitlets                 5.10.0       Traitlets Python configuration system
typing-extensions         4.8.0        Backported and Experimental Type Hin...
tzdata                    2023.3       Provider of IANA time zone data
uri-template              1.3.0        RFC 6570 URI Template Processor
urllib3                   2.0.5        HTTP library with thread-safe connec...
wcwidth                   0.2.6        Measures the displayed width of unic...
webcolors                 1.13         A library for working with the color...
webencodings              0.5.1        Character encoding aliases for legac...
websocket-client          1.6.3        WebSocket client for Python with low...
widgetsnbextension        4.0.9        Jupyter interactive widgets for Jupy...
steveberardi commented 1 year ago

were you able to compile shapely from source in this environment? I'm still trying to reproduce this, but I'm thinking it must be some kind of version mismatch, as you suggested.

steveberardi commented 1 year ago

@mrosseel just to follow up on this, I was able to reproduce this issue with Python 3.11 + Pydantic 2.4 and just pushed a fix to PyPi (v0.3.3) -- it also seems that you don't have to compile shapely from source with Python 3.11 😃

mrosseel commented 1 year ago

after doing a poetry update starplot upgrading from 0.3.1 to 0.3.3 the Orion example now indeed works! Only getting some font warnings: findfont: Font family 'GFS Didot' not found., which I could resolve by choosing another font from the mac 'font book' app (Hack Nerd Font). The image seems correctly generated.