def doStart(self, pos): self.doWriteScatteringsense(self.scatteringsense) qh, qk, ql, ny = pos ny = self._thz(ny) angles = self._attached_cell.cal_angles( [qh, qk, ql], ny, self.scanmode, self.scanconstant, self.scatteringsense[1], self.axiscoupling, self.psi360) mono, ana, phi, psi, alpha = self._attached_mono, self._attached_ana, \ self._attached_phi, self._attached_psi, self._attached_alpha self.log.debug('moving phi/stt to %s', angles[2]) phi.start(angles[2]) self.log.debug('moving psi/sth to %s', angles[3]) psi.start(angles[3]) if alpha is not None: self.log.debug('moving alpha to %s', angles[4]) alpha.start(angles[4]) self.log.debug('moving mono to %s', angles[0]) mono.start(from_k(angles[0], mono.unit)) if self.scanmode != 'DIFF': self.log.debug('moving ana to %s', angles[1]) ana.start(from_k(angles[1], ana.unit)) # spurion check if self.spurioncheck and self._mode == SIMULATION: self._spurionCheck(pos) # store the min and max values of h,k,l, and E for simulation self._sim_setValue(pos)
def test_from_k(): assert from_k(1, 'A-1') == 1 # include backward calculations into test in_out = in_fromk[:] in_out += [(r, u, v) for (v, u, r) in in_tok] for args in in_out: assert from_k(args[0], args[1]) == approx(args[2], abs=1e-4)
def _start(self, k): # first drive there, to determine if it is within limits tas = self._attached_tas base = self._attached_base pos = from_k(k, base.unit) base.start(pos) msg = False if tas.scanmode != self.scanmode: tas.scanmode = self.scanmode msg = True if tas.scanconstant != pos: tas.scanconstant = pos msg = True return msg
def _calpos(self, pos, printout=True, checkonly=True): qh, qk, ql, ny, sc, sm = pos ny = self._thz(ny) if sm is None: sm = self.scanmode if sc is None: sc = self.scanconstant try: angles = self._attached_cell.cal_angles([qh, qk, ql], ny, sm, sc, self.scatteringsense[1], self.axiscoupling, self.psi360) except ComputationError as err: if checkonly: self.log.error('cannot calculate position: %s', err) return else: raise if not printout: return angles ok, why = True, '' for devname, value in zip(['mono', 'ana', 'phi', 'psi', 'alpha'], angles): dev = self._adevs[devname] if dev is None: continue if isinstance(dev, Monochromator): devok, devwhy = dev.isAllowed(from_k(value, dev.unit)) else: devok, devwhy = dev.isAllowed(value) if not devok: ok = False why += 'target position %s outside limits for %s: %s -- ' % \ (dev.format(value, unit=True), dev, devwhy) self.log.info('ki: %8.3f A-1', angles[0]) if self.scanmode != 'DIFF': self.log.info('kf: %8.3f A-1', angles[1]) self.log.info('2theta sample: %8.3f deg', angles[2]) self.log.info('theta sample: %8.3f deg', angles[3]) if self._attached_alpha is not None: self.log.info('alpha: %8.3f deg', angles[4]) if ok: self._last_calpos = pos if checkonly: self.log.info('position allowed') else: if checkonly: self.log.warning('position not allowed: %s', why[:-4]) else: raise LimitError(self, 'position not allowed: ' + why[:-4])
def doStart(self, pos): self.doWriteScatteringsense(self.scatteringsense) qh, qk, ql, ny = pos ny = self._thz(ny) angles = self._attached_cell.cal_angles([qh, qk, ql], ny, self.scanmode, self.scanconstant, self.scatteringsense[1], self.axiscoupling, self.psi360) mono, ana, phi, psi, alpha = self._attached_mono, self._attached_ana, \ self._attached_phi, self._attached_psi, self._attached_alpha movefirst = [] self.log.debug('moving mono to %s', angles[0]) movefirst.append(SeqDev(mono, from_k(angles[0], mono.unit))) self.log.debug('moving phi/stt to %s', angles[2]) movefirst.append(SeqDev(phi, angles[2])) self.log.debug('moving psi/sth to %s', angles[3]) movefirst.append(SeqDev(psi, angles[3])) if alpha is not None: self.log.debug('moving alpha to %s', angles[4]) movefirst.append(SeqDev(alpha, angles[4])) seq = [] # move mono/sample all at once seq.append(movefirst) # afterwards correct ana if self.scanmode != 'DIFF': self.log.debug('moving ana to %s', angles[1]) seq.append(SeqDev(ana, from_k(angles[1], ana.unit))) # spurion check if self.spurioncheck and self._mode == SIMULATION: self._spurionCheck(pos) # store the min and max values of h,k,l, and E for simulation self._sim_setValue(pos) # start self._startSequence(seq)
def writeData(self, fp, image): mon = self.sink._attached_monitor timer = self.sink._attached_timer mono = self.sink._attached_mono write = fp.write write('''\ <measurement_file> <instrument_name>MIRA</instrument_name> <location>Forschungsreaktor Muenchen II - FRM2</location> <measurement_data> <Sample_Detector>%d</Sample_Detector> <wavelength>%.2f</wavelength> <lifetime>%.3f</lifetime> <beam_monitor>%d</beam_monitor> <resolution>1024</resolution> <detector_value>\n''' % (self.sink._attached_sampledet.read(), from_k(to_k(mono.read(), mono.unit), 'A'), timer.read()[0], mon.read()[0])) h, w = image.shape if self.sink._format is None or self.sink._format[0] != image.shape: p = [] for _x in range(w): for fx in range(1024 // w): for _y in range(h): for fy in range(1024 // h): if fx % 4 == 0 and fy % 4 == 0: p.append('%f ') else: p.append('0 ') p.append('\n') self.sink._format = (image.shape, ''.join(p)) filled = np.repeat(np.repeat(image, 256 // w, 0), 256 // h, 1) if filled.shape == (256, 256): write(self.sink._format[1] % tuple(filled.ravel() / 4.)) write('''\ </detector_value> </measurement_data> </measurement_file> ''')
def doIsAllowed(self, pos): qh, qk, ql, ny = pos ny = self._thz(ny) try: angles = self._attached_cell.cal_angles( [qh, qk, ql], ny, self.scanmode, self.scanconstant, self.scatteringsense[1], self.axiscoupling, self.psi360) except ComputationError as err: return False, str(err) # check limits for the individual axes for devname, value in zip(['mono', 'ana', 'phi', 'psi', 'alpha'], angles): dev = self._adevs[devname] if dev is None: continue if isinstance(dev, Monochromator): ok, why = dev.isAllowed(from_k(value, dev.unit)) else: ok, why = dev.isAllowed(value) if not ok: return ok, 'target position %s outside limits for %s: %s' % \ (dev.format(value, unit=True), dev, why) return True, ''
def doRead(self, maxage=0): mono = self._attached_base return from_k(to_k(mono.read(maxage), mono.unit), self._attached_tas.energytransferunit)