Commit 8be1b714 authored by Simon Sebastian Humpohl's avatar Simon Sebastian Humpohl
Browse files

Initial commit

# qutil
Long term goal is to gather utility functions here. It is not meant as a lightweight package. If you just want to use it you can install it via
pip install git+
However, this package profits from everybody's work so please make a development install and contribute your changes. You can do this via
git clone git+
cd qutil
python develop
This will link the files into your environment instead of copying them. If you are on windows you can use [SourceTree]( which is a nice GUI for git.
## qutil.matlab
In this module there are functions that are helpful for reading `.mat` files, especially those created with special measure. If you simply want to open a random `.mat` file you can use `hdf5storage.loadmat`.
__version__ = '0.1'
"""This module contains utility functions that help interacting with matlab and matlab files"""
import itertools
import numpy
import hdf5storage
import pandas
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
: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))
n_loops = loops.shape[-1]
n_points = loops['npoints'].squeeze(axis=2).astype(numpy.int64)
rngs = loops['rng']
setchan = loops['setchan'].squeeze(axis=2)
sweeps = []
for loop_idx in range(n_loops):
loop_sweeps = {}
for ch, rng, n in zip(setchan[loop_idx], rngs[loop_idx], n_points[loop_idx]):
ch = ch[0, 0]
span = numpy.linspace(*rng, num=n)
loop_sweeps[ch] = span
if not all(len(sweep) == 1 for sweep in sweeps):
raise RuntimeError('This code is too stupid to handle simultaneous'
# who needs readable code anyways?
labels, values = zip(*itertools.chain.from_iterable(map(dict.items, sweeps)))
idx = pandas.MultiIndex.from_product(values, names=labels)
getchan = loops['getchan']
measured = [ch[0, 0][0, 0] for ch in getchan if all(ch.shape)]
# always vector cell
data = file_contents['data'].flatten()
result = pandas.DataFrame(index=idx)
assert len(measured) == len(data)
for meas, val in zip(measured, data):
val = val.transpose()
assert val.shape == idx.levshape
result[meas] = val.flatten()
if squeeze_constant_setchan:
to_squeeze = [lvl_idx
for lvl_idx, lvl_dim in enumerate(idx.levshape)
if lvl_dim == 1]
result = result.droplevel(to_squeeze)
return result
from setuptools import setup, find_packages
import os.path
import re
def extract_version(version_file):
version_match ="^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
raise RuntimeError("Unable to find version string.")
root_dir = os.path.basename(__file__)
with open("", "r") as fh:
long_description =
with open(os.path.join(root_dir, 'qutil', ''), 'r') as init_file:
init_file_content =
description='Utility package of the Quantum Technology group of RWTH Aachen',
author='Quantum Technology Group, RWTH Aachen University',
package_dir={'qutil': 'qutil'},
install_requires=['numpy', 'hdf5storage', 'pandas'],
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
Markdown is supported
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