Main classes to deal with:
SerafinHeader
Read
(derived from Serafin
)Write
(derived from Serafin
)Read a binary Selafin file. Automatic dectection of precision (single or double) and endianness (big or little endian).
In [5]:
from pyteltools.slf import Serafin
with Serafin.Read('../scripts_PyTelTools_validation/data/Yen/fis_yen-exp.slf', 'en') as resin:
# Read header (SerafinHeader is stored in `header` attribute of `Serafin` class)
resin.read_header()
# Display a summary
print(resin.header.summary())
# Get time (in seconds) and display it
resin.get_time()
print(resin.time)
In [2]:
import numpy as np
from pyteltools.slf import Serafin
with Serafin.Read('../scripts_PyTelTools_validation/data/Yen/fis_yen-exp.slf', 'en') as resin:
resin.read_header()
# Copy header
output_header = resin.header.copy()
# Change some header attributes if required
#output_header.toggle_endianness()
#output_header.to_single_precision()
values = np.empty((output_header.nb_var, output_header.nb_nodes), dtype=output_header.np_float_type)
with Serafin.Write('/tmp/test.slf', 'fr', overwrite=True) as resout:
resout.write_header(output_header)
# Copy all frames
for time_index, time in enumerate(resin.time):
for i, var_ID in enumerate(output_header.var_IDs):
values[i, :] = resin.read_var_in_frame(time_index, var_ID)
resout.write_entire_frame(output_header, time, values)
Some custom exceptions are defined in pyteltools.slf.Serafin
:
SerafinRequestError
: Serafin file content checkingSerafinValidationError
: requesting invalid values from Serafin object