def run(self): calibr = CalibrationTables() for cur_board in STRIP_BOARD_NAMES: # Append the sequence of commands to turnon this board to # the JSON object self.command_emitter.command_list += self.turn_on_board(cur_board) # Wait a while after having turned on the board self.wait(seconds=5) # Verification step with StripTag( conn=self.command_emitter, name=f"PINCHOFF_VERIFICATION_1", ): self.wait(seconds=300) for cur_board in STRIP_BOARD_NAMES: # Now run the pinch-off procedure for each board with StripTag( conn=self.command_emitter, name=f"PINCHOFF_TILE_{cur_board}", ): for cur_horn_idx in range(8): if cur_board == "I" and cur_horn_idx == 7: continue if cur_horn_idx == 7: cur_horn_name = BOARD_TO_W_BAND_POL[cur_board] else: cur_horn_name = f"{cur_board}{cur_horn_idx}" self.conn.enable_electronics(polarimeter=cur_horn_name, pol_mode=5) for id_value_muA in (100, 4_000, 8_000, 12_000): for cur_lna in ("HA3", "HA2", "HA1", "HB3", "HB2", "HB1"): # Convert the current (μA) in ADU adu = calibr.physical_units_to_adu( polarimeter=cur_horn_name, hk="idrain", component=cur_lna, value=id_value_muA, ) self.conn.set_id(cur_horn_name, cur_lna, value_adu=adu) with StripTag( conn=self.command_emitter, name= f"PINCHOFF_IDSET_{cur_horn_name}_{cur_lna}_{id_value_muA:.0f}muA", ): self.conn.wait(seconds=18)
def _stable_acquisition(self, pol_name: str, state: str, proc_number: int): assert ( len(state) == 4 ), f'The state must be in the form BBBB, with B either 0 or 1, not "{state}"' # Convert a string like "0101" into a set of four `PhswPinMode` constants # using the correspondences # 1 → STILL_NO_SIGNAL # 0 → STILL_SIGNAL state_constants = [ PhswPinMode.STILL_NO_SIGNAL if x == "1" else PhswPinMode.STILL_SIGNAL for x in state ] self.conn.log( f"set phsw to {state} and acquiring for {self.pre_acquisition_time_s} s" ) with StripTag(conn=self.command_emitter, name=f"phsw_proc{proc_number}_{pol_name}_{state}"): for pin_idx, status in enumerate(state_constants): self.conn.set_phsw_status(polarimeter=pol_name, phsw_index=pin_idx, status=status) if self.pre_acquisition_time_s > 0: wait_with_tag( conn=self.command_emitter, seconds=self.pre_acquisition_time_s, name=f"phsw_acq_pol{pol_name}_{state}", )
def _forward( self, calibr: CalibrationTables, cur_board: str, pol_name: str, unit_test_data: UnitTestDC, proc_number: int, ): for pin, ps, phsw_state in PIN_PS_STATE_COMBINATIONS: # First do a stable acquisition… self._stable_acquisition(pol_name, phsw_state, proc_number=proc_number) # …and then acquire the curves try: Ifor = get_sequence_of_biases(unit_test_data, ps, "IFVF") except KeyError: log.warning(f"IFVF does not exist for {pol_name} {ps}") self.conn.log( message= f"IFVF does not exist for {pol_name} {ps} in unit-level tests. " "Using a synthetic curve instead") Ifor = get_sequence_of_biases(None, ps, "IFVF") Ifor *= 1e6 # Convert from A to µA self.conn.log( message= f"Acquiring PH/SW forward curve for {pol_name}, {ps} Vpin{pin}" ) with StripTag( conn=self.command_emitter, name= f"phsw_proc{proc_number}_fcurve_{pol_name}_{ps}_ipin{pin}", ): for i in Ifor: adu = calibr.physical_units_to_adu(pol_name, hk="iphsw", component=pin, value=i) self.conn.set_phsw_bias(pol_name, phsw_index=pin, vpin_adu=None, ipin_adu=adu) self.conn.set_hk_scan(cur_board) self.conn.log(message=f"Set I={i:.1f} µA = {adu} ADU") wait_with_tag( conn=self.command_emitter, seconds=5, name= f"phsw_proc{proc_number}_set_i_{pol_name}_{ps}_vpin{pin}", )
def run(self): turnon_proc = TurnOnOffProcedure(waittime_s=1.0, turnon=True) turnoff_proc = TurnOnOffProcedure(waittime_s=1.0, turnon=False) for cur_board, pol_idx, polname in polarimeter_iterator(args.board): self.conn.log( message=f"turning on {polname} for reference procedure 1…") with StripTag(conn=self.command_emitter, name=f"ref1_turnon_pol{polname}"): turnon_proc.set_board_horn_polarimeter( new_board=cur_board, new_horn=polname, new_pol=None, ) turnon_proc.run() self.command_emitter.command_list += turnon_proc.get_command_list( ) turnon_proc.clear_command_list() self.conn.log( message=f"{polname} is now on, start the reference procedure") proc_1(self, polname, cur_board, 1, wait_time_s=self.wait_time_s) self.conn.log( message= f"reference procedure 1 for {polname} has been completed, turning {polname} off…" ) with StripTag(conn=self.command_emitter, name=f"ref1_turnoff_pol{polname}"): # turn off polarimeter turnoff_proc.set_board_horn_polarimeter( new_board=cur_board, new_horn=polname, new_pol=None, ) turnoff_proc.run() self.command_emitter.command_list += turnoff_proc.get_command_list( ) turnoff_proc.clear_command_list()
def _reverse( self, calibr: CalibrationTables, cur_board: str, pol_name: str, unit_test_data: UnitTestDC, proc_number: int, ): for pin, ps, phsw_state in PIN_PS_STATE_COMBINATIONS: # First do a stable acquisition… self.stable_acquisition(pol_name, phsw_state) # …and then acquire the curves try: Vrev = get_sequence_of_biases(unit_test_data, ps, "IRVR") except KeyError: log.warning(f"IRVR does not exist for {pol_name} {ps}") self.conn.log( message= f"IRVR does not exist for {pol_name} {ps} in unit-level tests. " "Using a synthetic curve instead") Vrev = get_sequence_of_biases(None, ps, "IRVR") Vrev *= 1e3 # convert from V to mV self.conn.log( message= f"Acquiring PH/SW reverse curve for {pol_name}, {ps} Vpin{pin}" ) with StripTag( conn=self.command_emitter, name= f"phsw_proc{proc_number}_rcurve_{pol_name}_{ps}_ipin{pin}", ): for v in Vrev: adu = calibr.physical_units_to_adu(pol_name, hk="vphsw", component=pin, value=v) self.conn.set_phsw_bias(pol_name, phsw_index=pin, vpin_adu=adu, ipin_adu=None) self.conn.set_hk_scan(cur_board) self.conn.log(message=f"Set V={v:.1f} mV = {adu} ADU") wait_with_tag( conn=self.command_emitter, seconds=5, name= f"phsw_proc{proc_number}_set_v_{pol_name}_{ps}_vpin{pin}", )
def run(self): # turn on polarimeter turnon_proc = TurnOnOffProcedure(waittime_s=1.0, turnon=True) for cur_board, pol_idx, polname in polarimeter_iterator(args.board): with StripTag(conn=self.command_emitter, name=f"ref2_turnon_pol_{polname}"): turnon_proc.set_board_horn_polarimeter( new_board=cur_board, new_horn=polname, new_pol=None, ) turnon_proc.run() self.command_emitter.command_list += turnon_proc.get_command_list( ) turnon_proc.clear_command_list() proc_1(self, polname, cur_board, 2, wait_time_s=self.wait_time_s) self.conn.log(message="ref2_set phsw state to default bias") # set phsw modulation to default bias with StripTag( conn=self.command_emitter, name=f"ref2_set_pol{polname}_phsw_default_end", ): for h in range(4): self.conn.set_phsw_status( polarimeter=polname, phsw_index=h, status=PhswPinMode.DEFAULT_STATE, ) self.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=500) wait_with_tag( conn=self.conn, seconds=self.wait_time_s, name=f"ref2_acquisition_pol{polname}_phsw_default_end", )
def _restore_phsw_state(self, pol_name: str, proc_number: int): self.conn.log(message=f"set phsw for {pol_name} to nominal switching") # Set default bias with StripTag( conn=self.command_emitter, name=f"phsw_proc{proc_number}_set_default_{pol_name}", ): for pin_idx in range(4): self.conn.set_phsw_status( polarimeter=pol_name, phsw_index=pin_idx, status=PhswPinMode.NOMINAL_SWITCHING, )
def set_0_bias(procedure, polname, test_number): with StripTag( conn=procedure.command_emitter, name=f"ref{test_number}_set_pol{polname}_lna_zero_bias", ): for cur_lna in ("HA3", "HA2", "HA1", "HB3", "HB2", "HB1"): adu = procedure.calib.physical_units_to_adu( polarimeter=polname, hk="vdrain", component=cur_lna, value=0, ) procedure.conn.set_vd(polname, cur_lna, value_adu=adu) procedure.conn.set_pol_mode(polarimeter=polname, mode=5)
def run_turnon(self, turn_on_board=True, stable_acquisition_time_s=120): """Execute a turn-on procedure for the horn specified in `self.horn`. Optional parameters: - turn_on_board: if True, turn on the board. Set it to false if you are sure the board has already been turned on (default: True). - stable_acquisition_time_s: if nonzero, wait for the specified amount of seconds once the polarimeter has been fully turned on. """ assert not (self.horn is None) board_setup = SetupBoard( config=self.conf, board_name=self.board, post_command=self.command_emitter, bias_file_name=self.bias_file_name, ) current_time = datetime.now().strftime("%A %Y-%m-%d %H:%M:%S") board_setup.log( f"Here begins the turnon procedure for polarimeter {self.horn}, " + f"created on {current_time} using program_turnon.py") if self.bias_file_name: board_setup.log("The biases are taken from {}".format( Path(self.bias_file_name).absolute())) board_setup.log(f"We are using the setup for board {self.board}") if self.polarimeter: board_setup.log( f"This procedure assumes that horn {self.horn} is connected to polarimeter {self.polarimeter}" ) # 1 if turn_on_board: if self.board not in self.on_boards: with StripTag( conn=self.command_emitter, name="BOARD_TURN_ON", comment=f"Turning on board for {self.horn}", ): board_setup.log("Going to set up the board…") board_setup.board_setup() board_setup.log("Board has been set up") self.on_boards.add(self.board) # 2 with StripTag( conn=self.command_emitter, name=f"ELECTRONICS_ENABLE_{self.horn}", comment=f"Enabling electronics for {self.horn}", ): board_setup.log(f"Enabling electronics for {self.horn}…") board_setup.enable_electronics(polarimeter=self.horn) board_setup.log("The electronics has been enabled") # 3 for idx in (0, 1, 2, 3): with StripTag( conn=self.command_emitter, name=f"DETECTOR_TURN_ON_{self.horn}_{idx}", comment=f"Turning on detector {idx} in {self.horn}", ): board_setup.turn_on_detector(self.horn, idx) # 4 if self.polarimeter: biases = board_setup.ib.get_biases( polarimeter_name=self.polarimeter) board_setup.log(f"{self.polarimeter}: {biases_to_str(biases)}") else: biases = board_setup.ib.get_biases(module_name=self.horn) board_setup.log(f"{self.horn}: {biases_to_str(biases)}") for (index, vpin, ipin) in zip( range(4), [biases.vpin0, biases.vpin1, biases.vpin2, biases.vpin3], [biases.ipin0, biases.ipin1, biases.ipin2, biases.ipin3], ): try: with StripTag( conn=self.command_emitter, name=f"PHSW_BIAS_{self.horn}_{index}", comment= f"Setting biases for PH/SW {index} in {self.horn}", ): board_setup.set_phsw_bias(self.horn, index, vpin, ipin) except Exception as exc: log.warning( f"Unable to set bias for phsw diode #{index} ({type(exc)}: {exc})" ) # 5 for idx in (0, 1, 2, 3): with StripTag( conn=self.command_emitter, name=f"PHSW_STATUS_{self.horn}_{idx}", comment=f"Setting status for PH/SW {idx} in {self.horn}", ): board_setup.set_phsw_status(self.horn, idx, status=7) # 6 if self.zero_bias: steps = [0.0] else: steps = [0.0, 0.5, 1.0] board_setup.log( f"Going to turn on the amplifiers in {len(steps)} step(s): {steps}" ) for lna in ("HA3", "HA2", "HA1", "HB3", "HB2", "HB1"): for step_idx, cur_step in enumerate(steps): with StripTag( conn=self.command_emitter, name=f"VD_SET_{self.horn}_{lna}", comment= f"Setting drain voltages for LNA {lna} in {self.horn}", ): board_setup.setup_VD(self.horn, lna, step=cur_step) if step_idx == 0: board_setup.setup_VG(self.horn, lna, step=1.0) if False and cur_step == 1.0: # In mode 5, the following command should be useless… board_setup.setup_ID(self.horn, lna, step=1.0) if self.waittime_s > 0: with StripTag( conn=self.command_emitter, name=f"VD_SET_{self.horn}_{lna}_ACQUISITION", comment=f"Acquiring some data after VD_SET_{lna}", ): self.wait(seconds=self.waittime_s) board_setup.setup_VG(self.horn, "4A", step=1.0) board_setup.setup_VG(self.horn, "5A", step=1.0) if stable_acquisition_time_s > 0: board_setup.log( f"Horn {self.horn} has been turned on, stable acquisition for {stable_acquisition_time_s} s begins here" ) with StripTag(conn=self.command_emitter, name=f"STABLE_ACQUISITION_{self.horn}"): self.wait(seconds=stable_acquisition_time_s) board_setup.log(f"End of stable acquisition for horn {self.horn}") else: board_setup.log(f"Horn {self.horn} has been turned on")
def run(self): if self.turn_on_polarimeters: # turn on polarimeter turnon_proc = TurnOnOffProcedure(waittime_s=1.0, turnon=True) for cur_board, pol_idx, polname in polarimeter_iterator(args.board): with StripTag( conn=self.command_emitter, name=f"ref4_turnon_pol_{polname}" ): turnon_proc.set_board_horn_polarimeter( new_board=cur_board, new_horn=polname, new_pol=None, ) turnon_proc.run() self.command_emitter.command_list += turnon_proc.get_command_list() turnon_proc.clear_command_list() proc_1(self, polname, cur_board, 4) self.conn.log(message="ref4_set phsw state to default bias") # set phsw modulation to default bias for h in range(4): with StripTag( conn=self.command_emitter, name=f"ref4_set_pol{polname}_phsw_default_end", ): self.conn.set_phsw_status( polarimeter=polname, phsw_index=h, status=PhswPinMode.DEFAULT_STATE, ) self.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=500) wait_with_tag( conn=self.conn, seconds=self.wait_time_s, name=f"ref4_acquisition_pol{polname}_phsw_default_end", ) #################################################################################################################### # ------------------------------------------------------------------------------------------------------------------- # Procedura 4 # ------------------------------------------------------------------------------------------------------------------- # STATE 1 for cur_board, pol_idx, polname in polarimeter_iterator(args.board): with StripTag( conn=self.command_emitter, name=f"ref4_set_pol{polname}_phsw_unsw0101", ): for h, s in enumerate( [ PhswPinMode.STILL_SIGNAL, PhswPinMode.STILL_NO_SIGNAL, PhswPinMode.STILL_SIGNAL, PhswPinMode.STILL_NO_SIGNAL, ] ): self.conn.set_phsw_status( polarimeter=polname, phsw_index=h, status=s ) wait_with_tag( conn=self.conn, seconds=self.long_wait_time_s, name="ref4_acquisition_phsw_unsw0101", ) # STATE 2 for cur_board, pol_idx, polname in polarimeter_iterator(args.board): with StripTag( conn=self.command_emitter, name=f"ref4_set_pol{polname}_phsw_unsw1010", ): for h, s in enumerate( [ PhswPinMode.STILL_NO_SIGNAL, PhswPinMode.STILL_SIGNAL, PhswPinMode.STILL_NO_SIGNAL, PhswPinMode.STILL_SIGNAL, ] ): self.conn.set_phsw_status( polarimeter=polname, phsw_index=h, status=s ) wait_with_tag( conn=self.conn, seconds=self.long_wait_time_s, name="ref4_acquisition_phsw_unsw1010", ) # STATE 3 for cur_board, pol_idx, polname in polarimeter_iterator(args.board): with StripTag( conn=self.command_emitter, name=f"ref4_set_pol{polname}_phsw_unsw1001", ): for h, s in enumerate( [ PhswPinMode.STILL_NO_SIGNAL, PhswPinMode.STILL_SIGNAL, PhswPinMode.STILL_SIGNAL, PhswPinMode.STILL_NO_SIGNAL, ] ): self.conn.set_phsw_status( polarimeter=polname, phsw_index=h, status=s ) wait_with_tag( conn=self.conn, seconds=self.long_wait_time_s, name="ref4_acquisition_phsw_unsw1001", ) # STATE 4 for cur_board, pol_idx, polname in polarimeter_iterator(args.board): with StripTag( conn=self.command_emitter, name=f"ref4_set_pol_{polname}_phsw_unsw0110", ): for h, s in enumerate( [ PhswPinMode.STILL_SIGNAL, PhswPinMode.STILL_NO_SIGNAL, PhswPinMode.STILL_NO_SIGNAL, PhswPinMode.STILL_SIGNAL, ] ): self.conn.set_phsw_status( polarimeter=polname, phsw_index=h, status=s ) wait_with_tag( conn=self.conn, seconds=self.long_wait_time_s, name="ref4_acquisition_phsw_unsw0110", )
def proc_1(procedure, polname, cur_board, test_number, wait_time_s=120): # set to zero bias set_0_bias(procedure, polname, test_number) procedure.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=500) wait_with_tag( conn=procedure.conn, seconds=wait_time_s, name=f"ref{test_number}_acquisition_pol{polname}_zero_bias", ) procedure.conn.log(message="ref_set pol state to unsw 1010") # set pol state to unsw 1010 (STATO 1) with StripTag( conn=procedure.command_emitter, name=f"ref{test_number}_set_pol{polname}_phsw_unsw1010", ): for h, s in enumerate([ PhswPinMode.STILL_NO_SIGNAL, PhswPinMode.STILL_SIGNAL, PhswPinMode.STILL_NO_SIGNAL, PhswPinMode.STILL_SIGNAL, ]): procedure.conn.set_phsw_status(polarimeter=polname, phsw_index=h, status=s) procedure.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=500) # imposto un wait per l'acquisizione wait_with_tag( conn=procedure.conn, seconds=wait_time_s, name=f"ref{test_number}_acquisition_pol{polname}_zero_bias_unsw1010", ) # set pol to default bias board_setup = SetupBoard( config=procedure.conf, post_command=procedure.command_emitter, board_name=cur_board, ) procedure.conn.log(message="ref_set pol state to default bias") with StripTag( conn=procedure.command_emitter, name=f"ref{test_number}_set_pol{polname}_lna_nominal", ): for lna in ("HA3", "HA2", "HA1", "HB3", "HB2", "HB1"): board_setup.setup_VD(polname, lna, step=1.0) board_setup.setup_VG(polname, lna, step=1.0) procedure.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=500) wait_with_tag( conn=procedure.conn, seconds=wait_time_s, name=f"ref{test_number}_acquisition_pol{polname}_unsw1010", ) procedure.conn.log(message="ref_set pol state to unsw 0101") # set pol to unsw 0101 (STATO 2) with StripTag( conn=procedure.command_emitter, name=f"ref{test_number}_set_pol{polname}_phsw_unsw0101", ): for h, s in enumerate([ PhswPinMode.STILL_SIGNAL, PhswPinMode.STILL_NO_SIGNAL, PhswPinMode.STILL_SIGNAL, PhswPinMode.STILL_NO_SIGNAL, ]): procedure.conn.set_phsw_status(polarimeter=polname, phsw_index=h, status=s) procedure.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=200) wait_with_tag( conn=procedure.conn, seconds=wait_time_s, name=f"ref{test_number}_acquisition_pol{polname}_unsw0101", ) procedure.conn.log(message="ref_set phsw state to default bias") # set phsw modulation to default bias with StripTag( conn=procedure.command_emitter, name=f"ref{test_number}_set_pol{polname}_phsw_default", ): for h in range(4): procedure.conn.set_phsw_status( polarimeter=polname, phsw_index=h, status=PhswPinMode.DEFAULT_STATE, ) procedure.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=500) wait_with_tag( conn=procedure.conn, seconds=wait_time_s, name=f"ref{test_number}_acquisition_pol{polname}_default", ) procedure.conn.log(message="ref_set phsw state to antidefault bias") # set phsw modulation to antidefault bias with StripTag( conn=procedure.command_emitter, name=f"ref{test_number}_set_pol{polname}_phsw_default_inv", ): for h, s in enumerate([ PhswPinMode.SLOW_SWITCHING_FORWARD, PhswPinMode.SLOW_SWITCHING_REVERSE, PhswPinMode.FAST_SWITCHING_FORWARD, PhswPinMode.FAST_SWITCHING_REVERSE, ]): procedure.conn.set_phsw_status(polarimeter=polname, phsw_index=h, status=s) procedure.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=500) wait_with_tag( conn=procedure.conn, seconds=wait_time_s, name=f"ref{test_number}_acquisition_pol{polname}_default_inv", )
def run(self): assert self.horn board_setup = SetupBoard( config=self.conf, board_name=self.board, post_command=self.command_emitter ) board_setup.log( f"Test procedure for the phase switches of {self.horn} (board {self.board})" ) with StripTag( conn=self.command_emitter, name="PHSW_STATUS_NOMINAL_7_START", comment=f"Setting status for phase switches in {self.horn}", ): for idx in (0, 1, 2, 3): board_setup.set_phsw_status(self.horn, idx, status=7) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) with StripTag( conn=self.command_emitter, name="PHSW_STATUS_NOMINAL_0", comment=f"Setting status for phase switches in {self.horn}", ): for idx in (0, 1, 2, 3): board_setup.set_phsw_status(self.horn, idx, status=0) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) with StripTag( conn=self.command_emitter, name="PHSW_STATUS_EXPLICIT", comment=f"Setting status for phase switches in {self.horn}", ): for idx, status in [(0, 1), (1, 3), (2, 2), (3, 4)]: board_setup.set_phsw_status(self.horn, idx, status=status) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) with StripTag( conn=self.command_emitter, name="PHSW_STATUS_EXPLICIT_INVERSE", comment=f"Setting status for phase switches in {self.horn}", ): for idx, status in [(0, 3), (1, 1), (2, 4), (3, 2)]: board_setup.set_phsw_status(self.horn, idx, status=status) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) with StripTag( conn=self.command_emitter, name="PHSW_STATUS_NOSWITCH_1010", comment=f"Setting status for phase switches in {self.horn}", ): for idx, status in [(0, 5), (1, 6), (2, 5), (3, 6)]: board_setup.set_phsw_status(self.horn, idx, status=status) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) with StripTag( conn=self.command_emitter, name="PHSW_STATUS_NOSWITCH_0101", comment=f"Setting status for phase switches in {self.horn}", ): for idx, status in [(0, 6), (1, 5), (2, 6), (3, 5)]: board_setup.set_phsw_status(self.horn, idx, status=status) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) with StripTag( conn=self.command_emitter, name="PHSW_STATUS_NOSWITCH_0110", comment=f"Setting status for phase switches in {self.horn}", ): for idx, status in [(0, 6), (1, 5), (2, 5), (3, 6)]: board_setup.set_phsw_status(self.horn, idx, status=status) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) with StripTag( conn=self.command_emitter, name="PHSW_STATUS_NOSWITCH_1001", comment=f"Setting status for phase switches in {self.horn}", ): for idx, status in [(0, 5), (1, 6), (2, 6), (3, 5)]: board_setup.set_phsw_status(self.horn, idx, status=status) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) with StripTag( conn=self.command_emitter, name="PHSW_STATUS_NOMINAL_7_END", comment=f"Setting status for phase switches in {self.horn}", ): for idx in (0, 1, 2, 3): board_setup.set_phsw_status(self.horn, idx, status=7) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) board_setup.log( f"Test procedure for the phase switches of {self.horn} (board {self.board}) has completed" )
def run(self): # Turn on the polarimeter(s) for cur_board in STRIP_BOARD_NAMES: # Append the sequence of commands to turnon this board to # the JSON object # self.command_emitter.command_list += self.turn_on_board(cur_board) pass # Verification step with StripTag( conn=self.command_emitter, name="IVTEST_VERIFICATION_TURNON", ): # Wait a while after having turned on all the boards self.wait(seconds=10) # Load the matrices of the unit-test measurements done in # Bicocca and save them in "self.bicocca_data" self.bicocca_test = get_unit_test(args.bicocca_test_id) module_name = InstrumentBiases().polarimeter_to_module_name( self.bicocca_test.polarimeter_name) log.info( "Test %d for %s (%s) loaded from %s, is_cryogenic=%s", args.bicocca_test_id, self.bicocca_test.polarimeter_name, module_name, self.bicocca_test.url, str(self.bicocca_test.is_cryogenic), ) self.bicocca_data = load_unit_test_data(self.bicocca_test) assert isinstance(self.bicocca_data, UnitTestDC) log.info( " The polarimeter %s corresponds to module %s", self.bicocca_test.polarimeter_name, module_name, ) calibr = CalibrationTables() defaultBias = InstrumentBiases() lna_list = get_lna_list(pol_name=self.bicocca_test.polarimeter_name) #--> First test: ID vs VD --> For each VG, we used VD curves self.conn.tag_start(name=f"IVTEST_IDVD_{module_name}") for lna in lna_list: lna_number = get_lna_num(lna) #Read default configuration with StripTag( conn=self.command_emitter, name=f"{module_name}_{lna}_READDEFAULT_VGVD", ): # read bias in mV default_vg_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vgate", component=lna, value=defaultBias.get_biases(module_name, param_hk=f"VG{lna_number}"), ) # read bias in mV default_vd_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vdrain", component=lna, value=defaultBias.get_biases(module_name, param_hk=f"VD{lna_number}"), ) #Get the data matrix and the Gate Voltage vector. matrixIDVD = self.bicocca_data.components[lna].curves["IDVD"] #from V to mV vgate = np.mean(matrixIDVD["GateV"], axis=0) * 1000 selvg = vgate >= -360 vgate = vgate[selvg] # For each Vg, we have several curves varing Vd for vg_idx, vg in enumerate(vgate): vg_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vgate", component=lna, value=vg, ) self.conn.set_vg( polarimeter=module_name, lna=lna, value_adu=vg_adu, ) #from V to mV curve_vdrain = matrixIDVD["DrainV"][:, vg_idx] * 1000 for vd_idx, vd in enumerate(curve_vdrain): vd_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vdrain", component=lna, value=vd, ) self.conn.set_vd( polarimeter=module_name, lna=lna, value_adu=vd_adu, ) with StripTag( conn=self.command_emitter, name= f"{module_name}_{lna}_SET_VGVD_{vg_idx}_{vd_idx}", comment=f"VG_{vg:.2f}mV_VD_{vd:.2f}mV", ): self.conn.set_hk_scan(allboards=True) self.conn.wait(self.waittime_perconf_s) # Back to the default values of vd and vg (for each LNA) with StripTag( conn=self.command_emitter, name=f"{module_name}_{lna}_BACK2DEFAULT_VGVD", ): self.conn.set_vg( polarimeter=module_name, lna=lna, value_adu=default_vg_adu, ) self.conn.set_vd( polarimeter=module_name, lna=lna, value_adu=default_vd_adu, ) self.conn.wait(self.waittime_perconf_s) self.conn.tag_stop(name=f"IVTEST_IDVD_{module_name}") # #--> Second test: ID vs VG --> For each VD, we used VG curves self.conn.tag_start(name=f"IVTEST_IDVG_{module_name}") for lna in lna_list: lna_number = get_lna_num(lna) #Read default configuration with StripTag( conn=self.command_emitter, name=f"{module_name}_{lna}_READDEFAULT_VDVG", ): # read bias in mV default_vg_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vgate", component=lna, value=defaultBias.get_biases(module_name, param_hk=f"VG{lna_number}"), ) # read bias in mV default_vd_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vdrain", component=lna, value=defaultBias.get_biases(module_name, param_hk=f"VD{lna_number}"), ) #Get the data matrix and the Gate Voltage vector. matrixIDVG = self.bicocca_data.components[lna].curves["IDVG"] #from V to mV vdrain = np.mean(matrixIDVG["DrainV"], axis=0) * 1000 # For each Vd, we have several curves varing Vg for vd_idx, vd in enumerate(vdrain): vd_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vdrain", component=lna, value=vd, ) self.conn.set_vg( polarimeter=module_name, lna=lna, value_adu=vd_adu, ) #from V to mV curve_vgate = matrixIDVG["GateV"][:, vd_idx] * 1000. selcurvg = curve_vgate >= -360 curve_vgate = vgate[selvg] for vg_idx, vg in enumerate(curve_vgate): vg_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vgate", component=lna, value=vg, ) self.conn.set_vd( polarimeter=module_name, lna=lna, value_adu=vg_adu, ) with StripTag( conn=self.command_emitter, name=f"{module_name}_{lna}_VDVG_{vd_idx}_{vg_idx}", comment=f"VD_{vd:0.2f}mV_VG_{vg:.2f}mV", ): # self.conn.set_hk_scan(allboards=True) self.conn.wait(self.waittime_perconf_s) # Back to the default values of vd and vg (for each LNA) with StripTag( conn=self.command_emitter, name=f"IVTEST_IDVG_{module_name}_{lna}_BACK2DEFAULT_VDVG", ): self.conn.set_vg( polarimeter=module_name, lna=lna, value_adu=default_vg_adu, ) self.conn.set_vd( polarimeter=module_name, lna=lna, value_adu=default_vd_adu, ) self.conn.wait(self.waittime_perconf_s) self.conn.tag_stop(name=f"IVTEST_IDVG_{module_name}")
def run(self): # Turn on the polarimeter(s) for cur_board in STRIP_BOARD_NAMES: # Append the sequence of commands to turnon this board to # the JSON object # self.command_emitter.command_list += self.turn_on_board(cur_board) pass # Verification step with StripTag(conn=self.command_emitter, name="IVTEST_VERIFICATION_TURNON"): # Wait a while after having turned on all the boards self.wait(seconds=10) # Load the matriix with the min, max and step for # each LNA for each polarimeter count_conf = 0 for pol_name in self.polarimeters: module_name = self.inputBiasIV["Module"][pol_name] log.info("-->Polarimeter %s (%s)", pol_name, module_name) calibr = CalibrationTables() defaultBias = InstrumentBiases() lna_list = get_lna_list(pol_name=pol_name) # --> First test: ID vs VD --> For each VG, we used VD curves self.conn.tag_start(name=f"IVTEST_{module_name}") for lna in lna_list: lna_number = get_lna_num(lna) # Read default configuration with StripTag( conn=self.command_emitter, name=f"{module_name}_{lna}_READDEFAULT_VGVD", ): # read bias in mV default_vg_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vgate", component=lna, value=getattr(defaultBias.get_biases(module_name), f"vg{lna_number}"), ) # read bias in mV default_vd_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vdrain", component=lna, value=getattr(defaultBias.get_biases(module_name), f"vd{lna_number}"), ) # Get the data matrix and the Gate Voltage vector. # in mV vgate = self.get_bias_curve(pol_name, lna) vdrain = np.arange(0, 900, 50) count_conf += len(vgate) * len(vdrain) # For each Vg, we have several curves varing Vd for vg_idx, vg in enumerate(vgate): vg_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vgate", component=lna, value=vg) self.conn.set_vg(polarimeter=module_name, lna=lna, value_adu=vg_adu) for vd_idx, vd in enumerate(vdrain): vd_adu = calibr.physical_units_to_adu( polarimeter=module_name, hk="vdrain", component=lna, value=vd, ) self.conn.set_vd(polarimeter=module_name, lna=lna, value_adu=vd_adu) with StripTag( conn=self.command_emitter, name= f"{module_name}_{lna}_SET_VGVD_{vg_idx}_{vd_idx}", comment=f"VG_{vg:.2f}mV_VD_{vd:.2f}mV", ): if self.hk_scan == "True": # print(f"hk_scan is {self.hk_scan}") self.conn.set_hk_scan(allboards=True) self.conn.wait(self.waittime_perconf_s) # Back to the default values of vd and vg (for each LNA) with StripTag( conn=self.command_emitter, name=f"{module_name}_{lna}_BACK2DEFAULT_VGVD", ): self.conn.set_vg(polarimeter=module_name, lna=lna, value_adu=default_vg_adu) self.conn.set_vd(polarimeter=module_name, lna=lna, value_adu=default_vd_adu) self.conn.wait(self.waittime_perconf_s) count_conf += 1 self.conn.tag_stop(name=f"IVTEST_IDVD_{module_name}") log.info( "Number of configuration and time [hrs, days]: %s [%s, %s]\n", int(count_conf), np.around(count_conf * self.waittime_perconf_s / 3600.0, 1), np.around(count_conf * self.waittime_perconf_s / 3600 / 24, 3), )
def run_proc2(self): calibr = CalibrationTables() if self.turn_on: turnon_proc = TurnOnOffProcedure( waittime_s=1.0, turnon=True, bias_file_name=self.bias_file_name, ) with StripTag(conn=self.command_emitter, name="phsw_proc2_turnon_pol"): for cur_board, pol_idx, pol_name in polarimeter_iterator( args.board): # turnon pol turnon_proc.set_board_horn_polarimeter( new_board=cur_board, new_horn=pol_name, new_pol=None, ) turnon_proc.run() self.command_emitter.command_list += turnon_proc.get_command_list( ) turnon_proc.clear_command_list() self.conn.wait(seconds=self.pre_acquisition_time_s) for cur_board, pol_idx, pol_name in polarimeter_iterator(args.board): self._stable_acquisition(pol_name, "1111", proc_number=2) wait_with_tag( conn=self.command_emitter, seconds=self.pre_acquisition_time_s, name=f"acquisition_unsw0101_pol{pol_name}", ) # curves test_num, unit_test_data = load_unit_level_test( self.pol_unittest_associations, pol_name, no_unit_level_tests=self.no_unit_level_tests, cryo=self.cryo, ) if self.no_unit_level_tests: self.conn.log( f"The ph/sw test #2 for polarimeter {pol_name} is *not* based on unit-level tests" ) else: assert unit_test_data is not None self.conn.log( f"The ph/sw test #2 for polarimeter {pol_name} is based on unit test #{test_num}" ) if self.reverse_test: self._reverse(calibr, cur_board, pol_name, unit_test_data, proc_number=2) if self.forward_test: self._forward(calibr, cur_board, pol_name, unit_test_data, proc_number=2) self._restore_phsw_state(pol_name, proc_number=1)
def run_turnoff(self): "Execute a turn-off procedure for the horn specified in `self.horn`." assert self.horn board_setup = SetupBoard( config=self.conf, board_name=self.board, post_command=self.command_emitter, bias_file_name=self.bias_file_name, ) current_time = datetime.now().strftime("%A %Y-%m-%d %H:%M:%S (%Z)") board_setup.log( f"Here begins the turnoff procedure for polarimeter {self.horn}, " + f"created on {current_time} using program_turnon.py") board_setup.log(f"We are using the setup for board {self.board}") if self.polarimeter: board_setup.log( f"This procedure assumes that horn {self.horn} is connected to polarimeter {self.polarimeter}" ) # 1 if self.board not in self.off_boards: with StripTag( conn=self.command_emitter, name="BOARD_TURN_OFF", comment=f"Turning off board for {self.horn}", ): board_setup.log("Going to set up the board…") board_setup.board_setup() board_setup.log("Board has been set up") self.off_boards.add(self.board) # 6 for lna in reversed(["HA3", "HA2", "HA1", "HB3", "HB2", "HB1"]): for step_idx, cur_step in enumerate(reversed([0.0, 0.5, 1.0])): with StripTag( conn=self.command_emitter, name="VD_SET", comment= f"Setting drain voltages for LNA {lna} in {self.horn}", ): board_setup.setup_VD(self.horn, lna, step=cur_step) if step_idx == 0: board_setup.setup_VG(self.horn, lna, step=1.0) if False and cur_step == 1.0: # In mode 5, the following command should be useless… board_setup.setup_ID(self.horn, lna, step=1.0) if self.waittime_s > 0: self.wait(seconds=self.waittime_s) board_setup.setup_VG(self.horn, "4A", step=1.0) board_setup.setup_VG(self.horn, "5A", step=1.0) # 2 with StripTag( conn=self.command_emitter, name=f"ELECTRONICS_DISABLE_{self.horn}", comment=f"Disabling electronics for {self.horn}", ): board_setup.log(f"Disabling electronics for {self.horn}…") board_setup.disable_electronics(polarimeter=self.horn) board_setup.log("The electronics has been disabled") board_setup.log(f"Turnoff procedure for {self.horn} completed")
def _run_test( self, test_name, polarimeters, biases_per_pol: Dict[str, BiasConfiguration], sequence, ): # This method is used internally to implement both the # open-loop and closed-loop tests for cur_pol in polarimeters: # Append the sequence of commands to turnon all the polarimeters # to the JSON commands self.command_emitter.command_list += self.turn_on_polarimeters( [cur_pol]) if test_name == "OPEN_LOOP": self.conn.set_pol_mode(cur_pol, OPEN_LOOP_MODE) else: self.conn.set_pol_mode(cur_pol, CLOSED_LOOP_MODE) cur_biases = biases_per_pol[cur_pol]._asdict() self.used_biases.append({ "polarimeter": cur_pol, "test_name": test_name, "calibrated_biases": {key: val for (key, val) in cur_biases.items() if val}, }) bias_repr = ", ".join([ f"{key}={val:.1f}" for (key, val) in cur_biases.items() if val ]) with StripTag( conn=self.command_emitter, name=f"{test_name}_TEST_SETUP_{cur_pol}", comment=f"(calibrated) biases are: {bias_repr}", ): for component, param, key in sequence: params = { "polarimeter": cur_pol, "lna": component, "value_adu": self.calibr.physical_units_to_adu( polarimeter=cur_pol, hk=key, component=component, value=cur_biases[param], ), } if key == "vdrain": self.conn.set_vd(**params) elif key == "idrain": self.conn.set_id(**params) elif key == "vgate": self.conn.set_vg(**params) if not self.args.acquisition_at_end: with StripTag( conn=self.command_emitter, name=f"{test_name}_TEST_ACQUISITION_{cur_pol}", comment=f"Stable acquisition for polarimeter {cur_pol}", ): self.conn.wait(seconds=self.args.wait_time_s) if self.args.acquisition_at_end: with StripTag( conn=self.command_emitter, name=f"{test_name}_TEST_ACQUISITION", comment="Stable acquisition with polarimeters {pols}". format(pols=", ".join(polarimeters)), ): self.conn.wait(seconds=self.args.wait_time_s)
def run(self): # turn on polarimeter if self.turn_on_polarimeters: turnon_proc = TurnOnOffProcedure(waittime_s=1.0, turnon=True) for cur_board, pol_idx, polname in polarimeter_iterator( args.board): with StripTag(conn=self.command_emitter, name=f"ref3_turnon_pol_{polname}"): turnon_proc.set_board_horn_polarimeter( new_board=cur_board, new_horn=polname, new_pol=None, ) turnon_proc.run() self.command_emitter.command_list += turnon_proc.get_command_list( ) turnon_proc.clear_command_list() proc_1(self, polname, cur_board, 3, wait_time_s=self.wait_time_s) self.conn.log(message="ref3_set phsw state to default bias") # set phsw modulation to default bias for h in range(4): with StripTag( conn=self.command_emitter, name=f"ref3_set_pol{polname}_phsw_default_end", ): self.conn.set_phsw_status( polarimeter=polname, phsw_index=h, status=PhswPinMode.DEFAULT_STATE, ) self.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=500) wait_with_tag( conn=self.conn, seconds=self.wait_time_s, name=f"ref3_acquisition_pol{polname}_phsw_default_end", ) #################################################################################################################### # ------------------------------------------------------------------------------------------------------------------- # Procedura 3 # ------------------------------------------------------------------------------------------------------------------- # RUN 1 for cur_board, pol_idx, polname in polarimeter_iterator(args.board): for h in range(4): with StripTag( conn=self.command_emitter, name=f"ref3_set_pol_{polname}_phsw_{h}_default", ): self.conn.set_phsw_status( polarimeter=polname, phsw_index=h, status=PhswPinMode.DEFAULT_STATE, ) wait_with_tag( conn=self.conn, seconds=self.long_wait_time_s, name="ref3_acquisition_phsw_default", ) # RUN 2 for cur_board, pol_idx, polname in polarimeter_iterator(args.board): with StripTag( conn=self.command_emitter, name=f"ref3_set_pol{polname}_phsw_{h}_default_inv", ): for h, s in enumerate([ PhswPinMode.SLOW_SWITCHING_FORWARD, PhswPinMode.SLOW_SWITCHING_REVERSE, PhswPinMode.FAST_SWITCHING_FORWARD, PhswPinMode.FAST_SWITCHING_REVERSE, ]): self.conn.set_phsw_status(polarimeter=polname, phsw_index=h, status=s) wait_with_tag( conn=self.conn, seconds=self.long_wait_time_s, name="ref3_acquisition_phsw_default_inv", )