# s11ngh/pyscope architecture

> Architecture diagram of the GitHub repository s11ngh/pyscope, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/s11ngh/pyscope
- Repository: https://github.com/s11ngh/pyscope

## Overview

##### Project type and purpose
- pyscope is a pure-Python, open-source library/framework (not a web app) for robotic scheduling, operation, and control of small optical telescopes.
- It exposes both a programmatic API (subpackages under pyscope/) and command-line entry points (scripts in pyscope/bin/scripts).

##### File structure
- Top-level subpackages under pyscope/:
- observatory – device drivers and observatory abstractions (ASCOM, simulators, HTML monitors).
- scheduling – rule-based scheduler and optimizer for building observing queues.
- telrun – “telescope run” orchestration module & CLI interface.
- reduction – basic image calibration & WCS tools.
- analysis – convenience scripts for simple science calculations (e.g., calc_zmag).
- utils – shared utilities (config parsing, exceptions, HTML parsing, airmass calculations).
- pyscope/bin/cfg_templates: YAML/INI templates for configuring observatory, logging, notifications, sync, telrun, etc.
- pyscope/bin/scripts: executable wrappers to launch sync managers and telrun sessions.
- docs/ & README.rst: user/developer guides and API reference.
- tests/: end-to-end and unit tests organized by subpackage name.

##### README
- Confirms modular, extensible design built on ASCOM and Astropy.
- Highlights key features: observatory control, telrun module for full automation, data reduction/analysis tools.
- Lists dependencies: Python 3.x, Astropy ecosystem, ASCOM drivers or Maxim DL for hardware.

##### Diagramming recommendations
- CLI → Config → Core API → External drivers
- Core API → Data store (FITS files, logs)
- Analysis/Reduction → Data store
- Blue for CLI & Config
- Green for Core API subpackages
- Orange for External services/drivers
- Gray for data stores
- Rectangles for software modules

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Layer
    subgraph "CLI Layer"
        direction TB
        TEL["start_telrun"]:::cli
        SYNC["start_sync_manager"]:::cli
    end

    %% Configuration Store
    subgraph "Configuration Store"
        direction TB
        CFG["YAML/INI Templates"]:::config
    end

    %% Core API
    subgraph "Core API"
        direction TB
        OBS["pyscope.observatory"]:::core
        SCHED["pyscope.scheduling"]:::core
        TELRUN["pyscope.telrun"]:::core
        RED["pyscope.reduction"]:::core
        ANL["pyscope.analysis"]:::core
        UTIL["pyscope.utils"]:::core
        SIM["Simulator Server"]:::core
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        ASCOM["ASCOM Drivers"]:::external
        MAXIM["Maxim DL"]:::external
        ASTROPY["Astropy Ecosystem"]:::external
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        FITS["FITS Files (Raw/Calibrated)"]:::data
        LOGS["Log Files"]:::data
        SCHEDULES["Schedules (ECSV/SCH)"]:::data
    end

    %% Interactions
    TEL -->|"loads config"| CFG
    SYNC -->|"loads config"| CFG
    CFG -->|"provides settings"| TELRUN
    CFG -->|"provides settings"| SCHED
    TELRUN -->|"build queue"| SCHED
    TELRUN -->|"connect & command"| OBS
    OBS -->|"uses plugin"| SIM
    OBS -->|"uses drivers"| ASCOM
    OBS -->|"uses software"| MAXIM
    TELRUN -->|"write raw"| FITS
    RED -->|"read raw/write cal"| FITS
    RED -->|"log processing"| LOGS
    ANL -->|"analyze calibrated"| FITS
    ANL -->|"output metrics"| LOGS
    UTIL -->|"shared funcs"| TELRUN
    UTIL -->|"shared funcs"| OBS
    UTIL -->|"shared funcs"| SCHED
    UTIL -->|"shared funcs"| RED
    UTIL -->|"shared funcs"| ANL
    ASTROPY -.-> RED
    ASTROPY -.-> ANL

    %% Click Events
    click TEL "https://github.com/s11ngh/pyscope/tree/schedule-hotfix/pyscope/bin/scripts/start_telrun"
    click SYNC "https://github.com/s11ngh/pyscope/tree/schedule-hotfix/pyscope/bin/scripts/start_sync_manager"
    click CFG "https://github.com/s11ngh/pyscope/tree/schedule-hotfix/pyscope/bin/cfg_templates/"
    click OBS "https://github.com/s11ngh/pyscope/tree/schedule-hotfix/pyscope/observatory/"
    click SIM "https://github.com/s11ngh/pyscope/blob/schedule-hotfix/pyscope/observatory/simulator_server.py"
    click SCHED "https://github.com/s11ngh/pyscope/tree/schedule-hotfix/pyscope/scheduling/"
    click TELRUN "https://github.com/s11ngh/pyscope/tree/schedule-hotfix/pyscope/telrun/"
    click RED "https://github.com/s11ngh/pyscope/tree/schedule-hotfix/pyscope/reduction/"
    click ANL "https://github.com/s11ngh/pyscope/tree/schedule-hotfix/pyscope/analysis/"
    click UTIL "https://github.com/s11ngh/pyscope/tree/schedule-hotfix/pyscope/utils/"
    click Setup "https://github.com/s11ngh/pyscope/blob/schedule-hotfix/setup.py"
    click PyProject "https://github.com/s11ngh/pyscope/blob/schedule-hotfix/pyproject.toml"

    %% Legend (invisible for placement)
    classDef cli fill:#AED6F1,stroke:#333,stroke-width:1px;
    classDef config fill:#AED6F1,stroke:#333,stroke-width:1px;
    classDef core fill:#A9DFBF,stroke:#333,stroke-width:1px;
    classDef external fill:#F5B041,stroke:#333,stroke-width:1px;
    classDef data fill:#D7DBDD,stroke:#333,stroke-width:1px;
```
