Skip to main content

A Python library for accessing and analyzing Skylab mission data

Project description

Skylab2IAI

A Python library for accessing and analyzing Skylab mission data from astronomical plate archives.

Overview

Skylab2IAI provides a simple interface to query and download astronomical plate frame data from the Skylab mission. The library includes an embedded SQLite database containing metadata for thousands of plate frames and provides convenient methods to search, filter, and download FITS files.

Installation

From GitHub (for Google Colab or local use)

pip install git+https://github.com/tferrer/skylab2iai.git

For local development

git clone https://github.com/tferrer/skylab2iai.git
cd skylab2iai
pip install -e .

Quick Start

from skylab2iai import Skylab2iaiCatalog

# Create a catalog instance
catalog = Skylab2iaiCatalog()

# Get all plate frames
all_frames = catalog.get_plate_frames()
print(f"Total plate frames: {len(all_frames)}")

# Get a specific plate frame by name
frame = catalog.get_plate_frame("plate_frame_name")
print(frame)

# Get all frames for a specific plate
plate_frames = catalog.get_plate_frames_by_plate("plate_id")
print(f"Frames for this plate: {len(plate_frames)}")

Features

Data Retrieval

  • get_plate_frames(): Retrieve all plate frames from the database
  • get_plate_frame(plate_frame_name): Get a specific plate frame by name
  • get_plate_frames_by_plate(plate_name): Get all frames for a specific plate ID
  • get_plate_frames_by_query(query): Execute custom SQL queries (SELECT only, with SQL injection protection)

FITS File Downloads

Download FITS files directly from the archive:

# Download FITS files for specific plates
result_df, downloaded_files = catalog.download_fits_plate_frames(
    plate_names=("plate1", "plate2", "plate3"),
    output_dir="./fits_data"  # Optional, defaults to './fits_downloads'
)

print(f"Downloaded {len(downloaded_files)} files:")
for file_path in downloaded_files:
    print(f"  - {file_path}")

Custom Queries

Execute custom SQL queries with built-in safety features:

# Custom query example
query = "SELECT * FROM plate_frame WHERE PLATE_ID LIKE 'SKY%' LIMIT 10"
results = catalog.get_plate_frames_by_query(query)
print(results)

# Download FITS files from custom query
result_df, files = catalog.download_fits_plate_frames_from_custom_query(
    query="SELECT * FROM plate_frame WHERE PLATE_ID = 'specific_plate'",
    output_dir="./custom_downloads"
)

Note: Custom queries are restricted to SELECT statements only. DELETE, UPDATE, and INSERT operations are blocked for data integrity.

Architecture

The library follows a layered architecture:

skylab2iai/
├── catalog/
│   └── catalog.py          # Main API (Skylab2iaiCatalog)
└── storage/
    ├── sql_connection.py   # SQLite connection manager (singleton)
    ├── plate_frame.py      # Plate frame data access layer
    ├── plate.py            # Plate data access layer
    └── skylab-data.db      # Embedded SQLite database (~1.8MB, 6408 frames)

Key Components

  1. Skylab2iaiCatalog: Main public API class providing high-level methods for data access and FITS downloads
  2. _SqlStorage: Singleton connection manager for the embedded SQLite database
  3. _SkylabPlateStorage: Data access layer with SQL injection protection

Design Patterns

  • Singleton Pattern: Database connection and storage classes use singleton pattern to ensure single instance
  • Repository Pattern: Separation of data access logic from business logic
  • Immutability: Storage classes are marked as @final to prevent inheritance

Requirements

  • Python >= 3.10
  • pandas >= 2.0.0
  • requests >= 2.31.0

Database Schema

The embedded SQLite database contains a plate_frame table with the following key columns:

  • NAME: Unique plate frame identifier
  • PLATE_ID: Associated plate identifier
  • LINK_FTS: URL to download the FITS file
  • Additional metadata columns for astronomical observations

Usage Examples

Example 1: Explore the catalog

from skylab2iai import Skylab2iaiCatalog

catalog = Skylab2iaiCatalog()

