2323# Cofounder's compression library
2424try :
2525 import ndicompress
26+
2627 HAS_COMPRESS = True
2728except ImportError :
2829 HAS_COMPRESS = False
@@ -60,7 +61,7 @@ def demo_full_workflow():
6061 spike_times = np .random .choice (num_samples , size = 20 , replace = False )
6162 for st in spike_times :
6263 if st + 30 < num_samples :
63- data [st : st + 30 , ch ] += np .sin (np .linspace (0 , np .pi , 30 )) * 500
64+ data [st : st + 30 , ch ] += np .sin (np .linspace (0 , np .pi , 30 )) * 500
6465
6566 data = data .astype (np .int16 ) # Convert to int16 for ephys
6667 print (f" Data shape: { data .shape } " )
@@ -90,40 +91,30 @@ def demo_full_workflow():
9091 # In real usage, we'd load from JSON schema
9192 # For demo, we create a simple document structure
9293 doc_props = {
93- 'base' : {
94- 'id' : Ido ().id ,
95- 'datestamp' : timestamp (),
96- 'name' : 'ephys_recording_001' ,
97- 'session_id' : ''
98- },
99- 'document_class' : {
100- 'class_name' : 'ndi_document_ephys' ,
101- 'superclasses' : []
94+ "base" : {
95+ "id" : Ido ().id ,
96+ "datestamp" : timestamp (),
97+ "name" : "ephys_recording_001" ,
98+ "session_id" : "" ,
10299 },
103- 'ephys' : {
104- 'num_channels' : num_channels ,
105- 'sample_rate' : sample_rate ,
106- 'num_samples' : num_samples ,
107- 'duration_seconds' : num_samples / sample_rate ,
108- 'data_type' : 'int16' ,
109- 'compression' : 'ndi_compress_ephys'
100+ "document_class" : {"class_name" : "ndi_document_ephys" , "superclasses" : []},
101+ "ephys" : {
102+ "num_channels" : num_channels ,
103+ "sample_rate" : sample_rate ,
104+ "num_samples" : num_samples ,
105+ "duration_seconds" : num_samples / sample_rate ,
106+ "data_type" : "int16" ,
107+ "compression" : "ndi_compress_ephys" ,
110108 },
111- 'files' : {
112- 'file_list' : ['ephys_data.nbf_#' ],
113- 'file_info' : []
114- }
109+ "files" : {"file_list" : ["ephys_data.nbf_#" ], "file_info" : []},
115110 }
116111
117112 doc = Document (doc_props )
118113
119114 # === Step 4: Link compressed file to document ===
120115 print ("\n [4] Linking compressed file to document..." )
121116
122- doc = doc .add_file (
123- name = 'ephys_data.nbf_1' ,
124- location = compressed_file ,
125- ingest = True
126- )
117+ doc = doc .add_file (name = "ephys_data.nbf_1" , location = compressed_file , ingest = True )
127118
128119 print (f" Document ID: { doc .id } " )
129120 print (f" Document class: { doc .doc_class ()} " )
@@ -133,9 +124,9 @@ def demo_full_workflow():
133124 print ("\n [5] Query demonstration..." )
134125
135126 # These queries would work with ndi.database
136- q1 = Query (' ephys.num_channels' ) == 4
137- q2 = Query (' ephys.sample_rate' ) > 20000
138- q3 = Query (' base.name' ).contains (' ephys' )
127+ q1 = Query (" ephys.num_channels" ) == 4
128+ q2 = Query (" ephys.sample_rate" ) > 20000
129+ q3 = Query (" base.name" ).contains (" ephys" )
139130
140131 # Combined query
141132 _q_combined = q1 & q2 & q3
@@ -166,9 +157,9 @@ def demo_full_workflow():
166157 # Still show document creation without compression
167158 print ("\n [3] Creating ndi.Document (without compression)..." )
168159
169- doc = Document (' base' )
170- doc = doc .set_session_id (' demo_session' )
171- doc = doc .setproperties (** {' base.name' : ' ephys_demo' })
160+ doc = Document (" base" )
161+ doc = doc .set_session_id (" demo_session" )
162+ doc = doc .setproperties (** {" base.name" : " ephys_demo" })
172163
173164 print (f" Document ID: { doc .id } " )
174165 print (f" Session ID: { doc .session_id } " )
@@ -214,17 +205,19 @@ def demo_document_features():
214205 print ("=" * 60 )
215206
216207 # Create a document
217- doc = Document (' base' )
208+ doc = Document (" base" )
218209 print (f"\n 1. Created document with ID: { doc .id } " )
219210
220211 # Set session
221- doc = doc .set_session_id (' session_abc123' )
212+ doc = doc .set_session_id (" session_abc123" )
222213 print (f"2. Set session ID: { doc .session_id } " )
223214
224215 # Bulk property setting (useful for ephys metadata)
225- doc = doc .setproperties (** {
226- 'base.name' : 'neural_recording' ,
227- })
216+ doc = doc .setproperties (
217+ ** {
218+ "base.name" : "neural_recording" ,
219+ }
220+ )
228221 print ("3. Set name via setproperties" )
229222
230223 # Document equality (by ID)
@@ -233,9 +226,9 @@ def demo_document_features():
233226
234227 # Static methods for working with document arrays
235228 docs = [
236- Document (' base' ),
237- Document (' base' ),
238- Document (' base' ),
229+ Document (" base" ),
230+ Document (" base" ),
231+ Document (" base" ),
239232 ]
240233
241234 newest , idx , ts = Document .find_newest (docs )
@@ -251,6 +244,6 @@ def demo_document_features():
251244 print ("\n All features work and are ready to integrate with ndicompress!" )
252245
253246
254- if __name__ == ' __main__' :
247+ if __name__ == " __main__" :
255248 demo_full_workflow ()
256249 demo_document_features ()
0 commit comments