Skip to content

Commit

Permalink
clean up for bruker process
Browse files Browse the repository at this point in the history
not quite sure why I suppressed summary for sima - note to self
  • Loading branch information
zhounapeuw committed Nov 16, 2023
1 parent a4a4faa commit 99b2745
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
" start_idx = chunk_frames[0]\n",
" end_idx = chunk_frames[-1]+1\n",
"\n",
" data_to_save = tiff.imread(glob_list[start_idx:end_idx], key=0, is_ome=True)\n",
" data_to_save = tiff.imread(glob_list[start_idx:end_idx], key=0, is_ome=True) # key indicates the page in the tiff\n",
"\n",
" if save_format == 'tif':\n",
"\n",
Expand Down Expand Up @@ -414,6 +414,11 @@
" analog_xml = ET.parse(xml_fpath).getroot()\n",
" return float(analog_xml.findall('Experiment')[0].find('Rate').text)\n",
"\n",
"def read_analog_csv(csv_path):\n",
" cycle_df = pd.read_csv(csv_path)\n",
" cycle_df['Time(s)'] = cycle_df['Time(ms)'] / 1000.0\n",
" cycle_df['cycle_num'] = float(re.findall('Cycle(\\d+)', csv_path)[0]) # get cycle # from filename\n",
" return cycle_df\n",
"\n",
"\"\"\"\n",
"Concatenate the analog input csv files if there are multiple cycles. Also make a dataframe with the \n",
Expand All @@ -438,11 +443,8 @@
" analog_concat = pd.DataFrame()\n",
" for cycle_idx, cycle_path_csv in enumerate(glob_analog_csv):\n",
"\n",
" cycle_df = pd.read_csv(cycle_path_csv)\n",
" num_samples = len(cycle_df['Time(ms)'])\n",
" cycle_df['Time(s)'] = cycle_df['Time(ms)']/1000.0\n",
" cycle_df = self.read_analog_csv(cycle_path_csv)\n",
"\n",
" cycle_df['cycle_num'] = float(re.findall('Cycle(\\d+)', cycle_path_csv)[0]) # get cycle # from filename\n",
" if cycle_idx == 0: # initialize pd dataframe with first cycle's data\n",
" cycle_df['cumulative_time_ms'] = cycle_df['Time(ms)'].values\n",
" analog_concat = cycle_df\n",
Expand All @@ -456,16 +458,12 @@
" analog_concat.columns = analog_concat.columns.str.strip().str.lower().str.replace(' ', '_').str.replace('(', '_').str.replace(')', '')\n",
" \n",
" # loop through all analog columns and get the diff and threshold for event onsets\n",
" analog_column_names = [column for column in analog_concat.columns if 'input' in column]\n",
" num_analogs = len(analog_column_names) \n",
" analog_column_names = [column for column in analog_concat.columns if 'input' in column] \n",
" for idx, analog_column_name in enumerate(analog_column_names):\n",
" \n",
" ttl_thresh = fparams['analog_ttl_thresh']\n",
" if 'stim' in fparams['analog_names']: \n",
" if idx == fparams['analog_names'].index('stim'):\n",
" ttl_thresh = 0.01\n",
" if 'stim' in fparams['analog_names'] and idx == fparams['analog_names'].index('stim'): \n",
" ttl_thresh = 0.01\n",
" \n",
" \n",
" print(analog_column_name)\n",
" print(ttl_thresh)\n",
" analog_concat[analog_column_name + '_diff'] = np.append(np.diff(analog_concat[analog_column_name]) > ttl_thresh, \n",
Expand Down Expand Up @@ -835,6 +833,35 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.16"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
Expand Down
49 changes: 38 additions & 11 deletions napeca/prepreprocess/bruker_data_process.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@
" analog_xml = ET.parse(xml_fpath).getroot()\n",
" return float(analog_xml.findall('Experiment')[0].find('Rate').text)\n",
"\n",
"def read_analog_csv(csv_path):\n",
" cycle_df = pd.read_csv(csv_path)\n",
" cycle_df['Time(s)'] = cycle_df['Time(ms)'] / 1000.0\n",
" cycle_df['cycle_num'] = float(re.findall('Cycle(\\d+)', csv_path)[0]) # get cycle # from filename\n",
" return cycle_df\n",
"\n",
"\"\"\"\n",
"Concatenate the analog input csv files if there are multiple cycles. Also make a dataframe with the \n",
Expand All @@ -438,11 +443,8 @@
" analog_concat = pd.DataFrame()\n",
" for cycle_idx, cycle_path_csv in enumerate(glob_analog_csv):\n",
"\n",
" cycle_df = pd.read_csv(cycle_path_csv)\n",
" num_samples = len(cycle_df['Time(ms)'])\n",
" cycle_df['Time(s)'] = cycle_df['Time(ms)']/1000.0\n",
" cycle_df = self.read_analog_csv(cycle_path_csv)\n",
"\n",
" cycle_df['cycle_num'] = float(re.findall('Cycle(\\d+)', cycle_path_csv)[0]) # get cycle # from filename\n",
" if cycle_idx == 0: # initialize pd dataframe with first cycle's data\n",
" cycle_df['cumulative_time_ms'] = cycle_df['Time(ms)'].values\n",
" analog_concat = cycle_df\n",
Expand All @@ -456,16 +458,12 @@
" analog_concat.columns = analog_concat.columns.str.strip().str.lower().str.replace(' ', '_').str.replace('(', '_').str.replace(')', '')\n",
" \n",
" # loop through all analog columns and get the diff and threshold for event onsets\n",
" analog_column_names = [column for column in analog_concat.columns if 'input' in column]\n",
" num_analogs = len(analog_column_names) \n",
" analog_column_names = [column for column in analog_concat.columns if 'input' in column] \n",
" for idx, analog_column_name in enumerate(analog_column_names):\n",
" \n",
" ttl_thresh = fparams['analog_ttl_thresh']\n",
" if 'stim' in fparams['analog_names']: \n",
" if idx == fparams['analog_names'].index('stim'):\n",
" ttl_thresh = 0.01\n",
" if 'stim' in fparams['analog_names'] and idx == fparams['analog_names'].index('stim'): \n",
" ttl_thresh = 0.01\n",
" \n",
" \n",
" print(analog_column_name)\n",
" print(ttl_thresh)\n",
" analog_concat[analog_column_name + '_diff'] = np.append(np.diff(analog_concat[analog_column_name]) > ttl_thresh, \n",
Expand Down Expand Up @@ -835,6 +833,35 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.16"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion napeca/sima_extract_roi_sig.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def extract(fpath):
dataset = sima.ImagingDataset.load(os.path.join(fdir, fname + '_mc.sima')) # reload motion-corrected dataset
dataset.add_ROIs(rois, 'from_ImageJ')
print('Extracting roi signals from %s' % fdir)
signals = dataset.extract(rois)
signals = dataset.extract(rois, save_summary=False)
extracted_signals = np.asarray(signals['raw']) # turn signals list into an np array
np.save(os.path.join(fdir, fname + '_extractedsignals.npy'), extracted_signals)
np.savetxt(os.path.join(fdir, fname + '_extractedsignals.csv'), np.squeeze(extracted_signals), delimiter=",")
Expand Down

0 comments on commit 99b2745

Please sign in to comment.