# stingraysoftware/stingray architecture

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

- Interactive diagram: https://gitdiagram.com/stingraysoftware/stingray
- Repository: https://github.com/stingraysoftware/stingray

## Overview

##### Project Type and Purpose
- Stingray is an open-source Python package focused on spectral-timing analysis. It provides tools for time series analysis (such as power spectra, cross spectra, covariances, lags, etc.), simulation, and handling of X‑ray (and other) datasets. Its design is geared toward making advanced timing techniques accessible with a robust statistical framework.
- The README emphasizes functionality for time series methods, data simulation, and supporting scripts to load FITS files from various missions.

##### File Structure
- Main Package: The “stingray” directory is clearly the core library. Inside it are several modules such as:
- Base functionality (base.py, _astropy_init.py)
- Specialized modules (e.g., bexvar.py, bispectrum.py, crosscorrelation.py, crossspectrum.py)
- Specific subpackages handling aspects like “deadtime”, “mission_support”, “modeling”, “pulse”, “simulator”, etc.
- Testing: A comprehensive “stingray/tests” directory exists with data resources and multiple test files validating different modules.
- Documentation & Community Support: There’s a “docs” directory for Sphinx-based documentation; related GitHub workflows indicate CI/CD testing and documentation publishing.
- Other configurations: Files like pyproject.toml, setup.py, tox.ini, and various GitHub workflow YAML files set up environment and testing infrastructure.
- Additional materials: The “joss” directory with paper drafts and bibliographic references confirms a structured approach to open-source contributions.

##### Key Components
a. Core Library Components:
- Core Module: Base time-series functionality (e.g., stingray/base.py, events.py, io.py, loggingconfig.py, etc.).
- Specialized Analysis Modules: Power spectrum (powerspectrum.py, multitaper.py), cross-correlation (crosscorrelation.py, crossspectrum.py), Lomb-scargle analysis (lombscargle.py), and others.
- Simulation & Modeling: The “simulator” subpackage for simulating light curves and events; the “modeling” subpackage for parameter estimation and posterior analysis.
- Mission-Specific Support: “mission_support” module which abstracts data handling for different X‑ray missions.
- Pulsar/Timing Analysis: The “pulse” subpackage providing acceleration search, FFT-based fitting, and related pulsar timing utilities.
- Deadtime Corrections: The “deadtime” subpackage for handling detector deadtime issues.
- Ancillary Functions: Additional utility modules like “filters”, “spectroscopy”, “stats”, and “varenergyspectrum”.

b. Supporting Components:
- Testing Infrastructure: Separate testing modules and datasets for continuous integration.
- Documentation: Sphinx-based docs and pre-configured templates in the “docs” folder, including assets and auto-generated API docs.
- CI/CD elements: GitHub workflows (in .github/workflows) that manage testing, code quality, and docs publishing.
- Community & Contribution Elements: GitHub issue templates, pull request templates, and configuration files for code style and pre-commit hooks.

##### Relationships and Interactions
- The core library modules interact internally: for example, the main “base” functionalities support specialized modules. The “mission_support” components act as a bridge between raw data (from missions) and analysis modules.
- Simulation modules provide synthetic data that can be fed into analysis modules (spectrum and timing analysis).
- Testing modules are linked to each core component, ensuring that unit tests and integration tests cover the functionality.
- External pipelines (CI/CD workflows) tie together testing, documentation building, and deployment.

##### Architectural Patterns and Design Principles
- Modularity: The project is broken into well-separated subpackages and modules grouped by functionality (e.g., pulse, modeling, simulator). This supports maintainability and extensibility.
- Layered Design: Core functionality underpins high-level features. Data flows from input (FITS file reading or simulation) through processing (spectral-timing analysis) and into result visualization or simulation outputs.
- Reusable Components: Much like Astropy, the design follows best practices for Python packages, encouraging reusability and standardized API design.
- Testing & CI Pipeline: Emphasize automated tests and continuous integration as essential parts of the system architecture.

