def main(): # experiment, series id, x, y, z _tuples = [('SN16', 1, -1682.56, -5032.04, 3008.63), ('SN16', 2, -1670.75, -5478.9, 2994.73), ('SN16', 3, -236.84, -4688.53, 2936), ('SN16', 4, 220.026, -5278.16, 2996.12), ('SN16', 5, -116.687, -5416.64, 3011.1), ('SN16', 6, 182.096, -5594.65, 2973.24), ('SN16', 7, -348.477, -5602.94, 2941.42), ('SN16', 8, -2047.87, -6110.29, 2981.28), ('SN16', 9, -666.538, -6226.22, 2981.87), ('SN16', 10, -636.488, -4737.97, 3024.08), ('SN16', 11, -1876.03, -4453.93, 3027.78), ('SN16', 12, -458.544, -5354.8, 2959.91), ('SN16', 13, -874.443, -5466.59, 2934.34), ('SN16', 14, -967.547, -5734.82, 2971.74), ('SN16', 15, -700.906, -5530.6, 2986.42), ('SN16', 16, -1297.99, -5558.28, 2972.78), ('SN16', 17, -329.176, -5949.33, 3003.88), ('SN16', 18, -324.288, -6142.51, 3012.3), ('SN16', 19, -185.393, -6369.23, 3018.61), ('SN16', 20, -874.443, -5637.26, 2937.31), ('SN16', 21, 903.651, -4759.44, 2996.15)] for _tuple in _tuples: print(_tuple) _experiment, _series_id, _x, _y, _z = _tuple _properties = load.image_properties(_experiment, _series_id) _properties['position'] = {'x': _x, 'y': _y, 'z': _z} save.image_properties(_experiment, _series_id, _properties)
def process_series(_experiment, _series_id, _overwrite=False): _series_image_path = paths.serieses(_experiment, _series_id) _image_properties = load.image_properties(_experiment, _series_id) _series_image = tifffile.imread(_series_image_path) _cells_coordinates = load.cell_coordinates_tracked_series_file_data( _experiment, _series_id) _series_image_by_time_frames = [ np.array([ _z[IMAGE_FIBER_CHANNEL_INDEX] for _z in _series_image[_time_frame] ]) for _time_frame in range(_series_image.shape[0]) ] _tuples = load.experiment_groups_as_tuples(_experiment) _tuples = organize.by_experiment(_tuples)[_experiment] _tuples = filtering.by_real_pairs(_tuples) _tuples = filtering.by_real_fake_pairs(_tuples, _real_fake_pairs=False) _tuples = filtering.by_series_id(_tuples, _series_id) for _tuple in _tuples: _experiment, _series_id, _group = _tuple _cell_1_id, _cell_2_id = [ int(_value) for _value in _group.split('_')[1:] ] process_group( _experiment=_experiment, _series_id=_series_id, _cells_coordinates=_cells_coordinates, _cell_1_id=_cell_1_id, _cell_2_id=_cell_2_id, _series_image_by_time_frames=_series_image_by_time_frames, _resolutions=_image_properties['resolutions'], _image_properties=_image_properties, _overwrite=_overwrite)
def process_fake_following(_experiment, _series_id, _cell_1_id, _cell_2_id, _x_change, _y_change, _z_change=0, _overwrite=False): _series_image_path = paths.serieses(_experiment, _series_id) _image_properties = load.image_properties(_experiment, _series_id) _series_image = tifffile.imread(_series_image_path) _cells_coordinates = load.cell_coordinates_tracked_series_file_data( _experiment, _series_id) _series_image_by_time_frames = [ np.array([ _z[IMAGE_FIBER_CHANNEL_INDEX] for _z in _series_image[_time_frame] ]) for _time_frame in range(_series_image.shape[0]) ] process_group(_experiment=_experiment, _series_id=_series_id, _cells_coordinates=_cells_coordinates, _cell_1_id=_cell_1_id, _cell_2_id=_cell_2_id, _series_image_by_time_frames=_series_image_by_time_frames, _resolutions=_image_properties['resolutions'], _real_cells=False, _x_change=_x_change, _y_change=_y_change, _z_change=_z_change, _overwrite=_overwrite)
def by_dead_live(_experiments_tuples, _dead=None, _live=None): _experiments_tuples_filtered = [] for _tuple in _experiments_tuples: _experiment, _series_id, _group = _tuple _group_split = _group.split('_') _cell_id_1 = int(_group_split[1]) _cell_id_2 = int(_group_split[2]) _properties = load.image_properties(_experiment, _series_id) _cell_1_dead = _cell_id_1 in _properties['dead_cell_ids'] _cell_2_dead = _cell_id_2 in _properties['dead_cell_ids'] # both dead if _dead and not _live and _cell_1_dead and _cell_2_dead: _experiments_tuples_filtered.append(_tuple) # both live elif not _dead and _live and not _cell_1_dead and not _cell_2_dead: _experiments_tuples_filtered.append(_tuple) # at least one is dead elif _dead and _live is None and (_cell_1_dead or _cell_2_dead): _experiments_tuples_filtered.append(_tuple) # at least one is alive elif _dead is None and _live and (not _cell_1_dead or not _cell_2_dead): _experiments_tuples_filtered.append(_tuple) # one is dead, one is alive elif _dead and _live and ((_cell_1_dead and not _cell_2_dead) or (not _cell_1_dead and _cell_2_dead)): _experiments_tuples_filtered.append(_tuple) # return all elif _dead is None and _live is None: return _experiments_tuples return _experiments_tuples_filtered
def process_fake_static(_experiment, _series_id, _cell_1_id, _cell_2_id, _x1, _y1, _z1, _x2, _y2, _z2, _overwrite=False): _series_image_path = paths.serieses(_experiment, _series_id) _image_properties = load.image_properties(_experiment, _series_id) _series_image = tifffile.imread(_series_image_path) _cells_coordinates = [[ (_x1, _y1, _z1) for _time_frame in range(_series_image.shape[0]) ], [(_x2, _y2, _z2) for _time_frame in range(_series_image.shape[0])]] _series_image_by_time_frames = [ np.array([ _z[IMAGE_FIBER_CHANNEL_INDEX] for _z in _series_image[_time_frame] ]) for _time_frame in range(_series_image.shape[0]) ] process_group(_experiment=_experiment, _series_id=_series_id, _cells_coordinates=_cells_coordinates, _cell_1_id=0, _cell_2_id=1, _series_image_by_time_frames=_series_image_by_time_frames, _resolutions=_image_properties['resolutions'], _real_cells=False, _fake_cell_1_id=_cell_1_id, _fake_cell_2_id=_cell_2_id, _overwrite=_overwrite)
def by_main_cell(_experiments_tuples): _experiments_tuples_filtered = [] for _tuple in _experiments_tuples: _experiment, _series_id, _group = _tuple _cell_id = int(_group.split('_')[1]) _series_properties = load.image_properties(_experiment, _series_id) if _cell_id == _series_properties['main_cell_id']: _experiments_tuples_filtered.append(_tuple) return _experiments_tuples_filtered
def cell_z_position_from_substrate(_experiment, _series_id, _cell_id, _time_frame=0): _properties = load.image_properties(_experiment, _series_id) _series_z_position = _properties['position']['z'] _cells_coordinates_tracked = \ load.cell_coordinates_tracked_series_file_data(_experiment, _series_id) _cell_z_position = _cells_coordinates_tracked[int( _cell_id)][_time_frame][2] * _properties['resolutions']['z'] return _series_z_position + _cell_z_position
def pair_distance_in_cell_size(_experiment, _series_id, _cell_1_coordinates, _cell_2_coordinates): _image_properties = load.image_properties(_experiment, _series_id) _image_resolutions = _image_properties['resolutions'] _x1, _y1, _z1 = [float(_value) for _value in _cell_1_coordinates[0]] _x2, _y2, _z2 = [float(_value) for _value in _cell_2_coordinates[0]] _x1, _y1, _z1 = _x1 * _image_resolutions['x'], _y1 * _image_resolutions[ 'y'], _z1 * _image_resolutions['z'] _x2, _y2, _z2 = _x2 * _image_resolutions['x'], _y2 * _image_resolutions[ 'y'], _z2 * _image_resolutions['z'] return math.sqrt((_x1 - _x2)**2 + (_y1 - _y2)**2 + (_z1 - _z2)**2) / AVERAGE_CELL_DIAMETER_IN_MICRONS
def main(): _experiment = 'SN41' _series_id = 3 _group = 'static_0_1' _x1, _y1, _z1 = 23, 226, 10 _x2, _y2, _z2 = 228, 226, 10 _time_frame = 34 _series_image_path = paths.serieses(_experiment, _series_id) _image_properties = load.image_properties(_experiment, _series_id) _series_image = tifffile.imread(_series_image_path) _series_image_by_time_frames = [ np.array([ _z[IMAGE_FIBER_CHANNEL_INDEX] for _z in _series_image[_time_frame] ]) for _time_frame in range(_series_image.shape[0]) ] plt.imshow(_series_image_by_time_frames[_time_frame][30]) plt.show()
def process_experiment(_experiment, _overwrite=False): _arguments = [] for _series in paths.image_files(paths.serieses(_experiment)): _series_id = int(_series.split('_')[1]) _image_properties = load.image_properties(_experiment, _series_id) _cells_coordinates = load.cell_coordinates_tracked_series_file_data( _experiment, _series_id) for _cell_id in range(len(_cells_coordinates)): for _degrees_xy, _degrees_z in product(DEGREES_XY, DEGREES_Z): _arguments.append({ 'experiment': _experiment, 'series_id': _series_id, 'cell_id': _cell_id, 'degrees_xy': _degrees_xy, 'degrees_z': _degrees_z, 'cell_coordinates': _cells_coordinates, 'cell_type': 'real', 'resolutions': _image_properties['resolutions'], 'overwrite': _overwrite }) with Pool(CPUS_TO_USE) as _p: for _ in tqdm(_p.imap_unordered(process_group, _arguments), total=len(_arguments), desc='Creating'): pass _p.close() _p.join()
def main(): _experiment = 'DeadDead_201208' _tuples = load.experiment_groups_as_tuples(_experiment) _cell_ids = {} for _tuple in _tuples: _experiment, _series_id, _group = _tuple _group_split = _group.split('_') _cell_1_id = int(_group_split[1]) _cell_2_id = int(_group_split[2]) if _series_id not in _cell_ids: _cell_ids[_series_id] = [_cell_1_id, _cell_2_id] else: if _cell_1_id not in _cell_ids[_series_id]: _cell_ids[_series_id].append(_cell_1_id) if _cell_2_id not in _cell_ids[_series_id]: _cell_ids[_series_id].append(_cell_2_id) for _series_id in _cell_ids.keys(): _properties = load.image_properties(_experiment, _series_id) _properties['dead_cell_ids'] = _cell_ids[_series_id] save.image_properties(_experiment, _series_id, _properties) print(_experiment, _series_id, sep='\t')
def process_series(_experiment, _series_id, _overwrite=False): _normalization_path = paths.normalization(_experiment, _series_id) if not _overwrite and os.path.isfile(_normalization_path): return _series_image_first_time_frame = load.series_image(_experiment, _series_id)[0] _image_properties = load.image_properties(_experiment, _series_id) _cells = load.objects_time_frame_file_data(_experiment, _series_id, _time_frame=1) _cell_diameter_x = AVERAGE_CELL_DIAMETER_IN_MICRONS / _image_properties[ 'resolutions']['x'] _cell_diameter_y = AVERAGE_CELL_DIAMETER_IN_MICRONS / _image_properties[ 'resolutions']['y'] _cell_diameter_z = AVERAGE_CELL_DIAMETER_IN_MICRONS / _image_properties[ 'resolutions']['z'] _z_shape, _y_shape, _x_shape = _series_image_first_time_frame.shape _z_step, _y_step, _x_step = [ int(round(_value * STEP_PERCENTAGE)) for _value in [_z_shape, _y_shape, _x_shape] ] _averages = [] for _z, _y, _x in product(range(0, _z_shape, _z_step), range(0, _y_shape, _y_step), range(0, _x_shape, _x_step)): _x1 = _x - _cell_diameter_x / 2 _x2 = _x1 + _cell_diameter_x _y1 = _y - _cell_diameter_y / 2 _y2 = _y1 + _cell_diameter_y _z1 = _z - _cell_diameter_z / 2 _z2 = _z1 + _cell_diameter_z _x1, _y1, _z1, _x2, _y2, _z2 = [ int(round(_value)) for _value in [_x1, _y1, _z1, _x2, _y2, _z2] ] # window is in borders if all([ _x1 >= 0, _x2 < _x_shape, _y1 >= 0, _y2 < _y_shape, _z1 >= 0, _z2 < _z_shape ]): # make sure no cells are around _in_window = False for _cell in _cells: _cell_x, _cell_y, _cell_z = _cell # cover entire box around the cell for _value_x, _value_y, _value_z in product( CELL_BORDERS_VALUES, CELL_BORDERS_VALUES, CELL_BORDERS_VALUES): if is_in_window(_x1, _y1, _z1, _x2, _y2, _z2, _cell_x + _cell_diameter_x * _value_x, _cell_y + _cell_diameter_y * _value_y, _cell_z + _cell_diameter_z * _value_z): _in_window = True break # one cell is enough if _in_window: break # one cell is enough if _in_window: continue # no cells are around, compute _pixels = _series_image_first_time_frame[_z1:_z2, _y1:_y2, _x1:_x2] # convert to 8 bit color depth if CONVERT_TO_COLOR_DEPTH_8_BIT: _pixels = np.rint(_pixels / (math.pow(2, 16) - 1) * (math.pow(2, 8) - 1)).astype(np.uint8) _averages.append(np.mean(_pixels)) # compute average and std of averages _average, _std = np.mean(_averages), np.std(_averages) # save _normalization = {'average': _average, 'std': _std} save_lib.to_json(_normalization, _normalization_path) print('Saved', _experiment, _series_id, sep='\t')
def temporal_resolution_in_minutes(_experiment): _properties = load.image_properties(_experiment, _series_id=1) return round(_properties['frames_interval'] / 60)