Mercurial > hg > audiodb
comparison bindings/python/pyadb.py @ 743:63a75a2b5fa6
Added insert featureData and powerData from numpy ndarray pathway
author | mas01mc |
---|---|
date | Tue, 09 Nov 2010 08:21:49 +0000 |
parents | 70542745f473 |
children | 124ae047b968 |
comparison
equal
deleted
inserted
replaced
739:040f14b5a5fc | 743:63a75a2b5fa6 |
---|---|
52 Insert features into database. Can be done with data provided directly or by giving a path to a binary fftExtract style feature file. If power and/or timing is engaged in the database header, it must be provided (via the same means as the feature) or a Usage exception will be raised. Power files should be of the same binary type as features. Times files should be the ascii number length of time in seconds from the begining of the file to segment start, one per line. | 52 Insert features into database. Can be done with data provided directly or by giving a path to a binary fftExtract style feature file. If power and/or timing is engaged in the database header, it must be provided (via the same means as the feature) or a Usage exception will be raised. Power files should be of the same binary type as features. Times files should be the ascii number length of time in seconds from the begining of the file to segment start, one per line. |
53 If providing data directly, featData should be a numpy array with shape= (number of Dimensions, number of Vectors) | 53 If providing data directly, featData should be a numpy array with shape= (number of Dimensions, number of Vectors) |
54 """ | 54 """ |
55 #While python style normally advocates leaping before looking, these check are nessecary as | 55 #While python style normally advocates leaping before looking, these check are nessecary as |
56 #it is very difficult to assertain why the insertion failed once it has been called. | 56 #it is very difficult to assertain why the insertion failed once it has been called. |
57 if (self.hasPower and (((featFile) and powerFile==None) or ((featData) and powerData==None))): | 57 if (self.hasPower and (((featFile) and powerFile==None) or ((not featData==None) and powerData==None))): |
58 raise(Usage, "The db you are attempting an insert on (%s) expects power and you either\ | 58 raise(Usage, "The db you are attempting an insert on (%s) expects power and you either\ |
59 haven't provided any or have done so in the wrong format."%self.path) | 59 haven't provided any or have done so in the wrong format."%self.path) |
60 if (self.hasTimes and (((timesFile) and timesFile==None) or ((timesData) and timesData==None))): | 60 if (self.hasTimes and (((timesFile) and timesFile==None) or ((not timesData==None) and timesData==None))): |
61 raise(Usage, "The db you are attempting an insert on (%s) expects times and you either\ | 61 raise(Usage, "The db you are attempting an insert on (%s) expects times and you either\ |
62 haven't provided any or have done so in the wrong format."%self.path) | 62 haven't provided any or have done so in the wrong format."%self.path) |
63 args = {"db":self._db} | 63 args = {"db":self._db} |
64 if featFile: | 64 if featFile: |
65 args["features"] = featFile | 65 args["features"] = featFile |
68 else: | 68 else: |
69 raise(Usage, "Must provide some feature data!") | 69 raise(Usage, "Must provide some feature data!") |
70 if self.hasPower: | 70 if self.hasPower: |
71 if featFile: | 71 if featFile: |
72 args["power"]=powerFile | 72 args["power"]=powerFile |
73 elif featData: | 73 elif featData.any(): |
74 pass | 74 args["power"]=powerData |
75 if self.hasTimes: | 75 if self.hasTimes: |
76 if featFile: | 76 if featFile: |
77 args["times"]=timesFile | 77 args["times"]=timesFile |
78 elif timesData: | 78 elif timesData.any(): |
79 pass | 79 pass |
80 if key: | 80 if key: |
81 args["key"]=str(key) | 81 args["key"]=str(key) |
82 if featFile: | 82 if featFile: |
83 if not _pyadb._pyadb_insertFromFile(**args): | 83 if not _pyadb._pyadb_insertFromFile(**args): |
84 raise RuntimeError("Insertion from file failed for an unknown reason.") | 84 raise RuntimeError("Insertion from file failed for an unknown reason.") |
85 else: | 85 else: |
86 self._updateDBAttributes() | 86 self._updateDBAttributes() |
87 return | 87 return |
88 elif (featData != None): | 88 elif (featData != None): |
89 if (len(args["features"].shape) == 1) : args["features"] = args["features"].reshape((args["features"].shape[0],1)) | 89 if (len(args["features"].shape) == 1) : |
90 args["features"] = args["features"].reshape((args["features"].shape[0],1)) | |
90 args["nVect"], args["nDim"] = args["features"].shape | 91 args["nVect"], args["nDim"] = args["features"].shape |
91 args["features"] = args["features"].flatten() | 92 args["features"] = args["features"].flatten() |
93 if(powerData != None): | |
94 if (len(args["power"].shape) == 1) : | |
95 args["power"] = args["power"].reshape((args["power"].shape[0],1)) | |
96 args["power"] = args["power"].flatten() | |
92 print "args: " + str(args) | 97 print "args: " + str(args) |
93 ok = _pyadb._pyadb_insertFromArray(**args) | 98 ok = _pyadb._pyadb_insertFromArray(**args) |
94 if not (ok==0): | 99 if not (ok==0): |
95 raise RuntimeError("Direct data insertion failed for an unknown reason. err code = %i"%ok) | 100 raise RuntimeError("Direct data insertion failed for an unknown reason. err code = %i"%ok) |
96 else: | 101 else: |