def close(self, handle: ViSession): """ This function closes the instrument driver session. Note: The instrument must be reinitialized to use it again. """ log.spam(f"closing instrument with handle {handle.value}") WfsLib.result(self._dll.WFS_close(handle))
def set_mla(self, mla_index=0): """ This function selects one of the removable microlens arrays by its index. Appropriate calibration values are read out of the instrument and set active. """ log.spam(f"selecting MLA with index {mla_index}") WfsLib.result(self._dll.WFS_SelectMla(self._handle, mla_index))
def set_pupil(self, center=[0, 0], diameter=[3, 3]): """ This function defines the pupil in position and size. """ self.pupil_center = [ViReal64(center[0]), ViReal64(center[1])] self.pupil_diameter = [ViReal64(diameter[0]), ViReal64(diameter[1])] log.spam(f"configuring pupil") WfsLib.result( self._dll.WFS_SetPupil(self._handle, *self.pupil_center, *self.pupil_diameter))
def device_count(self): """ This function reads all Wavefront Sensor devices connected to the PC and returns the number of it. Use function GetInstrumentListInfo to retrieve information about each WFS instrument. """ count = ViInt32() WfsLib.result( self._dll.WFS_GetInstrumentListLen(VI_NULL(), byref(count))) log.spam(f"WFS_GetInstrumentListLen: {count.value} connected sensors") return count.value
def calc_deviations(self, cancel_spot_wavefront_tilt=True): """ This function calculates reference positions and deviations for all spots depending on the setting ref_idx(internal/user) set by function SetWavefrontReference. When option CancelWavefrontTilt is enabled the mean deviation in X and Y direction, which is measured within the pupil, is subtracted from the deviation data arrays. Reference positions can be retrieved using function GetSpotReferencePositions and calculated deviations by function GetSpotDeviations. """ self.cancel_spot_wavefront_tilt = ViInt32(cancel_spot_wavefront_tilt) log.spam("calculating spot deviation from reference") WfsLib.result( self._dll.WFS_CalcSpotToReferenceDeviations( self._handle, self.cancel_spot_wavefront_tilt))
def set_reference_plane(self, internal=True): """ This function defines the WFS Reference Plane to either Internal or User (external). """ self.reference_index = ViInt32(not internal) if internal: log.spam(f"configuring reference plane to internal") else: log.spam(f"configuring reference plane to external") WfsLib.result( self._dll.WFS_SetReferencePlane(self._handle, self.reference_index))
def calc_wavefront(self, wavefront_type=0, limit_to_pupil=True): """ This function calculates the wavefront based on the spot deviations. max_spots is a bit dirty, will be hopefully removed. """ self.wavefront_type = ViInt32(wavefront_type) self.limit_to_pupil = ViInt32(limit_to_pupil) array_wavefront = np.zeros(MAX_SPOTS[::-1], dtype=np.float32) log.spam(f"calculating wavefront type {self.wavefront_type.value}") # WFSLib.result(self._dll.WFS_CalcWavefront(self._handle, self.wavefront_type, self.limit_to_pupil, array_wavefront.ctypes.data)) WfsLib.result( self._dll.WFS_CalcWavefront(self._handle, self.wavefront_type, self.limit_to_pupil, array_wavefront)) return np.transpose( array_wavefront[:self.spots[1].value, :self.spots[0].value].copy())
def calc_spot(self, dynamic_noise_cut=True, calculate_diameters=False): """ This function calculates the centroids, diameters (optional) and intensities of all spots generated by the lenslets. Data arrays are returned by separate functions: GetSpotCentroids GetSpotDiameters GetSpotIntensities """ self.dynamic_noise_cut = ViInt32(dynamic_noise_cut) self.calculate_diameters = ViInt32(calculate_diameters) log.spam("calculating spot centroids and diameters") WfsLib.result( self._dll.WFS_CalcSpotsCentrDiaIntens(self._handle, self.dynamic_noise_cut, self.calculate_diameters))
def set_resolution(self, cam_resol_index): """ This function configures the WFS instrument's camera resolution and returns the max. number of detectable spots in X and Y direction. The result depends on the selected microlens array in function WFS_SelectMla(). """ self.pixel_format = ViInt32(0) self.cam_resol_index = ViInt32(cam_resol_index) self.spots = [ViInt32(), ViInt32()] WfsLib.result( self._dll.WFS_ConfigureCam(self._handle, self.pixel_format, self.cam_resol_index, byref(self.spots[0]), byref(self.spots[1]))) log.spam( f"sensor configured with {self.spots[0].value} x {self.spots[1].value} spots" )
def auto_exposure(self, max_tries=10): """ This function calls take_spot_field_image_auto_expos() over and over until errors are cleared """ # check if the device has been already initiated if self.configuration is None: self.configure() for c in range(max_tries): self._sdk.take_spot_field_image_auto_expos() status = self._sdk.get_status() # check if parameters are right if (not status["PTH"]) and (not status["PTL"]) and ( not status["HAL"]): log.spam(f"adjusting exposure took {c + 1} runs") return raise WfsError("auto adjusting parameters not successful")
def get_status(self): """ This function returns the device status of the Wavefront Sensor instrument. """ device_status = ViInt32() log.spam(f"querying device status") WfsLib.result( self._dll.WFS_GetStatus(self._handle, byref(device_status))) log.info(f"WFS_GetStatus: {device_status.value}") # check all status bits status = {} for key in WFS_STATUS: if WFS_STATUS[key] & device_status.value: status[key] = True else: status[key] = False return status
def open(self, list_index=0): """ This function initializes the instrument driver session and performs the following initialization actions: (1) Opens a session to the Default Resource Manager resource and a session to the selected device using the Resource Name. (2) Performs an identification query on the Instrument. (3) Resets the instrument to a known state. (4) Sends initialization commands to the instrument. (5) Returns an instrument handle. """ log.spam(f"opening sensor with index {list_index}") resource_name = ViRsrc() id_query = ViBoolean() reset_device = ViBoolean() handle = ViSession() # check if device is already in use instrument = self.device_info()[list_index] if instrument[1] != 0: raise WfsError(f"device is already in use!") resource_name.value = instrument[-1] WfsLib.result( self._dll.WFS_init(resource_name, id_query, reset_device, byref(handle))) log.spam(f"sensor initialized with handle {handle.value}") return WfsSDK(handle, self._dll)
def take_spot_field_image_auto_expos(self): """ This function tries to find optimal exposure and gain settings and then it receives a spotfield image from the WFS camera into a driver buffer. The reference to this buffer is provided by function GetSpotfieldImage() and an image copy is returned by function GetSpotfieldImageCopy(). The exposure and gain settings used for this image are returned. """ self.exposure_time_act = ViReal64() self.master_gain_act = ViReal64() log.spam(f"taking spot field with auto exposure") WfsLib.result( self._dll.WFS_TakeSpotfieldImageAutoExpos( self._handle, byref(self.exposure_time_act), byref(self.master_gain_act))) log.spam(f"exposure_time_act {self.exposure_time_act.value}") log.spam(f"master_gain_act {self.master_gain_act.value}")