Skip to content
Snippets Groups Projects
pyDevSBL.py 2.11 KiB
Newer Older
mwyman's avatar
mwyman committed
import numpy as np
import os

IMAGE = False

class surrogateBL():
    
    def __init__(self, beamline):
        '''
        beamline : Shadow-based beamline
        '''
           
        #create necessary inputs/output; initialize to zero/empty
        print(80*'#')
        print('Initializing pyDevice surrogate beamline object')
        self.beamline = beamline
        print(80*'#')
mwyman's avatar
mwyman committed
        self.motorPositions = []
        self.verbose = 1   
mwyman's avatar
mwyman committed

    def setupMotorLimits(self, subsFile):
        '''
        Go through shadow beamline and get DOF limits and set them as the motor
        limits
        
        Don't have a good way to do this; will manually update simulated motor
        substitutions file with limits
        '''
        pass
        
       
    def elementUpdate(self, element, dof, position):
mwyman's avatar
mwyman committed
        '''
        Update element position array but do not trigger detector
        '''
        if self.verbose: print(f'Setting element {element}, DOF {dof} to {position}')
        self.beamline.pos[element, dof]=position
        if self.verbose: print(f'Setting complete')
mwyman's avatar
mwyman committed
     
        
    def detectorUpdate(self):
mwyman's avatar
mwyman committed
        '''
        Update detector(s)
        '''
        
        # Update optical element positions
        if self.verbose: print(f'Adjusting OE settings ')
        self.beamline.adjust() 
        if self.verbose: print(f'Adjusting OE settings complete')
        
        # Trigger ray tracing
        if self.verbose: print(f'Running Shadow simulation')        
mwyman's avatar
mwyman committed
        results = self.beamline.run() 
mwyman's avatar
mwyman committed
        if self.verbose: 
            print(f'Run complete')
            print(f'Results: {results}')
            
        pydev.iointr('new_intensity', int(results))     
             
        if IMAGE:
            image_data = np.zeros(128,128) # need to add screen to shadow simulation
            flattened_data = image_date.flatten() # need to flatten for waveform
            pydev.iointr('raw_image', flattened_data)
mwyman's avatar
mwyman committed
        
    def updateVerbosity(self, verbosity):
        '''
        Turn on minor printing
        '''
        print(f'Verbosity set to {verbosity}')
        self.verbose = verbosity