class ID23PhotonFlux(Equipment): def __init__(self, *args, **kwargs): Equipment.__init__(self, *args, **kwargs) self.threshold = [] def init(self): self.counter = DeviceProxy(self.getProperty("url")) try: self.threshold = map(float,self.getProperty("threshold").split()) except AttributeError: self.threshold = [0, 9999] self.shutter = self.getDeviceByRole("shutter") self.energy_motor = self.getObjectByRole("energy") self.aperture = self.getObjectByRole("aperture") fname = self.getProperty("calibrated_diodes_file") self.flux_calc = CalculateFlux() self.flux_calc.init(fname) self.shutter.connect("shutterStateChanged", self.shutterStateChanged) self.counts_reading_task = self._read_counts_task(wait=False) @task def _read_counts_task(self): old_counts = None while True: counts = self._get_counts() if counts != old_counts: old_counts = counts self.countsUpdated(counts) time.sleep(1) def _get_counts(self): try: self.counter.MeasureSingle() counts = abs(self.counter.ReadData) if counts < self.threshold[0] or counts > self.threshold[1]: counts = 0 except AttributeError, TypeError: counts = 0 logging.getLogger("HWR").exception("%s: could not get counts", self.name()) try: egy = self.energy_motor.getCurrentEnergy()*1000.0 calib = self.flux_calc.calc_flux_coef(egy) except: logging.getLogger("HWR").exception("%s: could not get energy", self.name()) else: if self.aperture is None: aperture_coef = 1 else: try: aperture_coef = self.aperture.getApertureCoef() except: aperture_coef = 1. counts = math.fabs(counts * calib[0] * aperture_coef)*10e6 return counts
class ID30A3PhotonFlux(Equipment): def __init__(self, *args, **kwargs): Equipment.__init__(self, *args, **kwargs) def init(self): controller = self.getObjectByRole("controller") self.musst = controller.musst self.energy_motor = self.getDeviceByRole("energy") self.shutter = self.getDeviceByRole("shutter") self.factor = self.getProperty("current_photons_factor") self.shutter.connect("shutterStateChanged", self.shutterStateChanged) self.tg_device = DeviceProxy(self.getProperty("tango_device")) self.counts_reading_task = self._read_counts_task(wait=False) @task def _read_counts_task(self): old_counts = None while True: counts = self._get_counts() if counts != old_counts: old_counts = counts self.countsUpdated(counts) time.sleep(1) def _get_counts(self): """gain = 20 #20uA keithley_voltage = 2 musst_voltage = int("".join([x for x in self.musst.putget("#?CHCFG CH5") if x.isdigit()])) musst_fs = float(0x7FFFFFFF) counts = abs((gain/keithley_voltage)*musst_voltage*int(self.musst.putget("#?VAL CH5"))/musst_fs) """ #try: self.tg_device.MeasureSingle() counts = abs(self.tg_device.ReadData) * 1E6 return counts def connectNotify(self, signal): if signal == "valueChanged": self.emitValueChanged() def shutterStateChanged(self, _): self.countsUpdated(self._get_counts()) def updateFlux(self, _): self.countsUpdated(self._get_counts(), ignore_shutter_state=True) def countsUpdated(self, counts, ignore_shutter_state=False): if not ignore_shutter_state and self.shutter.getShutterState( ) != "opened": self.emitValueChanged(0) return flux = counts * self.factor self.emitValueChanged("%1.3g" % flux) """ try: counts = counts[self.index] except TypeError: logging.getLogger("HWR").error("%s: counts is None", self.name()) return flux = None try: egy = self.energy_motor.getPosition()*1000.0 except: logging.getLogger("HWR").exception("%s: could not get energy", self.name()) else: try: calib_dict = self.calibration_chan.getValue() if calib_dict is None: logging.getLogger("HWR").error("%s: calibration is None", self.name()) else: calibs = [(float(c["energy"]), float(c[self.counter])) for c in calib_dict.itervalues()] calibs.sort() E = [c[0] for c in calibs] C = [c[1] for c in calibs] except: logging.getLogger("HWR").exception("%s: could not get calibration", self.name()) else: try: aperture_coef = self.aperture.getApertureCoef() except: aperture_coef = 1 if aperture_coef <= 0: aperture_coef = 1 calib = numpy.interp([egy], E, C) flux = counts * calib * aperture_coef #logging.getLogger("HWR").debug("%s: flux-> %f * %f=%f , calib_dict=%r", self.name(), counts, calib, counts*calib, calib_dict) self.emitValueChanged("%1.3g" % flux) """ def getCurrentFlux(self): return self.current_flux def emitValueChanged(self, flux=None): if flux is None: self.current_flux = None self.emit("valueChanged", ("?", )) else: self.current_flux = flux self.emit("valueChanged", (self.current_flux, ))
class ID23PhotonFlux(Equipment): def __init__(self, *args, **kwargs): Equipment.__init__(self, *args, **kwargs) self.threshold = [] def init(self): self.counter = DeviceProxy(self.getProperty("url")) try: self.threshold = map(float, self.getProperty("threshold").split()) except AttributeError: self.threshold = [0, 9999] self.shutter = self.getDeviceByRole("shutter") self.aperture = self.getObjectByRole("aperture") fname = self.getProperty("calibrated_diodes_file") self.flux_calc = CalculateFlux() self.flux_calc.init(fname) self.shutter.connect("shutterStateChanged", self.shutterStateChanged) self.counts_reading_task = self._read_counts_task(wait=False) @task def _read_counts_task(self): old_counts = None while True: counts = self._get_counts() if counts != old_counts: old_counts = counts self.countsUpdated(counts) time.sleep(1) def _get_counts(self): try: self.counter.MeasureSingle() counts = abs(self.counter.ReadData) if counts < self.threshold[0] or counts > self.threshold[1]: counts = 0 except AttributeError: counts = 0 logging.getLogger("HWR").exception("%s: could not get counts", self.name()) try: egy = HWR.beamline.energy.get_value() * 1000.0 calib = self.flux_calc.calc_flux_coef(egy) except Exception: logging.getLogger("HWR").exception("%s: could not get energy", self.name()) else: if self.aperture is None: aperture_coef = 1 else: try: aperture_coef = self.aperture.getApertureCoef() except Exception: aperture_coef = 1.0 counts = math.fabs(counts * calib[0] * aperture_coef) * 10e6 return counts def connectNotify(self, signal): if signal == "valueChanged": self.emitValueChanged() def shutterStateChanged(self, _): self.countsUpdated(self._get_counts()) def updateFlux(self, _): self.countsUpdated(self._get_counts(), ignore_shutter_state=False) def countsUpdated(self, counts, ignore_shutter_state=False): self.emitValueChanged("%1.3g" % counts) def get_value(self): self.updateFlux("dummy") return self.current_flux def emitValueChanged(self, flux=None): if flux is None: self.current_flux = None self.emit("valueChanged", ("?", )) else: self.current_flux = flux self.emit("valueChanged", (self.current_flux, ))
class ID30A1PhotonFlux(Equipment): def __init__(self, *args, **kwargs): Equipment.__init__(self, *args, **kwargs) def init(self): controller = self.getObjectByRole("controller") self.musst = controller.musst self.energy_motor = self.getDeviceByRole("energy") self.shutter = self.getDeviceByRole("shutter") self.factor = self.getProperty("current_photons_factor") self.shutter.connect("shutterStateChanged", self.shutterStateChanged) self.tg_device = DeviceProxy("id30/keithley_massif1/i0") self.counts_reading_task = self._read_counts_task(wait=False) @task def _read_counts_task(self): old_counts = None while True: counts = self._get_counts() if counts != old_counts: old_counts = counts self.countsUpdated(counts) time.sleep(1) def _get_counts(self): """counts = abs((2/2.1)*10*int(self.musst.putget("#?VAL CH5")) / float(0x7FFFFFFF)) if counts < 0: counts = 0 """ self.tg_device.MeasureSingle() counts = abs(self.tg_device.ReadData)*1E6 return counts def connectNotify(self, signal): if signal == "valueChanged": self.emitValueChanged() def shutterStateChanged(self, _): self.countsUpdated(self._get_counts()) def updateFlux(self, _): self.countsUpdated(self._get_counts(), ignore_shutter_state=True) def countsUpdated(self, counts, ignore_shutter_state=False): #if not ignore_shutter_state and self.shutter.getShutterState()!="opened": # self.emitValueChanged(0) # return flux = counts * self.factor self.emitValueChanged("%1.3g" % flux) def getCurrentFlux(self): return self.current_flux def emitValueChanged(self, flux=None): if flux is None: self.current_flux = None self.emit("valueChanged", ("?", )) else: self.current_flux = flux self.emit("valueChanged", (self.current_flux, ))
class TangoKeithleyPhotonFlux(Equipment): def __init__(self, *args, **kwargs): Equipment.__init__(self, *args, **kwargs) def init(self): controller = self.getObjectByRole("controller") self.energy_motor = self.getDeviceByRole("energy") self.shutter = self.getDeviceByRole("shutter") self.aperture = self.getObjectByRole("aperture") self.factor = self.getProperty("current_photons_factor") self.shutter.connect("shutterStateChanged", self.shutterStateChanged) self.tg_device = DeviceProxy(self.getProperty("tango_device")) self.counts_reading_task = self._read_counts_task(wait=False) @task def _read_counts_task(self): old_counts = None while True: counts = self._get_counts() if counts != old_counts: old_counts = counts self.countsUpdated(counts) time.sleep(1) def _get_counts(self): self.tg_device.MeasureSingle() counts = abs(self.tg_device.ReadData) * 1E6 if self.aperture: try: aperture_coef = self.aperture.getApertureCoef() except Exception: aperture_coef = 1 else: aperture_coef = 1 counts *= aperture_coef return counts def connectNotify(self, signal): if signal == "valueChanged": self.emitValueChanged() def shutterStateChanged(self, _): self.countsUpdated(self._get_counts()) def updateFlux(self, _): self.countsUpdated(self._get_counts(), ignore_shutter_state=True) def countsUpdated(self, counts, ignore_shutter_state=False): if not ignore_shutter_state and self.shutter.getShutterState( ) != "opened": self.emitValueChanged(0) return flux = counts * self.factor self.emitValueChanged("%1.3g" % flux) def getCurrentFlux(self): return self.current_flux def emitValueChanged(self, flux=None): self.current_flux = flux if flux is None: self.emit("valueChanged", ("?", )) else: self.emit("valueChanged", (self.current_flux, ))