IO Module (stx.io)
Universal file I/O through stx.io.save() and stx.io.load().
Format is determined by file extension.
Quick Reference
import scitex as stx
# Save
stx.io.save(data, "output.csv") # DataFrame → CSV
stx.io.save(arr, "output.npy") # ndarray → NumPy
stx.io.save(fig, "output.png") # Figure → PNG + CSV + YAML recipe
stx.io.save(obj, "output.pkl") # any object → pickle
stx.io.save(d, "output.yaml") # dict → YAML
stx.io.save(d, "output.json") # dict → JSON
# Load
data = stx.io.load("input.csv") # → DataFrame
arr = stx.io.load("input.npy") # → ndarray
obj = stx.io.load("input.pkl") # → original object
d = stx.io.load("input.yaml") # → dict
Supported Formats
Extension |
Save Type |
Load Return |
|---|---|---|
|
DataFrame, dict, ndarray |
DataFrame |
|
ndarray |
ndarray |
|
dict of ndarrays |
NpzFile |
|
any Python object |
original object |
|
dict |
dict |
|
dict, list |
dict or list |
|
matplotlib Figure |
ndarray (image) or Figure |
|
dict, ndarray |
dict or ndarray |
|
dict |
dict |
|
PyTorch state_dict |
dict |
|
DataFrame |
DataFrame |
|
str |
str |
Figure Saving
When saving a matplotlib Figure, stx.io.save automatically:
Saves the image file (
.png,.svg, etc.)Exports a
.csvwith the plotted data extracted from axesExports a
.yamlrecipe for reproducing the figure
fig, ax = stx.plt.subplots()
ax.plot_line(x, y, label="signal")
stx.io.save(fig, "results/plot.png")
# Creates:
# results/plot.png (the figure)
# results/plot.csv (x, y data)
# results/plot.yaml (recipe for stx.plt.reproduce)
Provenance Tracking
Inside @stx.session, every save and load records file hashes
to a local SQLite database for reproducibility verification.
@stx.session
def main(logger=stx.INJECTED, **kw):
data = stx.io.load("input.csv") # hash recorded as input
stx.io.save(result, "output.csv") # hash recorded as output
Other Functions
stx.io.glob(pattern)– Find files matching a glob patternstx.io.load_configs(config_dir)– Load and merge YAML config files
API Reference
See scitex.io API Reference for the auto-generated Python API.