dj_helper_fn.py
Helper functions for manipulating information from DataJoint fetch calls.
sanitize_unix_name(name)
¶
Sanitize a string to be a valid unix name.
This function replaces any invalid characters with underscores and removes leading and trailing whitespace. It warns the user if the name has been changed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name to sanitize. |
required |
Returns:
Type | Description |
---|---|
str
|
Sanitized name. |
Source code in src/spyglass/utils/dj_helper_fn.py
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
declare_all_merge_tables()
¶
Ensures all merge tables in the spyglass core package are declared. - Prevents circular imports - Prevents errors from table declaration within a transaction - Run during nwb insertion
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
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 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 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 |
|
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', resolve_external_table=True)
¶
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'
|
resolve_external_table
|
bool
|
whether to update the external table. Set False if editing file outside the database, by default True |
True
|
Source code in src/spyglass/utils/dj_helper_fn.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
|
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.
Source code in src/spyglass/utils/dj_helper_fn.py
str_to_bool(value)
¶
Return whether the provided string represents true. Otherwise false.