qtt.utilities package
Submodules
qtt.utilities.debug module
- qtt.utilities.debug.dumpstring(txt, tag='dump', showfile=False)[source]
Dump a text string to temperary file on disk
qtt.utilities.imagetools module
- qtt.utilities.imagetools.Vtrace(cdata, param, fig=None)[source]
Calculate position of next V-trace from fitted model .
- Parameters:
cdata – TODO
param – TODO
fit (None or integer) – figure handle.
- qtt.utilities.imagetools.cleanSensingImage(im, dy=0, sigma=None, order=3, fixreversal=True, removeoutliers=False, verbose=0)[source]
Clean up image from sensing dot.
- qtt.utilities.imagetools.createCross(param, samplesize, l=20, w=2.5, lsegment=10, H=100, scale=None, lines=range(0, 4), istep=1, centermodel=True, linesegment=True, addX=True, verbose=0)[source]
Create a cross model. The parameters are [x, y, width, alpha_1, …, alpha_4, [rotation of polarization line] ] With the optional parameters psi (angle of transition line). The x, y, width are in mV. Angles in radians.
- Parameters:
param (array) – parameters of the model.
samplesize (int) – size of image patch in pixels.
l (float) – parameters of the model in mV?. lsegment is the length of the 4 addition lines w is width of lines in the model. l is not used by default.
w (float) – parameters of the model in mV?. lsegment is the length of the 4 addition lines w is width of lines in the model. l is not used by default.
lsegment (float) – parameters of the model in mV?. lsegment is the length of the 4 addition lines w is width of lines in the model. l is not used by default.
istep (float) – scan resolution in pixel/mV.
scale (None) – parameter not used any more.
addX (bool) – if True add polarization line to model.
H (float) – intensity of cross.
linesegment (bool) – if True create line segments instead of full lines.
- Returns:
return data.
- Return type:
modelpatch, (cc, lp, hp, ip, opr, w, H, lsegment)
- qtt.utilities.imagetools.evaluateCross(param, im, verbose=0, fig=None, istep=1, istepmodel=1, linewidth=2, usemask=False, use_abs=False, w=2.5)[source]
Calculate cross matching score.
- Parameters:
param (array or list) – used by createCross to create image template.
im (numpy array) – TODO.
- Returns:
cost, patch, cdata, tuple.
See also
createCross.
- qtt.utilities.imagetools.fitBackground(im, smooth=True, fig=None, order=3, verbose=1, removeoutliers=False, returndict=None)[source]
Fit smooth background to 1D or 2D image.
- Parameters:
im (array) – input image.
- Returns
vv (array): estimated background.
- qtt.utilities.imagetools.fitModel(param0, imx, verbose=1, cfig=None, ksizemv=41, istep=None, istepmodel=0.5, cb=None, use_abs=False, model_line_width=2.5)[source]
Fit model of an anti-crossing .
This is a wrapper around evaluateCross and the scipy optimization routines.
- Parameters:
param0 (array) – parameters for the anti-crossing model.
imx (array) – input image.
- qtt.utilities.imagetools.lineSegment(im, x0, x1=None, theta=None, w=2, l=12, H=200, ml=0)[source]
Plot half-line into image .
>>> lineSegment(np.zeros( (160,240)), [60,40], [70,40], w=10, l=60) >>> lineSegment(np.zeros( (160,240)), [60,40], theta=np.deg2rad(20), w=10, l=60)
qtt.utilities.json_serializer module
- qtt.utilities.json_serializer.decode_json(json_string: str) Any [source]
Decode Python object to JSON
- Parameters:
json_string – data to be decoded
- Returns
Python object
- qtt.utilities.json_serializer.encode_json(data: object) str [source]
Encode Python object to JSON
- Parameters:
data – data to be encoded
- Returns
String with formatted JSON
qtt.utilities.optimization module
- class qtt.utilities.optimization.AverageDecreaseTermination(N: int, tolerance: float = 0.0)[source]
Bases:
object
- property parameters
- property values
- class qtt.utilities.optimization.OptimizerCallback(show_progress: bool = False, store_data: bool = True, residual_fitting: bool = True)[source]
Bases:
object
- property data: DataFrame
Return data gathered by callback
- data_callback(iteration: int, parameters: Any, residual: float) None [source]
Callback used to store data
- Parameters:
iteration – Iteration on the optimization procedure
parameters – Current values of the parameters to be optimized
residual – Current residual (value of the objective function)
- lmfit_callback(parameters, iteration, residual, *args, **kws)[source]
Callback method for lmfit optimizers
- number_of_evaluations() int [source]
Return the number of callback evaluations
Note: this can differ from the number of objective evaluations
- optimization_time() float [source]
Return time difference between the first and the last invocation of the callback
- Returns:
Time in seconds
- property parameters: List[Any]
Returns list of parameters that have been used in evaluations
- Returns:
The list of parameters
qtt.utilities.tools module
- qtt.utilities.tools.addPPT_dataset(dataset, title=None, notes=None, show=False, verbose=1, paramname='measured', printformat='fancy', customfig=None, extranotes=None, **kwargs)[source]
Add slide based on dataset to current active Powerpoint presentation.
Dummy implementation.
- qtt.utilities.tools.addPPTslide(title: str | None = None, fig: int | ndarray | Figure | Any | None = None, txt: str | None = None, notes: str | Station | None = None, figsize: Tuple[int, int] | None = None, subtitle: str | None = None, maintext: str | None = None, show: bool = False, verbose: int = 1, activate_slide: bool = True, ppLayout: int | None = None, extranotes: str | None = None, background_color: Tuple | None = None, maximum_notes_size: int = 10000) Tuple[Any, Any] [source]
Add slide to current active Powerpoint presentation.
Dummy implementation.
- qtt.utilities.tools.cfigure(*args, **kwargs)[source]
Create Matplotlib figure with copy to clipboard functionality.
By pressing the ‘c’ key figure is copied to the clipboard.
- qtt.utilities.tools.clickGatevals(plot, drawmode='ro')[source]
Get gate values for all gates at clicked point in a heatmap.
- Parameters:
plot (qcodes MatPlot object) – plot of measurement data.
drawmode (string) – plotting style.
- Returns:
values of the gates at clicked point.
- Return type:
gatevals (dict)
- qtt.utilities.tools.code_version(repository_names=None, package_names=None, get_dirty_status=False, verbose=0)[source]
- Returns the python version, module version for; numpy, scipy, qupulse
and the git guid and dirty status for; qcodes, qtt, spin-projects and pycqed, if present on the machine. NOTE: currently the dirty status is not working correctly due to a bug in dulwich…
- Parameters:
- Returns:
python, modules and git repos status.
- Return type:
status (dict)
- qtt.utilities.tools.create_figure_ppt_callback(fig: int | Figure | None = None, title: str | None = None, notes: str | DataSet | None = None, position: Tuple[float, float, float, float] = (0.9, 0.925, 0.075, 0.05)) None [source]
Create a button on a matplotlib figure to copy data to PowerPoint slide.
The figure is copied to PowerPoint using @ref addPPTslide.
- Parameters:
fig – Handle to matplotlib window. If None, then use the current figure
title – title for the slide.
notes – notes to add to the slide.
position – position specified as fraction left, right, width, height.
Example
>>> plt.figure(10) >>> plt.plot(np.arange(100), np.random.rand(100), 'o', label='input data') >>> create_figure_ppt_callback(fig=10, title='test') >>> plt.show()
- qtt.utilities.tools.cutoffFilter(x, thr, omega)[source]
Smooth cutoff filter.
Filter definition from: http://paulbourke.net/miscellaneous/imagefilter/
Example
>>> plt.clf() >>> x=np.arange(0, 4, .01) >>> _=plt.plot(x, cutoffFilter(x, 2, .25), '-r')
- qtt.utilities.tools.deprecated(func)[source]
This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.
- qtt.utilities.tools.diffImage(im, dy, size=None)[source]
Simple differentiation of an image.
- Parameters:
im (numpy array) – input image.
dy (integer or string) – method of differentiation. For an integer it is the axis of differentiation. Allowed strings are ‘x’, ‘y’, ‘xy’.
size (str) – describes the size e.g. ‘same’.
- qtt.utilities.tools.diffImageSmooth(im, dy='x', sigma=2)[source]
Simple differentiation of an image.
- Parameters:
im (array) – input image.
dy (string or integer) – direction of differentiation. can be ‘x’ (0) or ‘y’ (1) or ‘xy’ (2) or ‘g’ (3).
sigma (float) – parameter for gaussian filter kernel.
- qtt.utilities.tools.flatten(lst)[source]
Flatten a list.
Example
>>> flatten([ [1,2], [3,4], [10] ]) [1, 2, 3, 4, 10]
- qtt.utilities.tools.fourierHighPass(imx, nc=40, omega=4, fs=1024, fig=None)[source]
Implement simple high pass filter using the Fourier transform.
- qtt.utilities.tools.get_git_versions(repos, get_dirty_status=False, verbose=0)[source]
- Returns the repository head guid and dirty status and package version number if installed via pip.
The version is only returned if the repo is installed as pip package without edit mode. NOTE: currently the dirty status is not working correctly due to a bug in dulwich…
- Parameters:
- Retuns:
r (dict): dictionary with repo names, head guid and (optionally) dirty status for each given repository.
- qtt.utilities.tools.get_module_versions(modules, verbose=0)[source]
Returns the module version of the given pip packages.
- qtt.utilities.tools.is_spyder_environment()[source]
Return True if the process is running in a Spyder environment
- qtt.utilities.tools.logging_context(level: int = 20, logger: Logger | None = None)[source]
A context manager that changes the logging level
- Parameters:
level – Logging level to set in the context
logger – Logger to update, if None then update the default logger
- class qtt.utilities.tools.measure_time(message: str | None = 'dt: ')[source]
Bases:
object
Create context manager that measures execution time and prints to stdout
- qtt.utilities.tools.rdeprecated(txt=None, expire=None)[source]
This is a decorator which can be used to mark functions as deprecated.
It will result in a warning being emitted when the function is used. After the expiration data the decorator will generate an Exception.
- qtt.utilities.tools.resampleImage(im)[source]
Resample the image so it has the similar sample rates (samples/mV) in both axis.
- Parameters:
im (DataArray) – input image.
- Returns:
resampled image. setpoints (list of 2 numpy arrays): setpoint arrays from resampled image.
- Return type:
imr (numpy array)
- qtt.utilities.tools.reshape_metadata(dataset, printformat='dict', add_scanjob=True, add_gates=True, add_analysis_results=True, verbose=0) str [source]
Reshape the metadata of a DataSet.
- Parameters:
dataset (DataSet or qcodes.Station) – a dataset of which the metadata will be reshaped.
printformat (str) – can be ‘dict’ or ‘txt’,’fancy’ (text format).
add_scanjob (bool) – If True, then add the scanjob at the beginning of the notes.
add_analysis_results (bool) – If True, then add the analysis_results at the beginning of the notes.
add_gates (bool) – If True, then add the scanjob at the beginning of the notes.
verbose (int) – verbosity (0 == silent).
- Returns:
The reshaped metadata.
- qtt.utilities.tools.set_ppt_slide_background(slide, color, verbose=0)[source]
Sets the background color of PPT slide.
- qtt.utilities.tools.showImage(im, extent=None, fig=None, title=None)[source]
Show image in figure window.
- qtt.utilities.tools.slopeClick(drawmode='r--', **kwargs)[source]
Calculate slope for line piece of two points clicked by user. Works with matplotlib but not with pyqtgraph. Uses the currently active figure.
- Parameters:
drawmode (string) – plotting style.
- Returns:
coordinates of the two clicked points. signedslope (float): slope of linepiece connecting the two points.
- Return type:
coords (2 x 2 array)
- qtt.utilities.tools.smoothFourierFilter(fs=100, thr=6, omega=2, fig=None)[source]
Create smooth ND filter for Fourier high or low-pass filtering.
Example
>>> F=smoothFourierFilter([24,24], thr=6, omega=2) >>> _=plt.figure(10); plt.clf(); _=plt.imshow(F, interpolation='nearest')
- qtt.utilities.tools.static_var(varname, value)[source]
Helper function to create a static variable.
- qtt.utilities.tools.stripDataset(dataset)[source]
Make sure a dataset can be pickled .
- Parameters:
dataset (qcodes DataSet) – TODO.
- Returns:
the dataset from the function argument.
- Return type:
dataset (qcodes DataSet)
qtt.utilities.visualization module
- qtt.utilities.visualization.combine_legends(axis_list: List[Axes], target_ax: Axes | None = None)[source]
Combine legends of a list of matplotlib axis objects into a single legend
- Parameters:
axis_list – List of matplotlib axis containing legends
target_ax – Axis to add the combined legend to. If None, use the first axis from the axis_list
Example
import matplotlib.pyplot as plt ax1=plt.gca() plt.plot([1,2,3], [.1,.2,.3], ‘.b’, label=’X’) plt.legend() ax2=ax1.twinx() ax2.plot([1,2,3], [1, 2, 3], ‘-r’, label=’miliX’ ) plt.legend() combine_legends([ax1, ax2])
- qtt.utilities.visualization.get_axis(handle: int | Axes | Figure | None) Axes [source]
Create or return matplotlib axis object
- Parameters:
handle – Specification of how to obtain the axis object. For an integer, generate a new figure. For an Axis object, return the handle. For a Figure, return the default axis of the figure. For None, use the matplotlib current axis.
- Returns:
Axis object
- qtt.utilities.visualization.plot_double_gaussian_fit(result_dict: dict, xdata: ndarray) None [source]
Plot a two Gaussians from a double Gaussian fit
- Parameters:
result_dict – Result of the double Gaussian fitting
xdata – Independent data
- qtt.utilities.visualization.plot_horizontal_line(x: float, color: str = 'c', alpha: float = 0.5, label: str | None = None, ax: Axes | None = None) Any [source]
Plot vertical alignment line
- Parameters:
x – Position on horizontal axis to plot the line
color – Color specification of the line
alpha – Value to use for the transparency of the line
label – Label for the line
ax – Matplotlib axis handle to plot to. If None, select the default handle
- Returns:
Handle to the plotted line
- qtt.utilities.visualization.plot_single_traces(traces: ndarray, time: ndarray | None = None, trace_color: ndarray | None = None, offset: None | bool | float = None, fig: int = 1, maximum_number_of_traces: int = 40)[source]
Plot single traces with offset for separation
- Parameters:
traces – Array with single traces in the rows
time – Option array for time axis
trace_color – Specification of trace color
offset – Offset to use between traces. For None automatically determine the offset
fig – Specification of Matplotlib window
maximum_number_of_traces – Maximum number of traces to plot
- qtt.utilities.visualization.plot_vertical_line(x: float, color: str = 'c', alpha: float = 0.5, label: str | None = None, ax: Axes | None = None) Any [source]
Plot vertical alignment line
- Parameters:
x – Position on horizontal axis to plot the line
color – Color specification of the line
alpha – Value to use for the transparency of the line
label – Label for the line
ax – Matplotlib axis handle to plot to. If None, select the default handle
- Returns:
Handle to the plotted line