44from os .path import join
55from pathlib import Path
66from string import Template
7- from bokeh . plotting import figure , ColumnDataSource
7+
88from bokeh .embed import components
99from bokeh .layouts import gridplot
10+ from bokeh .plotting import ColumnDataSource , figure
1011
1112from phys2bids import _version
1213
@@ -33,14 +34,17 @@ def _save_as_html(log_html_path, log_content, qc_html_path):
3334 Saves the html file
3435 """
3536 resource_path = Path (__file__ ).resolve ().parent
36- head_template_name = ' report_log_template.html'
37+ head_template_name = " report_log_template.html"
3738 head_template_path = resource_path .joinpath (head_template_name )
38- with open (str (head_template_path ), 'r' ) as head_file :
39+ with open (str (head_template_path ), "r" ) as head_file :
3940 head_tpl = Template (head_file .read ())
4041
41- html = head_tpl .substitute (version = _version .get_versions ()['version' ],
42- log_html_path = log_html_path , log_content = log_content ,
43- qc_html_path = qc_html_path )
42+ html = head_tpl .substitute (
43+ version = _version .get_versions ()["version" ],
44+ log_html_path = log_html_path ,
45+ log_content = log_content ,
46+ qc_html_path = qc_html_path ,
47+ )
4448 return html
4549
4650
@@ -67,16 +71,18 @@ def _update_fpage_template(tree_string, bokeh_id, bokeh_js, log_html_path, qc_ht
6771 """
6872 resource_path = Path (__file__ ).resolve ().parent
6973
70- body_template_name = ' report_plots_template.html'
74+ body_template_name = " report_plots_template.html"
7175 body_template_path = resource_path .joinpath (body_template_name )
72- with open (str (body_template_path ), 'r' ) as body_file :
76+ with open (str (body_template_path ), "r" ) as body_file :
7377 body_tpl = Template (body_file .read ())
74- body = body_tpl .substitute (tree = tree_string ,
75- content = bokeh_id ,
76- javascript = bokeh_js ,
77- version = _version .get_versions ()['version' ],
78- log_html_path = log_html_path ,
79- qc_html_path = qc_html_path )
78+ body = body_tpl .substitute (
79+ tree = tree_string ,
80+ content = bokeh_id ,
81+ javascript = bokeh_js ,
82+ version = _version .get_versions ()["version" ],
83+ log_html_path = log_html_path ,
84+ qc_html_path = qc_html_path ,
85+ )
8086 return body
8187
8288
@@ -94,13 +100,13 @@ def _generate_file_tree(out_dir):
94100 tree_string: String with the tree of files in directory
95101 """
96102 # prefix components:
97- space = '  '
98- branch = ' │ '
103+ space = "  "
104+ branch = " │ "
99105 # pointers:
100- tee = ' ├── '
101- last = ' └── '
106+ tee = " ├── "
107+ last = " └── "
102108
103- def tree (dir_path : Path , prefix : str = '' ):
109+ def tree (dir_path : Path , prefix : str = "" ):
104110 """Generate tree structure.
105111
106112 Given a directory Path object
@@ -119,9 +125,9 @@ def tree(dir_path: Path, prefix: str = ''):
119125 # i.e. space because last, └── , above so no more |
120126 yield from tree (path , prefix = prefix + extension )
121127
122- tree_string = ''
128+ tree_string = ""
123129 for line in tree (Path (out_dir )):
124- tree_string += line + ' <br>'
130+ tree_string += line + " <br>"
125131 return tree_string
126132
127133
@@ -145,7 +151,7 @@ def _generate_bokeh_plots(phys_in, figsize=(250, 500)):
145151 --------
146152 https://phys2bids.readthedocs.io/en/latest/howto.html
147153 """
148- colors = [' #ff7a3c' , ' #008eba' , ' #ff96d3' , ' #3c376b' , ' #ffd439' ]
154+ colors = [" #ff7a3c" , " #008eba" , " #ff96d3" , " #3c376b" , " #ffd439" ]
149155
150156 time = phys_in .timeseries .T [0 ] # assumes first phys_in.timeseries is time
151157 ch_num = len (phys_in .ch_name )
@@ -158,29 +164,30 @@ def _generate_bokeh_plots(phys_in, figsize=(250, 500)):
158164 # build a data source for each plot, with only the data + index (time)
159165 # for the purpose of reporting, data is downsampled 10x
160166 # doesn't make much of a difference to the naked eye, fine for reports
161- source = ColumnDataSource (data = dict (
162- x = time [::downsample ],
163- y = timeser [::downsample ]))
167+ source = ColumnDataSource (data = dict (x = time [::downsample ], y = timeser [::downsample ]))
164168
165169 i = row + 1
166170
167- tools = ['wheel_zoom,pan,reset' ]
168- q = figure (plot_height = figsize [0 ], plot_width = figsize [1 ],
169- tools = tools ,
170- title = f' Channel { i } : { phys_in .ch_name [i ]} ' ,
171- sizing_mode = 'stretch_both' )
172- q .line ('x' , 'y' , color = colors [i - 1 ], alpha = 0.9 , source = source )
173- q .xaxis .axis_label = 'Time (s)'
171+ tools = ["wheel_zoom,pan,reset" ]
172+ q = figure (
173+ plot_height = figsize [0 ],
174+ plot_width = figsize [1 ],
175+ tools = tools ,
176+ title = f" Channel { i } : { phys_in .ch_name [i ]} " ,
177+ sizing_mode = "stretch_both" ,
178+ )
179+ q .line ("x" , "y" , color = colors [i - 1 ], alpha = 0.9 , source = source )
180+ q .xaxis .axis_label = "Time (s)"
174181 # hovertool commented for posterity because I (KB) will be triumphant
175182 # eventually
176183 # q.add_tools(HoverTool(tooltips=[
177184 # (phys_in.ch_name[i], '@y{0.000} ' + phys_in.units[i]),
178185 # ('HELP', '100 :D')
179186 # ], mode='vline'))
180187 plot_list .append ([q ])
181- p = gridplot (plot_list , toolbar_location = 'right' ,
182- plot_height = 250 , plot_width = 750 ,
183- merge_tools = True )
188+ p = gridplot (
189+ plot_list , toolbar_location = "right" , plot_height = 250 , plot_width = 750 , merge_tools = True
190+ )
184191 script , div = components (p )
185192 return script , div
186193
@@ -207,27 +214,27 @@ def generate_report(out_dir, log_path, phys_in):
207214 https://phys2bids.readthedocs.io/en/latest/howto.html
208215 """
209216 # Copy assets into output folder
210- pkgdir = sys .modules [' phys2bids' ].__path__ [0 ]
211- assets_path = join (pkgdir , ' reporting' , ' assets' )
212- copy_tree (assets_path , join (out_dir , ' assets' ))
217+ pkgdir = sys .modules [" phys2bids" ].__path__ [0 ]
218+ assets_path = join (pkgdir , " reporting" , " assets" )
219+ copy_tree (assets_path , join (out_dir , " assets" ))
213220
214221 # Read log
215- with open (log_path , 'r' ) as f :
222+ with open (log_path , "r" ) as f :
216223 log_content = f .read ()
217224
218- log_content = log_content .replace (' \n ' , ' <br>' )
219- log_html_path = join (out_dir , ' phys2bids_report_log.html' )
220- qc_html_path = join (out_dir , ' phys2bids_report.html' )
225+ log_content = log_content .replace (" \n " , " <br>" )
226+ log_html_path = join (out_dir , " phys2bids_report_log.html" )
227+ qc_html_path = join (out_dir , " phys2bids_report.html" )
221228
222229 html = _save_as_html (log_html_path , log_content , qc_html_path )
223230
224- with open (log_html_path , 'wb' ) as f :
225- f .write (html .encode (' utf-8' ))
231+ with open (log_html_path , "wb" ) as f :
232+ f .write (html .encode (" utf-8" ))
226233
227234 # Read in output directory structure & create tree
228235 tree_string = _generate_file_tree (out_dir )
229236 bokeh_js , bokeh_div = _generate_bokeh_plots (phys_in , figsize = (250 , 750 ))
230237 html = _update_fpage_template (tree_string , bokeh_div , bokeh_js , log_html_path , qc_html_path )
231238
232- with open (qc_html_path , 'wb' ) as f :
233- f .write (html .encode (' utf-8' ))
239+ with open (qc_html_path , "wb" ) as f :
240+ f .write (html .encode (" utf-8" ))
0 commit comments