##### Final Detailed Steps for the Principal Software Engineer
- Branch out to show supporting subpackages:
- “mission_support” connected to raw data inputs.
- “deadtime” and “pulse” as specialized branches under timing corrections and pulsar analysis.
- Testing infrastructure, indicating that each core module is covered by dedicated test suites (pointing from “tests” directory).
- CI/CD pipelines (GitHub workflows) linking to code validation and documentation updates.
- Clear, descriptive labels for each element.

## Diagram (Mermaid)

```mermaid
flowchart TD
    SC["Stingray Core Library"]:::core

    subgraph "Core Modules"
        CF["Core Functionality"]:::core
        PSA["Power Spectrum & Fourier Analysis"]:::analysis
        CCB["Cross-Correlation & Bispectrum"]:::analysis
        LSA["Lomb-Scargle Analysis"]:::analysis
        AU["Ancillary Utilities"]:::core
    end

    MS["Mission-Specific Support"]:::analysis

    subgraph "Simulation & Modeling"
        SIM["Simulation"]:::analysis
        MOD["Modeling"]:::analysis
    end

    subgraph "Advanced Timing"
        PT["Pulsar Timing Analysis"]:::analysis
        DT["Deadtime Corrections"]:::analysis
    end

    subgraph "Support Infrastructure"
        TEST["Testing Infrastructure"]:::infra
        CI["CI/CD & Community Support"]:::infra
        DOC["Documentation"]:::infra
        PUB["Publication & Community Materials"]:::infra
    end

    %% Core Library connections
    SC --> CF
    SC --> MS
    SC --> SIM
    SC --> PT

    %% Internal module relationships
    CF -->|"supports"| PSA
    CF -->|"supports"| CCB
    CF -->|"supports"| LSA
    CF -->|"utilizes"| AU
    MS -->|"feeds"| CF
    SIM -->|"provides data"| PSA
    SIM -->|"provides data"| CCB
    SIM -->|"provides data"| LSA
    CF -->|"interfaces"| MOD
    CF -->|"provides basis for"| PT
    CF -->|"provides basis for"| DT

    %% Support infrastructure interactions
    TEST -->|"validates"| SC
    CI -->|"triggers"| TEST
    CI -->|"updates"| DOC
    DOC -->|"documents"| SC
    PUB -->|"supports"| CI

    %% Styles
    classDef core fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef analysis fill:#a3e4d7,stroke:#117864,stroke-width:2px;
    classDef infra fill:#f9e79f,stroke:#b7950b,stroke-width:2px;

    %% Click events for mapped components
    click CF "https://github.com/stingraysoftware/stingray/blob/main/stingray/base.py"
    click PSA "https://github.com/stingraysoftware/stingray/blob/main/stingray/powerspectrum.py"
    click CCB "https://github.com/stingraysoftware/stingray/blob/main/stingray/crosscorrelation.py"
    click LSA "https://github.com/stingraysoftware/stingray/blob/main/stingray/lombscargle.py"
    click SIM "https://github.com/stingraysoftware/stingray/tree/main/stingray/simulator"
    click MOD "https://github.com/stingraysoftware/stingray/tree/main/stingray/modeling"
    click MS "https://github.com/stingraysoftware/stingray/tree/main/stingray/mission_support"
    click PT "https://github.com/stingraysoftware/stingray/tree/main/stingray/pulse"
    click DT "https://github.com/stingraysoftware/stingray/tree/main/stingray/deadtime"
    click AU "https://github.com/stingraysoftware/stingray/blob/main/stingray/filters.py"
    click TEST "https://github.com/stingraysoftware/stingray/tree/main/stingray/tests"
    click DOC "https://github.com/stingraysoftware/stingray/tree/main/docs"
    click CI "https://github.com/stingraysoftware/stingray/blob/main/.github"
    click PUB "https://github.com/stingraysoftware/stingray/tree/main/joss"
```
