Skip to main content

Ghosty - GHOST Brillouin Spectrometer Control

Python interface for controlling the GHOST Brillouin spectrometer software via TCP/IP communication.

Features

  • Asynchronous control interface for the GHOST spectrometer
  • Automatic timing calculations based on clock frequency
  • Robust acquisition with timeout handling and retry logic
  • Acquisition timing logging
  • Working directory management
  • Comprehensive error handling and recovery
  • Support for both standard (4 kHz) and high-speed (10 kHz) modes

Installation

From Git Repository

  1. Clone the repository:
git clone https://github.com/timm-landes/ghosty.git
cd ghosty
  1. Create and activate a virtual environment (recommended):
python -m venv venv
# On Windows:
.\venv\Scripts\activate
# On Linux/Mac:
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Install in development mode:
pip install -e .

Quick Start

import asyncio
from ghosty import BrillouinSpectrometer

async def main():
    # Create spectrometer instance (4 kHz standard mode)
    spec = BrillouinSpectrometer(clock_frequency_khz=4)
    
    try:
        # Initialize connection
        await spec.initialize()
        
        # Set working directory
        await spec.set_working_directory("C:/Data")
        
        # Acquire data
        await spec.acquire_and_save(cycles=10, fname="spectrum.DAT")
        
    finally:
        # Clean up
        await spec.close()

asyncio.run(main())

Operating Modes

Standard Mode (4 kHz)

  • Uses full 2048 MCA channels
  • Scan time: ~512 ms
  • Total cycle time: ~615 ms (scan + retract)

High-Speed Mode (10 kHz)

  • Uses 512 MCA channels
  • Scan time: ~205 ms
  • Total cycle time: ~250 ms (scan + retract)
  • Requires hardware modifications

Communication Protocol

The GHOST software uses a TCP/IP protocol with the following specifications:

  • Port: 4000 (default)
  • Encoding: UTF-8
  • Command termination: \r\n (CR+LF)
  • Maximum command length: 80 characters
  • Default timeout: 5 seconds

Key Components

BrillouinSpectrometer

High-level interface providing:

  • Connection management
  • Acquisition control
  • Timing calculations
  • Error handling
  • Status monitoring

TcpIpController

Low-level communication handling:

  • TCP/IP connection management
  • Command sending/receiving
  • Protocol implementation
  • Basic error checking

Command Reference

Available commands through the TcpIpController:

Command Description Response Expected
OBSERVE Start observation No
STATUS Get system status Yes
START n Start n acquisition cycles No
STOP Stop acquisition No
SAVE name Save data to file No
DELETE Clear data buffer No
WDIR path Set working directory No

Timing Details

Timing calculations are based on the spectrometer's clock frequency:

cycle_time_ms = (2460 / clock_frequency) * 1000

Safety margins:

  • Minimum wait: 60% of theoretical time
  • Timeout: theoretical time + 10 cycles
  • Status confirmation: 2 consecutive IDLE states

Error Handling

The library implements multiple layers of error handling:

  1. Connection-level errors
  2. Command validation
  3. Response verification
  4. Timeout protection
  5. Status monitoring
  6. Resource cleanup

Logging

Uses loguru for comprehensive logging:

  • Debug level: Command details
  • Info level: Operation status
  • Warning level: Timing issues
  • Error level: Operation failures
  • Trace level: Detailed status

Requirements

  • Python ≤ 3.12.9 (for telnetlib) or telnetlib3 when using Python ≥ 3.13
  • asyncio
  • loguru

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

License

MIT License - See LICENSE file for details

Acknowledgments

Based on the GHOST spectrometer software communication protocol.

Development Setup

For development work:

  1. Clone the repository as described above
  2. Install development dependencies:
pip install -r requirements.txt
  1. Setup pre-commit hooks:
pre-commit install

Repository

The project is hosted on GitLab at the University of Hannover: https://gitlab.uni-hannover.de/phytophotonics/ghosty (internal use) and publically available hosted at GitHub: https://github.com/timm-landes/ghosty

Authors

Project Lead:

Contributors:

Citing Ghosty

If you use Ghosty in your research, please cite it as follows:

BibTeX

@software{ghosty2024,
  author       = {Landes, Timm and Heinemann, Dag},
  title        = {Ghosty: A Python Interface for GHOST Brillouin Spectrometer Control},
  year         = {2025},
  version      = {0.1.1},
  url          = {https://gitlab.uni-hannover.de/phytophotonics/ghosty},
  institution  = {Leibniz University Hannover}
}

APA Style

Landes, T., & Heinemann, D. (2025). Ghosty: A Python Interface for GHOST Brillouin 
Spectrometer Control (Version 0.1.1) [Computer software]. 
Leibniz University Hannover. https://gitlab.uni-hannover.de/phytophotonics/ghosty

Related Publications

If applicable, please also cite the following related publications:

Landes, T., Khanal, B.P., Bethge, H.L. et al. Micromechanical behavior of the apple fruit cuticle investigated by Brillouin light scattering microscopy. Commun Biol 8, 174 (2025). https://doi.org/10.1038/s42003-025-07555-5

Metadata

Release files for ghosty 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ghosty 0.1.2
File Size Uploaded
ghosty-0.1.2.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ghosty 0.1.2
File Interpreter ABI Platform
ghosty-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 22.2 kB

Release files / ghosty-0.1.2.tar.gz

Download URL ghosty-0.1.2.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
05414de77a5bc00b597478ab2a392ac57506d3e567a133d6c3e9624df9503c47
BLAKE2b-256 checksum
How to use checksums
02548777137b65ce8163d175f8642b6c09a136d0e1fc89008bb04c75e30faf6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / ghosty-0.1.2-py3-none-any.whl

Download URL ghosty-0.1.2-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7349a6b371e67f132043cc4b9c031bda868ce83abd381e5c661a4e8a3d3479c1
BLAKE2b-256 checksum
How to use checksums
da6009b398b7fa79167035d520fec38317864e180918806157c07e53f643e65c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page