Commit 5c2a9782 authored by Simon Sebastian Humpohl's avatar Simon Sebastian Humpohl
Browse files

Factor dataframe conversion out of load_special_measure_scan and incliude a caching loader

parent b5e10fff
"""This module contains utility functions that help interacting with matlab and matlab files"""
import itertools
import numpy
import hdf5storage
import pandas
import qutil.caching
def load_special_measure_scan(file_name: str, squeeze_constant_setchan: bool = True) -> pandas.DataFrame:
"""
__all_ = ['load_special_measure_scan', 'cached_load_mat_file', 'special_measure_to_dataframe']
:param file_name: Path of the file to load
:param squeeze_constant_setchan: If true, "set channels" that are constant are not included in the index
:return: Data frame with a multi-index that corresponds to the "set channels" and columns that correspond to the
"get channels".
"""
# this is slow as the scan stuct is quite complicated and hdf5storage creates a dtype for the whole thing
file_contents = hdf5storage.loadmat(file_name)
loops = file_contents['scan']['loops'].squeeze(axis=(0, 1))
def special_measure_to_dataframe(loaded_scan_data: dict,
squeeze_constant_setchan: bool = True) -> pandas.DataFrame:
loops = loaded_scan_data['scan']['loops'].squeeze(axis=(0, 1))
n_loops = loops.shape[-1]
n_points = loops['npoints'].squeeze(axis=2).astype(numpy.int64)
......@@ -48,7 +42,7 @@ def load_special_measure_scan(file_name: str, squeeze_constant_setchan: bool = T
measured = [ch[0, 0][0, 0] for ch in getchan if all(ch.shape)]
# always vector cell
data = file_contents['data'].flatten()
data = loaded_scan_data['data'].flatten()
result = pandas.DataFrame(index=idx)
assert len(measured) == len(data)
......@@ -66,4 +60,22 @@ def load_special_measure_scan(file_name: str, squeeze_constant_setchan: bool = T
return result
def load_special_measure_scan(file_name: str,
squeeze_constant_setchan: bool = True) -> pandas.DataFrame:
"""
:param file_name: Path of the file to load
:param squeeze_constant_setchan: If true, "set channels" that are constant are not included in the index
:param use_cache:
:return: Data frame with a multi-index that corresponds to the "set channels" and columns that correspond to the
"get channels".
"""
# this is slow as the scan stuct is quite complicated and hdf5storage creates a dtype for the whole thing
file_contents = hdf5storage.loadmat(file_name)
return special_measure_to_dataframe(file_contents, squeeze_constant_setchan)
@qutil.caching.file_cache
def cached_load_mat_file(filename):
return hdf5storage.loadmat(filename)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment