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
instance_table(table)
¶
Instantiate a DataJoint table from its class, if uninstantiated.
Source code in src/spyglass/utils/dj_helper_fn.py
fetch_nwb(*attrs, **kwargs)
¶
Deprecated. Use (table & key).fetch_nwb() instead.
Migration guide: https://lorenfranklab.github.io/spyglass/latest/Features/Mixin/
Source code in src/spyglass/utils/dj_helper_fn.py
get_child_tables(table)
¶
Get all child tables of a given table.
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.
Source code in src/spyglass/utils/dj_helper_fn.py
bytes_to_human_readable(size)
¶
Convert a byte size to a human-readable format.
Source code in src/spyglass/utils/dj_helper_fn.py
accept_divergence(key, new_value, existing_value, test_mode=False, table_name=None)
¶
Prompt to accept divergence in values between existing and new entries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Name of the column where the divergence is found |
required |
new_value
|
Any
|
New value to be inserted into the table |
required |
existing_value
|
Any
|
Existing value in the table that is different from the new value |
required |
test_mode
|
bool
|
If True, will not prompt and return False, by default False |
False
|
table_name
|
str
|
Name of the table where the divergence is found, by default None |
None
|