Starplot Python Library

repository·main·Indexed 41 days ago

https://github.com/steveberardi/starplot

A Python library for creating high-quality star charts, sky maps, and optic simulations. It features a high-performance data backend using DuckDB and Ibis, supporting 10+ customizable projections, trajectory plotting for comets and satellites, and export options for PNG, SVG, and JPEG. Starplot includes official catalogs for IAU constellations, OpenNGC deep sky objects, and Big Sky stars, while allowing users to build custom catalogs with Hive partitioning and HEALPix optimization for large datasets.

Tokens
27.7K
Snippets
105
Records
153
Agent score
51%

What's inside Starplot

  1. Overview of Starplot capabilities

    main

    Starplot is a Python library designed for creating high-quality star charts and maps of the sky. It supports various astronomical visualizations including:

    • Maps: Over 10 customizable projections.
    • Zenith Charts: Visualizations of the entire sky from a specific time and location.
    • Horizon Charts: Views of the horizon from a specific time and location.
    • Optic Simulations: Simulations of what is visible through an optic (e.g., a telescope) at a specific time and place.
    • Galactic Charts: Mollweide projections in galactic coordinates.
    • Object Support: Plotting of Planets, Deep Sky Objects (DSOs) with true extent, Comets, and Satellites (including trajectory plotting).
    • Customization: Custom styles for all objects and 8+ built-in themes.
    • Export Formats: Supports png, svg, and jpeg.
    • Data Backend: Uses DuckDB and Ibis for high-performance object lookup.
    • Advanced Features: Label collision avoidance for readability and localization support for Chinese, French, Italian, Lithuanian, Persian, and Spanish.
  2. View Deep Sky Objects (DSOs) from OpenNGC

    main
    The starplot project provides access to deep sky objects (DSOs) via OpenNGC data. The available objects include metadata such as Name, Type, Right Ascension (RA), Declination (DEC), Magnitude, and Geometry. This data is typically served via a JSON endpoint (e.g., ../data/ongc.json).
  3. Create a Zenith star chart with Starplot

    main

    Starplot is a Python library for generating star charts and sky maps. You can create various types of visualizations including Zenith charts (the entire sky from a specific time/place), Horizon charts, Optic simulations (telescope views), and Galactic charts.

    Key features include:

    • 10+ customizable projections
    • Support for Planets and Deep Sky Objects (DSOs) with true extent plotting
    • Trajectory plotting for comets and satellites
    • 8+ built-in themes and custom styling
    • High-performance data backend using DuckDB and Ibis
    • Export support for png, svg, and jpeg formats.
    from datetime import datetime
    from zoneinfo import ZoneInfo
    from starplot import ZenithPlot, Observer, styles, _
    
    tz = ZoneInfo("America/Los_Angeles")
    dt = datetime.now(tz).replace(hour=22)
    
    observer = Observer(
        dt=dt,
        lat=33.363484,
        lon=-116.836394,
    )
    
    p = ZenithPlot(
        observer=observer,
        style=styles.PlotStyle().extend(
            styles.extensions.BLUE_MEDIUM,
        ),
        resolution=4096,
        autoscale=True,
    )
    p.constellations()
    p.stars(where=[_.magnitude < 4.6])
    p.constellation_labels()
    p.horizon()
    p.export("starchart.png")
  4. Identify available data sources for Starplot

    main

    Starplot utilizes several external catalogs and datasets to render celestial features. When configuring or extending your star map, you can reference these primary sources for specific astronomical data:

    • Stars: Big Sky Catalog (Hipparcos, Tycho-1, Tycho-2 in Epoch J2000).
    • Constellation Lines: Stellarium (via Sky & Telescope).
    • Constellation Borders: IAU Constellation page and VizieR VI/49 (via d3-celestial).
    • Deep Sky Objects (DSOs): OpenNGC (NGC and IC catalogs).
    • Moon & Planet Sizes: NASA Solar System and Moon facts.
    • Milky Way Outline: NASA Deep Star Maps (processed via QGIS + GDAL).

    Note: Starplot now supports custom data catalogs for stars, constellations, and DSOs.

  5. Use callables to customize star properties

    main

    Callables are functions used to dynamically calculate style properties for stars, such as size, alpha (opacity), color, and label.

    Note that Deep Sky Objects (DSOs) only support callables for alpha and labels.

    When you provide a callable to a star plotting method, Starplot passes an instance of a Star object to your function, allowing you to access any of its properties (like magnitude, ra, dec, etc.) to determine the return value.

  6. How Starplot models are used

    main

    Starplot uses models to represent the observer and various celestial objects. These models serve several core functions in the library:

    • Observing Context: Defining the specific time and geographic location of an observer.
    • Object Selection: Filtering which objects to plot using the where keyword argument.
    • Dynamic Styling: Creating callables to calculate visual properties like size, color, or alpha values.
    • Object Management: Tracking plotted objects using starplot.ObjectList.
    • Positioning & Querying:
      • Using .get() to retrieve an object's position at a specific time.
      • Using .find() to retrieve a list of objects that satisfy specific conditions.
  7. Configure label collision handling in Starplot

    main

    Starplot uses a CollisionHandler to manage label positioning and prevent overlaps between labels and map features. You can control how different types of labels behave by specifying handlers for three distinct categories:

    • Points (point_label_handler): Used for stars, DSOs, etc.
    • Areas (area_label_handler): Used for constellations.
    • Paths (path_label_handler): Used for the ecliptic, celestial equator, etc.

    You can set these handlers globally when creating a plot, or override them individually in any function that plots text.

    # Example of setting global handlers during plot creation (conceptual)
    plot = Starplot(
        point_label_handler=my_point_handler,
        area_label_handler=my_area_handler,
        path_label_handler=my_path_handler
    )
  8. Create zenith plots (all-sky star charts)

    main

    Zenith plots (also known as star charts or all-sky charts) show the entire sky as seen from a specific time and place, with the zenith at the center of the plot. In starplot, stars on zenith plots are plotted using their astrometric positions.

    You can use the starplot.ZenithPlot class to generate these visualizations.

    # Example usage of ZenithPlot
    from starplot import ZenithPlot
    
    # Initialize the plot (specific parameters depend on your data and location)
    plot = ZenithPlot()
  9. Use the Catalog class to manage sky objects

    main

    The starplot.data.Catalog class is used to represent a collection of sky objects. Currently, Starplot supports the following object types within catalogs:

    • Stars
    • Constellations
    • Deep Sky Objects (DSOs)

    All catalogs are stored as Parquet files to ensure fast object lookup. If you attempt to plot an object type using a catalog that does not exist locally but has a defined URL, Starplot will automatically download the catalog from that URL.

  10. Optimize small catalogs (< 1M objects) with sorting columns

    main

    For catalogs containing fewer than 1 million objects, you can improve query performance by specifying sorting_columns during the build process.

    If you frequently query a specific field that has medium or high standard deviation, sorting the catalog by that field allows the data backend to scan data more efficiently. Pass a list of field names to the sorting_columns parameter in the build method.

  11. Representing observers and sky objects

    main

    Starplot provides a hierarchy of models to represent the observer and celestial bodies:

    Observer

    • starplot.Observer: Represents the person or device observing the sky.

    Sky Objects

    All sky objects inherit from starplot.models.base.SkyObject. Available models include:

    • starplot.Star: Individual stars.
    • starplot.Constellation: Groups of stars.
    • starplot.DSO: Deep Sky Objects (categorized by starplot.models.dso.DsoType).
    • starplot.Planet: Planets in the solar system.
    • starplot.Sun: The Sun.
    • starplot.Moon: The Moon.
    • starplot.Comet: Comets.
    • starplot.Satellite: Artificial satellites.

    Object Management

    • starplot.ObjectList: A container used to keep track of multiple plotted objects.
  12. Use Callables to define star style properties

    main

    Callables allow you to define custom functions to calculate specific style properties for stars, such as size, alpha (opacity), color, and their labels.

    Important Compatibility Note:

    • DSOs (Data Source Objects) only support callables for alpha and labels.
    • Starplot supports callables for size, alpha, color, and labels.

    Starplot includes several built-in callables (e.g., color_by_bv for colorizing stars based on their B-V index), but you can also implement your own custom functions to drive these properties dynamically.

    # Example concept: using a built-in callable like color_by_bv
    # to colorize stars based on their B-V index.