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 databaseget_plate_frame(plate_frame_name): Get a specific plate frame by nameget_plate_frames_by_plate(plate_name): Get all frames for a specific plate IDget_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
- Skylab2iaiCatalog: Main public API class providing high-level methods for data access and FITS downloads
- _SqlStorage: Singleton connection manager for the embedded SQLite database
- _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
@finalto 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 identifierPLATE_ID: Associated plate identifierLINK_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:
-
Restart the runtime and reinstall:
# In Google Colab: Runtime > Restart runtime !pip install --force-reinstall git+https://github.com/tferrer/skylab2iai.git
-
Clear pip cache before installing:
!pip cache purge !pip install git+https://github.com/tferrer/skylab2iai.git
-
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:
- Write tests for new features
- Ensure all tests pass
- Maintain 100% code coverage
- Follow existing code style
License
MIT License - see LICENSE file for details
Author
Tiago Ferrer (ferrertiago@gmail.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skylab2iai-0.0.10.tar.gz.
File metadata
- Download URL: skylab2iai-0.0.10.tar.gz
- Upload date:
- Size: 240.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d47ff14c7a76a2c33f05e56f706b8d09326474e670060b7e7dcb4d88642dafce
|
|
| MD5 |
ce1a5bedbe33a14108471307d52c3c3c
|
|
| BLAKE2b-256 |
f95c6cc87cf6ba1a309f853c42f56c318b0af14b8114db69c721951ca7a52cd6
|
File details
Details for the file skylab2iai-0.0.10-py3-none-any.whl.
File metadata
- Download URL: skylab2iai-0.0.10-py3-none-any.whl
- Upload date:
- Size: 240.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d9ee34c1f071e7a0b1a289fb773d097a1ab5be7837b59d2182db40dc7c2e18f
|
|
| MD5 |
29d76f74c45a28cf5bceb89b72ee0a76
|
|
| BLAKE2b-256 |
ef5e8b250e0a5aa840c15484e0397cb29eb34c03d0885d62bf7e94369145b1cb
|