@@ -232,10 +232,9 @@ def load_rhs(folder: str, file_expr: str):
232232 >>> rhs_data = load_rhs("/home/inbox/organoids21/032520_US_885kHz_sham", file_expr="amp*dat")
233233
234234 # Plot data
235- >>> for signal in rhs_data["signals"]:
236- >>> plt.plot(rhs_data["time"], signal)
235+ >>> plt.plot(rhs_data["time"], rhs_data["recordings"]["amp-B-000.dat"])
237236 >>> plt.xlabel("Time (s)")
238- >>> plt.ylabel("Signal (microvolts) ")
237+ >>> plt.ylabel("Reading ")
239238 >>> plt.show()
240239
241240 Args:
@@ -245,7 +244,7 @@ def load_rhs(folder: str, file_expr: str):
245244 Returns:
246245 rhs_data (dict): RHS data.
247246 rhs_data["header"] (dict): Header.
248- rhs_data["signals "] (np.array_like ): Signal amplitudes in microvolts.
247+ rhs_data["recordings "] (dict ): Readings from various files
249248 rhs_data["timestamps"] (np.array_like): Relative timestamps in seconds.
250249 """
251250
@@ -260,12 +259,29 @@ def load_rhs(folder: str, file_expr: str):
260259 / header ["frequency_parameters" ]["amplifier_sample_rate" ]
261260 )
262261
263- file_paths = list (Path (folder ).glob (file_expr ))
264- signals = np .empty ([len (file_paths ), len (timestamps )])
262+ rhs_data = dict (header = header , timestamps = timestamps , recordings = {})
263+
264+ file_paths = Path (folder ).glob (file_expr )
265+ file_paths = [x for x in file_paths if x .as_posix () != "time.dat" ]
266+
267+ for file_path in file_paths :
268+ file_path = file_path .as_posix ()
269+ if "amp" in file_path :
270+ signal = np .memmap (file_path , dtype = np .int16 )
271+ signal = signal * 0.195 # Convert to microvolts
272+ elif "board-ANALOG-IN" in file_path or "board-ANALOG-OUT" in file_path :
273+ signal = np .memmap (file_path , dtype = np .uint16 )
274+ signal = (signal - 32768 ) * 0.0003125 # Convert to volts
275+ elif "dc-" in file_path :
276+ signal = np .memmap (file_path , dtype = np .uint16 )
277+ signal = (signal - 512 ) * 19.23 # Convert to milivolts
278+ elif "board-DIGITAL-IN" in file_path or "board-DIGITAL-OUT" in file_path :
279+ signal = np .memmap (file_path , dtype = np .uint16 )
280+ elif "stim-" in file_path :
281+ data = np .memmap (file_path , dtype = np .uint16 )
282+ i = np .bitwise_and (data , 255 ) * header ["stim_step_size" ]
283+ sign = (128 - np .bitwise_and (data , 255 )) / 128
284+ signal = i * sign
285+ rhs_data ["recordings" ][Path (file_path ).relative_to (folder ).stem ] = signal
265286
266- for i , file_path in enumerate (file_paths ):
267- signals [i , :] = np .memmap (file_path , dtype = np .int16 )
268- signals = signals * 0.195 # Convert to microvolts
269-
270- rhs_data = dict (header = header , signals = signals , timestamps = timestamps )
271287 return rhs_data
0 commit comments