def step_xia_scan(motor, filename, energy_grid, integration_times=np.array([])): """ Example ------- >>> TODO """ xia1_chan1_array = [] xia1_chan2_array = [] xia1_chan3_array = [] xia1_chan4_array = [] i0_array = [] if (len(integration_times)) == 0: integration_times = np.ones(len(energy_grid)) * xia1.real_time.value #energy_grid = np.arange(7112 - 50, 7112 + 50, 1)#get_xia_energy_grid(energy_start, e0, edge_start, edge_end, energy_end, preedge_spacing, xanes, exafsk) pba1.adc7.filepath.put('') pba1.adc7.enable_sel.put(0) xia1.collect_mode.put(0) while (xia1.collect_mode.value != 0): ttime.sleep(.01) for i in range(len(energy_grid)): print("[{}/{}]".format(i + 1, len(energy_grid))) if (xia1.real_time.value != integration_times[i]): xia1.real_time.put(integration_times[i]) ttime.sleep(.005) motor.move(xray.energy2encoder(energy_grid[i]) / 360000) while (np.abs(motor.read()['hhm_theta']['value'] - motor.read()['hhm_theta_user_setpoint']['value']) > 0.00001 or motor.moving == True): ttime.sleep(.005) xia1.erase_start.put(1) ttime.sleep(.1) while (xia1.acquiring.value): ttime.sleep(.005) ttime.sleep(.1) i0_array.append([energy_grid[i], pba1.adc7.volt.value]) xia1_chan1_array.append(xia1.mca_array1.value) xia1_chan2_array.append(xia1.mca_array2.value) xia1_chan3_array.append(xia1.mca_array3.value) xia1_chan4_array.append(xia1.mca_array4.value) pba1.adc7.enable_sel.put(1) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-i0', np.array(i0_array)) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-1', np.array(xia1_chan1_array)) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-2', np.array(xia1_chan2_array)) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-3', np.array(xia1_chan3_array)) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-4', np.array(xia1_chan4_array))
def calibrate_offset(self): ret = self.questionMessage( 'Confirmation', 'Are you sure you would like to calibrate it?') if not ret: print('[E0 Calibration] Aborted!') return False new_value = str( self.hhm.angle_offset.value - (xray.energy2encoder(float(self.edit_E0_2.text( )), self.hhm.pulses_per_deg) - xray.energy2encoder( float(self.edit_ECal.text()), self.hhm.pulses_per_deg)) / self.hhm.pulses_per_deg) if self.set_new_angle_offset(new_value): return print('[E0 Calibration] New value: {}\n[E0 Calibration] Completed!'. format(new_value))
def calibrate_offset(self): ret = question_message_box( self, 'Confirmation', 'Are you sure you would like to calibrate it?') if not ret: print('[E0 Calibration] Aborted!') return False new_value = str( self.hhm.angle_offset.value - (xray.energy2encoder(float(self.edit_E0.text( )), self.hhm.pulses_per_deg) - xray.energy2encoder( float(self.edit_ECal.text()), self.hhm.pulses_per_deg)) / self.hhm.pulses_per_deg) if self.set_new_angle_offset(new_value): return print('[E0 Calibration] New value: {}\n[E0 Calibration] Completed!'. format(new_value)) message_box( 'Reload trajectory', 'Switch to Trajectory tab and re-load and re-initialize the trajectory' )
def step_xia_scan(motor, filename, energy_grid, integration_times = np.array([])): """ Example ------- >>> TODO """ xia1_chan1_array = [] xia1_chan2_array = [] xia1_chan3_array = [] xia1_chan4_array = [] i0_array = [] if(len(integration_times)) == 0: integration_times = np.ones(len(energy_grid)) * xia1.real_time.value #energy_grid = np.arange(7112 - 50, 7112 + 50, 1)#get_xia_energy_grid(energy_start, e0, edge_start, edge_end, energy_end, preedge_spacing, xanes, exafsk) pba1.adc7.filepath.put('') pba1.adc7.enable_sel.put(0) xia1.collect_mode.put(0) while(xia1.collect_mode.value != 0): ttime.sleep(.01) for i in range(len(energy_grid)): print("[{}/{}]".format(i + 1, len(energy_grid))) if(xia1.real_time.value != integration_times[i]): xia1.real_time.put(integration_times[i]) ttime.sleep(.005) motor.move(xray.energy2encoder(energy_grid[i])/360000) while(np.abs(motor.read()['hhm_theta']['value'] - motor.read()['hhm_theta_user_setpoint']['value']) > 0.00001 or motor.moving == True): ttime.sleep(.005) xia1.erase_start.put(1) ttime.sleep(.1) while(xia1.acquiring.value): ttime.sleep(.005) ttime.sleep(.1) i0_array.append([energy_grid[i], pba1.adc7.volt.value]) xia1_chan1_array.append(xia1.mca_array1.value) xia1_chan2_array.append(xia1.mca_array2.value) xia1_chan3_array.append(xia1.mca_array3.value) xia1_chan4_array.append(xia1.mca_array4.value) pba1.adc7.enable_sel.put(1) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-i0', np.array(i0_array)) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-1', np.array(xia1_chan1_array)) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-2', np.array(xia1_chan2_array)) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-3', np.array(xia1_chan3_array)) np.savetxt('/GPFS/xf08id/xia_files/' + filename + '-4', np.array(xia1_chan4_array))
def e2encoder(self, offset): self.encoder_grid = -xray.energy2encoder(self.energy_grid, offset)
def load(self, orig_file_name, new_file_path, is_energy, offset, new_file_name='hhm.txt'): ip = self.hhm.ip orig_file_path = self.hhm.traj_filepath print('[Load Trajectory] Starting...') traj_fn = orig_file_name # Check if new_file_path is between the possible values if int(new_file_path) > 9 or int(new_file_path) < 1: print( "[Load Trajectory] Path '{}' not possible. Please use a value in the range 1 <= new_file_path <= 9." .format(new_file_path)) return False # Get number of lines in file file_size = self.file_len(orig_file_path + orig_file_name) print( '[Load Trajectory] Number of lines in file: {}'.format(file_size)) # Get min and max of trajectory in eV if orig_file_path[-1] != '/': fp += '/' traj = pd.read_table('{}{}'.format(orig_file_path, orig_file_name), header=None, comment='#') name = orig_file_name header = self.read_header('{}{}'.format(orig_file_path, orig_file_name)) if is_energy: min_energy = int(np.round(traj).min()) max_energy = int(np.round(traj).max()) enc = np.int64( np.round( xray.energy2encoder(-traj, self.hhm.pulses_per_deg, -offset))) orig_file_name = '.energy_traj_aux.txt' np.savetxt('{}{}'.format(orig_file_path, orig_file_name), enc, fmt='%d', header=header, comments='') else: min_energy = int( xray.encoder2energy((-traj, self.hhm.pulses_per_deg).min())) max_energy = int( xray.encoder2energy((-traj, self.hhm.pulses_per_deg).max())) print('[Load Trajectory] Min energy: {}'.format(min_energy)) print('[Load Trajectory] Max energy: {}'.format(max_energy)) # Create ftp connection with default credential ftp = FTP(ip) ftp.login() s = pxssh.pxssh() ssh_login = s.login(ip, 'root', 'deltatau') if ssh_login: # Check if the directory exists in /usrflash/lut/. If it does not, create it. if str(new_file_path) != '': ftp.cwd('/usrflash/') dir_list = ftp.nlst() dir_exists = 0 for dir_name in dir_list: if dir_name == 'lut': dir_exists = 1 if not dir_exists: print('[Load Trajectory] mkdir: /usrflash/lut') ftp.mkd('/usrflash/lut') s.sendline('chown ftp:root /var/ftp/usrflash/lut') s.sendline('chmod a+wrx /var/ftp/usrflash/lut') ftp.cwd('/usrflash/lut/') dir_list = ftp.nlst() dir_exists = 0 for dir_name in dir_list: if dir_name == str(new_file_path): dir_exists = 1 if not dir_exists: print('[Load Trajectory] mkdir: /usrflash/lut/{}'.format( new_file_path)) ftp.mkd('/usrflash/lut/{}'.format(new_file_path)) s.sendline( 'chown ftp:root /var/ftp/usrflash/lut/{}'.format( new_file_path)) s.sendline('chmod a+wrx /var/ftp/usrflash/lut/{}'.format( new_file_path)) s.sendline( 'chown ftp:root /var/ftp/usrflash/lut/{}/hhm.txt'.format( new_file_path)) s.sendline('chmod 777 /var/ftp/usrflash/lut/{}/hhm.txt'.format( new_file_path)) ftp_file_path = '/var/ftp/usrflash/lut/{}/{}'.format( new_file_path, new_file_name) # Open file and transfer to the power pmac f = open(orig_file_path + str(orig_file_name), 'rb') if (f.readable()): line = f.readline().decode('utf-8') if line[0] == '#': element = line[line.find('element:') + 9:line.find(',')].lstrip() edge_value = line[line.find('edge:') + 6:line. find(',', line.find('edge:'))].lstrip() e0_value = line[line.find('E0:') + 4:].lstrip() curr_hhm_traj = getattr(self.hhm, 'traj{}'.format(new_file_path)) curr_hhm_traj.filename.put(traj_fn) curr_hhm_traj.elem.put(element) curr_hhm_traj.edge.put(edge_value) curr_hhm_traj.e0.put(e0_value) else: curr_hhm_traj = getattr(self.hhm, 'traj{}'.format(new_file_path)) curr_hhm_traj.filename.put(traj_fn) curr_hhm_traj.elem.put('') curr_hhm_traj.edge.put('') curr_hhm_traj.e0.put('') f.close() f = open(orig_file_path + str(orig_file_name), 'rb') result = ftp.storbinary( 'STOR ' + '/usrflash/lut/' + str(new_file_path) + '/' + new_file_name, f) if (result == '226 File receive OK.'): print('[Load Trajectory] File sent OK') s.sendline( 'chown ftp:root /var/ftp/usrflash/lut/{}/{}'.format( new_file_path, new_file_name)) s.sendline( 'chmod a+wrx /var/ftp/usrflash/lut/{}/{}'.format( new_file_path, new_file_name)) s.sendline( 'echo "{}\n{}\n{}\n{}" > /var/ftp/usrflash/lut/{}/hhm-size.txt' .format(file_size, name, min_energy, max_energy, new_file_path)) ttime.sleep(0.01) ftp.close() print('[Load Trajectory] Permissions OK') f.close() s.logout() s.pid = None print('[Load Trajectory] Completed!') else: print( '[Load Trajectory] Fail! Not able to ssh into the controller...' )
def e2encoder(self, offset): self.encoder_grid = -xray.energy2encoder( self.energy_grid, self.hhm.pulses_per_deg, offset)