示例#1
0
    def test_pad(self):
        shape_0, shape_1 = zip(
            *[cell_obj.data.shape for cell_obj in self.cells])
        shape_0_max, shape_1_max = np.max(shape_0), np.max(shape_1)
        cell_list = CellList([
            pad_cell(cell_obj, (shape_0_max, shape_1_max))
            for cell_obj in self.cells
        ])
        for cell in cell_list:
            self.assertEqual((shape_0_max, shape_1_max), cell.data.shape)
            self.assertEqual((shape_0_max, shape_1_max), cell.coords.shape)

        # pad by zero and check if the results are the same
        x, y = self.cells.r_dist(20, 1, method='box')
        cell_list = CellList([
            pad_cell(cell_obj, cell_obj.data.shape) for cell_obj in self.cells
        ])
        xn, yn = cell_list.r_dist(20, 1, method='box')
        self.assertArrayEqual(y, yn)

        #pad by known amount and check of storm coords more accordingly
        cell = self.cells[0]
        shape_0, shape_1 = cell.data.shape
        padded_cell = pad_cell(cell, (shape_0 + 10, shape_1 + 10))
        self.assertArrayEqual(cell.data.data_dict['storm']['x'] + 5,
                              padded_cell.data.data_dict['storm']['x'])
    def _test_cell_list(self):
        #todo check order
        print(hashlib.md5(self.data).hexdigest())
        cell_list = data_to_cells(self.data,
                                  initial_crop=2,
                                  cell_frac=0.5,
                                  rotate='binary')
        print(hashlib.md5(self.data).hexdigest())
        cell_list = data_to_cells(self.data,
                                  initial_crop=2,
                                  cell_frac=0.5,
                                  rotate='binary')
        print(hashlib.md5(self.data).hexdigest())

        d = self.data.copy()
        print(d == self.data)

        cl = CellList(cell_list)
        self.assertEqual(len(cl), 48)
        c5 = cl[5]
        self.assertIsInstance(c5, Cell)

        del cl[5]
        self.assertEqual(len(cl), 47)
        self.assertTrue(cl[3] in cl)
        cl.append(c5)
        self.assertTrue(c5 in cl)

        vol = cl.volume
        self.assertEqual(len(vol), 48)
示例#3
0
 def test_crop(self):
     shape_0, shape_1 = 20, 30
     cell_list = CellList([
         crop_cell(cell_obj, (shape_0, shape_1)) for cell_obj in self.cells
     ])
     for cell in cell_list:
         self.assertEqual((shape_0, shape_1), cell.data.shape)
         self.assertEqual((shape_0, shape_1), cell.coords.shape)
示例#4
0
 def __init__(self, cell_list, pad=True):
     if pad:
         shape_0, shape_1 = zip(
             *[cell_obj.data.shape for cell_obj in cell_list])
         self.cell_list = CellList([
             pad_cell(cell_obj, (np.max(shape_0), np.max(shape_1)))
             for cell_obj in cell_list
         ])
     else:
         self.cell_list = cell_list
    def setUp(self):
        self.data = load_testdata('ds1')
        f_path = os.path.dirname(os.path.realpath(__file__))
        self.storm_cells_1 = load(
            os.path.join(f_path, 'test_data/test_single_spot_storm.hdf5'))
        self.storm_cells_2 = load(
            os.path.join(f_path, 'test_data/test_double_spot_storm.hdf5'))

        cells_no_flu = []
        for c in self.storm_cells_2:
            d = Data()
            d.add_data(c.data.binary_img, 'binary')
            d.add_data(c.data.data_dict['storm_1'], 'storm', 'storm_1')
            d.add_data(c.data.data_dict['storm_2'], 'storm', 'storm_2')
            cell = Cell(d)
            cells_no_flu.append(cell)

        self.storm_cells_2_no_flu = CellList(cells_no_flu)
示例#6
0
def load(file_path):
    """
    Load ``Cell`` or ``CellList`` from disk.

    Parameters
    ----------
    file_path : :obj:`str`
        Source file path.

    Returns
    -------
    cell : :class:`~colicoords.cell.Cell` or :class:`~colicoords.cell.CellList`
        Loaded ``Cell`` or ``CellList``
    """

    with h5py.File(file_path, 'r') as f:
        cell_list = [_load_cell(f[key]) for key in f.keys()]

        if len(cell_list) == 1:
            return cell_list[0]
        else:
            return CellList(cell_list)