Esempio n. 1
0
def expose_fpc_dataset(datasetID, dirLocal, expno, exptime):
    '''
    it takes a dataset to create each master image. the dataset is taken when
    nothing is moving.
     
    each dataset is saved in dirLocal/datasetID/. datasetID should increase by
    1 for each pos movement.
    
    expno is the number of exposures in each sequence
    
    exptime is used for dark and object frames
    '''

    datasetDirLocal = os.path.join(dirLocal, datasetID)
    expidini = 1  # initial value for exposure id

    #role1 = 'ILLUMINATOR'
    role2 = 'FPC'
    #led = None
    fpc = None

    #Identify Applications
    s = Seeker('-dos-', 'DOStest')
    #while led == None:
    #    print('Connecting to ILLUMINATOR')
    #    s.seek()
    #    if role1 in s.devices:
    #        led = Pyro4.Proxy(s.devices[role1]['pyro_uri'])
    #        print('ILLUMINATOR connected')
    #    time.sleep(1)

    while fpc == None:
        print('Connecting to FPC')
        s.seek()
        if role2 in s.devices:
            fpc = Pyro4.Proxy(s.devices[role2]['pyro_uri'])
            print('FPC connected')
        time.sleep(1)

    fpc.set(image_dir=datasetDirLocal)

    print('Taking dataset to be saved in: {}'.format(datasetDirLocal))
    expids = np.arange(expidini, expidini + expno, 1, dtype=int)
    for expid in expids:
        print('Exposing bias frame {}'.format(expid))
        fpc.expose(expid, exptype="bias", exptime=0, local_copy=False)
        write_fits(fpc.get_data(expid), expid)
    expids = expids + expno
    print(expids)
    for expid in expids:
        print('Exposing dark frame {}'.format(expid))
        fpc.expose(expid, exptype="dark", exptime=exptime, local_copy=False)
        write_fits(fpc.get_data(expid), expid)
    expids = expids + expno
    for expid in expids:
        print('Exposing object frame {}'.format(expid))
        fpc.expose(expid, exptype="object", exptime=exptime, local_copy=False)
        write_fits(fpc.get_data(expid), expid)
Esempio n. 2
0
    def __init__(self, device, **options):
        """
        Find the petal controller (device) and connect to it
        Options include the fipos settings for LED control
        """
        # Log functions
        for level in ['msg', 'debug', 'info', 'warn', 'error']:
            if hasattr(Log, level):
                setattr(self,level, getattr(Log, level))

        self.petal_controller = device
        # Setup Seeker
        self.seeker_thread = None
        self.repeat = threading.Event()
        self.repeat.clear()
        self.found_controller = threading.Event()
        self.found_controller.clear()
        self.stype = '-dos-'
        self.service = options.get('service', 'PetalControl')
        self.device = {}
        delay = options.get('delay', 15.0)
        # Did we get controller information or should we seek?
        print('89755')
        print(options)
        print('89756')
        print(options['controller'])
        if 'controller' in options and isinstance(options['controller'], dict):
            print('89757')
            self.device = {'connected2instance': 'EXTERN',
                           'device_instance': '',
                           'last_updated': '',
                           'node': options['controller'].get('ip', '140.254.79.198'),
                           'service': self.service,
                           'stype': self.stype,
                           'uid' : '81df0e9a-9409-11e8-b17c-b0d5cc1ef486',
                           }
            print('89757a')
            print('897575'+str(options['controller']))
            if 'port' in options['controller']:
                print('89758')
                self.device['pyro_uri'] = 'PYRO:%s@%s:%s' % (self.petal_controller,
                                                             str(self.device['node']),
                                                             str(options['controller']['port']))
                print(self.device['pyro_uri'])
        else:
            # Setup DOS Seeker
            self.seeker = Seeker(self.stype, self.service, found_callback = self._found_dev)
            # Start Seeker thread
            self.repeat.set()
            self.delay = 0.5
            self.seeker_thread = threading.Thread(target=self._repeat_seeker)
            self.seeker_thread.setDaemon(True)
            self.seeker_thread.start()
            self.info('Seeker thread is now running. Delay %s' % str(self.delay))
            # wait briefly for seeker to find all devices
            self.info('Waiting for device %s' % self.petal_controller)
            self.found_controller.wait(timeout = delay + 1.0)
            self.delay = 10.0

        # Make sure we have a device to connect to
        start = time.time()
        while self.device == {} and delay<(time.time() - start):
            self.device['proxy'] = Pyro4.Proxy(self.device['pyro_uri'])
            self.info('Now connected to device %s' % self.device)
            break
            
        if self.device == {}:
            raise_error('fipos_comm: Timeout connecting to controller %s' % (self.petal_controller), level='ERROR', function='init')
