+ added framework code for training modus
[qpalma.git] / scripts / SettingsParser.py
index 7abcd59..ac66128 100644 (file)
@@ -21,53 +21,63 @@ def parseSettingsFile(filename):
    """
    This function parse all key value pairs from the given filename
    """
-   global_settings = {}
+   settings = {}
    for line in open(filename):
       if (not line.strip()) or line.startswith('#'):
          pass
       else:
          key, val = line.strip().replace(' ', '').split('=')
-         global_settings[key] = val
+         settings[key] = val
 
-   return global_settings
+   return settings
 
 
-def makeSettings(global_settings):
+def makeSettings(settings):
    """
    
    """
-   assert os.path.exists(global_settings['result_dir']),'Error: You have to specify a existing result directory!'
-   result_dir = global_settings['result_dir']
-   global_settings['approximation_dir'] = jp(result_dir, 'approximation')
-   global_settings['preproc_dir'] = jp(result_dir, 'preprocessing')
-   global_settings['postproc_dir'] = jp(result_dir, 'postprocessing')
-   global_settings['prediction_dir'] = jp(result_dir, 'prediction')
-   global_settings['training_dir'] = jp(result_dir, 'training')
-
-   for dir_name in ['approximation_dir', 'preproc_dir', 'postproc_dir',\
+   assert os.path.exists(settings['result_dir']),'Error: You have to specify a existing result directory!'
+   result_dir = settings['result_dir']
+   settings['approximation_dir'] = jp(result_dir, 'approximation')
+   settings['dataset_dir'] = jp(result_dir, 'dataset')
+   settings['preproc_dir'] = jp(result_dir, 'preprocessing')
+   settings['postproc_dir'] = jp(result_dir, 'postprocessing')
+   settings['prediction_dir'] = jp(result_dir, 'prediction')
+   settings['training_dir'] = jp(result_dir, 'training')
+
+   for dir_name in ['approximation_dir','dataset_dir', 'preproc_dir', 'postproc_dir',\
      'prediction_dir', 'training_dir']:
       try:
-         os.mkdir(global_settings[dir_name])
+         os.mkdir(settings[dir_name])
          continue
       except:
          print ('Error: There was a problem generating the subdirectory: %s' % dir_name)
 
+   ddir = settings['dataset_dir']
+   settings['prediction_dataset_fn']      = jp(ddir,'prediction_data.pickle')
+   settings['prediction_dataset_keys_fn'] = jp(ddir,'prediction_data.keys.pickle')
+   settings['training_dataset_fn']        = jp(ddir,'training_data.pickle')
+   settings['training_dataset_keys_fn']   = jp(ddir,'training_data.keys.pickle')
+
+
    try:
-      os.mkdir(global_settings['global_log_fn'])
+      os.mkdir(settings['global_log_fn'])
    except:
-      print 'Error: There was a problem generating the logfile %s' % global_settings['global_log_fn']
+      print 'Error: There was a problem generating the logfile %s' % settings['global_log_fn']
 
-   
    try:
-      global_settings['num_splits'] = int(global_settings['num_splits'])
+      settings['num_splits'] = int(settings['num_splits'])
    except:
       print 'Error: num_splits has to be a positive integer'
 
-   return global_settings
+   settings['allowed_fragments'] = eval(settings['allowed_fragments'])
+   settings['half_window_size']  = int(settings['half_window_size'])
+
+   return settings
 
 
-def checkSettings(global_settings):
-   for (key, val,) in global_settings.items():
+def checkSettings(settings):
+   for (key, val,) in settings.items():
       if key.endswith('_fn'):
          assert os.path.exists(val), 'Error: Path/File %s with value %s does not seem to exist!' % (key,val)
       if key.endswith('_dir'):
@@ -77,8 +87,8 @@ def checkSettings(global_settings):
 
 
 def parseSettings(filename):
-   global_settings = parseSettingsFile(filename)
-   global_settings = makeSettings(global_settings)
-   assert checkSettings(global_settings),'Check your settings some entries were invalid!'
+   settings = parseSettingsFile(filename)
+   settings = makeSettings(settings)
+   assert checkSettings(settings),'Check your settings some entries were invalid!'
 
-   return global_settings
+   return settings