acq2sqlite¶
+Convert db.txt
into a sqlite database.
Functions
++ | These names match what's used by dcmmeta2tsv.py and 00_build_db.bash CSA first, normal dicom headers, and then filename. |
+
|
++ |
Classes
+
|
+Convenient SQL queries for tracking dicom headers/metadata. |
+
-
+
- +class acq2sqlite.DBQuery(sql=None)[source]¶ +
Convenient SQL queries for tracking dicom headers/metadata.
+This class is a poorly implemented, ad-hoc/bespoke ORM for database defined in
+schema.sql
-
+
- +CONSTS = ['Project', 'SequenceName', 'iPAT', 'Comments', 'SequenceType', 'PED_major', 'Phase', 'TR', 'TE', 'Matrix', 'PixelResol', 'BWP', 'BWPPE', 'FA', 'TA', 'FoV'][source]¶ +
+CONSTS
is a list of expected aquisition-invarient parameters. +The values of these attributes should be the same for every acquisition +sharing aProject × SequenceName
pair (across all sessions of a Project).We consider the acquisition to have a Quallity Assurance error +when the value of any of these parameters in a single acquisition +fails to match the template.
+For example
+ +TR
for task EPI acquisition identified by +SequenceName=RewardedAnti
inProject=WPC-8620
+should always be1300
ms.
-
+
- +check_acq(d)[source]¶ +
Is this exact acquisition (time, id, series) already in the database?
+-
+
- Parameters: +
d (dict[str, str]) – All parameters of an acquisition
+
+- Returns: +
True/False if dict params exist
+
+- Return type: +
bool
+
+
-
+
- +dict_to_db_row(d)[source]¶ +
insert a dicom header (representative of acquisition) into db
+-
+
- Parameters: +
d (dict[str, str])
+
+- Return type: +
None
+
+
-
+
- +get_template(pname, seqname)[source]¶ +
Find the template from
+template_by_count
. Seemake_template_by_count.sql
-
+
- Parameters: +
-
+
pname (str) – protocol name
+sqname – sequence name
+seqname (str)
+
+- Returns: +
template row matching prot+seq name pair
+
+- Return type: +
Row
+
+
-
+
- +is_template(param_id)[source]¶ +
Check if param id is the ideal template.
+-
+
- Parameters: +
param_id (int)
+
+- Return type: +
bool
+
+
-
+
- +param_rowid(d)[source]¶ +
-
+
- Parameters: +
d (dict[str, str]) – dicom headers
+
+- Returns: +
+acq_param
(new or existing) rowid identifying unique set ofCONSTS
+- Return type: +
int | None
+
+
Find or insert the combination of parameters for an acquisition. +Using
+CONSTS
, the header parameters that should be invariant +across acquisitions of the same name within a study.++>>> db = DBQuery(sqlite3.connect(':memory:')) +>>> with open('schema.sql') as f: _ = [db.sql.execute(c) for c in f.read().split(";")] +... +>>> # db.sql.execute(".read schema.sql") +>>> example = {k: 'x' for k in db.CONSTS} +>>> db.param_rowid(example) +1 +>>> db.param_rowid(example) +1 +>>> db.param_rowid({**example, 'Project': 'b'}) +2 +>>> str(db.param_rowid({})) +'None' +
-
+
- +acq2sqlite.column_names()[source]¶ +
These names match what’s used by dcmmeta2tsv.py and 00_build_db.bash +CSA first, normal dicom headers, and then filename.
+Defaults to reading from
+taglist.txt
+This provides a language agnostic lookup for columns inschema.sql
These column names should match what is output by +
+./dcmmeta2tsv.bash
or./dcmmeta2tsv.py
Also see
+dcmmeta2tsv.read_known_tags()
++>>> cn = column_names() # reads taglist.txt +>>> cn[0] # hard coded here +'Phase' +>>> cn[3] # from taglist.xt +'AcqDate' +