def _get_truth_db_rois(subimg_path_base, filename_base, db_path_base=None): """Get ROIs from a truth database. Args: subimg_path_base (str): Base path with sub-image. filename_base (str): Base path without sub-image to find the experiment, used only if an experiment cannot be found based on ``subimg_path_base``. db_path_base (str): Path to database to load; defaults to None to use :attr:`config.truth_db`. Returns: str, list[:class:`sqlite3.Row`]: Found experiment name and list of database ROI rows in that experiment, or None for each if the ROIs are not found. """ name = None exp_rois = None if db_path_base: # load truth DB _logger.debug("Loading truth db for verifications from '%s'", db_path_base) sqlite.load_truth_db(db_path_base) if config.truth_db is not None: # load experiment and ROIs from truth DB using the sub-image-based # name; series not included in exp name since in ROI name = sqlite.get_exp_name(subimg_path_base) _logger.debug("Loading truth ROIs from experiment '%s'", name) exp_rois = config.truth_db.get_rois(name) if exp_rois is None: # exp may have been named without sub-image old_name = name name = sqlite.get_exp_name(filename_base) _logger.debug( "'%s' experiment name not found, will try without any " "sub-image offset/size: '%s'", old_name, name) exp_rois = config.truth_db.get_rois(name) if exp_rois is None: # exp may differ from image name all together _logger.debug( "'%s' experiment name not found, will try first " "available experiment", name) exps = config.truth_db.select_experiment() if exps: name = exps[0]["name"] _logger.debug( "Loading ROIs from first available experiment: '%s'", name) exp_rois = config.truth_db.get_rois(name) if not exp_rois: _logger.warn("No matching experiments found in the truth database") return name, exp_rois
def _get_truth_db_rois(subimg_path_base, filename_base, db_path_base=None): """Get ROIs from a truth database. Args: subimg_path_base (str): Base path with sub-image. filename_base (str): Base path without sub-image to find the experiment, used only if an experiment cannot be found based on ``subimg_path_base``. db_path_base (str): Path to database to load; defaults to None to use :attr:`config.truth_db`. Returns: str, list[:class:`sqlite3.Row`]: Found experiment name and list of database ROI rows in that experiment, or None for each if the ROIs are not found. """ name = None exp_rois = None if db_path_base: # load truth DB print("Loading truth db for verifications from", db_path_base) sqlite.load_truth_db(db_path_base) if config.truth_db is not None: # load experiment and ROIs from truth DB using the sub-image-based # name; series not included in exp name since in ROI name = sqlite.get_exp_name(subimg_path_base) print("Loading truth ROIs from experiment:", name) exp_rois = config.truth_db.get_rois(name) if exp_rois is None: # exp may have been named without sub-image print("{} experiment name not found, will try without " "sub-image offset/size".format(name)) name = sqlite.get_exp_name(filename_base) exp_rois = config.truth_db.get_rois(name) return name, exp_rois
def make_density_images_mp(img_paths, scale=None, shape=None, suffix=None, channel=None): """Make density images for a list of files as a multiprocessing wrapper for :func:``make_density_image`` Args: img_paths (List[str]): Sequence of image paths, which will be used to indentify the blob files. scale (int, float): Rescaling factor as a scalar value. If set, the corresponding image for this factor will be opened. If None, the full size image will be used. Defaults to None. shape (List[int]): Sequence of target shape defining the voxels for the density map; defaults to None. suffix (str): Modifier to append to end of ``img_path`` basename for registered image files that were output to a modified name; defaults to None. channel (List[int]): Sequence of channels to include in density image; defaults to None to use all channels. """ start_time = time() pool = chunking.get_mp_pool() pool_results = [] for img_path in img_paths: print("Making density image from blobs related to:", img_path) if config.channel: # get blob matches for the given channels if available; must load # from db outside of multiprocessing to avoid MemoryError matches = colocalizer.select_matches( config.db, config.channel, exp_name=sqlite.get_exp_name(img_path)) else: matches = None pool_results.append( pool.apply_async(make_density_image, args=(img_path, scale, shape, suffix, None, channel, matches, config.atlas_profile))) for result in pool_results: _, path = result.get() print("finished {}".format(path)) pool.close() pool.join() print("time elapsed for making density images:", time() - start_time)
def _get_roi_id(db, offset, shape, exp_name=None): """Get database ROI ID for the given ROI position within the main image5d. Args: db (:obj:`sqlite.ClrDB`): Database object. offset (List[int]): ROI offset in z,y,x. shape (List[int]): ROI shape in z,y,x. exp_name (str): Name of experiment; defaults to None to attempt discovery through any image loaded to :attr:`config.img5d`. Returns: int: ROI ID or found or inserted ROI. """ if exp_name is None: exp_name = sqlite.get_exp_name( config.img5d.path_img if config.img5d else None) exp_id = sqlite.select_or_insert_experiment( db.conn, db.cur, exp_name, None) roi_id = sqlite.select_or_insert_roi( db.conn, db.cur, exp_id, config.series, offset, shape)[0] return roi_id