tvaLib
batch-run.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # tvaLib Copyright (c) 2012-2016 Paul G. St-Aubin
3 # Ecole Polytechnique de Montreal, McGill University
4 # Python 2.7; (dt) Spyder Windows 10 64-bit; ipython Ubuntu 15.04 64-bit
5 version = 'R2.3.0 u. 2017-03-22'
6 
7 '''
8 -w -a -y cg -n fr --figure-format pdf --figure-resize 16.0 10.0 --hli-report --concat-data -i 5
9 '''
10 
11 
12 
15 def main():
16  try:
17 
18 
22  import sys, os, time, logging, subprocess
23  from site import addsitedir
24  from warnings import filterwarnings
25  filterwarnings('ignore')
26 
27  #Add parent library
28  if(os.path.isfile(os.path.join(os.getcwd(), os.pardir, 'main.py'))):
29  addsitedir(os.path.join(os.getcwd(), os.pardir))
30  os.chdir(os.path.join(os.getcwd(), os.pardir))
31 
32  import include.config as tvaConfig
33  import include.local as tvaLocal
34 
35 
38  commands = tvaConfig.commands()
39  config = tvaConfig.Config(readonly=commands.configreadonly)
40 
41 
44  try: #Colorama, optional, required for Windows if coloured text is desired
45  from colorama import init as colorama_init
46  colorama_init(strip=False)
47  from colorama import Fore, Back, Style
48  except ImportError:
49  Fore = tvaConfig.Fore()
50  Back = tvaConfig.Back()
51  Style = tvaConfig.Style()
52  if(commands.logging or config.disable_colour):
53  config.disable_colour = True
54  Fore = tvaConfig.Fore(forceOff=True)
55  Back = tvaConfig.Back(forceOff=True)
56  Style = tvaConfig.Style(forceOff=True)
57 
58 
61  import include.runtime as tvaRuntime
62 
63 
66  if(not config.advanced_runtime): tvaRuntime.checkDependancies()
67 
68 
72 
73 
78  if(not config.debug): oldstdout = sys.stdout;sys.stdout = tvaConfig.NullWriter()
79  try:
80  import lib.scene as tvaScene
81  import lib.tools as tvaLib
82  finally:
83  if(not config.debug): sys.stdout = oldstdout #Re-enable output
84 
85 
88  if(config.debug): logging.basicConfig(level=logging.DEBUG, format='[%(levelname)s] (%(threadName)-10s) %(message)s')
89 
90 
93  if(commands.dir): config.dir = commands.dir
94  if(commands.dbn): config.dbn = commands.dbn
95  if(commands.language): config.language = commands.language
96  local = tvaLocal.Local(config.language)
97  #Override module colour options
98  tvaLib.Fore = Fore;tvaLib.Back = Back;tvaLib.Style = Style
99  tvaRuntime.Fore = Fore;tvaRuntime.Back = Back;tvaRuntime.Style = Style
100 
101  sites = tvaScene.Sites(config)
102  site_analyses = tvaScene.SiteAnalyses(config, sites=sites)
103  analyses = tvaScene.Analyses(config)
104  verbose_child = 0
105  config.version = tvaLib.Parse.versionFromHgCommit(version)
106  print('Running analysis version '+config.version+' in batch mode.')
107 
108 
111  if(commands.homo or commands.trafint or commands.play or commands.sample_traj or commands.draw or commands.draw_align or commands.draw_align_no_trk or commands.draw_mask or commands.draw_zone or commands.draw_loops or commands.draw_transform or commands.snap_align):
112  tvaLib.printWarning('The following options are not supported in batch mode and will be ignored: --homo, --trafint, -p, --sample-traj, -r, --draw-align, --draw-mask, --draw-zone, --draw-loops, --draw-transform, --snap-align, -v (forced '+str(verbose_child)+')', local['gen_warning'])
113 
114 
115  command_ = '-o '+str(commands.max_obj)+' --log --configreadonly '
116  if(commands.dir): command_ += '-z "'+str(commands.dir)+'" '
117  if(commands.dbn): command_ += '-d "'+str(commands.dbn)+'" '
118  if(commands.hli): command_ += '-y '+str(commands.hli)+' '
119  if(commands.export_traj): command_ += '-x '
120  if(commands.stat): command_ += '-q '
121  if(commands.save_data): command_ += '-a '
122  if(commands.save_data_flush): command_ += '-u '
123  if(commands.hli_only): command_ += '--hli-only '
124  if(commands.save_data_flush_objects): command_ += '--flush-objects '
125  if(commands.save_data_flush_indicators): command_ += '--flush-indicators '
126  if(commands.suppress_features): command_ += '--supress-features '
127  if(commands.memory_clean_feature): command_ += '--mem-clean-feature '
128  if(commands.save_data_flush_dmp): command_ += '--flush-dmp '
129  if(commands.save_data_gen_dmp): command_ += '--gen-dmp '
130  if(commands.auto_bounds): command_ += '--auto-bounds '
131  if(commands.force_reclassify): command_ += '--force-reclassify '
132  if(commands.commit_classify): command_ += '--commit-classify '
133 
134 
135  command_indicators = '-i "'+commands.indicators+'" '
136  commands.indicators = tvaLib.Parse.list1D(commands.indicators, i_type='int')
137 
138 
141  command_comp = '--mem-clean-feature '
142  if(commands.fig_save): command_comp += '-w '
143  if(commands.language): command_comp += '-n '+commands.language+' '
144  if(commands.fig_format): command_comp += '--figure-format '+commands.fig_format+' '
145  if(commands.fig_resize): command_comp += '--figure-resize '+commands.fig_resize[0]+' '+commands.fig_resize[1]+' '
146  if(commands.hli_report): command_comp += '--hli-report '
147 
148 
149 
153  if(commands.interactive): commands = tvaRuntime.interactiveSiteAnalysisSelection(commands, config, site_analyses, sites, local)
154  elif(commands.analysis):
155  aIx = analyses.interpret(commands.analysis)[0]
156  commands.s_analysis = analyses[aIx].site_analyses.write()
157  saIxs = site_analyses.interpret(commands.s_analysis)
158  if(commands.multicore): child_threads = 1
159  else: child_threads = commands.threads
160  for saIx in saIxs:
161 
162  if(commands.auto_bounds or commands.oneseqpersite):
163  if(len(site_analyses[saIx].site) and len(site_analyses[saIx].site[0])):
164 
165  if(len(site_analyses[saIx].site[0]) > 1): fileIx=1
166  else: fileIx=0
167  combined_cmd_stacks = ['python main.py -v '+str(verbose_child)+' -b '+str(site_analyses[saIx].idx)+' -s '+str(site_analyses[saIx].site.idx)+' -c '+str(1)+' -f '+str(fileIx+1)+' '+command_+command_indicators+command_comp]
168  if(commands.multicore): combined_cmd_stacks[-1] += ' -t '+str(commands.threads)
169  tvaLib.command_async_pool(combined_cmd_stacks, threads=child_threads, timeout=0, prependMsg=' ', debug=config.debug, logging=logging, verbose=commands.verbose)
170 
171 
172  elif(not commands.concat and not commands.save_data_gen_dmp):
173 
174  camIxs = tvaRuntime.targetCameraIxs(commands, site_analyses[saIx].site, site_analyses[saIx])
175  for camIx in camIxs:
176 
177  combined_cmd_stacks = []
178  fileIxs = tvaRuntime.targetSequenceIxs(commands, site_analyses[saIx].site[camIx], site_analyses[saIx])
179  for fileIx in fileIxs:
180  local_cmd_stack = command_+command_indicators
181  combined_cmd_stacks.append('python main.py -v '+str(verbose_child)+' -b '+str(site_analyses[saIx].idx)+' -s '+str(site_analyses[saIx].site.idx)+' -c '+str(camIx+1)+' -f '+str(fileIx+1)+' '+local_cmd_stack)
182  if(commands.multicore): combined_cmd_stacks[-1] += ' -t '+str(commands.threads)
183  tvaLib.command_async_pool(combined_cmd_stacks, threads=child_threads, timeout=0, prependMsg=' ', debug=config.debug, logging=logging, verbose=commands.verbose)
184 
185  #Compile data
186  if((not commands.skip_concat or commands.save_data_gen_dmp) and not commands.auto_bounds):
187  if(commands.verbose): print(str(time.asctime(time.localtime(time.time())))+' Compiling data for site-analysis: '+site_analyses[saIx].name+'...')
188  tvaLib.command_timeout('python main.py -v '+str(verbose_child)+' -t '+str(commands.threads)+' -b '+str(site_analyses[saIx].idx)+' '+command_+command_indicators+command_comp, prependMsg=' ', debug=config.debug, logging=logging, verbose=commands.verbose)
189  raise Exception, [0003, 'Batch processing complete.']
190 
191 
195  except KeyboardInterrupt:
196  if(commands.verbose): print('==User exited== [0000]\nRuntime: {0}'.format(round(time.clock())))
197 
198  except SystemExit, e:
199  try:
200  if(commands.verbose): print('==Execution finished== [0001]\nRuntime: {0}'.format(round(time.clock())))
201  except UnboundLocalError: pass
202 
203  except Exception, e:
204  if('commands' in dir()): verbose = commands.verbose
205  else: verbose = 1
206  if('config' in dir()): debug = config.debug
207  else: debug = True
208  from include.runtime import debug as tvaRuntime_debug
209  tvaRuntime_debug(e, time, logging=logging, verbose=verbose, force=debug)
210 
211 
214 if __name__ == "__main__":
215  main()
def main()
main()
Definition: batch-run.py:15
Definition: main.py:1