def diffDataset(alldata, diff_dir='y', sigma=2, fig=None, meas_arr_name='measured'): """ Differentiate a dataset and plot the result. Args: alldata (qcodes DataSet) diff_dir (str): direction to differentiate in meas_arr_name (str): name of the measured array to be differentiated fig (int): the number for the figure to plot sigma (float): parameter for gaussian filter kernel """ meas_arr_name = alldata.default_parameter_name(meas_arr_name) meas_array = alldata.arrays[meas_arr_name] imx = qtt.utilities.tools.diffImageSmooth(meas_array.ndarray, dy=diff_dir, sigma=sigma) name = 'diff_dir_%s' % diff_dir name = uniqueArrayName(alldata, name) data_arr = qcodes.DataArray( name=name, label=name, array_id=name, set_arrays=meas_array.set_arrays, preset_data=imx) alldata.add_array(data_arr) if fig is not None: plt.figure(fig) plt.clf() plot = MatPlot(interval=0, num=fig) plot.add(alldata.arrays[name]) plot.fig.axes[0].autoscale(tight=True) plot.fig.axes[1].autoscale(tight=True) return alldata
def process_dataarray(dataset: DataSet, input_array_name: str, output_array_name: str, processing_function: Callable, label: Optional[str] = None, unit: Optional[str] = None, ) -> DataSet: """ Apply a function to a DataArray in a DataSet Args: dataset: Input dataset containing the data array input_array_name: Name of the data array to be processed output_array_nane: Name of the output array or None to operate in place processing_function: Method to apply to the data array label: Label for the output array unit: Unit for the output array """ array = dataset.default_parameter_array(input_array_name) data = processing_function(np.array(array)) if label is None: label = array.label if unit is None: unit = array.unit if output_array_name is None: array.ndarray[:] = data else: data_array = qcodes.DataArray(array_id=output_array_name, name=output_array_name, label=label, set_arrays=array.set_arrays, preset_data=data, unit=unit) dataset.add_array(data_array) return dataset
def plot_cooldown(datas): """ Plot resistance of ohmics during cooldown Datas is the datasets that make up the cooldown """ # Calculate how many data points are in each array lengths = [] for data in datas: time = data.time lengths.append(np.where(np.isnan(time))[0][0] - 1) # Make a new DataSet new_data = qc.DataSet(location="data/Cooldown") new_length = np.sum(lengths) # And add new dataarrays for each dataarray in the original data for d_arr in datas[0].arrays.values(): data_array = qc.DataArray( name=d_arr.name, full_name=d_arr.full_name, label=d_arr.full_name, array_id=d_arr.array_id, unit=d_arr.unit, is_setpoint=d_arr.is_setpoint, shape=(new_length, *d_arr.shape[1:])) data_array.init_data() new_data.add_array(data_array) # Then, update each of the set arrays for key, d_arr in new_data.arrays.items(): d_arr.set_arrays = tuple(new_data.arrays[s_arr.name + "_set"] for s_arr in datas[0].arrays[key].set_arrays) # Then, fill in each item cumsum = 0 for data, length in zip(datas, lengths): for key, d_arr in data.arrays.items(): new_data.arrays[key][cumsum:cumsum+length] = d_arr.ndarray[0:length] cumsum += length # We also need to make time keep counting upwards cumsum = 0 offs = 0 for i, l in enumerate(lengths[:-1]): cumsum += l offs += new_data.time[l-1] new_data.time[cumsum:cumsum+lengths[i+1]] += offs return new_data
def _dictionary_to_data_array(array_dictionary): preset_data = array_dictionary['ndarray'] array_id = array_dictionary.get('array_id', array_dictionary['name']) array_name = array_dictionary['name'] if array_name is None: array_name = array_id array_full_name = array_dictionary['full_name'] if array_full_name is None: array_full_name = array_name data_array = qcodes.DataArray(name=array_name, full_name=array_dictionary['full_name'], label=array_dictionary['label'], unit=array_dictionary['unit'], is_setpoint=array_dictionary['is_setpoint'], shape=array_dictionary['shape'], array_id=array_id, preset_data=preset_data) return data_array
def calc_rho(field, data_xx, data_xy, curr=1e-9, width=50e-6, length=100e-6, field_center=1, name="Analyzed_Field_Sweep"): """ Calculate rho_xx, rho_xy from given data sweeps: Parameters: - field: field setpoints - data_xx: V_xx DataArray - data_xy: V_xy DataArray - curr: Either the current as a number or as a DataArray. If a DataArray is given, the trace will be averaged to extract a mean current. - width/length: Width of the hall bar/distance between V_xx probes to extract a sheet resistance - field_center: - name: Name to save output data """ path = "data" / Path(name) np_field = field.ndarray.copy() np_xx = data_xx.ndarray.copy() np_xy = data_xy.ndarray.copy() if isinstance(curr, qc.DataArray): curr = np.average(-1 * (curr.ndarray.copy()) / 1e6) print(curr) # Calculate resistances rho_xy = np_xy / curr # rho_xx is scaled by the width+length of the hall bar to get a sheet resistivity rho_xx = (np_xx / curr) * (width / length) # Calculate density # We want to do a fit between (field_center, -field_center) tesla as there is some extra structure # above these values min_ind = np.where(np.abs(np_field + field_center) < 0.01)[0][0] max_ind = np.where(np.abs(np_field - field_center) < 0.01)[0][0] min_ind, max_ind = np.min((min_ind, max_ind)), np.max((min_ind, max_ind)) res = np.polyfit(np_field[min_ind:max_ind], rho_xy[min_ind:max_ind], 1) poly = np.poly1d(res) # Then the density is given by 1/(|e| dp/dB), in cm^2 density = 1 / (const.e * res[0]) density *= 1e-4 print("Density is: {:.2e} cm^-2".format(density)) # And the calculated mobility is given by mu=1/(rho_xx |e| ns) mu = 1 / (rho_xx * const.e * density) # And let's quote the density slightly offset from 0, at 0.1T mob_ind = np.where(np.abs(np_field - 0.1) < 0.005)[0][0] mobility = mu[mob_ind] print("Mobility is: {:.2e} cm^2/V s".format(mobility)) # And finally, let's create a new dataset. Leave location unset for now... dataset = qc.DataSet(location=str(path)) da_field = qc.DataArray(array_id="Field", label="Field", unit="T", is_setpoint=True, preset_data=np_field) da_reduced_field = qc.DataArray(array_id="Reduced_Field", label="Field", unit="T", is_setpoint=True, preset_data=np_field[min_ind:max_ind]) da_poly = qc.DataArray(array_id="Poly_Deg", label="Polynomial Degree", is_setpoint=True, preset_data=list(range(2))[::-1]) da_rho_xy = qc.DataArray(array_id="Rho_XY", label="Rho XY", unit="Ohms", set_arrays=(da_field, ), preset_data=rho_xy) da_rho_xy_fit = qc.DataArray(array_id="fit_Rho_XY", label="Rho XY", unit="Ohms", set_arrays=(da_reduced_field, ), preset_data=poly(np_field[min_ind:max_ind])) da_rho_xy_coef = qc.DataArray(array_id="coef_Rho_XY", label="Poly Coefficients", set_arrays=(da_poly, ), preset_data=res) da_rho_xx = qc.DataArray(array_id="Rho_XX", label="Rho XX", unit="Ohms", set_arrays=(da_field, ), preset_data=rho_xx) da_mu = qc.DataArray(array_id="mu", label="Mobility", unit="cm<sup>2</sup> (V s)<sup>-1</sup>", set_arrays=(da_field, ), preset_data=mu) dataset.add_array(da_field) dataset.add_array(da_reduced_field) dataset.add_array(da_poly) dataset.add_array(da_rho_xy) dataset.add_array(da_rho_xy_fit) dataset.add_array(da_rho_xy_coef) dataset.add_array(da_rho_xx) dataset.add_array(da_mu) # Save the data dataset.finalize() # Make some nice plots # Showing Density (Rho_XY) analysis fig, ax = plt.subplots() ax.plot(dataset.Field, dataset.Rho_XY, 'r') ax.plot(dataset.Field, dataset.fit_Rho_XY, 'k') ax.set_xlabel(format_ax(dataset.Field)) ax.set_ylabel(format_ax(dataset.Rho_XY)) ax.text( 0.05, 0.95, "Using {} current<br>".format(qtplot.siFormat(curr, suffix="A")) + "From a linear fit:<br>" + "dρ/dB = {}<br>".format(qtplot.siFormat(res[0], suffix="Ω")) + "n<sub>s</sub> = 1/(|e| dρ/dB) = {:e} cm<sup>-2</sup>".format(density), transform=ax.transAxes) fig.savefig(path / "rho_xy.png") # Showing Mobility analysis fig, ax = plt.subplots() ax.plot(dataset.Field, dataset.mu, c=color_cycle[5]) ax.set_xlabel(format_ax(dataset.Field)) ax.set_ylabel(format_ax(dataset.mu)) ax.text( 0.05, 0.95, "Mobility extracted from:<br>" + "μ = 1/ρ<sub>xx</sub> |e| n<sub>s</sub>, with n<sub>s</sub>= {:.2e} cm<sup>-2</sup><br>" .format(density) + "And using W = {}, L = {}".format(qtplot.siFormat(width, suffix="m"), qtplot.siFormat(length, suffix="m")), transform=ax.transAxes) fig.savefig(path / "mobility.png") return dataset
def resampleImage(im): """ Resample the image so it has the similar sample rates (samples/mV) in both axis Args: im (DataArray): input image Returns: imr (numpy array): resampled image setpoints (list of 2 numpy arrays): setpoint arrays from resampled image """ setpoints = im.set_arrays mVrange = [ abs(setpoints[0][-1] - setpoints[0][0]), abs(setpoints[1][0, -1] - setpoints[1][0, 0]) ] samprates = [im.shape[0] // mVrange[0], im.shape[1] // mVrange[1]] factor = int(max(samprates) // min(samprates)) if factor >= 2: axis = int(samprates[0] - samprates[1] < 0) if axis == 0: facrem = im.shape[0] % factor if facrem > 0: im = im[:-facrem, :] facrem = facrem + 1 im = im.reshape(im.shape[0] // factor, factor, im.shape[1]).mean(1) spy = np.linspace(setpoints[0][0], setpoints[0][-facrem], im.shape[0]) spx = np.tile( np.expand_dims( np.linspace(setpoints[1][0, 0], setpoints[1][0, -1], im.shape[1]), 0), im.shape[0]) setpointy = qcodes.DataArray( name='Resampled_' + setpoints[0].array_id, array_id='Resampled_' + setpoints[0].array_id, label=setpoints[0].label, unit=setpoints[0].unit, preset_data=spy, is_setpoint=True) setpointx = qcodes.DataArray( name='Resampled_' + setpoints[1].array_id, array_id='Resampled_' + setpoints[1].array_id, label=setpoints[1].label, unit=setpoints[1].unit, preset_data=spx, is_setpoint=True) setpoints = [setpointy, setpointx] else: facrem = im.shape[1] % factor if facrem > 0: im = im[:, :-facrem] facrem = facrem + 1 im = im.reshape(im.shape[0], im.shape[1] // factor, factor).mean(-1) spx = np.tile( np.expand_dims( np.linspace(setpoints[1][0, 0], setpoints[1][0, -facrem], im.shape[1]), 0), [im.shape[0], 1]) idx = setpoints[1].array_id if idx is None: idx = 'x' idy = setpoints[1].array_id if idy is None: idy = 'y' setpointx = qcodes.DataArray(name='Resampled_' + idx, array_id='Resampled_' + idy, label=setpoints[1].label, unit=setpoints[1].unit, preset_data=spx, is_setpoint=True) setpoints = [setpoints[0], setpointx] return im, setpoints
liveplotwindow=plot, diff_dir=diff_dir, wait_time=None, background=False) plot.fig.axes[0].autoscale(tight=True) plot.fig.axes[1].autoscale(tight=True) gates.resetgates(activegates, gatevals) RF.off() if 0: diff_dir = 'x' imx = qtt.diffImageSmooth(alldata.measured.ndarray, dy=diff_dir) data_arr = qcodes.DataArray(name='diff', label='diff', array_id='diff', set_arrays=alldata.measured.set_arrays, preset_data=imx) alldata.add_array(data_arr) plot_2 = plot # reserving this plot for later analysis #%% ADDED(TF): multiple fast-2D scans with single virtual plunger sweep, mainly for capacitance measurements import qtt.scans from imp import reload reload(qtt.scans) from qtt.scans import scan2Dfast from qtt.tools import mouseClick ## set gate voltages to the center of the relevant charging line before running