Utility Functions & Classes

utils is a module containing useful classes and functions that come up in the course of a scanning SQUID experiment.

class utils.Counter[source]

Simple counter used to keep track of progress in a Loop.

utils.fit_line(x: Union[list, numpy.ndarray], y: Union[list, numpy.ndarray]) → Tuple[numpy.ndarray, float][source]

Fits a line to x, y(x) and returns (polynomial_coeffs, rms_residual).

Parameters
  • x – List or np.ndarry, independent variable.

  • y – List or np.ndarry, dependent variable.

Returns

p, rms

Array of best-fit polynomial coefficients, rms of residuals.

Return type

Tuple[np.ndarray, float]

utils.load_json_ordered(filename: str) → collections.OrderedDict[source]

Loads json file as an ordered dict.

Parameters

filename – Path to json file to be loaded.

Returns

odict

OrderedDict containing data from json file.

Return type

OrderedDict

utils.make_scan_grids(scan_vectors: Dict[str, Sequence[float]], slow_ax: str, fast_ax: str, fast_ax_pts: int, plane: Dict[str, float], height: float) → Dict[str, Any][source]

Makes meshgrids of scanner positions to write to DAQ analog outputs.

Parameters
  • scan_vectors – Dict of {axis_name: axis_vector} for x, y axes (from make_scan_vectors).

  • slow_ax – Name of the scan slow axis (‘x’ or ‘y’).

  • fast_ax – Name of the scan fast axis (‘x’ or ‘y’).

  • fast_ax_pts – Number of points to write to DAQ analog outputs to scan fast axis.

  • plane – Dict of x, y, z values defining the plane to scan (provided by scanner.get_plane).

  • height – Height above the sample surface (in DAQ voltage) at which to scan. More negative means further from sample; 0 means ‘in contact’.

Returns

scan_grids

{axis_name: axis_scan_grid} for x, y, z, axes.

Return type

Dict

utils.make_scan_surface(surface_type: str, scan_vectors: Dict[str, Sequence[float]], slow_ax: str, fast_ax: str, fast_ax_pts: int, plane: Dict[str, float], height: float, interpolator: Optional[Callable] = None)[source]

Makes meshgrids of scanner positions to write to DAQ analog outputs.

Parameters
  • surface_type – Either ‘plane’ or ‘surface’.

  • scan_vectors – Dict of {axis_name: axis_vector} for x, y axes (from make_scan_vectors).

  • slow_ax – Name of the scan slow axis (‘x’ or ‘y’).

  • fast_ax – Name of the scan fast axis (‘x’ or ‘y’).

  • fast_ax_pts – Number of points to write to DAQ analog outputs to scan fast axis.

  • plane – Dict of x, y, z values defining the plane to scan (provided by scanner.get_plane).

  • height – Height above the sample surface (in DAQ voltage) at which to scan. More negative means further from sample; 0 means ‘in contact’.

  • interpolator – Instance of scipy.interpolate.Rbf used to interpolate touchdown points. Only required if surface_type == ‘surface’. Default: None.

Returns

scan_grids

{axis_name: axis_scan_grid} for x, y, z, axes.

Return type

Dict

utils.make_scan_vectors(scan_params: Dict[str, Any], ureg: Any) → Dict[str, Sequence[float]][source]

Creates x and y vectors for given scan parameters.

Parameters
  • scan_params – Scan parameter dict

  • ureg – pint UnitRegistry, manages units.

Returns

scan_vectors

{axis_name: axis_vector} for x, y axes.

Return type

Dict

utils.make_xy_grids(scan_vectors: Dict[str, Sequence[float]], slow_ax: str, fast_ax: str) → Dict[str, Any][source]

Makes meshgrids from x, y scan_vectors (used for plotting, etc.).

Parameters
  • scan_vectors – Dict of {axis_name: axis_vector} for x, y axes (from make_scan_vectors).

  • slow_ax – Name of scan slow axis (‘x’ or ‘y’).

  • fast_ax – Name of scan fast axis (‘x’ or ‘y’).

Returns

xy_grids

{axis_name: axis_grid} for x, y axes.

Return type

Dict

utils.moving_avg(x: Union[List, numpy.ndarray], y: Union[List, numpy.ndarray], window_width: int) → Tuple[numpy.ndarray][source]

Given 1D arrays x and y, calculates the moving average of y.

Parameters
  • x – x data (1D array).

  • y – y data to be averaged (1D array).

  • window_width – Width of window over which to average.

