magmap.io.sqlite module¶
Connects with a SQLite database for experiment and image analysis storage.
- class magmap.io.sqlite.ClrDB[source]¶
Bases:
objectMagellanMapper experiment database handler.
Stores detection related data for ground truth sets, automated detections, and their comparisons.
- Variables:
( (cur) – obj:`sqlite3.Connection): Connection object.
( – obj:`sqlite3.Cursor): Cursor object.
blobs_truth (List[int]) – Truth blobs list as returned by
select_blobs_confirmed().path (str) – Path from which the database was loaded.
- blobs_truth = None¶
- conn = None¶
- cur = None¶
- get_rois(exp_name, ignore_ext=True)[source]¶
Get all ROIs for the given experiment.
- Parameters:
- Returns:
Sequence of all ROIs for the experiment.
- Return type:
List[
sqlite3.Row]
- insert_blob_matches(roi_id, matches)[source]¶
Insert blob matches.
- Parameters:
roi_id (int) – ROI ID.
matches (
magmap.cv.colocalizer.BlobMatch) – Blob matches object.
- Returns:
List of blob match IDs.
- Return type:
- load_db(path, new_db=False)[source]¶
Load a database from an existing path, raising an exception if the path does not exist.
- select_blob(roi_id, blob)[source]¶
Select a blob based on position and status.
- Parameters:
roi_id (int) – ROI ID.
blob (
np.ndarray) – Blob as a 1D array ofz, y, x, r, confirmed, truth, channel.
- Returns:
The blob as a 1D array. The blob ID if available. If more than one blow is found, only the first blob is returned.
- Return type:
np.ndarray, int
- select_blob_by_id(blob_id)[source]¶
Select a blob by ID.
- Parameters:
blob_id (int) – Blob ID.
- Returns:
The blob as a 1D array.
- Return type:
np.ndarray, int
- select_blob_matches(roi_id, offset=None, shape=None)[source]¶
Select blob matches for the given ROI.
- select_blob_matches_by_blob_id(row_id, blobn, blob_ids, max_params=100000)[source]¶
Select blob matches corresponding to the given blob IDs in the given blob column.
- Parameters:
row_id (
int) – Row ID.blobn (
int) – 1 or 2 to indicate the first or second blob column, respectively.max_params (
int, default:100000) – Maximum number of parameters for the SELECT statements; defaults to 100000. The max is determined by SQLITE_MAX_VARIABLE_NUMBER set at the sqlite3 compile time. If this number is exceeded, this function is called recursively with half the given max_params.
- Return type:
- Returns:
Blob match object, which is empty if not matches are found.
- Raises:
sqlit3.OperationalError – if the maximum number of
parameters is < 1. –
- Deprecated: 1.6.0
Use
select_blob_matches()instead.
- select_blobs_by_position(roi_id, offset, size)[source]¶
Select blobs from the given region defined by offset and size.
An ROI ID is still required in cases blobs have been inserted from overlapping ROIs.
- select_blobs_by_roi(roi_id)[source]¶
Select blobs from the given ROI.
- Parameters:
roi_id (int) – ROI ID.
- Returns:
Blobs in the given ROI. List of blob IDs if available.
- Return type:
numpy.ndarray, list[int]
- select_or_insert_experiment(exp_name=None, date=None)[source]¶
Selects an experiment from the given name, or inserts the experiment if not found.
- Parameters:
- Return type:
- Returns:
The ID of the selected or inserted experiment.
- magmap.io.sqlite.clean_up_blobs(db)[source]¶
Clean up blobs from pre-v.0.5.0, where user-added radii have neg values rather than 0.0, and remove all unconfirmed blobs since dragging/dropping decreases the number of delete/adds required for proper blob placement.
- Parameters:
db – Database to clean up, typically a truth database.
- magmap.io.sqlite.delete_blobs(conn, cur, roi_id, blobs)[source]¶
Deletes blobs matching the given blobs’ ROI ID and coordinates.
- Parameters:
conn – The connection.
cur – Connection’s cursor.
roi_id (int) – ROI ID.
blobs – Array of blobs arrays, assumed to be formatted accorind to :func:
detector.format_blob.
- Returns:
The number of rows deleted.
- magmap.io.sqlite.insert_about(conn, cur, version, date)[source]¶
Inserts an experiment into the database.
- Parameters:
conn – The connection.
cur – Connection’s cursor.
name – Name of the experiment.
date – The date as a SQLite date object.
- magmap.io.sqlite.insert_blobs(conn, cur, roi_id, blobs)[source]¶
Inserts blobs into the database, replacing any duplicate blobs.
- Parameters:
conn – The connection.
cur – Connection’s cursor.
roi_id (int) – ROI ID.
blobs – Array of blobs arrays, assumed to be formatted according to :func:
detector.format_blob. “Confirmed” is given as -1 = unconfirmed, 0 = incorrect, 1 = correct.
- magmap.io.sqlite.insert_experiment(conn, cur, name, date=None)[source]¶
Inserts an experiment into the database.
- magmap.io.sqlite.insert_roi(conn, cur, exp_id, series, offset, size)[source]¶
Inserts an ROI into the database.
- Parameters:
( (cur) – obj:`sqlite3.Connection): Connection object.
( – obj:`sqlite3.Cursor): Cursor object.
exp_id (int) – ID of the experiment.
series (int) – Series within the experiment. Can be None, in which case the series will be set to 0.
offset (List[int) – ROI offset as (x, y, z).
size (List[int) – ROI size as (x, y, z)
- Returns:
ID of the selected or inserted row and the feedback string.
- Return type:
- magmap.io.sqlite.load_truth_db(filename_base)[source]¶
Convenience function to load a truth database associated with an image.
- Parameters:
filename_base – MagellanMapper-oriented base name associated with an image path. If the file is not found, :const:
DB_SUFFIX_TRUTHwill be appended and directories removed.- Returns:
The :class:
ClrDBtruth database associated with the image.
- magmap.io.sqlite.match_elements(src, delim, repeat)[source]¶
Repeat a value to match the same number of delimited string elements.
- magmap.io.sqlite.select_blobs_confirmed(cur, confirmed)[source]¶
Selects ROIs from the given experiment
- Parameters:
cur – Connection’s cursor.
confirmed (int) – Blob confirmation status.
- Returns:
Blobs in the given ROI.
- magmap.io.sqlite.select_or_insert_roi(conn, cur, exp_id, series, offset, size)[source]¶
Selects an ROI from the given parameters, or inserts the ROI if not found.
- Parameters:
( (cur) – obj:`sqlite3.Connection): Connection object.
( – obj:`sqlite3.Cursor): Cursor object.
exp_id (int) – ID of the experiment.
series (int) – Series within the experiment. Can be None, in which case all series will be allowed.
offset (List[int) – ROI offset as (x, y, z).
size (List[int) – ROI size as (x, y, z)
- Returns:
ID of the selected or inserted row and feedback on the result.
- Return type:
- magmap.io.sqlite.select_roi(cur, roi_id)[source]¶
Selects an ROI from the ID.
- Parameters:
cur – Connection’s cursor.
roi_id – The ID of the ROI.
- Returns:
The ROI.
- magmap.io.sqlite.select_rois(cur, exp_id)[source]¶
Selects ROIs from the given experiment.
- Parameters:
- Returns:
Sequence of all ROIs for the experiment.
- Return type:
List[
sqlite3.Row]
- magmap.io.sqlite.update_rois(conn, cur, offset, size)[source]¶
Updates ROI positions and size.
- Parameters:
cur – Connection’s cursor.
offset – Amount to subtract from the offset.
size – Amount to add to the size.