Measurement#
- class pyscan.measurement.run_info.RunInfo#
Object that contains information of how to run the experiment.
- Attributes:
- scan<#>: ps.PropertyScan, ps.RepeatScan, ps.FunctionScan, ps.FunctionScan
Instance of ps.AbstractScan to a scan object representing one independent experimental variable. The scan property or function will be scanned during the experiment, with scan0 being the innermost scan loop.
- measuredlist
List that contains the names of collected data, defined by the measure_function return.
- measure_functionfunc
User-defined function that controls how to measure data. It should accept a ps.Experiment object as its only parameter, and returns an ItemAttribute object containing the measured data. The names of the measured data, each being an attribute of the return object, will appear as keys of the experiment after it is run.
- initial_pausefloat
Pause before first setting instruments in seconds, defaults to 0.1.
- _pyscan_versionstr
Current version of pyscan to be saved as metadata.
- (Properties)
scanslistReturns array of all scans
dimstupleReturns tuple containing the length of each scan, in order from scan0 to scan3, and excludes scans of size 1
average_dimstupleReturns tuple containing the length of each scan, excluding scans of size 1 and the averaged scan
ndimintReturns number of scans
has_average_scanboolReturns a boolean of whether or not an average scan is present.
indiciestupleReturns tuple of the current scan iteration indicies,
average_indiciestupleReturns tuple of the current scan iteration indicies, excluding scans of size 1 and averaged scan.
average_indexintReturns the index of the scan to be averaged.
Methods
check()
check_sequential_scans()
check_property_scan()
check_repeat_scan()
check_average_scan()
check_continuous_scan()
- property average_dims#
Returns tuple containing the length of each scan, excluding scans of size 1 and the averaged scan
- property average_index#
Returns the index of the scan to be averaged. Used by pyscan.AverageExperiment.
- property average_indicies#
Returns tuple of the current scan iteration indicies, excluding scans of size 1 and averaged scan. Used by .AverageExperiment.
- check()#
Checks to see if runinfo is properly formatted. Called by Experiment object’s run() methods.
Automatically sets self.average_index to the correct scan index (i.e., the scan which contains an instance of .AverageScan) to average over.
- check_average_scan()#
Checks to see if there is an average scan present and sets self.average_index to the correct index.
- check_property_scans()#
Checks to see if there are any errors with PropertyScans
- check_repeat_scan()#
Checks to see if there a repeat scan present and if there are more the one repeat scans
- property continuous_index#
Returns the index of the scan to be averaged. Used by pyscan.AverageExperiment.
- property dims#
Returns tuple containing the length of each scan, in order from scan0 to scan3, and excludes scans of size 1
- property has_average_scan#
Returns a boolean of whether or not an average scan is present.
- property has_continuous_scan#
Returns a boolean of whether or not an continuous scan is present.
- property indicies#
Returns tuple of the current scan iteration indicies,
- property n_average_dim#
Returns number of scans that are neither size-1 nor average scans
- property ndim#
Returns number of scans
- property scans#
Returns array of all scans
Scans#
- class pyscan.measurement.scans.AbstractScan(dictionary=None)#
Abstract class for different scan types. Inherits from .ItemAttribute.
Methods
A function to be implemented by inheriting Scan classes.
iterate(index, devices)A function to be implemented by inheriting Scan classes.
- check_same_length()#
A function to be implemented by inheriting Scan classes.
- iterate(index, devices)#
A function to be implemented by inheriting Scan classes.
- class pyscan.measurement.scans.AverageScan(n_average, dt=0)#
Class for averaging inner loops.
- Parameters:
- n_averageint
Number of times to average data from inner loops
- dtfloat
Wait time in seconds before each measurement. Used by Experiment classes, defaults to 0.
Methods
- check_same_length()#
Not used
- iterate(expt, i, d)#
Place holder, does nothing
- iterator()#
The following iterates over n
- class pyscan.measurement.scans.ContinuousScan(n_max=None, dt=0)#
Class for performing a continuous scan, which runs indefinitely or until a specified maximum number of iterations. Inherits from pyscan.measurement.scans.AbstractScan.
- Parameters:
- dtfloat, optional
Wait time in seconds after each iteration. Used by experiment classes, defaults to 0.
- n_maxint, optional
Maximum number of iterations to run. If not specified, the scan will run indefinitely.
Methods
iterate(expt, i, d)A function to be implemented by inheriting Scan classes.
iterator()The following iterates over n_max if n_max is specified, otherwise it iterates indefinitely.
- iterate(expt, i, d)#
A function to be implemented by inheriting Scan classes.
- iterator()#
The following iterates over n_max if n_max is specified, otherwise it iterates indefinitely.
- class pyscan.measurement.scans.FunctionScan(function, values, dt=0)#
Class for iterating a function with input values inside an experimental loop. Inherits from pyscan.measurement.scans.AbstractScan.
- Parameters:
- functionfunc
Function to be applied during each iteration. Must take a single argument representing one item in the values array. The function’s return value is not used.
- valueslist
An array of values to run the function on.
- dt: float
Wait time in seconds after running function once, and before the
runinfo.measure_functionis called. Used by experiment classes, defaults to 0.
Methods
A function to be implemented by inheriting Scan classes.
iterate(expt, i, d)Executes function(self.values[index]).
iterator()The following iterates over n
- check_same_length()#
A function to be implemented by inheriting Scan classes.
- iterate(expt, i, d)#
Executes function(self.values[index]). Used by a Experiment class’s run() function.
- Parameters:
- index
The index of the values array to run the function on. The FunctionScan’s values at the given index will be the function input.
- devices:
Not used
- iterator()#
The following iterates over n
- class pyscan.measurement.scans.PropertyScan(input_dict, prop, dt=0)#
Class for iterating a property of an intruments inside an experimental loop. Inherits from pyscan.measurement.scans.AbstractScan.
- Parameters:
- input_dictdict{string:array}
key:value pairs of device name strings and arrays of values representing the new prop values you want to set for each device.
- propstr
String that indicates the property of the device(s) to be changed
- dtfloat
Wait time in seconds after changing a single property value, and before the measure_function is called. Used by experiment classes, defaults to 0.
Methods
Check that the input_dict has values that are arrays of the same length.
iterate(expt, i, d)Changes prop of the listed devices to the value of PropertyScan's input_dict at the given index.
iterator()The following iterates over n
- check_same_length()#
Check that the input_dict has values that are arrays of the same length.
- iterate(expt, i, d)#
Changes prop of the listed devices to the value of PropertyScan’s input_dict at the given index.
- Parameters:
index – The index of the data array
devices (ItemAttribute) – ItemAttribute instance of experimental devices
- iterator()#
The following iterates over n
- class pyscan.measurement.scans.RepeatScan(nrepeat, dt=0)#
Class for repeating inner loops.
- Parameters:
- n_repeatint
Number of times to repeat inner loops.
- dtfloat
Wait time in seconds after repeat. Used by experiment classes, defaults to 0.
Methods
- check_same_length()#
Not used
- iterate(expt, i, d)#
Iterates repeat loop.
- iterator()#
The following iterates over n
Experiments#
- class pyscan.measurement.experiment.Experiment(runinfo, devices, data_dir=None)#
Experiment class that takes data after each scan0 iteration.
- Parameters:
- runinfops.RunInfo instance
Contains all information about the experiment
- devicesItemAttribute instance
ItemAttribute instance containing all experiment devices
- data_dirstr, optional
The path to save the data, defaults to ‘./backup’
- Attributes:
- runinfops.RunInfo
Contains all information about the experiment
- devicesItemAttribute
ItemAttribute instance containing all experiment devices
Methods
# Setup methods
setup_data_dir(data_dir)
check_runinfo()
save_metadata(metadata_name)
# Data methods
preallocate(data)
reallocate(data)
rolling_average(data)
save_point(data)
# Running experiment methods
start_thread()
stop()
run()
- check_runinfo()#
Function that is run at the beginning of experiment to ensure runinfo is property formatted.
- preallocate(data)#
Preallocate save data based on the first value of the measurement function
- Parameters:
- dataItemAttribute
ItemAttribute instance containing data from self.runinfo.measure_function
- reallocate(data)#
Reallocates memory for continuous experiments save files and measurement attribute arrays.
- Parameters:
- dataItemAttribute
ItemAttribute instance containing data from self.runinfo.measure_function
- rolling_average(data)#
Does a rolling average of newly measured data
- Parameters:
- data
ItemAttribute instance of newly measured data point
- save_metadata(metadata_name)#
Formats and saves metadata to the hdf5 file
- Parameters:
- metadata_namestr
Name of the metadata to be saved, ex. “runinfo”, “devices”
- save_point(data)#
Saves single point of data for current scan indicies. Does not return anything.
- setup_data_dir(data_dir)#
Creates save directory if it does not exist
- Parameters:
- data_dirstr, optional
Path to save the data, defaults to ‘./backup’
- start_thread()#
Starts experiment as a background thread, this works in conjunction with live plot
- stop()#
Stops the experiment after the next data point is take ensuring that the data is saved properly. Sets the associated runinfo.complete setting to ‘stopped’ and runinfo.running to False.
- pyscan.measurement.load_experiment.find_measured_datasets(runinfo, all_datasets)#
HDF5 files contain two types of datasets. Measured datasets are data from the measure_function, and while running a list of measured datasets is included in runinfo.measured. Pyscan generated datasets are created when the experiment runs. This function identifies the generated dataset from each scan.
- Returns:
List of datasets generated by pyscan.
- pyscan.measurement.load_experiment.load_experiment(file_name)#
Function to load experimental data created by pyscan
- Parameters:
- file_namestr
Path to file that is to be loaded