Skip to main content

Package to read and write SDDS files

Project description


pySDDS

Efficient Python SDDS reader and writer

GitHub CI GitHub release (latest by date) GitHub release (latest by date including pre-releases)
Table of Contents
  1. About
  2. Getting Started
  3. Usage
  4. Advanced considerations
  5. Roadmap
  6. Version history
  7. Contributing
  8. License

About

Self Describing Data Set (SDDS) file format is a common format used in accelerator physics, notably by elegant simulation code and other tools developed at the Advanced Photon Source/ANL. pysdds is a pure-Python SDDS reader and writer with several nifty features that help with integration into standard Python ML and data analysis workflows.

Getting started

Prerequisites

  • Python >= 3.8
  • numpy >= 1.19
  • pandas >=1.0

Installation

Clone this repository:

git clone https://github.com/nikitakuklev/pysdds.git

and add to path during runtime or install in pip development mode:

sys.path.append(<location where repo was cloned>/pysdds)

If you have access to ANL APS network, you can install latest development version with:

pip install -e /home/oxygen/NKUKLEV/software/pysdds

Usage

Reading a file:

import pysdds

# All parameters are automatically inferred
sdds = pysdds.read('file.sdds')

# Compressed files will be decompressed on the fly
sdds = pysdds.read('file.sdds.xz')

# All reader options can be explicitly provided
sdds = pysdds.read('file.sdds.xz', mode='binary', compression='xz', endianness='little')

# Select only the necessary arrays, columns, and pages - other data is discarded without memory allocation
sdds = pysdds.read('file.sdds', pages=[0,2], columns=['x','y'], arrays=['matrix1'])

Working with data:

sdds = pysdds.read('file.sdds')

# Get column 'x' and parameter 'betax'
column = sdds.col('x')
parameter = sdds.par('betax')

# NumPy array of values for column 'x' on page 0
column.data[0]

# Single value for parameter 'betax' on page 3
parameter.data[3]

# Convert page 1 to a dataframe with appropriate column labels
sdds.columns_to_df(page=1)

# Convert all parameters to a dataframe, indexed by page number
sdds.parameters_to_df()

Writing data:

# Easiest way to write SDDS is to create sdds object from dataframes
sdds = pysdds.SDDSFile.from_df([df_page1, df_page2], parameter_dict={'param1': ['v0', 'v1']})
pysdds.write(sdds, 'filepath.sdds')

# If necessary, SDDS objects can be manually assembled (but you really shouldn't)
sdds = pysdds.SDDSFile()
col = pysdds.Column(namelist,sdds)
col.data = [...]
sdds.columns = [col]
...

See demos directory for more examples.

Advanced considerations

pysdds is designed for maximum performance (insofar as possible in Python) without depending on any compiled code beyond standard library and numpy/pandas). It is an independent implementation based on SDDS specification, not associated with the official SDDSPython3 package.

Major differences are:

  • Pure Python, and platform agnostic (official package is a thin wrapper for core C library)
  • Comparable read performance for numerical data, but slower for text data. You should do your own benchmarks if performance is critical.
  • Intelligent file buffering - helps with network file systems
  • Large file reads without full memory pre-allocation
  • Serializable data structures (for example allowing data passing during batch computations through Dask)
  • Easier debugging and partial parsing of corrupted/abnormal data

Package architecture is straightforward - file header is first parsed to determine overall structure. Then, dispatch method picks one of multiple reader and writer implementations depending on file contents and compatibility constraints. Custom implementations can be provided as well (might perform better for your particular use case).

Contributing

Pull requests are welcome, but current codebase is expected to evolve quickly until 1.0 release. It is probably more useful to just submit a feature request.

Should you decide to contribute, please ensure that all tests pass and that your code conforms to Google Python styleguide with exception of comments, which should follow NumPy convention.

License

This project has been developed as personal helper tool for various accelerator physics research, and is released under a permissive MIT license. Notably however, I am not responsible if this breaks your shiny particle accelerator toys.

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

pysdds-0.5.1.tar.gz (54.8 kB view details)

Uploaded Source

Built Distribution

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

pysdds-0.5.1-py3-none-any.whl (52.4 kB view details)

Uploaded Python 3

File details

Details for the file pysdds-0.5.1.tar.gz.

File metadata

  • Download URL: pysdds-0.5.1.tar.gz
  • Upload date:
  • Size: 54.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for pysdds-0.5.1.tar.gz
Algorithm Hash digest
SHA256 a3d283f46079dca8a5528b3d8c44dcea6996910ddbc225fc9944199f35ccff7c
MD5 cbeedf874f1de93881424b7b990b06a1
BLAKE2b-256 78d6c7dbd20a24ec0794212ff365b0c4cda8b320244cddc2f398d3c19da95166

See more details on using hashes here.

File details

Details for the file pysdds-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: pysdds-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 52.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for pysdds-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a60e57321f105d8ebf14b6b30bfa2e335710f9013bd830740e14649fd4a0301
MD5 022aa31fd5619def97b841d139088ae3
BLAKE2b-256 7c3612b60c9b7fc8fdbbf2f122b0d9b2e0d02c501774418181ba376ec302ae3d

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