spyglass icon indicating copy to clipboard operation
spyglass copied to clipboard

A more pythonic user interface

Open khl02007 opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe. Most users who know python do not know the datajoint-specific syntax required to interact with the pipelines. A more pythonic, object-oriented interface could improve the user experience.

Example Ingesting an NWB file returns a spyglass session object:

import spyglass as sg
nwb_file = 'test.nwb'
session = sg.insert_session(nwb_file)

One can access everything about the session (e.g. information in the common table) as attributes of the session object. Calling these attributes prints the datajoint table. For example, session.electrode prints spyglass.common.Electrode & {'nwb_file_name': 'test.nwb'}.

To do analysis, set parameters by calling methods associated with the session object:

session.insert_electrode_group(electrode_group_name='tetrode1', electrode_ids=[1,2,3,4])
session.insert_interval(interval_name='epoch1', interval=[10,20])

and then run the computation

# this runs spyglass.lfp.LFP.populate() under the hood
session.compute_lfp(electrode_group_name='tetrode1', interval_name='epoch1', filter_param_name='default')
# see results 
print(session.lfp) # this prints spyglass.lfp.LFP &  {'nwb_file_name': 'test.nwb'}
# select a computed LFP with index and create visualization
session.lfp[0].generate_figurl()

Later, the user can reinstantiate the session object from the NWB file.

session = sg.load_session('test.nwb')

Advantages

  • the user doesn't interact directly with the database, so cannot make mistakes like accidental deletes or drops
  • simpler and more intuitive than interacting with datajoint tables
  • awkwardness in the pipelines (e.g. Selection tables, or unintuitive names) are hidden
  • adding this doesn't lead to dropping any tables or breaking the database, so relatively low risk
  • the user doesn't need to carry around a long dictionary to identify a row in a table (can use tab-completion instead)

Disadvantages

  • cannot do complex queries or joins; for this we would just need to use the datajoint API
  • possibly limited in scope; unclear if one will be able to conform every pipeline to this structure

khl02007 avatar Jun 01 '23 06:06 khl02007