ULM files¶
Simple and efficient pythonic file-format.
Stores ndarrays as binary data and Python’s built-in datatypes (bool, int, float, complex, str, dict, list, tuple, None) as json.
File layout when there is only a single item:
0: "- of Ulm" (magic prefix, ascii)
8: " " (tag, ascii)
24: version (int64)
32: nitems (int64)
40: 48 (position of offsets, int64)
48: p0 (offset to json data, int64)
56: array1, array2, ... (8-byte aligned ndarrays)
p0: n (length of json data, int64)
p0+8: json data
p0+8+n: EOF
Writing:
>>> import numpy as np
>>> import ase.io.ulm as ulm
>>> with ulm.open('x.ulm', 'w') as w:
... w.write(a=np.ones(7), b=42, c='abc')
... w.write(d=3.14)
Reading:
>>> r = ulm.open('x.ulm')
>>> print(r.c)
abc
To see what’s inside ‘x.ulm’ do this:
$ ase ulm x.ulm
x.ulm (tag: "", 1 item)
item #0:
{
a: <ndarray shape=(7,) dtype=float64>,
b: 42,
c: abc,
d: 3.14}
Versions:
- Initial version.
- Added support for big endian machines. Json data may now have _little_endian=False item.
- Changed magic string from “AFFormat” to “- of Ulm”.
-
class
ase.io.ulm.
Writer
(fd, mode='w', tag='', data=None)[source]¶ Create writer object.
- fd: str
- Filename.
- mode: str
- Mode. Must be ‘w’ for writing to a new file (overwriting an existing one) and ‘a’ for appending to an existing file.
- tag: str
- Magic ID string.
-
add_array
(name, shape, dtype=<class 'float'>)[source]¶ Add ndarray object.
Set name, shape and dtype for array and fill in the data in chunks later with the fill() method.
-
sync
()[source]¶ Write data dictionary.
Write bool, int, float, complex and str data, shapes and dtypes for ndarrays.
-
write
(*args, **kwargs)[source]¶ Write data.
Examples:
writer.write('n', 7) writer.write(n=7) writer.write(n=7, s='abc', a=np.zeros(3), abc=obj)
If obj is not one of the supported data types (bool, int, float, complex, tupl, list, dict, None or ndarray) then it must have a obj.write(childwriter) method.