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 set_rois(self): '''Read ROI values from a JSON serialization on disk and set all 16 ROIs for channels 1-4. ''' with open(os.path.join(startup_dir, 'rois.json'), 'r') as fl: js = fl.read() allrois = json.loads(js) for i, el in enumerate(self.slots): if el == 'OCR': for channel in self.iterate_channels(): mcaroi = channel.get_mcaroi(mcaroi_number=i + 1) self.set_roi(mcaroi, name='OCR', min_x=allrois['OCR']['low'], size_x=allrois['OCR']['high'] - allrois['OCR']['low']) continue elif el is None: continue edge = 'k' if Z_number(el) > 45: edge = 'l3' if el == user_ns['BMMuser'].element: edge = user_ns['BMMuser'].edge.lower() for channel in self.iterate_channels(): mcaroi = channel.get_mcaroi(mcaroi_number=i + 1) #print(f"element: {el} edge: {edge} mcaroi number: {mcaroi.mcaroi_number} ") self.set_roi(mcaroi, name=f'{el.capitalize()}{channel.channel_number}', min_x=allrois[el][edge]['low'], size_x=allrois[el][edge]['high'] - allrois[el][edge]['low'])
def set_rois(self): '''Read ROI values from a JSON serialization on disk and set all 16 ROIs for channel8. ''' startup_dir = get_ipython().profile_dir.startup_dir with open(os.path.join(startup_dir, 'rois.json'), 'r') as fl: js = fl.read() allrois = json.loads(js) for i, el in enumerate(self.slots): if el == 'OCR': self.set_roi_channel(channel=8, index=i + 1, name='OCR', low=allrois['OCR']['low'], high=allrois['OCR']['high']) continue elif el is None: continue edge = 'k' if Z_number(el) > 46: edge = 'l3' self.set_roi_channel(channel=8, index=i + 1, name=f'{el.capitalize()}8', low=allrois[el][edge]['low'], high=allrois[el][edge]['high'])
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_roi(self, i, el): '''Configure an ROI channel i ∈ (1 .. 3) for element el''' if Z_number(el) is None: self.slots[i - 1] = None else: self.slots[i - 1] = element_symbol(el) BMM_log_info('Set ROI channel %d to %s' % (i, str(self.slots[i - 1])))
def move(self, el): '''Move to the slot configured for element el''' if type(el) is int: if el < 1 or el > 5: print(error_msg('\n%d is not a valid foil slot\n' % el)) return (yield from null()) el = self.slots[el - 1] if el is None: print(error_msg('\nThat slot is empty\n')) return (yield from null()) el = el.capitalize() if Z_number(el) is None: print(error_msg('\n%s is not an element\n' % el)) return (yield from null()) moved = False for i in range(5): if element_symbol(el) == self.slots[i]: yield from mv(xafs_linxs, self.position(i)) report('Moved xafs_linxs to %s at slot %d' % (el.capitalize(), i + 1)) moved = True if not moved: print( warning_msg( '%s is not in the reference holder, not moving xafs_linxs' % el.capitalize())) yield from null()
def set_slot(self, i, el): '''Configure a slot i ∈ (0 .. 4) for element el''' if Z_number(el) is None: self.slots[i - 1] = None else: self.slots[i - 1] = element_symbol(el) BMM_log_info('Set reference slot %d to %s' % (i, str(self.slots[i - 1])))
def element_text(self): if Z_number(self.element) is None: return '' else: thistext = f'{self.element} ' thistext += f'(<a href="https://en.wikipedia.org/wiki/{element_name(self.element)}">' thistext += f'{element_name(self.element)}</a>, ' thistext += f'{Z_number(self.element)})' return thistext
def overhead_per_point(self, element, edge=None): a = json.load(open(self.json)) element = element_symbol(element) if edge is not None and edge.lower() in ('l2', 'l1'): return ([self.interpolate(edge_energy(element, edge)), 0]) if element in a and 'dpp' in a[element]: return (a[element]['dpp']) else: if edge is None or edge.lower() not in ('l2', 'l1'): edge = 'k' if Z_number(element) > 45: edge = 'l3' return ([self.interpolate(edge_energy(element, edge)), 0])