comparison python/storage.py @ 813:ef8795dba5ed

avoid crash for missing configuration filename
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 10 Jun 2016 17:46:54 -0400
parents 21f10332c72b
children 0ddcc41663f5
comparison
equal deleted inserted replaced
812:21f10332c72b 813:ef8795dba5ed
3 '''Various utilities to save and load data''' 3 '''Various utilities to save and load data'''
4 4
5 import utils, moving, events, indicators, shutil 5 import utils, moving, events, indicators, shutil
6 from base import VideoFilenameAddable 6 from base import VideoFilenameAddable
7 7
8 from os import path
8 import sqlite3, logging 9 import sqlite3, logging
9 from numpy import log, min as npmin, max as npmax, round as npround, array, sum as npsum, loadtxt 10 from numpy import log, min as npmin, max as npmax, round as npround, array, sum as npsum, loadtxt
10 from pandas import read_csv, merge 11 from pandas import read_csv, merge
11 12
12 13
1132 1133
1133 class ClassifierParameters(VideoFilenameAddable): 1134 class ClassifierParameters(VideoFilenameAddable):
1134 'Class for the parameters of object classifiers' 1135 'Class for the parameters of object classifiers'
1135 def loadConfigFile(self, filename): 1136 def loadConfigFile(self, filename):
1136 from ConfigParser import ConfigParser 1137 from ConfigParser import ConfigParser
1137 from os import path
1138 1138
1139 config = ConfigParser() 1139 config = ConfigParser()
1140 config.readfp(FakeSecHead(openCheck(filename))) 1140 config.readfp(FakeSecHead(openCheck(filename)))
1141 self.sectionHeader = config.sections()[0] 1141 self.sectionHeader = config.sections()[0]
1142 1142
1164 self.scaleCyclistSpeed = config.getfloat(self.sectionHeader, 'cyc-speed-scale') 1164 self.scaleCyclistSpeed = config.getfloat(self.sectionHeader, 'cyc-speed-scale')
1165 self.meanVehicleSpeed = config.getfloat(self.sectionHeader, 'mean-veh-speed') 1165 self.meanVehicleSpeed = config.getfloat(self.sectionHeader, 'mean-veh-speed')
1166 self.stdVehicleSpeed = config.getfloat(self.sectionHeader, 'std-veh-speed') 1166 self.stdVehicleSpeed = config.getfloat(self.sectionHeader, 'std-veh-speed')
1167 1167
1168 def __init__(self, filename = None): 1168 def __init__(self, filename = None):
1169 if filename is not None: 1169 if filename is not None and path.exists(filename):
1170 self.loadConfigFile(filename) 1170 self.loadConfigFile(filename)
1171 else:
1172 print('Configuration filename {} could not be loaded.'.format(filename))
1171 1173
1172 def convertToFrames(self, frameRate, speedRatio = 3.6): 1174 def convertToFrames(self, frameRate, speedRatio = 3.6):
1173 '''Converts parameters with a relationship to time in 'native' frame time 1175 '''Converts parameters with a relationship to time in 'native' frame time
1174 speedRatio is the conversion from the speed unit in the config file 1176 speedRatio is the conversion from the speed unit in the config file
1175 to the distance per second 1177 to the distance per second
1196 1198
1197 Note: framerate is already taken into account''' 1199 Note: framerate is already taken into account'''
1198 1200
1199 def loadConfigFile(self, filename): 1201 def loadConfigFile(self, filename):
1200 from ConfigParser import ConfigParser 1202 from ConfigParser import ConfigParser
1201 from os import path
1202 1203
1203 config = ConfigParser() 1204 config = ConfigParser()
1204 config.readfp(FakeSecHead(openCheck(filename))) 1205 config.readfp(FakeSecHead(openCheck(filename)))
1205 self.sectionHeader = config.sections()[0] 1206 self.sectionHeader = config.sections()[0]
1206 # Tracking/display parameters 1207 # Tracking/display parameters
1238 self.maxExtremeAcceleration = config.getfloat(self.sectionHeader, 'max-extreme-acceleration')/self.videoFrameRate**2 1239 self.maxExtremeAcceleration = config.getfloat(self.sectionHeader, 'max-extreme-acceleration')/self.videoFrameRate**2
1239 self.maxExtremeSteering = config.getfloat(self.sectionHeader, 'max-extreme-steering')/self.videoFrameRate 1240 self.maxExtremeSteering = config.getfloat(self.sectionHeader, 'max-extreme-steering')/self.videoFrameRate
1240 self.useFeaturesForPrediction = config.getboolean(self.sectionHeader, 'use-features-prediction') 1241 self.useFeaturesForPrediction = config.getboolean(self.sectionHeader, 'use-features-prediction')
1241 1242
1242 def __init__(self, filename = None): 1243 def __init__(self, filename = None):
1243 if filename is not None: 1244 if filename is not None and path.exists(filename):
1244 self.loadConfigFile(filename) 1245 self.loadConfigFile(filename)
1246 else:
1247 print('Configuration filename {} could not be loaded.'.format(filename))
1245 1248
1246 class SceneParameters(object): 1249 class SceneParameters(object):
1247 def __init__(self, config, sectionName): 1250 def __init__(self, config, sectionName):
1248 from ConfigParser import NoOptionError 1251 from ConfigParser import NoOptionError
1249 from ast import literal_eval 1252 from ast import literal_eval