def generate_cell_parameters(outputfile, **kwargs): """ Generates random cell parameters and save them into a given csv file. Parameters ---------- outputfile : str Path to save cell parameters. kwargs : key, value pairings Keyword arguments passed to the `CellParams` class. """ if not outputfile.endswith('.csv'): outputfile += '.csv' params = CellParams(**kwargs) params.save(outputfile)
def test_cell_from_params(self): celldata = CellParams(number_of_cells=5, spikiness_range=(0, 1), spike_size_range=(0.1, 1), coordinates=False) cell = Cell(input_voxel_size=0.5, **dict(celldata.iloc[0])) self.assertIsNotNone(cell.image)
def test_read_write(self): celldata = CellParams(number_of_cells=5, spikiness_range=(0, 0.5), spike_size_range=(0.1, 1)) celldata.save('data/celldata.csv') celldata2 = CellParams() celldata2.read_from_csv('data/celldata.csv') self.assertEqual(len(celldata), len(celldata2)) for c in celldata.columns: self.assertEqual(c in celldata2.columns, True) shutil.rmtree('data/')
def generate_cells_batch(params_file, **kwargs): """ Generate synthetic cells with given parameters in a parallel mode and saves them in a given directory. Parameters ---------- params_file : str Path to a csv file with cell parameters. Keyword arguments ----------------- outputfolder : str Output directory to save the generated cells. input_voxel_size : scalar or sequence of scalars, optional Voxel size in z, y and x used to generate the cell image. If one value is provided, the voxel size is assume to be equal along all axes. max_threads : int, optional The maximal number of processes to run in parallel. Default is 8. print_progress : bool, optional If True, the progress of the computation will be printed. Default is True. """ if not os.path.exists(params_file): raise ValueError('Parameter file does not exist!') params = CellParams() params.read_from_csv(filename=params_file) if 'stack' in params.columns: items = [] for st in params['stack'].unique(): items.append(('stack_%03d.tif' % st, params[params['stack'] == st].reset_index())) kwargs['items'] = items run_parallel(process=__generate_stacks_batch_helper, process_name='Generation of stacks', **kwargs) else: items = [] for i in range(len(params)): items.append(('cell_%03d.tif' % i, params.iloc[i])) kwargs['items'] = items run_parallel(process=__generate_cells_batch_helper, process_name='Generation of cells', **kwargs)
def test_valid_types(self, kind): celldata = CellParams(kind=kind) celldata.save('data/celldata.csv') self.assertEqual(os.path.exists('data/celldata.csv'), True) shutil.rmtree('data/')
def test_cell_data(self, size): celldata = CellParams(number_of_cells=1, size_mean_and_std=size) celldata.save('data/celldata.csv') celldata.plot_size_distribution() shutil.rmtree('data/')
def test_range_for_number_of_cells(self): params = CellParams(number_of_stacks=3, number_of_cells=[5, 10]) stack = Stack(cell_params=params[params['stack'] == 2].reset_index(), input_voxel_size=0.5, stack_size=[10, 10, 10]) self.assertIsNotNone(stack.image)
def test_from_stack_params(self): params = CellParams(number_of_stacks=1, number_of_cells=5) stack = Stack(cell_params=params[params['stack'] == 0], input_voxel_size=0.5, stack_size=[10, 10, 10]) self.assertIsNotNone(stack.image)