def read_data(paths, t_max=193): df = pd.read_csv(paths['tracks_path']) df = df.loc[:, ~df.columns.str.contains('^Unnamed')] #arr, shape = get_stack(paths['data_path'], t_max=t_max, w_shape=True) arr = single_zarr(paths['data_path']) shape = arr.shape return df, arr, shape
save=True, base=track_view_base) args = parser.parse_args() paths = get_paths( args, # will simplify all of this in another PR 'random_tracks_engine', get={ 'data_path': 'image', 'tracks_path': 'track', 'save_dir': 'save', 'coords_path': 'coords' }) # Read Data # --------- array = single_zarr(paths['data_path']) shape = array.shape # tracks = pd.read_csv(paths['tracks_path']) coords = pd.read_csv(paths['coords_path']) # Cost evaluation attempt # ----------------------- # cost_eval = CostEvaluation(tracks, array, shape) # cost_eval.annotate_all() # Optimisation Attempt # -------------------- params = [{ 'name': 'dist_thresh', 'type': 'int', 'options': (40, 60),
local_dir = os.getcwd() paths = glob.glob(os.path.join(d, '*.pkl')) import btrack_tracking import importlib importlib.reload(btrack_tracking) dfs = {} for path in paths: name = Path(path).stem name = name[:name.find('.2020')] df = pd.read_pickle(path) save_name = os.path.join(d, name + '_objs.csv') df.to_csv(save_name) zarr_path = os.path.join(data_path, name + '.zarr') print(zarr_path) shape = single_zarr(zarr_path).shape tracks_df = btrack_tracking.track_objects(df, shape, local_dir=local_dir) save_name = os.path.join(d, name + '_btracks.csv') tracks_df.to_csv(save_name) # add to df so the object is acessible from ipython dfs[name] = {'obsj': df, 'tracks': tracks_df} # View tracks # ----------- for name in dfs.keys(): zarr_path = os.path.join(data_path, name + '.zarr') img = single_zarr(zarr_path) dfs[name]['image'] = img import napari
def __init__(self, image_file, labels_file, time_index, scale=(1, 1, 4), c=2, t=None): """ Correct labels to create a ground truth with five opperations, each of which correspond to the following number key. (1) toggel selection of points - to seed watershed to split labels. (2) watershed - recompute watershed for joined labels based on chosen points. (3) toggle pick label colour - choose the colour of the label with which to paint. (4) toggle label fill mode - for merging labels (5) toggel paint mode - paint new label. Output can be saved to a new file by using Control-s. Note that this is not necessary if using tensorstore, as annotations will be written to file. However, this is still useful for generating separate copies of GT data (if completing annotations of whole frames). If time_index is None, the save operation will make a copy of the currently displayed frame (dim = t) and the file will have a suffix of the form "t<idx>_GT.zarr". If the labels_file parameter is given a dict, this will be assumed to be JSON-like spec for tensorstore. - ASSUMES IMAGES ARE (c, t, z, y, x) - ASSUMES LABELS ARE (t, z, y, x) - ASSUMES GT FILES ARE (z, y, x) Parameters ---------- image_file: str Path to the image data (.zarr) labels_file: str or dict str: Path to the labels data (.zarr) dict: tensorstore spec for opening the file (also .zarr) time_index: int or None None: all frames int: one frame TODO: slice: selection of frames (must reindex ts when slicing or napari has issues) scale: tuple of int scale of image and labels for napari c: int the channel to read from the image t: int or none position of the time index in the labels file (if this exists). If ndim > 3 and None specified the format will be assumed to be (c*, t, z, y, x) Attributes ---------- tensorstore: bool Should the lables be accessed via tensorstore? This is set to True when the inputted labels_file is a dict (JSON-esque spec for ts.open) gt_file: bool Is this a file ending in the suffix _GT? If so it is assumed to be the saved output of another annotation session time_index: slice, int, or None Gives the point/s in time to be selected labels: ndarray or tensorstore.TensorStore image: dask array scale: tuple of int """ # switches # -------- # tensorstore -> open zarr with tensorstore # affects how we need to open data # gt_file -> already using a ground truth labels # affects how we need to save and access the file # i.e., indexes are thought to apply only to the image # the ground truth is assumed to be the indexed image self.tensorstore = isinstance(labels_file, dict) self.gt_file = None # is reassigned to a bool within _get_path_info # Read/Write Info # --------------- self.labels_file = labels_file self.time_index = time_index self._save_path = self._get_path_info() # Lazy Data # --------- if time_index is None: self.time_index = slice( None) # ensure that the following two lines # work # NOTE: single_zarr opens one channel of a multichannel image # img[c, ...] self.image = single_zarr(image_file, c=c)[self.time_index] self.labels = self._open_labels() # Vis Info # -------- self.viewer = None self.scale = scale self.ndim = len(self.image.shape) if self.ndim > 3 and t == None: t = -4 self.t = t