def makeDataSet1D(x, yname='measured', y=None, location=None, loc_record=None, return_names=False): ''' Make DataSet with one or multiple 1D arrays and one setpoint array. Arguments: x (array): the setpoint array of data yname (str or list): name(s) of measured array(s) y (array or None): optional array to fill the DataSet location (str or None): location for the DataSet loc_record (dict): will be added to the location return_names (bool): if True return array names in output ''' xx = np.array(x) yy = np.NaN * np.ones(xx.size) x = DataArray(name=x.name, array_id=x.name, label=x.parameter.label, unit=x.parameter.unit, preset_data=xx, is_setpoint=True) if isinstance(yname, str): measure_names = [yname] if y is not None: preset_data = [y] else: measure_names = yname mnamesx = measure_names measure_names = [] for p in mnamesx: if isinstance(p, str): measure_names += [p] else: # assume p is a Parameter measure_names += [p.full_name] dd = new_data(arrays=(), location=location, loc_record=loc_record) for idm, mname in enumerate(measure_names): ytmp = DataArray(name=mname, array_id=mname, label=mname, preset_data=np.copy(yy), set_arrays=(x, )) dd.add_array(ytmp) if y is not None: getattr(dd, mname).ndarray = np.array(preset_data[idm]) dd.add_array(x) if return_names: set_names = x.name return dd, (set_names, measure_names) else: return dd
def makeDataSet2Dplain(xname, x, yname, y, zname='measured', z=None, xunit=None, yunit=None, zunit=None, location=None, loc_record=None): ''' Make DataSet with one 2D array and two setpoint arrays Arguments: xname, yname (string): the name of the setpoint array x, y (array): the setpoint data zname (str or list): the name of the measured array z (array or list): the measured data ''' yy = np.array(y) xx0 = np.array(x) xx = np.tile(xx0, [yy.size, 1]) zz = np.NaN * np.ones((yy.size, xx0.size)) ya = DataArray(name=yname, array_id=yname, preset_data=yy, unit=yunit, is_setpoint=True) xa = DataArray(name=xname, array_id=xname, preset_data=xx, unit=xunit, set_arrays=(ya, ), is_setpoint=True) dd = new_data(arrays=(), location=location, loc_record=loc_record) if isinstance(zname, str): zname = [zname] if isinstance(z, np.ndarray): z = [z] for ii, name in enumerate(zname): za = DataArray(name=name, array_id=name, label=name, preset_data=np.copy(zz), unit=zunit, set_arrays=(ya, xa)) dd.add_array(za) if z is not None: getattr(dd, name).ndarray = np.array(z[ii]) dd.add_array(xa) dd.add_array(ya) dd.last_write = -1 return dd
def test_array(location=None, name=None): # DataSet with one 2D array with 4 x 6 points yy, xx = np.meshgrid(np.arange(0, 10, .5), range(3)) zz = xx**2 + yy**2 # outer setpoint should be 1D xx = xx[:, 0] x = DataArray(name='x', label='X', preset_data=xx, is_setpoint=True) y = DataArray(name='y', label='Y', preset_data=yy, set_arrays=(x, ), is_setpoint=True) z = DataArray(name='z', label='Z', preset_data=zz, set_arrays=(x, y)) return z
def fit_addition_line(dataset, trimborder=True): """Fits a FermiLinear function to the addition line and finds the middle of the step. Args: dataset (qcodes dataset): The 1d measured data of addition line. trimborder (bool): determines if the edges of the data are taken into account for the fit. Returns: m_addition_line (float): x value of the middle of the addition line result_dict (dict): dictionary with the following results fit parameters (array): fit parameters of the Fermi Linear function parameters initial guess (array): parameters of initial guess dataset fit (qcodes dataset): dataset with fitted Fermi Linear function dataset initial guess (qcodes dataset):dataset with guessed Fermi Linear function See also: FermiLinear and fitFermiLinear """ y_array = dataset.default_parameter_array() setarray = y_array.set_arrays[0] x_data = np.array(setarray) y_data = np.array(y_array) if trimborder: cut_index = max(min(int(x_data.size / 40), 100), 1) x_data = x_data[cut_index:-cut_index] y_data = y_data[cut_index:-cut_index] setarray = setarray[cut_index:-cut_index] m_addition_line, result_dict = fit_addition_line_array(x_data, y_data, trimborder=False) y_initial_guess = FermiLinear( x_data, *list(result_dict['parameters initial guess'])) dataset_guess = DataArray(name='fit', label='fit', preset_data=y_initial_guess, set_arrays=(setarray, )) y_fit = FermiLinear(x_data, *list(result_dict['fit parameters'])) dataset_fit = DataArray(name='fit', label='fit', preset_data=y_fit, set_arrays=(setarray, )) return m_addition_line, { 'dataset fit': dataset_fit, 'dataset initial guess': dataset_guess }
def save_single_raw_file(xdata, my_raw_data, rawdatacounter, maincounter): xarr = DataArray(preset_data=xdata, is_setpoint=True, name='time', label='Time', unit='s') yarr = DataArray(preset_data=my_raw_data, set_arrays=(xarr, ), name='demodulated_signal', label='Demodulated Signal', unit='V') name = '{0:06d}'.format(rawdatacounter) locstring = '{}{:03}_raw{}'.format(CURRENT_EXPERIMENT['exp_folder'], maincounter, sep) rawdataset = new_data(location=locstring, arrays=[xarr, yarr]) rawdataset.formatter.number_format = '{:g}' rawdataset.formatter.extension = '.raw' rawdataset.finalize(filename=name, write_metadata=False)
def makeDataSet1Dplain(xname, x, yname, y=None, xunit=None, yunit=None, location=None, loc_record=None): ''' Make DataSet with one 1D array and one setpoint array Arguments: xname (string): the name of the setpoint array x (array): the setpoint data yname (str or list): the name of the measured array y (array): the measured data ''' xx = np.array(x) yy = np.NaN * np.ones(xx.size) if y is None else np.array(y) x = DataArray(name=xname, array_id=xname, preset_data=xx, unit=xunit, is_setpoint=True) dd = new_data(arrays=(), location=location, loc_record=loc_record) dd.add_array(x) if isinstance(yname, str): y = DataArray(name=yname, array_id=yname, preset_data=yy, unit=yunit, set_arrays=(x, )) dd.add_array(y) else: for ii, name in enumerate(yname): y = DataArray(name=name, array_id=name, preset_data=yy[ii], unit=yunit, set_arrays=(x, )) dd.add_array(y) return dd
def __init__(self, measured_param, sweep_values, delay): name = measured_param.name super().__init__(names=(name, )) self._instrument = getattr(measured_param, '_instrument', None) self.measured_param = measured_param self.sweep_values = sweep_values self.delay = delay self.shapes = ((len(sweep_values), ), ) set_array = DataArray(parameter=sweep_values.parameter, preset_data=sweep_values) self.setpoints = ((set_array, ), ) if hasattr(measured_param, 'label'): self.labels = (measured_param.label, )
def fit_addition_line(dataset, trimborder=True): """Fits a FermiLinear function to the addition line and finds the middle of the step. Args: dataset (qcodes dataset): 1d measured data of additionline trimborder (bool): determines if the edges of the data are taken into account for the fit Returns: m_addition_line (float): x value of the middle of the addition line pfit (array): fit parameters of the Fermi Linear function pguess (array): parameters of initial guess dataset_fit (qcodes dataset): dataset with fitted Fermi Linear function dataset_guess (qcodes dataset):dataset with guessed Fermi Linear function See also: FermiLinear and fitFermiLinear """ y_array = dataset.default_parameter_array() setarray = y_array.set_arrays[0] xdata = np.array(setarray) ydata = np.array(y_array) if trimborder: ncut = max(min(int(xdata.size / 40), 100), 1) xdata, ydata, setarray = xdata[ncut: -ncut], ydata[ncut:-ncut], setarray[ncut:-ncut] # fitting of the FermiLinear function pp = fitFermiLinear(xdata, ydata, verbose=1, fig=None) pfit = pp[0] # fit parameters pguess = pp[1]['p0'] # initial guess parameters y0 = FermiLinear(xdata, *list(pguess)) dataset_guess = DataArray(name='fit', label='fit', preset_data=y0, set_arrays=(setarray,)) y = FermiLinear(xdata, *list(pfit)) dataset_fit = DataArray(name='fit', label='fit', preset_data=y, set_arrays=(setarray,)) m_addition_line = pfit[2] result_dict = {'fit parameters': pfit, 'parameters initial guess': pguess, 'dataset fit': dataset_fit, 'dataset initial guess': dataset_guess} return m_addition_line, result_dict
def makeDataSet2D(p1, p2, measure_names='measured', location=None, loc_record=None, preset_data=None, return_names=False): """ Make DataSet with one or multiple 2D array and two setpoint arrays. If the preset_data is used for multiple 2D arrays, then the order of measure_names should match the order of preset_data. Args: p1 (array): first setpoint array of data p2 (array): second setpoint array of data mname (str or list): name(s) of measured array(s) location (str or None): location for the DataSet preset_data (array or None): optional array to fill the DataSet return_names (bool): if True return array names in output Returns: dd (DataSet) names (tuple, optional) """ xx = np.array(p1) yy0 = np.array(p2) yy = np.tile(yy0, [xx.size, 1]) zz = np.NaN * np.ones((xx.size, yy0.size)) set_names = [p1.name, p2.name] x = DataArray(name=p1.name, array_id=p1.name, label=p1.parameter.label, unit=p1.parameter.unit, preset_data=xx, is_setpoint=True) y = DataArray(name=p2.name, array_id=p2.name, label=p2.parameter.label, unit=p2.parameter.unit, preset_data=yy, set_arrays=(x, ), is_setpoint=True) if isinstance(measure_names, str): measure_names = [measure_names] if preset_data is not None: preset_data = [preset_data] mnamesx = measure_names measure_names = [] for p in mnamesx: if isinstance(p, str): measure_names += [p] else: # assume p is a Parameter measure_names += [p.full_name] dd = new_data(arrays=(), location=location, loc_record=loc_record) for idm, mname in enumerate(measure_names): z = DataArray(name=mname, array_id=mname, label=mname, preset_data=np.copy(zz), set_arrays=(x, y)) dd.add_array(z) if preset_data is not None: getattr(dd, mname).ndarray = np.array(preset_data[idm]) dd.add_array(x) dd.add_array(y) dd.last_write = -1 if return_names: return dd, (set_names, measure_names) else: return dd