def extract_time_and_grid_information(root_name, settings, queue_com, name):
    """
    Extract the time and grid information from the micrograph names.

    Arguments:
    root_name - Name to extract information from.
    settings - TranSPHIRE settings.
    queue_com - Queue for communication.
    name - Name of the process.

    Returns:
    hole_number, spot1_number, spot2_number, date, time
    """
    message = None
    if settings['Input']['Software'] == 'Just Stack':
        hole = 0
        grid_number = 0
        spot1 = 0
        spot2 = 0
        date = 0
        time = 0

    elif settings['Input']['Software'] == 'Latitude S':
        if settings['Input']['Camera'] in ('Falcon2', 'Falcon3'):
            message = '\n'.join([
                'Falcon2/Falcon3 is not supported for Software {0}.'.format(
                    settings['Input']['Software']),
                'Please contact the TranSPHIRE authors!'
            ])

        elif settings['Input']['Camera'] in ('K2', 'K3'):
            search_results = re.search(
                r'(?P<date>\d{8})_(?P<project>.*)_A(?P<atlas>\d{3,})_G(?P<grid>\d{3,})_H(?P<hole>\d{3,})_D(?P<spot>\d{3,})',
                root_name)
            grid_number = '{0}_{1}'.format(search_results.group('atlas'),
                                           search_results.group('grid'))
            hole = search_results.group('hole')
            spot1 = search_results.group('spot')
            spot2 = ''
            date = search_results.group('date')
            with open('{0}.gtg'.format(root_name), 'rb') as read:
                reader = DigitalMicrographReader(read)
                reader.parse_file()
            time = datetime.datetime.strptime(
                reader.tags_dict['DataBar']['Acquisition Time'],
                '%I:%M:%S %p').strftime('%H%M%S')

        else:
            message = '\n'.join([
                'Camera {0} for Software {1} not known!'.format(
                    settings['Input']['Camera'],
                    settings['Input']['Software']),
                'Please contact the TranSPHIRE authors!'
            ])

    elif settings['Input']['Software'] == 'EPU >=1.8':

        if settings['Input']['Camera'] == 'Falcon2' \
                or settings['Input']['Camera'] == 'Falcon3' \
                or settings['Input']['Camera'] in ('K2', 'K3'):
            *skip, grid, skip, old_file = \
                os.path.realpath(root_name).split('/')
            grid_number = grid.split('_')[1]
            *skip, hole, skip, spot1, spot2, date, time = old_file.split('_')
            del skip

        else:
            message = '\n'.join([
                'Camera {0} for Software {1} not known!'.format(
                    settings['Input']['Camera'],
                    settings['Input']['Software']),
                'Please contact the TranSPHIRE authors!'
            ])

    elif settings['Input']['Software'] == 'EPU >=1.9':

        if settings['Input']['Camera'] == 'Falcon2' \
                or settings['Input']['Camera'] == 'Falcon3' \
                or settings['Input']['Camera'] in ('K2', 'K3'):
            *skip, grid, skip, old_file = \
                os.path.realpath(root_name).split('/')
            grid_number = grid.split('_')[1]
            *skip, hole, skip, spot1, spot2, date, time = old_file.split('_')
            del skip

        elif settings['Input']['Camera'] in ('K2', 'K3'):
            *skip, grid, skip, old_file = \
                os.path.realpath(root_name).split('/')
            grid_number = grid.split('_')[1]
            *skip, hole, skip, spot1, spot2, date, time = old_file.split('_')
            del skip

        else:
            message = '\n'.join([
                'Camera {0} for Software {1} not known!'.format(
                    settings['Input']['Camera'],
                    settings['Input']['Software']),
                'Please contact the TranSPHIRE authors!'
            ])

    else:
        message = '\n'.join([
            'Software {0} not known!'.format(settings['Input']['Software']),
            'Please contact the TranSPHIRE authors!'
        ])

    if message is None:
        pass
    else:
        queue_com['error'].put(message, name)
        raise IOError(message)

    return hole, grid_number, spot1, spot2, date, time
Пример #2
0
 def _load_file(self, fname):
     with open(fname, "rb") as f:
         dm = DigitalMicrographReader(f)
         dm.parse_file()
         self.imdict = dm.get_image_dictionaries()
     return [ImageObject(imdict, fname) for imdict in self.imdict]
Пример #3
0
 def _load_file(self, fname):
     with open(fname, "rb") as f:
         dm = DigitalMicrographReader(f)
         dm.parse_file()
         self.imdict = dm.get_image_dictionaries()
     return [ImageObject(imdict, fname) for imdict in self.imdict]