mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-03 08:42:39 +02:00
Fixed some bugs in mocap.py where errors weren't being raised when file format was incorrect and made datasets.py check for 404 errors which previously were occuring silently ... shhhhh
This commit is contained in:
parent
7c1c50cf55
commit
e349c12cf0
2 changed files with 20 additions and 8 deletions
|
|
@ -3,7 +3,6 @@ import numpy as np
|
||||||
import GPy
|
import GPy
|
||||||
import scipy.io
|
import scipy.io
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
import urllib as url
|
|
||||||
import zipfile
|
import zipfile
|
||||||
import tarfile
|
import tarfile
|
||||||
import datetime
|
import datetime
|
||||||
|
|
@ -15,7 +14,7 @@ except ImportError:
|
||||||
ipython_available=False
|
ipython_available=False
|
||||||
|
|
||||||
|
|
||||||
import sys, urllib
|
import sys, urllib2
|
||||||
|
|
||||||
def reporthook(a,b,c):
|
def reporthook(a,b,c):
|
||||||
# ',' at the end of the line is important!
|
# ',' at the end of the line is important!
|
||||||
|
|
@ -82,7 +81,18 @@ def download_url(url, store_directory, save_name = None, messages = True, suffix
|
||||||
print "Downloading ", url, "->", os.path.join(store_directory, file)
|
print "Downloading ", url, "->", os.path.join(store_directory, file)
|
||||||
if not os.path.exists(dir_name):
|
if not os.path.exists(dir_name):
|
||||||
os.makedirs(dir_name)
|
os.makedirs(dir_name)
|
||||||
urllib.urlretrieve(url+suffix, save_name, reporthook)
|
try:
|
||||||
|
response = urllib2.urlopen(url+suffix)
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
if not hasattr(e, "code"):
|
||||||
|
raise
|
||||||
|
response = e
|
||||||
|
if response.code == 404:
|
||||||
|
raise ValueError('Url ' + url + suffix + ' 404 not found.')
|
||||||
|
with open(save_name, 'wb') as f:
|
||||||
|
f.write(response.read())
|
||||||
|
|
||||||
|
#urllib.urlretrieve(url+suffix, save_name, reporthook)
|
||||||
|
|
||||||
def authorize_download(dataset_name=None):
|
def authorize_download(dataset_name=None):
|
||||||
"""Check with the user that the are happy with terms and conditions for the data set."""
|
"""Check with the user that the are happy with terms and conditions for the data set."""
|
||||||
|
|
|
||||||
|
|
@ -67,14 +67,14 @@ class tree:
|
||||||
for i in range(len(self.vertices)):
|
for i in range(len(self.vertices)):
|
||||||
if self.vertices[i].id == id:
|
if self.vertices[i].id == id:
|
||||||
return i
|
return i
|
||||||
raise Error, 'Reverse look up of id failed.'
|
raise ValueError('Reverse look up of id failed.')
|
||||||
|
|
||||||
def get_index_by_name(self, name):
|
def get_index_by_name(self, name):
|
||||||
"""Give the index associated with a given vertex name."""
|
"""Give the index associated with a given vertex name."""
|
||||||
for i in range(len(self.vertices)):
|
for i in range(len(self.vertices)):
|
||||||
if self.vertices[i].name == name:
|
if self.vertices[i].name == name:
|
||||||
return i
|
return i
|
||||||
raise Error, 'Reverse look up of name failed.'
|
raise ValueError('Reverse look up of name failed.')
|
||||||
|
|
||||||
def order_vertices(self):
|
def order_vertices(self):
|
||||||
"""Order vertices in the graph such that parents always have a lower index than children."""
|
"""Order vertices in the graph such that parents always have a lower index than children."""
|
||||||
|
|
@ -433,6 +433,8 @@ class acclaim_skeleton(skeleton):
|
||||||
lin = self.read_line(fid)
|
lin = self.read_line(fid)
|
||||||
while lin != ':DEGREES':
|
while lin != ':DEGREES':
|
||||||
lin = self.read_line(fid)
|
lin = self.read_line(fid)
|
||||||
|
if lin == '':
|
||||||
|
raise ValueError('Could not find :DEGREES in ' + fid.name)
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
lin = self.read_line(fid)
|
lin = self.read_line(fid)
|
||||||
|
|
@ -443,9 +445,9 @@ class acclaim_skeleton(skeleton):
|
||||||
if frame_no:
|
if frame_no:
|
||||||
counter += 1
|
counter += 1
|
||||||
if counter != frame_no:
|
if counter != frame_no:
|
||||||
raise Error, 'Unexpected frame number.'
|
raise ValueError('Unexpected frame number.')
|
||||||
else:
|
else:
|
||||||
raise Error, 'Single bone name ...'
|
raise ValueError('Single bone name ...')
|
||||||
else:
|
else:
|
||||||
ind = self.get_index_by_name(parts[0])
|
ind = self.get_index_by_name(parts[0])
|
||||||
bones[ind].append(np.array([float(channel) for channel in parts[1:]]))
|
bones[ind].append(np.array([float(channel) for channel in parts[1:]]))
|
||||||
|
|
@ -573,7 +575,7 @@ class acclaim_skeleton(skeleton):
|
||||||
return
|
return
|
||||||
lin = self.read_line(fid)
|
lin = self.read_line(fid)
|
||||||
else:
|
else:
|
||||||
raise Error, 'Unrecognised file format'
|
raise ValueError('Unrecognised file format')
|
||||||
self.finalize()
|
self.finalize()
|
||||||
|
|
||||||
def read_units(self, fid):
|
def read_units(self, fid):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue