Esempio n. 1
0
def make_training_data(direc_name,
                       file_name_save,
                       channel_names,
                       dimensionality,
                       training_direcs=None,
                       raw_image_direc='raw',
                       annotation_direc='annotated',
                       annotation_name='feature',
                       reshape_size=None,
                       **kwargs):
    """Wrapper function for other make_training_data functions (2d, 3d)
    Calls one of the above functions based on the dimensionality of the data.
    """
    # Validate Arguments
    if not isinstance(dimensionality, (int, float)):
        raise ValueError(
            'Data dimensionality should be an integer value, typically 2 or 3. '
            'Recieved {}'.format(type(dimensionality).__name__))

    if not isinstance(channel_names, (list, )):
        raise ValueError(
            'channel_names should be a list of strings (e.g. [\'DAPI\']). '
            'Found {}'.format(type(channel_names).__name__))

    if training_direcs is None:
        training_direcs = get_immediate_subdirs(direc_name)

    dimensionality = int(dimensionality)

    if dimensionality == 2:
        make_training_data_2d(direc_name,
                              file_name_save,
                              channel_names,
                              training_direcs=training_direcs,
                              reshape_size=reshape_size,
                              raw_image_direc=raw_image_direc,
                              annotation_name=annotation_name,
                              annotation_direc=annotation_direc)

    elif dimensionality == 3:
        make_training_data_3d(direc_name,
                              file_name_save,
                              channel_names,
                              training_direcs=training_direcs,
                              annotation_name=annotation_name,
                              raw_image_direc=raw_image_direc,
                              annotation_direc=annotation_direc,
                              reshape_size=reshape_size,
                              montage_mode=kwargs.get('montage_mode', False),
                              num_frames=kwargs.get('num_frames', 50))

    else:
        raise NotImplementedError('make_training_data is not implemented for '
                                  'dimensionality {}'.format(dimensionality))
Esempio n. 2
0
 def test_get_immediate_subdirs(self):
     dirs = []
     temp_dir = self.get_temp_dir()
     self.addCleanup(shutil.rmtree, temp_dir)
     for x in range(2, -1, -1):  # iterate backwards to test sorting
         sub_dir = os.path.join(temp_dir, str(x))
         try:
             os.makedirs(sub_dir)
         except OSError as err:
             if err.errno != os.errno.EEXIST:
                 raise
         dirs.append(str(x))
     subdirs = io_utils.get_immediate_subdirs(temp_dir)
     self.assertListEqual(subdirs, list(reversed(dirs)))