def plot_summary( x, y, xlabel, ylabel, legend=None, title=None, append_to_filename="", ylim=(None, None), plot_kwargs={}, **params, ): """Plot 1-dimensional data and save figure.""" if len(x.shape) > 1: logger.warning(f"Failed to plot {params['labber_filename']}: " f"data is more than 1D ({x.shape=})") return if x.shape[0] != y.shape[0]: logger.warning( f"Failed to plot {params['labber_filename']}: " f"first dimensions of data don't match ({x.shape=}, {y.shape=})") return try: fig = Figure() ax = fig.add_subplot() plot( x, y, xlabel=xlabel, ylabel=ylabel, title=title, ax=ax, label=legend, **plot_kwargs, ) except Exception as e: logger.warning( f"Failed to plot data from {params['labber_filename']}: caught {repr(e)}" ) logger.exception("ERROR") return ax.set_ylim(ylim) scan_id = flat_clfs(params)["scan"] stamp(ax, scan_id) fig.savefig(out_dir(params) / (scan_id + append_to_filename + ".png"), format="png")
def reconstruct_current(name, obj): scan = name.split("/")[-1].split("::")[-1] if scan not in scans.keys(): return None print(scan, name) params = scans[scan] field = obj["x magnet field"] ibias = obj["dc current bias"] dvdi = np.abs(obj["lock-in (impedance)"]) # extract fraunhofer from data ic = extract_switching_current(ibias, dvdi, threshold=params["threshold"]) fig, ax = plot2d(field, ibias, dvdi) plot( np.unique(field), ic, ax=ax, title="Ic extraction", color="k", lw="0", marker=".", markersize=5, ) ax.axis("off") stamp(ax, scan) fig.savefig(outdir / f"{scan}_ic-extraction.png") field = np.unique(field) # center fraunhofer argmax_ic = find_fraunhofer_center(field, ic) ic_n = extract_switching_current(ibias, dvdi, threshold=params["threshold"], side="negative") argmax_ic_n = find_fraunhofer_center(field, np.abs(ic_n)) field -= (argmax_ic + argmax_ic_n) / 2 # field = recenter_fraunhofer(np.unique(field), ic) # if just centering at argmax(Ic+) fig, ax = plot( field / 1e-3, np.array([ic, ic_n]).T / 1e-6, xlabel="field (mT)", ylabel="critical current (μA)", title="fraunhofer centered", ) ax.axvline(0, color="k") fig.savefig(outdir / f"{scan}_fraunhofer-centered.png") # reconstruct current distribution x, jx = extract_current_distribution( field, ic, f2k=2 * np.pi * params["jj_length"] / phys_c["mag. flux quantum"][0], jj_width=params["jj_width"], jj_points=400, ) fig, ax = subplots() ax.fill_between(x / 1e-6, jx) ax.set_xlabel("position (μA)") ax.set_ylabel("critical current density (μA/μm)") ax.set_title( f"$\ell_\mathrm{{eff}}$ = {round(params['jj_length'] / 1e-6, 1)}μm") fig.savefig(outdir / f"{scan}_current-distribution.png")
zlabel="dV/dI (Ω)", title="raw data", stamp=COOLDOWN_SCAN, ) fig.savefig(str(OUTPATH) + "_raw-data.png") # extract the switching currents ic_n, ic_p = extract_switching_current( ibias, dvdi, side="both", threshold=RESISTANCE_THRESHOLD, interp=True, ) ax.set_title("$I_c$ extraction") plot(bfield / 1e-3, ic_p / 1e-6, ax=ax, color="w", lw=0, marker=".") plot(bfield / 1e-3, ic_n / 1e-6, ax=ax, color="w", lw=0, marker=".") fig.savefig(str(OUTPATH) + "_ic-extraction.png") # in vector10, positive Bx points into the daughterboard if FRIDGE == "vector10": bfield = np.flip(bfield) * -1 ic_p = np.flip(ic_p) # in vector9, positive Bx points out of the daughterboard elif FRIDGE == "vector9": pass else: warnings.warn(f"I don't recognize fridge `{FRIDGE}`") # parameterize the fit params = Parameters()
def estimate_bfield_offset(bfield: np.ndarray, ic_p: np.ndarray, ic_n=None): """Estimate the coil field at which the true flux is integral. The position of a maximum near the center of the `bfield` range is returned. If `ic_n` is given, a better estimate is midway between a peak in `ic_p` and the closest valley in `ic_n`. """ peak_locs, _ = find_peaks(ic_p, prominence=(np.max(ic_p) - np.min(ic_p)) / 2) guess_loc = peak_locs[len(peak_locs) // 2] bfield_guess = bfield[guess_loc] if ic_n is not None: peak_locs_n, _ = find_peaks(-ic_n, prominence=(np.max(ic_n) - np.min(ic_n)) / 2) guess_loc_n = peak_locs_n[len(peak_locs_n) // 2] bfield_guess_n = bfield[guess_loc_n] bfield_guess = (bfield_guess + bfield_guess_n) / 2 # plot the guess if ic_n is None: fig, ax = plt.subplots() ax.set_xlabel("x coil field [mT]") else: fig, (ax, ax2) = plt.subplots(2, 1, sharex=True) ax2.set_xlabel("x coil field [mT]") plot( bfield / 1e-3, ic_n / 1e-6, ylabel="supercurrent [μA]", ax=ax2, marker=".", ) ax2.plot( bfield[peak_locs_n] / 1e-3, ic_n[peak_locs_n] / 1e-6, lw=0, marker="*", label="$I_{c-}$ peaks", ) ax2.plot( bfield[guess_loc_n] / 1e-3, ic_n[guess_loc_n] / 1e-6, lw=0, marker="*", label="$I_{c-}$ guess", ) ax2.axvline(bfield_guess / 1e-3, color="k") ax2.legend() plot( bfield / 1e-3, ic_p / 1e-6, ylabel="supercurrent [μA]", title="bfield offset guess", stamp=config["COOLDOWN"] + "_" + config["SCAN"], ax=ax, marker=".", ) ax.axvline(bfield_guess / 1e-3, color="k") ax.plot( bfield[peak_locs] / 1e-3, ic_p[peak_locs] / 1e-6, lw=0, marker="*", label="$I_{c+}$ peaks", ) ax.plot( bfield[guess_loc] / 1e-3, ic_p[guess_loc] / 1e-6, lw=0, marker="*", label="$I_{c+}$ guess", ) ax.text( 0.5, 0.5, f"bfield offset $\\approx$ {np.round(bfield_guess / 1e-3, 3)} mT", va="center", ha="center", transform=ax.transAxes, ) ax.legend() fig.savefig(str(OUTPATH) + "_bfield-offset.png") return bfield_guess
zlabel="dV/dI (Ω)", title="raw data", stamp=config["COOLDOWN"] + "_" + config["SCAN"], ) fig.savefig(str(OUTPATH) + "_raw-data.png") # extract the switching currents ic_n, ic_p = extract_switching_current( ibias, dvdi, side="both", threshold=config.getfloat("RESISTANCE_THRESHOLD", fallback=None), interp=True, ) ax.set_title("$I_c$ extraction") plot(bfield / 1e-3, ic_p / 1e-6, ax=ax, color="k", lw=1) plot(bfield / 1e-3, ic_n / 1e-6, ax=ax, color="k", lw=1) fig.savefig(str(OUTPATH) + "_ic-extraction.png") # in vector10, positive Bx points into the daughterboard (depends on mount orientation) if config["FRIDGE"] == "vector10": bfield = np.flip(bfield) * -1 ic_p = np.flip(ic_p) ic_n = np.flip(ic_n) # in vector9, positive Bx points out of the daughterboard elif config["FRIDGE"] == "vector9": pass else: warnings.warn(f"I don't recognize fridge `{config['FRIDGE']}`")
# from vector9 fridge FILENAME = "JS602-SE1_4xFlQpcSq-v1_N_WFSBHE01-071" PATH = get_data_dir() / f"2021/10/Data_1030/{FILENAME}.hdf5" with LabberData(PATH) as f: bfield = f.get_data("Vector Magnet - Field X") ibias, dc_volts = f.get_data("VITracer - VI curve", get_x=True) dc_volts /= 100 # amplifier gain 100x iflux = f.get_data("circleFL 6 - Source current") # plot extracted switching current for a few flux current values ic = extract_switching_current(ibias, dc_volts, threshold=3.5e-5) fig, ax = plot( np.unique(bfield) / 1e-6, ic[::2].T / 1e-6, label=[f"{int(i / 1e-6)} μA" for i in np.unique(iflux[::2])], xlabel="Vector Magnet Field (μT)", ylabel="Current Bias (μA)", ) fig.savefig(OUTDIR / f"{FILENAME}_Ic.png") # broadcast scalar data over vectorial data to have same shape iflux, bfield, ibias, dc_volts = np.broadcast_arrays(iflux[..., np.newaxis], bfield[..., np.newaxis], ibias, dc_volts) # plot the first CPR fig, ax = plot2d( bfield[0] / 1e-6, ibias[0] / 1e-6, np.diff(dc_volts[0]) / np.diff(ibias[0]),