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)

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.6.0.tar.gz (55.6 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.6.0-py3-none-any.whl (53.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pysdds-0.6.0.tar.gz
Algorithm Hash digest
SHA256 0df981d19c63ce03c84f795b3b9a69ab8bbcb5f0aa3c8dbd94f6062dbdc39b94
MD5 ca4a31f8f5805338fb83977420bbfb14
BLAKE2b-256 66bd4882475c574b9c519429072c2dd6b2dd257f335087c8e75f0adf90d72af8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pysdds-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62fc3e7187673f9e42c2afd1241474c9090920b7644f2981228e1b651f4d2358
MD5 689d6765e2ae268345459d16f2b652eb
BLAKE2b-256 8ca244bc0cf09c3584da7e831d516e2c6b686f9da90c11a9c18edd0635b9b197

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