comparison python/utils.py @ 971:9897a13772fb

added utils to load video sequence in metadata
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 13 Dec 2017 14:06:20 -0500
parents 5d788d2e8ffc
children 4f3f88a27dae
comparison
equal deleted inserted replaced
970:bf401567a933 971:9897a13772fb
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 ''' Generic utilities.''' 3 ''' Generic utilities.'''
4 4
5 import matplotlib.pyplot as plt 5 import matplotlib.pyplot as plt
6 from datetime import time, datetime 6 from datetime import time, datetime
7 from argparse import ArgumentTypeError
7 from math import sqrt, ceil, floor 8 from math import sqrt, ceil, floor
8 from scipy.stats import kruskal, shapiro, lognorm 9 from scipy.stats import kruskal, shapiro, lognorm
9 from scipy.spatial import distance 10 from scipy.spatial import distance
10 from scipy.sparse import dok_matrix 11 from scipy.sparse import dok_matrix
11 from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, median, isnan, ones, convolve, dtype, isnan, NaN, mean, ma, isinf, savez, load as npload, log 12 from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, median, isnan, ones, convolve, dtype, isnan, NaN, mean, ma, isinf, savez, load as npload, log
21 22
22 def upperCaseFirstLetter(s): 23 def upperCaseFirstLetter(s):
23 words = s.split(' ') 24 words = s.split(' ')
24 lowerWords = [w[0].upper()+w[1:].lower() for w in words] 25 lowerWords = [w[0].upper()+w[1:].lower() for w in words]
25 return ' '.join(lowerWords) 26 return ' '.join(lowerWords)
27
28 class TimeConverter:
29 def __init__(self, datetimeFormat = datetimeFormat):
30 self.datetimeFormat = datetimeFormat
31
32 def convert(self, s):
33 try:
34 return datetime.strptime(s, self.datetimeFormat)
35 except ValueError:
36 msg = "Not a valid date: '{0}'.".format(s)
37 raise ArgumentTypeError(msg)
26 38
27 ######################### 39 #########################
28 # Enumerations 40 # Enumerations
29 ######################### 41 #########################
30 42