From fdceeef16e8808f40ea090bcdc521e0c060b234c Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Mon, 22 Jul 2024 17:02:57 -0400 Subject: clean up --- qolab/hardware/scope/_basic.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/qolab/hardware/scope/_basic.py b/qolab/hardware/scope/_basic.py index c39ef1f..f86c3b3 100644 --- a/qolab/hardware/scope/_basic.py +++ b/qolab/hardware/scope/_basic.py @@ -153,7 +153,7 @@ class Scope(BasicInstrument): self.setRun(old_run_status) # start running if it was old run state return allTraces - def chanAutoScale(self, chNum, margin=0.25, timeout=5): + def chanAutoScale(self, chNum, margin=0.125, timeout=5): """Auto scale channel to fit signal on screen. Tunes Volts per division and Channel offset to fit signal @@ -165,13 +165,19 @@ class Scope(BasicInstrument): Channel to auto scale margin: float How much extra space (margin) to have with respect to full screen. - Default is 0.25 (i.e. 25%), - i.e. 1 vertical division at top and bottom for 8 division scope. + Default is 0.125 (i.e. 12.5%). + Note that margin = 0.25 corresponds to 1 vertical division + at top and bottom for 8 division scope. """ starttime = time.time() deadline = starttime + timeout scaled_corectly = False + # maximally zoom out to get full signal + self.setChanVoltageOffset(chNum, 0) + self.setChanVoltsPerDiv(chNum, 10) + self.setRun(True) + while (not scaled_corectly) and (time.time() < deadline): tr = self.getTrace(chNum) vPerDiv = self.getChanVoltsPerDiv(chNum) @@ -182,19 +188,18 @@ class Scope(BasicInstrument): y = tr.y.values tr_max = y.max() tr_min = y.min() - top_margin = (v_max - tr_max) / v_range - bottom_margin = (tr_min - v_min) / v_range - is_top_margin_good = (top_margin > margin / 2) and (top_margin < margin) - is_bottom_margin_good = (bottom_margin > margin / 2) and ( - bottom_margin < margin - ) - if (is_bottom_margin_good) and (is_top_margin_good): + margin_t = (v_max - tr_max) / v_range + margin_b = (tr_min - v_min) / v_range + is_margin_t_good = (margin_t > margin * 0.5) and (margin_t < margin*0.6) + is_margin_b_good = (margin_b > margin * 0.5) and (margin_b < margin*0.6) + if (is_margin_b_good) and (is_margin_t_good): scaled_corectly = True break offset = -(tr_max + tr_min) / 2 - vPerDiv = (tr_max - tr_min) / (self.vertDivOnScreen * (1 - margin * 1.5)) - + vPerDiv = (tr_max - tr_min) / (self.vertDivOnScreen * (1 - margin * 1.2)) + logger.info(f"Requesting {offset=} for {chNum=}.") self.setChanVoltageOffset(chNum, offset) + logger.info(f"Requesting {vPerDiv=} for {chNum=}.") self.setChanVoltsPerDiv(chNum, vPerDiv) scaled_corectly = False if time.time() > deadline: -- cgit v1.2.3