dj_helper_fn.py
Helper functions for manipulating information from DataJoint fetch calls.
ensure_names(table=None, force_list=False)
¶
Ensure table is a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table |
Union[str, Table, Iterable]
|
Table to ensure is a string, by default None. If passed as iterable, will ensure all elements are strings. |
None
|
force_list |
bool
|
Force the return to be a list, by default False, only used if input is iterable. |
False
|
Returns:
Type | Description |
---|---|
Union[str, List[str], None]
|
Table as a string or list of strings. |
Source code in src/spyglass/utils/dj_helper_fn.py
fuzzy_get(index, names, sources)
¶
Given lists of items/names, return item at index or by substring.
Source code in src/spyglass/utils/dj_helper_fn.py
unique_dicts(list_of_dict)
¶
deprecated_factory(classes, old_module='')
¶
Creates a list of classes and logs a warning when instantiated
Parameters:
Name | Type | Description | Default |
---|---|---|---|
classes |
list
|
list of tuples containing old_class, new_class |
required |
Returns:
Type | Description |
---|---|
list
|
list of classes that will log a warning when instantiated |
Source code in src/spyglass/utils/dj_helper_fn.py
dj_replace(original_table, new_values, key_column, replace_column)
¶
Given the output of a fetch() call from a schema and a 2D array made up of (key_value, replace_value) tuples, find each instance of key_value in the key_column of the original table and replace the specified replace_column with the associated replace_value. Key values must be unique.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original_table |
Result of a datajoint .fetch() call on a schema query. |
required | |
new_values |
list
|
List of tuples, each containing (key_value, replace_value). |
required |
replace_column |
str
|
The name of the column where to-be-replaced values are located. |
required |
Returns:
Type | Description |
---|---|
original_table
|
Structured array of new table entries that can be inserted back into the schema |
Source code in src/spyglass/utils/dj_helper_fn.py
get_all_tables_in_stack(stack)
¶
Get all classes from a stack of tables.
Source code in src/spyglass/utils/dj_helper_fn.py
get_fetching_table_from_stack(stack)
¶
Get all classes from a stack of tables.
Source code in src/spyglass/utils/dj_helper_fn.py
get_nwb_table(query_expression, tbl, attr_name, *attrs, **kwargs)
¶
Get the NWB file name and path from the given DataJoint query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_expression |
query
|
A DataJoint query expression (e.g., join, restrict) or a table to call fetch on. |
required |
tbl |
table
|
DataJoint table to fetch from. |
required |
attr_name |
str
|
Attribute name to fetch from the table. |
required |
*attrs |
list
|
Attributes from normal DataJoint fetch call. |
()
|
**kwargs |
dict
|
Keyword arguments from normal DataJoint fetch call. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
nwb_files |
list
|
List of NWB file names. |
file_path_fn |
function
|
Function to get the absolute path to the NWB file. |
Source code in src/spyglass/utils/dj_helper_fn.py
fetch_nwb(query_expression, nwb_master, *attrs, **kwargs)
¶
Get an NWB object from the given DataJoint query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_expression |
query
|
A DataJoint query expression (e.g., join, restrict) or a table to call fetch on. |
required |
nwb_master |
tuple
|
Tuple (table, attr) to get the NWB filepath from. i.e. absolute path to NWB file can be obtained by looking up attr column of table table is usually Nwbfile or AnalysisNwbfile; attr is usually 'nwb_file_abs_path' or 'analysis_file_abs_path' |
required |
*attrs |
list
|
Attributes from normal DataJoint fetch call. |
()
|
**kwargs |
dict
|
Keyword arguments from normal DataJoint fetch call. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
nwb_objects |
list
|
List of dicts containing fetch results and NWB objects. |
Source code in src/spyglass/utils/dj_helper_fn.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
get_child_tables(table)
¶
Get all child tables of a given table.
Source code in src/spyglass/utils/dj_helper_fn.py
update_analysis_for_dandi_standard(filepath, age='P4M/P8M')
¶
Function to resolve common nwb file format errors within the database
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
str
|
abs path to the file to edit |
required |
age |
str
|
age to assign animal if missing, by default "P4M/P8M" |
'P4M/P8M'
|
Source code in src/spyglass/utils/dj_helper_fn.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
dandi_format_names(experimenter)
¶
Make names compliant with dandi standard of "Last, First"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
experimenter |
List
|
List of experimenter names |
required |
Returns:
Type | Description |
---|---|
List
|
reformatted list of experimenter names |
Source code in src/spyglass/utils/dj_helper_fn.py
make_file_obj_id_unique(nwb_path)
¶
Make the top-level object_id attribute of the file unique
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nwb_path |
str
|
path to the NWB file |
required |
Returns:
Type | Description |
---|---|
str
|
the new object_id |
Source code in src/spyglass/utils/dj_helper_fn.py
populate_pass_function(value)
¶
Pass function for parallel populate.
Note: To avoid pickling errors, the table must be passed by class, NOT by instance. Note: This function must be defined in the global namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
(table, key, kwargs)
|
Class of table to populate, key to populate, and kwargs for populate |
required |
Source code in src/spyglass/utils/dj_helper_fn.py
NonDaemonPool
¶
Bases: Pool
Non-daemonized pool for multiprocessing.
Used to create a pool of non-daemonized processes, which are required for parallel populate operations in DataJoint.
Source code in src/spyglass/utils/dj_helper_fn.py
Process(*args, **kwds)
¶
Return a non-daemonized process.