[docs]classAPOGEEDomeFlatMacro(Macro):"""Take an APOGEE dome flat after an exposure."""name="apogee_dome_flat"__PRECONDITIONS__=["gang_at_cart"]__STAGES__=[("ffs","open_shutter"),"expose"]__CLEANUP__=["cleanup"]__ffs_initial_state:str|None=None
[docs]asyncdefgang_at_cart(self):"""Checks that the gang connected is at the cart."""ifnotself.command.actor.helpers.apogee.gang_helper.at_cartridge():raiseMacroError("The APOGEE gang connector is not at the cart.")returnTrue
[docs]asyncdefffs(self):"""Check the FFS status and closes it."""assertself.command.actor.helpers.ffs,"FFS helper not available."ifself.command.actor.helpers.ffs.all_closed():self.command.debug("FFS already closed.")self.__ffs_initial_state="closed"returnelifself.command.actor.helpers.ffs.all_open():self.__ffs_initial_state="open"else:raiseMacroError("Cannot determine state of FFS.")self.command.info("Closing FFS.")awaitself.command.actor.helpers.ffs.close(self.command)
[docs]asyncdefopen_shutter(self):"""Opens the APOGEE cold shutter."""apogee=self.command.actor.helpers.apogeeifnotawaitapogee.shutter(self.command,True):raiseMacroError("Failed opening APOGEE shutter.")
[docs]asyncdefexpose(self):"""Takes the dome flat. Turns on the FFS after the fourth read."""apogee=self.command.actor.helpers.apogeeself.command.actor.models["apogee"]["utrReadState"].register_callback(self._flash_lamps)self.command.info("Taking APOGEE dome flat.")awaitapogee.expose(self.command,50,exp_type="DomeFlat")returnTrue
asyncdef_flash_lamps(self,key:TronKey):"""Flashes the FF lamps."""iflen(key.value)==0:returnstate=key.value[1]n_read=int(key.value[2])ifn_read==3andstate=="Reading":time_to_flash=4.0self.command.info(text="Calling ff_lamp.on")asyncio.create_task(self.send_command("mcp","ff.on",time_limit=config["timeouts"]["lamps"],))awaitasyncio.sleep(time_to_flash)lamp_off=awaitself.command.send_command("mcp","ff.off")iflamp_off.status.did_fail:raiseMacroError("Failed flashing lamps.")return
[docs]asyncdefcleanup(self):"""Closes the shutter and does cleanup."""assertself.command.actor.helpers.ffs,"FFS helper not available."apogee=self.command.actor.helpers.apogeetry:self.command.actor.models["apogee"]["utrReadState"].remove_callback(self._flash_lamps)exceptAssertionError:passifnotawaitapogee.shutter(self.command,False):self.command.error("Failed closing APOGEE shutter.")ifself.__ffs_initial_state=="open":self.command.info("Reopening FFS.")awaitself.command.actor.helpers.ffs.open(self.command)else:self.command.info("Keeping FFS closed.")