pylablib.aux_libs.file_formats package¶
Submodules¶
pylablib.aux_libs.file_formats.cam module¶
Standard .cam format.
A .cam file is a set of frames (in raw binary <u2 format), each of which is prepended by two 4-byte integers denoting the frame dimensions.
-
class
pylablib.aux_libs.file_formats.cam.
CamReader
(path, same_size=False)[source]¶ Bases:
object
Reader class for .cam files.
Allows transparent access to frames by reading them from the file on the fly (without loading the whole file). Supports determining length, indexing (only positive single-element indices) and iteration.
Parameters: - path (str) – path to .cam file.
- same_size (bool) – if
True
, assume that all frames have the same size, which speeds up random access and obtaining number of frames; otherwise, the first time the length is determined or a large-index frame is accessed can take a long time (all subsequent calls are faster).
-
get_data
(idx)[source]¶ Get a single frame at the given index (only non-negative indices are supported)
-
pylablib.aux_libs.file_formats.cam.
iter_cam_frames
(path, start=0, step=1)[source]¶ Iterate of frames in a .cam datafile.
Yield 2D array (one array per frame). Frames are loaded only when yielded, so the function is suitable for large files.
-
pylablib.aux_libs.file_formats.cam.
load_cam
(path, same_size=True)[source]¶ Load .cam datafile.
Return list of 2D numpy arrays, one array per frame. If
same_size==True
, raise error if different frames have different size.
-
pylablib.aux_libs.file_formats.cam.
combine_cam_frames
(path, func, init=None, start=0, step=1, max_frames=None, return_total=False)[source]¶ Combine .cam frames using the function func.
func takes 2 arguments (the accumulated result and a new frame) and returns the combined result. init is the initial result value; if
init is None
it is initialized to the first frame. If max_frames is notNone
, it specifies the maximal number of frames to read. Ifreturn_total==True'
, return a tuple(result, n)'
, where n is the total number of frames.
pylablib.aux_libs.file_formats.ecam module¶
-
class
pylablib.aux_libs.file_formats.ecam.
ECamFrame
(data, uid='new', timestamp='new', **kwargs)[source]¶ Bases:
object
A data frame for .ecam format.
Parameters: - data – frame data (numpy array with between 1 and 4 dimensions)
- uid (bytes) – 8-byte unique ID of the frame (by default, generate a new random ID).
- timetamps (float) – frame timestamp (by default, use current time)
- **kwargs – additional frame blocks (values and meaning depend on the block type, and can be expanded later)
-
class
pylablib.aux_libs.file_formats.ecam.
THeader
(header_size, image_bytes, version, shape, dtype, stype, uid, timestamp, blocks)¶ Bases:
tuple
-
blocks
¶
-
dtype
¶
-
header_size
¶
-
image_bytes
¶
-
shape
¶
-
stype
¶
-
timestamp
¶
-
uid
¶
-
version
¶
-
-
exception
pylablib.aux_libs.file_formats.ecam.
ECamFormatError
[source]¶ Bases:
OSError
Generic ECam reading error
-
class
pylablib.aux_libs.file_formats.ecam.
ECamFormatter
(stype='raw', dtype=None, shape=(None, None))[source]¶ Bases:
object
Formatter for .ecam files.
Class responsible for writing and reading arbitrary ECam frames.
Parameters: - stype (str) – storage type for the data. Can be
"raw"
(write as raw binary),"zlib"
(raw binary compressed using standard Python zlib module), or"none"
(write zeros instead of data). Used only for writing; in reading, all storage types are supported. - dtype – default data dtype. If suppled, any written data will be converted to this dtype, and any read data will have this dtype by default (unless specified explicitly). Otherwise, use supplied data dtype when writing.
- shape (tuple) – default data shape (tuple of length 2 or 3). If suppled, any written and read data is supposed to have this shape (also use this as default shape if none is provided in the file).
-
read_frame
(f, return_format='frame')[source]¶ Read next frame starting at the current position within the file f.
return_format is the format for return data. Can be
"frame"
(returnECamFrame
object with all metadata),"image"
(return only image array), or"raw"
(return tuple(header, image)
with raw data).
- stype (str) – storage type for the data. Can be
-
pylablib.aux_libs.file_formats.ecam.
save_ecam
(frames, path, append=True, formatter=None)[source]¶ Save frames into a .ecam datafile.
If
append==False
, clear the file before writing the frames. formatter specifiesECamFormatter
instance for frame saving.
-
pylablib.aux_libs.file_formats.ecam.
save_ecam_single
(frame, path, append=True, **kwargs)[source]¶ Save a single frame into a .ecam datafile.
If
append==False
, clear the file before writing the frames.**kwargs
specify parameters passed to theECamFormatter
constructor for the saving formatter.
-
class
pylablib.aux_libs.file_formats.ecam.
ECamReader
(path, same_size=False, return_format='frame', formatter=None)[source]¶ Bases:
object
Reader class for .ecam files.
Allows transparent access to frames by reading them from the file on the fly (without loading the whole file). Supports determining length, indexing (only positive single-element indices) and iteration.
Parameters: - path (str) – path to .ecam file.
- same_size (bool) – if
True
, assume that all frames have the same size (including header), which speeds up random access and obtaining number of frames; otherwise, the first time the length is determined or a large-index frame is accessed can take a long time (all subsequent calls are faster). - return_format (str) – format for return data. Can be
"frame"
(returnECamFrame
object with all metadata),"image"
(return only image array), or"raw"
(return tuple(header, image)
with raw data). - formatter (ECamFormatter) – formatter for saving
-
get_data
(idx)[source]¶ Get a single frame at the given index (only non-negative indices are supported)
pylablib.aux_libs.file_formats.waveguide module¶
File formats generated by the LabView code on the waveguide project.
-
pylablib.aux_libs.file_formats.waveguide.
load_info
(path)[source]¶ Load the info file (ends with
"_info.txt"
).Return information as a dictionary
{name: value}
, where value is a list (single-element list for a scalar property).
-
pylablib.aux_libs.file_formats.waveguide.
load_sweep
(prefix, force_info=True)[source]¶ Load binary sweep located at
prefix+".dat"
with an associated info file located atprefix+"_info.txt"
.Return tuple
(table, info)
, where table is the data table, and info is the info dictionary (seeload_info()
). Ifforce_info==True
, raise an error if the info file is missing. The columns for table are extracted from the info file. If it is missing or the channels info is not in the file, table has a single column.
-
pylablib.aux_libs.file_formats.waveguide.
cut_outliers
(sweep, jump_size, length, padding=0, x_column=None, ignore_last=0)[source]¶ Cut out sections of the waveform with large jumps.
Remove sections of the waveform which are at most length long and have jumps of at least jump_size on both size. If
padding>0
, remove additional padding points on both sides of the outlier section. ifignore_last>0
, do not consider jumps in the last ignore_last points. For multi-column data, x_column specifies the columns of interest.
-
pylablib.aux_libs.file_formats.waveguide.
trim_jumps
(sweep, jump_size, trim=1, x_column=None)[source]¶ Clean up jumps in the data by removing several data points around them.
Remove trim datapoints on both sides of jumps if at least jump_size. For multi-column data, x_column specifies the columns of interest.
-
pylablib.aux_libs.file_formats.waveguide.
prepare_sweep_frequency
(sweep, allowed_frequency_jump=None, ascending_frequency=True, rescale=True)[source]¶ Clean up the sweep frequency data (exclude jumps and rescale in Hz).
Find the longest continuous chunk with frequency steps within allowed_frequency_jump’ range (by default, it is ``(-5*mfs,infty)`, where
mfs
is the median frequency step). Ifascending_frequency==True
, sort the data so that frequency is in the ascending order. Ifrescale==True
, rescale frequency in Hz.
-
pylablib.aux_libs.file_formats.waveguide.
interpolate_sweep
(sweep, columns, frequency_step, rng=None, frequency_column='Wavemeter')[source]¶ Interpolate sweep data over a regular frequency grid with the spacing frequency_step.
-
pylablib.aux_libs.file_formats.waveguide.
load_prepared_sweeps
(prefix, reps, min_sweep_length=1, **add_info)[source]¶ Load sweeps with the given prefix and reps and normalize their frequency axes.
Return list of tuples
(sweep, info)
. add_info is added to the info dictionary (rep index is added automatically). min_sweep_length specifies the minimal sweep length (after frequency normalization) to be included in the list.
pylablib.aux_libs.file_formats.zi module¶
Files generated by the Zurich Instruments ziControl (old LabView version).
-
pylablib.aux_libs.file_formats.zi.
load_spectr_file
(path, result_format='xy')[source]¶ Load a single demod scope (demod samples vs. time) file.
-
pylablib.aux_libs.file_formats.zi.
load_spectr_folder
(path, result_format='xy')[source]¶ Load a folder containing demod scope files.
Return a list of 6 elements (one pere demod), which are either
None
, if there’s not data for this demod, or contain that demod’s trace.