dj_helper_fn.py
Helper functions for manipulating information from DataJoint fetch calls.
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
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 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 |
|
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
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 393 394 |
|
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
NonDaemonPool. Used to create a pool of non-daemonized processes, which are required for parallel populate operations in DataJoint.