Esempio n. 1
0
def get_current_state():
    """Save current pd_savepath, specfilename, and scan number to
    restore the current state after callibration
    
    Returns:
        pd_savepath -- Current PD Savepath
        filename -- Current SPEC filename
        scan_n -- Current SPEC scan number
    """
    
    print('Saving current state..\n')
    
    command = "print PD_SAVEPATH ' ' DATAFILE  ' ' SCAN_N"
    specCommand(command, queue=True)
    wait_until_SPECfinished()
    
    while 1:
        try:
            out = get_console_output(idx=1)[0]
            break
        except:
            pass
        
    pd_savepath, filename, scan_n = out.split(' ')
    return pd_savepath, filename, scan_n
Esempio n. 2
0
def restore_state(saved_state):
    """Restore saved pd_savepath, specfilename, and scan number
    
    args:
        saved_state: Tuple containing pd_savepath, specfilename and scan number
    """
    
    pd_savepath, filename, scan_n = saved_state
    
    command = f'pd savepath {pd_savepath}; newfile_f("{filename}", {scan_n})'
    specCommand(command, queue=True)
    
    print('Saved state restored\n')
Esempio n. 3
0
    def send_command(self):
        """Sends command in command line to spec, and calls
        commandLine send_command method to add command to list of
        commands.
        """
        command = self.specCommandLine.text()
        if not (command.isspace() or command == ''):
            try:
                specCommand(command, queue=True)
            except Exception as e:
                print(e)
                print(f"Command '{command}' not sent")

        commandLine.send_command(self.specCommandLine)
Esempio n. 4
0
def set_PD_savepath(img_path):
    """Change PD Savepath to img_path
    
    args:
        img_path: New PD savepath
    """

    print(f'Changing PD SavePath to {img_path}')
    command = f'pd savepath {img_path}'
    try:
        specCommand(command, queue=True)
    except Exception as e:
        print(e)
        print(f"Command '{command}' not sent")
        sys.exit()
Esempio n. 5
0
def create_SPEC_file(path):
    """Create new calibration spec file with date time stamp"""
    
    timestr = time.strftime("%Y%m%d-%H%M%S")
    calibScan = f'calib_{timestr}'

    print(f'Creating new SPEC file {calibScan} for calibration scan in {path}..')
    command = f'newfile {path}/{calibScan}'
    try:
        specCommand(command, queue=True)
    except Exception as e:
        print(e)
        print(f"Command '{command}' not sent")
        sys.exit()    
        
    return calibScan
Esempio n. 6
0
def create_remote_paths(scan_path, img_path):
    """Create folders on SPEC machine to store calibration scan and images if they don't exist"""
    
    command = f'u mkdir {scan_path}'
    try:
        specCommand(command, queue=True)
    except Exception as e:
        print(e)
        print(f"Command '{command}' not sent")
        sys.exit()    

    # Create images folder on SPEC machine if it doesn't exist
    command = f'u mkdir {img_path}'
    try:
        specCommand(command, queue=True)
    except Exception as e:
        print(e)
        print(f"Command '{command}' not sent")
        sys.exit()    
Esempio n. 7
0
def run_direct_beam_scan(tth, steps):
    """Function to run direct beam scan to calibrate

    Arguments:
        tth {float} -- maximum 2th value to scan. Scan is performed from -tth to +tth
        steps {int} -- number of steps
    """
    command = f'ascan  tth -{tth} {tth} {steps} 1'
    print(f'Running direct beam scan [{command}]')
    try:
        specCommand(command, queue=True)
    except Exception as e:
        print(e)
        print(f"Command '{command}' not sent")
        sys.exit()
        
    # Wait till Scan is finished to continue
    print('Waiting for scan to finish..')
    wait_until_SPECfinished(polling_time=5)
    time.sleep(5)
    print('Done', '\n')