def test_threshold_with_1d_arrays(self): bias = np.array([-2, -1, 0, 1, 2]) dvdi = np.array([1, 0, 0, 0, 1]) self.assertEqual(extract_switching_current(bias, dvdi, threshold=0.5), 2) self.assertEqual( extract_switching_current(bias, dvdi, threshold=0.5, side="negative"), -2) self.assertEqual( extract_switching_current(bias, dvdi, threshold=0.5, side="both"), (-2, 2))
def test_threshold_with_2d_arrays(self): bias = np.array([[-2, -1, 0, 1, 2], [-20, -10, 0, 10, 20]]) dvdi = np.array([[1, 0, 0, 0, 1], [1, 1, 0, 1, 1]]) assert_array_equal( extract_switching_current(bias, dvdi, threshold=0.5), [2, 10]) assert_array_equal( extract_switching_current(bias, dvdi, threshold=0.5, side="negative"), [-2, -10], ) assert_array_equal( extract_switching_current(bias, dvdi, threshold=0.5, side="both"), ([-2, -10], [2, 10]), )
def test_interpolation(self): # 2x3 bias sweeps of [-2, -1, 0, 1, 2] bias = np.tile(np.linspace(-2, 2, 5), (2, 3, 1)) dvdi = np.array([ [[1, 0, 0, 0, 1], [1, 0, 0, 1, 1], [1, 1, 0, 0, 1]], [[1, 1, 0, 1, 1], [1, 1, 0, 0, 1], [1, 0, 0, 0, 1]], ]) assert_array_equal( extract_switching_current(bias, dvdi, threshold=0.5, interp=True), [[1.5, 0.5, 1.5], [0.5, 1.5, 1.5]], )
def test_threshold_with_3d_arrays(self): # 2x3 bias sweeps of [-2, -1, 0, 1, 2] bias = np.tile(np.linspace(-2, 2, 5), (2, 3, 1)) dvdi = np.array([ [[1, 0, 0, 0, 1], [1, 0, 0, 1, 1], [1, 1, 0, 0, 1]], [[1, 1, 0, 1, 1], [1, 1, 0, 0, 1], [1, 0, 0, 0, 1]], ]) assert_array_equal( extract_switching_current(bias, dvdi, threshold=0.5), [[2, 1, 2], [1, 2, 2]]) assert_array_equal( extract_switching_current(bias, dvdi, threshold=0.5, side="negative"), [[-2, -2, -1], [-1, -1, -2]], ) assert_array_equal( extract_switching_current(bias, dvdi, threshold=0.5, side="both"), ([[-2, -2, -1], [-1, -1, -2]], [[2, 1, 2], [1, 2, 2]]), )
def test_auto_threshold_1d(self): bias = np.array([-2, -1, 0, 1, 2]) dvdi = np.array([2, 1, 0, 4, 8]) self.assertEqual( extract_switching_current(bias, dvdi, threshold=None, interp=True), 1) self.assertEqual( extract_switching_current(bias, dvdi, threshold=None, side="negative", interp=True), -1, ) self.assertEqual( extract_switching_current(bias, dvdi, threshold=None, side="both", interp=True), (-1, 1), )
def test_auto_threshold_2d(self): bias = np.array([[-2, -1, 0, 1, 2], [-4, -2, 0, 2, 4]]) dvdi = np.array([[2, 1, 0, 2, 4], [10, 5, 0, 3, 6]]) assert_array_equal( extract_switching_current(bias, dvdi, threshold=None, interp=True), [1, 2]) assert_array_equal( extract_switching_current(bias, dvdi, threshold=None, side="negative", interp=True), [-1, -2], ) assert_array_equal( extract_switching_current(bias, dvdi, threshold=None, side="both", interp=True), [[-1, -2], [1, 2]], )
# plot the raw data fig, ax = plot2d( *np.broadcast_arrays(bfield[..., np.newaxis] / 1e-3, ibias / 1e-6, dvdi), xlabel="x coil field (mT)", ylabel="dc bias (μA)", 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
# plot the raw data fig, ax = plot2d( *np.broadcast_arrays(bfield[..., np.newaxis] / 1e-3, ibias / 1e-6, dvdi), xlabel="x coil field (mT)", ylabel="dc bias (μA)", 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":