def show_water(): text = ' ' + datetime.datetime.now().strftime( '%A %d %B, %Y %I:%M %p') + '\n\n' text += ' Sensor Value\n' text += ' ==============================================\n' for pv in (bmm_di.dm1_flow, bmm_di.dcm_flow, bmm_di.supply_pressure, bmm_di.supply_temperature, bmm_di.return_pressure, bmm_di.return_temperature, pbs_di_a, pbs_di_b, pcw_return_temperature, pcw_supply_temperature): if pv.alarm_status.value: text += error_msg( ' %-28s %.1f %s\n' % (pv.name, float(pv.get()), pv.describe()[pv.name]['units'])) else: text += ' %-28s %.1f %s\n' % (pv.name, float( pv.get()), pv.describe()[pv.name]['units']) if foe_leak_detector.get() > 0: text += ' %-28s %s\n' % ( foe_leak_detector.name, foe_leak_detector.enum_strs[foe_leak_detector.get()].replace( ' ', ' ')) else: text += error_msg( ' %-28s %s\n' % (foe_leak_detector.name, foe_leak_detector.enum_strs[foe_leak_detector.get()].replace( ' ', ' '))) return text[:-1]
def move_after_scan(thismotor): ''' Call this to pluck a point from a plot and move the plotted motor to that x-value. ''' BMMuser = user_ns['BMMuser'] if BMMuser.motor is None: print(error_msg('\nThere\'s not a current plot on screen.\n')) return (yield from null()) if thismotor is not BMMuser.motor: print( error_msg( '\nThe motor you are asking to move is not the motor in the current plot.\n' )) return (yield from null()) print('Single click the left mouse button on the plot to pluck a point...') cid = BMMuser.fig.canvas.mpl_connect( 'button_press_event', interpret_click) # see derivedplot.py and while BMMuser.x is None: # https://matplotlib.org/users/event_handling.html yield from sleep(0.5) if BMMuser.motor2 is None: yield from mv(thismotor, BMMuser.x) else: print('%.3f %.3f' % (BMMuser.x, BMMuser.y)) #yield from mv(BMMuser.motor, BMMuser.x, BMMuser.motor2, BMMuser.y) cid = BMMuser.fig.canvas.mpl_disconnect(cid) BMMuser.x = BMMuser.y = None
def select(self, el): '''Choose the ROI configured for element el''' if type(el) is int: if el < 1 or el > 3: self.myprint(error_msg('\n%d is not a valid ROI channel\n' % el)) return el = self.slots[el-1] if el is None: self.myprint(error_msg('\nThat ROI is not configured\n')) return if Z_number(el) is None: self.myprint(error_msg('\n%s is not an element\n' % el)) return selected = False vor = user_ns['vor'] BMMuser = user_ns['BMMuser'] for i in range(3): if element_symbol(el) == self.slots[i]: BMMuser.roi_channel = i+1 if i == 0: # help out the best effort callback (BMMuser.roi1, BMMuser.roi2, BMMuser.roi3, BMMuser.roi4) = ('ROI1', 'ROI2', 'ROI3', 'ROI4') (BMMuser.dtc1, BMMuser.dtc2, BMMuser.dtc3, BMMuser.dtc4) = ('DTC1', 'DTC2', 'DTC3', 'DTC4') vor.set_hints(1) elif i == 1: (BMMuser.roi1, BMMuser.roi2, BMMuser.roi3, BMMuser.roi4) = ('ROI2_1', 'ROI2_2', 'ROI2_3', 'ROI2_4') (BMMuser.dtc1, BMMuser.dtc2, BMMuser.dtc3, BMMuser.dtc4) = ('DTC2_1', 'DTC2_2', 'DTC2_3', 'DTC2_4') vor.set_hints(2) elif i == 2: (BMMuser.roi1, BMMuser.roi2, BMMuser.roi3, BMMuser.roi4) = ('ROI3_1', 'ROI3_2', 'ROI3_3', 'ROI3_4') (BMMuser.dtc1, BMMuser.dtc2, BMMuser.dtc3, BMMuser.dtc4) = ('DTC3_1', 'DTC3_2', 'DTC3_3', 'DTC3_4') vor.set_hints(3) report('Set ROI channel to %s at channel %d' % (el.capitalize(), i+1)) selected = True if not selected: self.myprint(whisper('%s is not in a configured channel, not changing BMMuser.roi_channel' % el.capitalize()))
def reset_rois(self, el=None): BMMuser = user_ns['BMMuser'] if el is None: el = BMMuser.element if el in self.slots: print(error_msg(f'Resetting rois with {el} as the active ROI')) BMMuser.element = el self.set_rois() self.measure_roi() show_edges() else: print(error_msg(f'Cannot reset rois, {el} is not in {self.name}.slots'))
def spreadsheet(self, spreadsheet=None, energy=False): '''Convert a wheel macro spreadsheet to a BlueSky plan. Examples -------- To create a macro from a spreadsheet called "MySamples.xlsx" >>> xlsx('MySamples') To specify a change_edge() command at the beginning of the macro: >>> xlsx('MySamples', energy=True) ''' if spreadsheet is None: spreadsheet = present_options('xlsx') if spreadsheet is None: print(error_msg('No spreadsheet specified!')) return None if spreadsheet[-5:] != '.xlsx': spreadsheet = spreadsheet + '.xlsx' self.source = os.path.join(self.folder, spreadsheet) self.basename = os.path.splitext(spreadsheet)[0] self.basename = re.sub('[ -]+', '_', self.basename) self.wb = load_workbook(self.source, read_only=True) self.ws = self.wb.active self.ini = os.path.join(self.folder, self.basename + '.ini') self.macro = os.path.join(self.folder, self.basename + '_macro.py') self.measurements = list() #self.do_first_change = False #self.close_shutters = True if energy is True: self.do_first_change = True if self.ws['H5'].value.lower( ) == 'e0': # accommodate older xlsx files which have e0 values in column H self.has_e0_column = True self.do_first_change = self.truefalse(self.ws['G2'].value) self.close_shutters = self.truefalse(self.ws['J2'].value) self.append_element = str(self.ws['L2'].value) self.instrument = str(self.ws['B1'].value).lower() isok, explanation = self.read_spreadsheet() if isok is False: print(error_msg(explanation)) return None self.write_macro() return 0
def set_slot(self, n): '''Move to a numbered slot on a sample wheel.''' if type(n) is not int: print( error_msg( 'Slots numbers must be integers between 1 and 24 (argument was %s)' % type(n))) return (yield from null()) if n < 1 or n > 24: print(error_msg('Slots are numbered from 1 to 24')) return (yield from null()) angle = self.angle_from_current(n) yield from mvr(self, angle) report('Arrived at sample wheel slot %d' % n, level='bold')
def recover_diagnostics(): dm2_fs = user_ns['dm2_fs'] dm3_fs = user_ns['dm3_fs'] dm3_bct = user_ns['dm3_bct'] dm3_bpm = user_ns['dm3_bpm'] dm3_foils = user_ns['dm3_foils'] yield from mv(dm2_fs.home_signal, 1) yield from mv(dm3_fs.home_signal, 1) yield from mv(dm3_bct.home_signal, 1) yield from mv(dm3_bpm.home_signal, 1) yield from mv(dm3_foils.home_signal, 1) yield from sleep(1.0) print('Begin homing dm2_fs, dm3_fs, dm3_bct, dm3_bpm, and dm3_foils:\n') hvalues = (dm2_fs.hocpl.get(), dm3_fs.hocpl.get(), dm3_bct.hocpl.get(), dm3_bpm.hocpl.get(), dm3_foils.hocpl.get()) while any(v == 0 for v in hvalues): hvalues = (dm2_fs.hocpl.get(), dm3_fs.hocpl.get(), dm3_bct.hocpl.get(), dm3_bpm.hocpl.get(), dm3_foils.hocpl.get()) strings = ['dm2_fs', 'dm3_fs', 'dm3_bct', 'dm3_bpm', 'dm3_foils'] for i,v in enumerate(hvalues): strings[i] = go_msg(strings[i]) if hvalues[i] == 1 else error_msg(strings[i]) print(' '.join(strings), end='\r') yield from sleep(1.0) print('\n') #yield from mv(dm3_bct.kill_cmd, 1) yield from mv(dm3_foils.kill_cmd, 1) ## take these from Modes.xlsx, mode D -- all out of the beam path yield from mv(dm2_fs, 67, dm3_fs, 55, dm3_bct, 43.6565, dm3_bpm, 5.511, dm3_foils, 41)
def recover_mirrors(): m2_xu, m2_xd, m2_yu, m2_ydo, m2_ydi = user_ns['m2_xu'], user_ns['m2_xd'], user_ns['m2_yu'], user_ns['m2_ydo'], user_ns['m2_ydi'] m3_xu, m3_xd, m3_yu, m3_ydo, m3_ydi = user_ns['m3_xu'], user_ns['m3_xd'], user_ns['m3_yu'], user_ns['m3_ydo'], user_ns['m3_ydi'] yield from mv(m2_yu.home_signal, 1) yield from mv(m2_xu.home_signal, 1) yield from mv(m3_yu.home_signal, 1) yield from mv(m3_xu.home_signal, 1) yield from sleep(1.0) print('Begin homing lateral and vertical motors in M2 and M3:\n') hvalues = (m2_yu.hocpl.get(), m2_ydo.hocpl.get(), m2_ydi.hocpl.get(), m2_xu.hocpl.get(), m2_xd.hocpl.get(), m3_yu.hocpl.get(), m3_ydo.hocpl.get(), m3_ydi.hocpl.get(), m3_xu.hocpl.get(), m3_xd.hocpl.get()) while any(v == 0 for v in hvalues): hvalues = (m2_yu.hocpl.get(), m2_ydo.hocpl.get(), m2_ydi.hocpl.get(), m2_xu.hocpl.get(), m2_xd.hocpl.get(), m3_yu.hocpl.get(), m3_ydo.hocpl.get(), m3_ydi.hocpl.get(), m3_xu.hocpl.get(), m3_xd.hocpl.get()) strings = ['m2_yu', 'm2_ydo', 'm2_ydi', 'm2_xu', 'm2_xd', 'm3_yu', 'm3_ydo', 'm3_ydi', 'm3_xu', 'm3_xd',] for i,v in enumerate(hvalues): strings[i] = go_msg(strings[i]) if hvalues[i] == 1 else error_msg(strings[i]) print(' '.join(strings), end='\r') yield from sleep(1.0) print('\n') yield from mv(m2_yu, MODEDATA['m2_yu']['E'], m2_ydo, MODEDATA['m2_ydo']['E'], m2_ydi, MODEDATA['m2_ydi']['E'], m2_xu, MODEDATA['m2_xu']['E'], m2_xd, MODEDATA['m2_xd']['E'], m3_yu, MODEDATA['m3_yu']['E'], m3_ydo, MODEDATA['m3_ydo']['E'], m3_ydi, MODEDATA['m3_ydi']['E'], m3_xu, MODEDATA['m3_xu']['E'], m3_xd, MODEDATA['m3_xd']['E'])
def homed(): for m in mcs8_motors: if m.hocpl.get(): print("%-12s : %s" % (m.name, m.hocpl.enum_strs[m.hocpl.get()])) else: print("%-12s : %s" % (m.name, error_msg(m.hocpl.enum_strs[m.hocpl.get()])))
def verify_roi(self, xs, el, edge, tab=''): print(bold_msg(f'{tab}Attempting to set ROIs for {el} {edge} edge')) try: ## if el is not one of the "standard" 12 ROI sets, insert it into xs.slots[12]/index 13 if xs.check_element(el, edge): forceit = False if el.capitalize() in ('Pb', 'Pt') and edge.capitalize() in ('L2', 'L1'): forceit = True # Pb and Pt L3 edges are "standard" ROIs if el not in xs.slots or forceit: with open(os.path.join(startup_dir, 'rois.json'), 'r') as fl: js = fl.read() allrois = json.loads(js) xs.slots[14] = el for channel in xs.iterate_channels(): xs.set_roi_channel( channel, index=15, name=f'{el.capitalize()}', low=allrois[el.capitalize()][edge.lower()]['low'], high=allrois[el.capitalize()][ edge.lower()]['high']) xs.set_rois() xs.measure_roi() else: report( f'{tab}No tabulated ROIs for the {el.capitalize()} {edge.capitalize()} edge. Not setting ROIs for mesaurement.', level='bold', slack=True) xs.reset_rois(tab=tab) except Exception as E: print(error_msg(E))
def do_AdjustSlits(self): print( go_msg( 'You would like to adjust the size of the hutch slits...\n')) which = input(" Horizontal or vertical? [H/v] ") which = which.lower() if which.startswith('h') or which == '': size = input(' Horizontal size (in mm): ') is_horiz = True elif which.startswith('v'): size = input(' Vertical size (in mm): ') is_horiz = False else: self.do_nothing() return try: size = float(size) except: print(error_msg(f'\n "{size}" cannot be interpreted as a number')) yield from null() return if is_horiz: #print(disconnected_msg(f'yield from mv(slits3.hsize, {size})')) #yield from null() yield from mv(user_ns['slits3'].hsize, size) else: #print(disconnected_msg(f'yield from mv(slits3.vsize, {size})')) #yield from null() yield from mv(user_ns['slits3'].vsize, size)
def do_ChangeEdge(self): print(go_msg('You would like to change to a different edge...\n')) el = input(" What element? ") el = el.capitalize() if el == '': print(whisper('doing nothing')) return (yield from null()) if el not in ELEMENTS: print(error_msg(f'{el} is not an element')) return (yield from null()) if Z_number(el) < 46: default_ed = 'K' prompt = go_msg('K') + '/L3/L2/L1' else: default_ed = 'L3' prompt = 'K/' + go_msg('L3') + '/L2/L1' ed = input(f' What edge? [{prompt}] ') ed = ed.capitalize() if ed not in ('K', 'L3', 'L2', 'L1'): ed = default_ed focus = input(' Focused beam? [y/N] ') if focus.lower() == 'y': focus = True else: focus = False print( disconnected_msg( f'yield from change_edge("{el}", focus={focus}, edge="{ed}")')) yield from null()
def set(self, elements): '''Configure the ROI channels so that an energy change knows which channel to use. Parameters ---------- elements : list of str a list of 3 elements, top to bottom in the SCAs if the list is a space separated string, it will be split into a list ''' if type(elements) is str: elements = elements.split() if len(elements) != 3: self.myprint(error_msg('\nThe list of rois must have three elements\n')) return() for i in range(3): self.set_roi(i+1, elements[i]) vor, BMMuser = user_ns['vor'], user_ns['BMMuser'] vor.channel_names(*elements) BMMuser.rois = elements self.myprint(self.show()) ######################################################## # save the ROI configuration to the user serialization # ######################################################## jsonfile = os.path.join(os.environ['HOME'], 'Data', '.user.json') if os.path.isfile(jsonfile): user = dict() if os.path.isfile(jsonfile): user = json.load(open(jsonfile)) user['rois'] = ' '.join(map(str, elements)) os.chmod(jsonfile, 0o644) with open(jsonfile, 'w') as outfile: json.dump(user, outfile) os.chmod(jsonfile, 0o444)
def status(self): text = f'\nCurrent temperature = {self.readback.get():.1f}, setpoint = {self.setpoint.get():.1f}\n\n' code = int(self.status_code.get()) if code & 1: text += error_msg('Error : yes') + '\n' else: text += 'Error : no\n' if code & 2: text += go_msg('At setpoint : yes') + '\n' else: text += 'At setpoint : no\n' if code & 4: text += go_msg('Heater : on') + '\n' else: text += 'Heater : off\n' if code & 8: text += go_msg('Pump : on') + '\n' else: text += 'Pump : off\n' if code & 16: text += go_msg('Pump Auto : yes') + '\n' else: text += 'Pump Auto : no\n' boxedtext(f'Linkam {self.model}, stage {self.stage_model}', text, 'brown', width = 45)
def pds_motors_ready(): m3, m2, m2_bender, dm3_bct = user_ns['m3'], user_ns['m2'], user_ns[ 'm2_bender'], user_ns['dm3_bct'] dcm_pitch, dcm_roll, dcm_perp, dcm_roll, dcm_bragg = user_ns[ "dcm_pitch"], user_ns["dcm_roll"], user_ns["dcm_perp"], user_ns[ "dcm_roll"], user_ns["dcm_bragg"] mcs8_motors = [ m3.xu, m3.xd, m3.yu, m3.ydo, m3.ydi, m2.xu, m2.xd, m2.yu, m2.ydo, m2.ydi, m2_bender, dcm_pitch, dcm_roll, dcm_perp, dcm_roll, dcm_bragg, dm3_bct ] count = 0 for m in mcs8_motors: if m.amfe.get() or m.amfae.get(): print( error_msg("%-12s : %s / %s" % (m.name, m.amfe.enum_strs[m.amfe.get()], m.amfae.enum_strs[m.amfae.get()]))) count += 1 else: pass if count > 0: return (False) else: return (True)
def ls2dat(datafile, key): ''' Export a linescan database entry to a simple column data file. ls2dat('/path/to/myfile.dat', '0783ac3a-658b-44b0-bba5-ed4e0c4e7216') or ls2dat('/path/to/myfile.dat', 1533) The arguments are a data file name and the database key. ''' #BMMuser, db = user_ns['BMMuser'], user_ns['db'] if os.path.isfile(datafile): print(error_msg('%s already exists! Bailing out....' % datafile)) return handle = open(datafile, 'w') dataframe = user_ns['db'][key] devices = dataframe.devices() # note: this is a _set_ (this is helpful: https://snakify.org/en/lessons/sets/) if 'vor' in devices: abscissa = dataframe['start']['motors'][0] column_list = [abscissa, 'I0', 'It', 'Ir', BMMuser.dtc1, BMMuser.dtc2, BMMuser.dtc3, BMMuser.dtc4, BMMuser.roi1, 'ICR1', 'OCR1', BMMuser.roi2, 'ICR2', 'OCR2', BMMuser.roi3, 'ICR3', 'OCR3', BMMuser.roi4, 'ICR4', 'OCR4'] template = " %.3f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f\n" elif 'DualI0' in devices: abscissa = dataframe['start']['motors'][0] column_list = [abscissa, 'Ia', 'Ib',] template = " %.3f %.6f %.6f\n" else: abscissa = dataframe['start']['motors'][0] template = " %.3f %.6f %.6f %.6f\n" column_list = [abscissa, 'I0', 'It', 'Ir'] #print(column_list) table = dataframe.table() this = table.loc[:,column_list] handle.write('# XDI/1.0 BlueSky/%s\n' % bluesky_version) handle.write('# Scan.uid: %s\n' % dataframe['start']['uid']) handle.write('# Scan.transient_id: %d\n' % dataframe['start']['scan_id']) try: handle.write('# Facility.GUP: %s\n' % dataframe['start']['XDI']['Facility']['GUP']) except: pass try: handle.write('# Facility.SAF: %s\n' % dataframe['start']['XDI']['Facility']['SAF']) except: pass handle.write('# ==========================================================\n') handle.write('# ' + ' '.join(column_list) + '\n') for i in range(0,len(this)): handle.write(template % tuple(this.iloc[i])) handle.flush() handle.close() print(bold_msg('wrote linescan to %s' % datafile))
def _pressure(self): if self.pressure.get() == 'OFF': return (disconnected_msg(-1.1e-15)) if float(self.pressure.get()) > 1e-1: return warning_msg(self.pressure.get()) if float(self.pressure.get()) > 6e-3: return error_msg(self.pressure.get()) return (self.pressure.get())
def show_shutters(): ena_text = ' Beamline: ' try: if bl_enabled.get() == 1: ena_text += 'enabled ' else: ena_text += error_msg('disabled ') except: ena_text += whisper('unavailable ') bmps_text = ' BMPS: ' try: bmps_state = bool(bmps.state.get()) if bmps_state is True: bmps_text += 'open' else: bmps_text += error_msg('closed') except: bmps_text += whisper('unavailable ') idps_text = ' IDPS: ' try: idps_state = bool(idps.state.get()) if idps_state is True: idps_text += 'open' else: idps_text += error_msg('closed') except: idps_text += whisper('unavailable ') # sha_state = bool(sha.enabled.get()) and bool(sha.state.get()) # sha_text = ' FOE Shutter: ' # if sha_state is True: # sha_text += 'open' # else: # sha_text += error_msg('closed') shb_state = bool(shb.state.get()) shb_text = ' Photon Shutter: ' if shb_state is False: shb_text += 'open' else: shb_text += error_msg('closed') return (ena_text + bmps_text + idps_text + shb_text)
def main_plan(start, stop, nsteps, move, slp, force): (ok, text) = BMM_clear_to_start() if force is False and ok is False: print(error_msg(text)) yield from null() return user_ns['RE'].msg_hook = None BMMuser.motor = dm3_bct func = lambda doc: (doc['data'][motor.name], doc['data']['I0']) plot = DerivedPlot(func, xlabel=motor.name, ylabel='I0', title='I0 signal vs. slit height') line1 = '%s, %s, %.3f, %.3f, %d -- starting at %.3f\n' % \ (motor.name, 'i0', start, stop, nsteps, motor.user_readback.get()) rkvs.set('BMM:scan:type', 'line') rkvs.set('BMM:scan:starttime', str(datetime.datetime.timestamp(datetime.datetime.now()))) rkvs.set('BMM:scan:estimated', 0) @subs_decorator(plot) #@subs_decorator(src.callback) def scan_slit(slp): #if slit_height < 0.5: # yield from mv(slits3.vsize, 0.5) yield from mv(quadem1.averaging_time, 0.1) yield from mv(motor.velocity, 0.4) yield from mv(motor.kill_cmd, 1) uid = yield from rel_scan([quadem1], motor, start, stop, nsteps, md={'plan_name' : f'rel_scan linescan {motor.name} I0'}) user_ns['RE'].msg_hook = BMM_msg_hook BMM_log_info('slit height scan: %s\tuid = %s, scan_id = %d' % (line1, uid, user_ns['db'][-1].start['scan_id'])) if move: t = user_ns['db'][-1].table() signal = t['I0'] #if get_mode() in ('A', 'B', 'C'): # position = com(signal) #else: position = peak(signal) top = t[motor.name][position] yield from sleep(slp) yield from mv(motor.kill_cmd, 1) yield from sleep(slp) yield from mv(motor, top) else: action = input('\n' + bold_msg('Pluck motor position from the plot? [Y/n then Enter] ')) if action.lower() == 'n' or action.lower() == 'q': return(yield from null()) yield from sleep(slp) yield from mv(motor.kill_cmd, 1) #yield from mv(motor.inpos, 1) yield from sleep(slp) yield from move_after_scan(motor) yield from mv(quadem1.averaging_time, 0.5) yield from scan_slit(slp)
def initialize_redis(): '''Check to see if a successful response can be obtained from a redis server. If not, complain on screen. ''' if rkvs.get(REDISVAR) is not None: print(f'{TAB}Found Redis server: {CHECK}') else: print(error_msg(f'{TAB}Did not find redis server'))
def _state(self, info=False): t = "%.1f" % self.temperature.get() if self.temperature.get() > self.alarm.get(): return(error_msg(t)) if self.temperature.get() > self.warning.get(): return(warning_msg(t)) if info is True and self.temperature.get() > (0.5 * self.warning.get()): return(info_msg(t)) return(t)
def initialize_nas(): '''Check if a the NAS1 mount point is mounted. If not, complain on screen. ''' if os.path.ismount(NAS): print(f'{TAB}Found NAS1 mount point: {CHECK}') else: print(error_msg(f'{TAB}NAS1 is not mounted!'))
def off(self, number=None): '''Turn off the specified spinner''' if number is None: self.alloff() return if not self.valid(number): print(error_msg('The fans are numbered from 1 to 8')) return this = getattr(self, f'spinner{number}') this.put(0)
def _current(self): curr = float(self.current.get()) if curr > 2e-3: out = '%.1f' % (1e3 * curr) return (error_msg(out)) if curr > 5e-4: out = '%.1f' % (1e3 * curr) return (warning_msg(out)) out = '%.1f' % (1e6 * curr) return (out)
def check(self, mc): '''Verify the string identifying the motor controller. Identify the motor controller by these strings: 'dcm', 'slits2', 'm2', 'm3', 'dm3' ''' if mc is None: print( error_msg( "Specify a device: ks.kill(device), device is dcm/slits2/m2/m3/dm3" )) return False if mc.lower() not in ('dcm', 'slits2', 'm2', 'm3', 'dm3'): print( error_msg( "Specify a device: ks.kill(device), device is dcm/slits2/m2/m3/dm3" )) return False return True
def on(self, number): '''Turn on the specified spinner''' if self.spin is False: print(warning_msg('The spinners are currently disabled. do "ga.spin = True" to re-enable.')) return if not self.valid(number): print(error_msg('The fans are numbered from 1 to 8')) return this = getattr(self, f'spinner{number}') this.put(1)
def _pressure(self): #print(self.pressure.get()) #print(type(self.pressure.get())) if self.pressure.get() == 'OFF': return (disconnected_msg(-1.1E-15)) if float(self.pressure.get()) > 1e-6: return error_msg(self.pressure.get()) if float(self.pressure.get()) > 1e-8: return warning_msg(self.pressure.get()) return (self.pressure.get())
def angle_from_current(self, n): '''Return the angle from the current position to the target''' if type(n) is not int: print( error_msg( 'Slots numbers must be integers between 1 and 24 (argument was %s)' % type(n))) return (0) if n < 1 or n > 24: print(error_msg('Slots are numbered from 1 to 24')) return (0) current = self.current_slot() distance = n - current if distance > 12: distance = distance - 24 elif distance < -12: distance = 24 + distance angle = -15 * distance return angle
def _current(self): if self.connected is False: return(disconnected_msg('?????')) curr = float(self.current.get()) if curr > 2e-3: out = '%.1f' % (1e3*curr) return(error_msg(out)) if curr > 5e-4: out = '%.1f' % (1e3*curr) return(warning_msg(out)) out = '%.1f' % (1e6*curr) return(out)
def recover(self): '''Home and re-position all DCM motors after a power interruption. ''' user_ns['dcm_bragg'].acceleration.put(BMMuser.acc_fast) user_ns['dcm_para'].velocity.put(0.6) user_ns['dcm_para'].hvel_sp.put(0.4) user_ns['dcm_perp'].velocity.put(0.2) user_ns['dcm_perp'].hvel_sp.put(0.2) user_ns['dcm_x'].velocity.put(0.6) ## initiate homing for Bragg, pitch, roll, para, perp, and x yield from mv(user_ns['dcm_bragg'].home_signal, 1) yield from mv(user_ns['dcm_pitch'].home_signal, 1) yield from mv(user_ns['dcm_roll'].home_signal, 1) yield from mv(user_ns['dcm_para'].home_signal, 1) yield from mv(user_ns['dcm_perp'].home_signal, 1) yield from mv(user_ns['dcm_x'].home_signal, 1) yield from sleep(1.0) ## wait for them to be homed print('Begin homing DCM motors:\n') hvalues = (user_ns['dcm_bragg'].hocpl.get(), user_ns['dcm_pitch'].hocpl.get(), user_ns['dcm_roll'].hocpl.get(), user_ns['dcm_para'].hocpl.get(), user_ns['dcm_perp'].hocpl.get(), user_ns['dcm_x'].hocpl.get()) while any(v == 0 for v in hvalues): hvalues = (user_ns['dcm_bragg'].hocpl.get(), user_ns['dcm_pitch'].hocpl.get(), user_ns['dcm_roll'].hocpl.get(), user_ns['dcm_para'].hocpl.get(), user_ns['dcm_perp'].hocpl.get(), user_ns['dcm_x'].hocpl.get()) strings = ['Bragg', 'pitch', 'roll', 'para', 'perp', 'x'] for i, v in enumerate(hvalues): strings[i] = go_msg( strings[i]) if hvalues[i] == 1 else error_msg(strings[i]) print(' '.join(strings), end='\r') yield from sleep(1.0) ## move x into the correct position for Si(111) print('\n') yield from mv(user_ns['dcm_x'], 1) yield from mv(user_ns['dcm_x'], 0.3) ## move pitch and roll to the Si(111) positions this_energy = self.energy.readback.get() yield from self.kill_plan() yield from mv(user_ns['dcm_pitch'], approximate_pitch(this_energy), user_ns['dcm_roll'], -6.26) yield from mv(self.energy, this_energy) print('DCM is at %.1f eV. There should be signal in I0.' % dcm.energy.readback.get()) yield from sleep(2.0) yield from self.kill_plan()