Esempio n. 3
0
class FiposComm(object):
    """
    Handles communication between the fiducials class and the petal controller
    """

    def __init__(self, device, **options):
        """
        Find the petal controller (device) and connect to it
        Options include the fipos settings for LED control
        """
        # Log functions
        for level in ['msg', 'debug', 'info', 'warn', 'error']:
            if hasattr(Log, level):
                setattr(self,level, getattr(Log, level))

        self.petal_controller = device
        # Setup Seeker
        self.seeker_thread = None
        self.repeat = threading.Event()
        self.repeat.clear()
        self.found_controller = threading.Event()
        self.found_controller.clear()
        self.stype = '-dos-'
        self.service = options.get('service', 'PetalControl')
        self.device = {}
        delay = options.get('delay', 15.0)
        # Did we get controller information or should we seek?
        print('89755')
        print(options)
        print('89756')
        print(options['controller'])
        if 'controller' in options and isinstance(options['controller'], dict):
            print('89757')
            self.device = {'connected2instance': 'EXTERN',
                           'device_instance': '',
                           'last_updated': '',
                           'node': options['controller'].get('ip', '140.254.79.198'),
                           'service': self.service,
                           'stype': self.stype,
                           'uid' : '81df0e9a-9409-11e8-b17c-b0d5cc1ef486',
                           }
            print('89757a')
            print('897575'+str(options['controller']))
            if 'port' in options['controller']:
                print('89758')
                self.device['pyro_uri'] = 'PYRO:%s@%s:%s' % (self.petal_controller,
                                                             str(self.device['node']),
                                                             str(options['controller']['port']))
                print(self.device['pyro_uri'])
        else:
            # Setup DOS Seeker
            self.seeker = Seeker(self.stype, self.service, found_callback = self._found_dev)
            # Start Seeker thread
            self.repeat.set()
            self.delay = 0.5
            self.seeker_thread = threading.Thread(target=self._repeat_seeker)
            self.seeker_thread.setDaemon(True)
            self.seeker_thread.start()
            self.info('Seeker thread is now running. Delay %s' % str(self.delay))
            # wait briefly for seeker to find all devices
            self.info('Waiting for device %s' % self.petal_controller)
            self.found_controller.wait(timeout = delay + 1.0)
            self.delay = 10.0

        # Make sure we have a device to connect to
        start = time.time()
        while self.device == {} and delay<(time.time() - start):
            self.device['proxy'] = Pyro4.Proxy(self.device['pyro_uri'])
            self.info('Now connected to device %s' % self.device)
            break
            
        if self.device == {}:
            raise_error('fipos_comm: Timeout connecting to controller %s' % (self.petal_controller), level='ERROR', function='init')

    def is_connected(self):
        """
        Returns the status of the found_controller flag.
        """
        return self.found_controller.is_set()
    
    # Internal callback and utility functions
    def _repeat_seeker(self):
        while self.repeat.is_set():
            self.seeker.seek()
            time.sleep(self.delay)

    def _found_dev(self, dev):
        for key in dev:
            if dev[key]['service'] == self.service:   # Found a petal controller
                # Extract unit number and compare to self.petal_controller
                if key == self.petal_controller:
                    # Found the matching petal controller
                    if 'name' not in self.device or self.device['name'] != key:
                        self.info('_found_dev: Found new device %s' % str(key))
                        self.device['name'] = key
                    # update proxy information?
                    if 'uid' in self.device and self.device['uid'] != dev[key]['uid']:
                        self.info('_found_dev: Device %s rediscovered.' % key)
                        if 'proxy' in self.device:     # remove potentially stale info
                            del self.device['proxy']
                    self.device.update(dev[key])   # make a copy
                    self.found_controller.set()
                        
    def call_device(self, cmd, *args, **kwargs):
        """
        Call remote function
        Input:  cmd   = function name
                args, kwargs are passed to the remove function
        Returns: return value received from remote function
        """
        try:
            return getattr(self.device['proxy'],cmd)(*args, **kwargs)
        except:
            if 'pyro_uri' in self.device:
                try:
                    self.device['proxy'] = Pyro4.Proxy(self.device['pyro_uri'])
                    return getattr(self.device['proxy'],cmd)(*args, **kwargs)
                except Exception as e:
                    raise RuntimeError('call_device: Exception for command %s. Message: %s' % (str(cmd),str(e)))
            # Failed to get status from device
            raise RuntimeError('call_device: remote device not reachable %s' % '' if 'name' not in self.device else self.device)
Esempio n. 4
0
#Read in Arguments
led_mode = sys.argv[1]
fvc_image = sys.argv[2]

# initialization done when starting petal application
petal_id = 0
role1 = 'ILLUMINATOR'
role2 = 'FVC'
role3 = 'PC0'
led = None
fvc = None
pc0 = None

# Find Illuminator and FVC applications
s = Seeker('-dos-','DOStest')
while led == None:
    s.seek()
    if role1 in s.devices:
        led = Pyro4.Proxy(s.devices[role1]['pyro_uri'])
        print('ILLUMINATOR connected')
    time.sleep(1)
    
while fvc == None:
    s.seek()
    if role2 in s.devices:
        fvc = Pyro4.Proxy(s.devices[role2]['pyro_uri'])
        print('FVC connected')
    else:
        print('Not connecting to anything using Pyro')
    time.sleep(1)
Esempio n. 5
0
"""

etime = sys.argv[1]
image_id = sys.argv[2]

#etime = 0.3 #sys.argv[1]
data_dir = os.getcwd()
print(data_dir)

# initialization done when starting petal application
role1 = 'FPC'
fpc = None


# Find FPC application
s = Seeker('-dos-','DOStest')
while fpc == None:
    s.seek()
    if role1 in s.devices:
        fpc = Pyro4.Proxy(s.devices[role1]['pyro_uri'])
        print('FPC connected')
    else:
        print('Not connecting to anything using Pyro')
    time.sleep(1)
    
#Configure FPC
fpc.configure()
fpc.set(image_dir=data_dir)

def create_fits(data,num,type):
    image = data['primary']['data']