# Get all frames
frames = catalog.get_plate_frames()
print(f"Total frames: {len(frames)}")
print(frames.head())

# Check available columns
print(frames.columns.tolist())

Example 2: Download specific plates

from skylab2iai import Skylab2iaiCatalog

catalog = Skylab2iaiCatalog()

# Download FITS files for specific plates
plates_to_download = ("plate_001", "plate_002", "plate_003")
df, files = catalog.download_fits_plate_frames(
    plate_names=plates_to_download,
    output_dir="./my_fits_data"
)

print(f"Successfully downloaded {len(files)} FITS files")

Example 3: Custom query with download

from skylab2iai import Skylab2iaiCatalog

catalog = Skylab2iaiCatalog()

# Find frames matching specific criteria
query = """
    SELECT * FROM plate_frame 
    WHERE PLATE_ID LIKE 'SKY%' 
    LIMIT 5
"""

# Get the data
results = catalog.get_plate_frames_by_query(query)
print(results)

# Download FITS files for these results
df, files = catalog.download_fits_plate_frames_from_custom_query(
    query=query,
    output_dir="./skylab_subset"
)

Troubleshooting

Google Colab: "unable to open database file" or "no such table"

If you encounter database errors in Google Colab:

  1. Restart the runtime and reinstall:

    # In Google Colab: Runtime > Restart runtime
    !pip install --force-reinstall git+https://github.com/tferrer/skylab2iai.git
    
  2. Clear pip cache before installing:

    !pip cache purge
    !pip install git+https://github.com/tferrer/skylab2iai.git
    
  3. Verify the installation:

    from skylab2iai import Skylab2iaiCatalog
    catalog = Skylab2iaiCatalog()
    frames = catalog.get_plate_frames()
    print(f"Loaded {len(frames)} plate frames")
    

The library includes a ~1.8MB SQLite database with 6408 plate frames. If you see this count, everything is working correctly!

Import Errors

If you encounter import errors, ensure you're using the correct import:

# Correct
from skylab2iai import Skylab2iaiCatalog

# Not PlateFrameService or other names

Development

Running Tests

The library includes a comprehensive test suite with 100% code coverage.

Install development dependencies

pip install -e ".[dev]"

Run tests

# Unix/macOS
./run_tests.sh

# Windows
run_tests.bat

# Or use pytest directly
pytest --cov=skylab2iai --cov-report=term-missing

Test coverage

The test suite covers:

  • Unit tests for all modules
  • Integration tests for complete workflows
  • SQL injection prevention
  • Error handling
  • Singleton pattern implementation
  • Mock tests for HTTP requests

See test/README.md for detailed testing documentation.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

When contributing:

  1. Write tests for new features
  2. Ensure all tests pass
  3. Maintain 100% code coverage
  4. Follow existing code style

License

MIT License - see LICENSE file for details

Author

Tiago Ferrer (ferrertiago@gmail.com)

Version

Current version: 0.0.7

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skylab2iai-0.0.8.tar.gz (240.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skylab2iai-0.0.8-py3-none-any.whl (240.2 kB view details)

Uploaded Python 3

File details

Details for the file skylab2iai-0.0.8.tar.gz.

File metadata

  • Download URL: skylab2iai-0.0.8.tar.gz
  • Upload date:
  • Size: 240.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for skylab2iai-0.0.8.tar.gz
Algorithm Hash digest
SHA256 d0035ea8435e0cd5a2e396e852e3e5475223528fcf3930e1f770fe84dfce574a
MD5 bba46ba5d90e8e8f4a26f8656d26f59d
BLAKE2b-256 e93458b53dbb0c653524daba0aa7a7059b736442b03f80d3f8b459292c1ce16e

See more details on using hashes here.

File details

Details for the file skylab2iai-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: skylab2iai-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 240.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for skylab2iai-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d8a05ec0f325dd1bff177e55f577fd36ab4a03246c9efcb7fc810cac673cdb64
MD5 bbeb659506940fa1226d6427061fdc22
BLAKE2b-256 041d4fc36515e846ea8a206d9eea1d6110f0a2114da00c2563e6e44890608dec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page