RosettaSciIO

0.13.0 · active · verified Thu Apr 16

RosettaSciIO is a Python library for reading and writing various scientific file formats, designed with a focus on ease of use and integration with scientific data analysis tools like HyperSpy. It supports a wide range of formats including HDF5, TIFF, DigitalMicrograph (DM3/DM4), and more, often leveraging optional backend libraries. The current version is 0.13.0, and new minor releases occur every few months, introducing new features and format support.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to save a NumPy array to a common image format (PNG) and then read it back using RosettaSciIO. This leverages the `Pillow` dependency, which is installed by default.

import rsciio
import numpy as np
import os

# Create a dummy NumPy array (e.g., a simple image)
data_to_save = np.arange(100).reshape(10, 10).astype(np.uint8)
filename_png = "my_dummy_data.png"

print(f"Saving data to {filename_png} using rsciio.write...")
# rsciio.write handles numpy arrays and uses Pillow (a core dependency) for PNG.
rsciio.write(data_to_save, filename_png)
print(f"Successfully saved data to {filename_png}")

print(f"Reading data from {filename_png} using rsciio.read...")
# rsciio.read returns a numpy array by default
read_data = rsciio.read(filename_png)
print(f"Successfully read data from {filename_png}. Shape: {read_data.shape}")
print(f"Data type: {read_data.dtype}")

# Clean up the dummy file
os.remove(filename_png)
print(f"Cleaned up {filename_png}")

view raw JSON →