Returns

x, ymvg_avg

x data with ends trimmed according to width_width, moving average of y data

Return type

Tuple[np.ndarray]

utils.next_file_name(fpath: str, extension: str) → str[source]
Appends an integer to fpath to create a unique file name:

fpath + {next unused integer} + ‘.’ + extension

Parameters
  • fpath – Path to file you want to create (no extension).

  • extension – Extension of file you want to create.

Returns

next_file_name

Unique file name starting with fpath and ending with extension.

Return type

str

utils.scan_to_arrays(scan_data: Any, ureg: Optional[Any] = None, real_units: Optional[bool] = True, xy_unit: Optional[str] = None) → Dict[str, Any][source]

Extracts scan data from DataSet and converts to requested units.

Parameters
  • scan_data – qcodes DataSet created by Microscope.scan_plane

  • ureg – pint UnitRegistry, manages physical units.

  • real_units – If True, converts z-axis data from DAQ voltage into units specified in measurement configuration file.

  • xy_unit – String describing quantity with dimensions of length. If xy_unit is not None, scanner x, y DAQ ao voltage will be converted to xy_unit according to scanner constants defined in microscope configuration file.

Returns

arrays

Dict of x, y vectors and grids, and measured data in requested units.

Return type

Dict

utils.scan_to_mat_file(scan_data: Any, real_units: Optional[bool] = True, xy_unit: Optional[bool] = None, fname: Optional[str] = None, interpolator: Optional[Callable] = None) → None[source]

Export DataSet created by microscope.scan_surface to .mat file for analysis.

Parameters
  • scan_data – qcodes DataSet created by Microscope.scan_plane

  • real_units – If True, converts z-axis data from DAQ voltage into units specified in measurement configuration file.

  • xy_unit – String describing quantity with dimensions of length. If xy_unit is not None, scanner x, y DAQ ao voltage will be converted to xy_unit according to scanner constants defined in microscope configuration file.

  • fname – File name (without extension) for resulting .mat file. If None, uses the file name defined in measurement configuration file.

  • interpolator – Instance of scipy.interpolate.Rbf, used to interpolate touchdown points. Default: None.

utils.td_to_arrays(td_data: Any, ureg: Optional[Any] = None, real_units: Optional[bool] = True) → Dict[str, Any][source]

Extracts scan data from DataSet and converts to requested units.

Parameters
  • td_data – qcodes DataSet created by Microscope.td_cap

  • ureg – pint UnitRegistry, manages physical units.

  • real_units – If True, converts data from DAQ voltage into units specified in measurement configuration file.

Returns

arrays

Dict of measured data in requested units.

Return type

Dict

utils.td_to_mat_file(td_data: Any, real_units: Optional[bool] = True, fname: Optional[str] = None) → None[source]

Export DataSet created by microscope.td_cap to .mat file for analysis.

Parameters
  • td_data – qcodes DataSet created by Microscope.td_cap

  • real_units – If True, converts data from DAQ voltage into units specified in measurement configuration file.

  • fname – File name (without extension) for resulting .mat file. If None, uses the file name defined in measurement configuration file.

utils.to_real_units(data_set: Any, ureg: Any = None) → Any[source]
Converts DataSet arrays from DAQ voltage to real units using recorded metadata.

Preserves shape of DataSet arrays.

Parameters
  • data_set – qcodes DataSet created by Microscope.scan_plane

  • ureg – Pint UnitRegistry. Default None.

Returns

data

ndarray like the DataSet array, but in real units as prescribed by factors in DataSet metadata.

Return type

np.ndarray

utils.validate_scan_params(scanner_config: Dict[str, Any], scan_params: Dict[str, Any], scan_grids: Dict[str, Any], pix_per_line: int, pts_per_line: int, temp: str, ureg: Any, logger: Any) → None[source]

Checks whether requested scan parameters are consistent with microscope limits.

Parameters
  • scanner_config – Scanner configuration dict as defined in microscope configuration file.

  • scan_params – Scan parameter dict as defined in measurements configuration file.

  • scan_grids – Dict of x, y, z scan grids (from make_scan_grids).

  • pix_per_line – Number of pixels per line of the scan.

  • pts_per_line – Number of points per line sampled by the DAQ (to be averaged down to pix_per_line)

  • temp – Temperature mode of the microscope (‘LT’ or ‘RT’).

  • ureg – pint UnitRegistry, manages physical units.

  • logger – Used to log the fact that the scan was validated.

Returns

None