utils.py
QuietStdOut
¶
Context for quieting standard output, and setting datajoint loglevel to warning
Used in pytest functions to render clear output showing only pass/fail
Example
with QuietStdOut(): table.delete(safemode=False)
Source code in element_interface/utils.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
dict_to_uuid(key)
¶
Given a dictionary key, returns a hash string as UUID
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
dict
|
Any python dictionary |
required |
Source code in element_interface/utils.py
98 99 100 101 102 103 104 105 106 107 | |
find_full_path(root_directories, relative_path)
¶
Given a list of roots and a relative path, search and return the full-path
Root directories are searched in the provided order
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_directories |
list
|
potential root directories |
required |
relative_path |
str
|
the relative path to find the valid root directory |
required |
Returns:
| Type | Description |
|---|---|
pathlib.PosixPath
|
full-path (pathlib.Path object) |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
No valid full path |
Source code in element_interface/utils.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
find_root_directory(root_directories, full_path)
¶
Given multiple potential root directories and a full-path, return parent root.
Search and return one directory that is the parent of the given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_directories |
list
|
potential root directories |
required |
full_path |
str
|
the full path to search the root directory |
required |
Returns:
| Type | Description |
|---|---|
pathlib.PosixPath
|
root_directory (pathlib.Path object) |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
Full path does not exist |
FileNotFoundError
|
No valid root directory |
Source code in element_interface/utils.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
ingest_csv_to_table(csvs, tables, verbose=True, skip_duplicates=True, ignore_extra_fields=True, allow_direct_insert=False)
¶
Inserts data from a series of csvs into their corresponding table:
Example
ingest_csv_to_table(['./lab_data.csv', './proj_data.csv'], [lab.Lab(),lab.Project()]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csvs |
list
|
list of paths to CSV files relative to current directory. CSV are delimited by commas. |
required |
tables |
list
|
list of datajoint tables with terminal |
required |
verbose |
bool
|
print number inserted (i.e., table length change) |
True
|
skip_duplicates |
bool
|
skip duplicate entries. See DataJoint's |
True
|
ignore_extra_fields |
bool
|
if a csv feeds multiple tables, the subset of
columns not applicable to a table will be ignored. See DataJoint's |
True
|
allow_direct_insert |
bool
|
permit insertion into Imported and Computed tables
See DataJoint's |
False
|
Source code in element_interface/utils.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
value_to_bool(value)
¶
Return whether the provided value represents true. Otherwise false.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
(str, bool, int)
|
Any input |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if value in ("y", "yes", "t", "true", "on", "1") |
Source code in element_interface/utils.py
156 157 158 159 160 161 162 163 164 165 166 167 | |