Skip to content

Commit

Permalink
unregistered get_model_array_attribute_chunk restful endpoint for tes…
Browse files Browse the repository at this point in the history
…ting, see #174.
  • Loading branch information
Matthew Letter committed Sep 8, 2015
1 parent e07cd46 commit 69bf1bf
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion packages/slycat/web/server/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def abspath(path):
dispatcher.connect("get-configuration-version", "/configuration/version", slycat.web.server.handlers.get_configuration_version, conditions={"method" : ["GET"]})
dispatcher.connect("get-configuration-wizards", "/configuration/wizards", slycat.web.server.handlers.get_configuration_wizards, conditions={"method" : ["GET"]})
dispatcher.connect("get-global-resource", "/resources/global/{resource:.*}", slycat.web.server.handlers.get_global_resource, conditions={"method" : ["GET"]})
dispatcher.connect("get-model-array-attribute-chunk", "/models/:mid/arraysets/:aid/arrays/:array/attributes/:attribute/chunk", slycat.web.server.handlers.get_model_array_attribute_chunk, conditions={"method" : ["GET"]})
#dispatcher.connect("get-model-array-attribute-chunk", "/models/:mid/arraysets/:aid/arrays/:array/attributes/:attribute/chunk", slycat.web.server.handlers.get_model_array_attribute_chunk, conditions={"method" : ["GET"]})
dispatcher.connect("get-model-arrayset-data", "/models/:mid/arraysets/:aid/data", slycat.web.server.handlers.get_model_arrayset_data, conditions={"method" : ["GET"]})
dispatcher.connect("get-model-arrayset-metadata", "/models/:mid/arraysets/:aid/metadata", slycat.web.server.handlers.get_model_arrayset_metadata, conditions={"method" : ["GET"]})
dispatcher.connect("get-model-file", "/models/:mid/files/:aid", slycat.web.server.handlers.get_model_file, conditions={"method" : ["GET"]})
Expand Down
114 changes: 57 additions & 57 deletions packages/slycat/web/server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,63 +707,63 @@ def delete_project_cache_object(pid, key):

raise cherrypy.HTTPError(404)

def get_model_array_attribute_chunk(mid, aid, array, attribute, **arguments):
try:
attribute = int(attribute)
except:
raise cherrypy.HTTPError("400 Malformed attribute argument must be a zero-based integer attribute index.")

try:
ranges = [int(spec) for spec in arguments["ranges"].split(",")]
i = iter(ranges)
ranges = list(itertools.izip(i, i))
except:
raise cherrypy.HTTPError("400 Malformed ranges argument must be a comma separated collection of half-open index ranges.")

byteorder = arguments.get("byteorder", None)
if byteorder is not None:
if byteorder not in ["little", "big"]:
raise cherrypy.HTTPError("400 Malformed byteorder argument must be 'little' or 'big'.")
accept = cherrypy.lib.cptools.accept(["application/octet-stream"])
else:
accept = cherrypy.lib.cptools.accept(["application/json"])
cherrypy.response.headers["content-type"] = accept

database = slycat.web.server.database.couchdb.connect()
model = database.get("model", mid)
project = database.get("project", model["project"])
slycat.web.server.authentication.require_project_reader(project)

artifact = model.get("artifact:%s" % aid, None)
if artifact is None:
raise cherrypy.HTTPError(404)
artifact_type = model["artifact-types"][aid]
if artifact_type not in ["hdf5"]:
raise cherrypy.HTTPError("400 %s is not an array artifact." % aid)

with slycat.web.server.hdf5.lock:
with slycat.web.server.hdf5.open(artifact) as file:
hdf5_arrayset = slycat.hdf5.ArraySet(file)
hdf5_array = hdf5_arrayset[array]

if not(0 <= attribute and attribute < len(hdf5_array.attributes)):
raise cherrypy.HTTPError("400 Attribute argument out-of-range.")
if len(ranges) != hdf5_array.ndim:
raise cherrypy.HTTPError("400 Ranges argument doesn't contain the correct number of dimensions.")

ranges = [(max(dimension["begin"], range[0]), min(dimension["end"], range[1])) for dimension, range in zip(hdf5_array.dimensions, ranges)]
index = tuple([slice(begin, end) for begin, end in ranges])

attribute_type = hdf5_array.attributes[attribute]["type"]
data = hdf5_array.get_data(attribute)[index]

if byteorder is None:
return json.dumps(data.tolist())
else:
if sys.byteorder != byteorder:
return data.byteswap().tostring(order="C")
else:
return data.tostring(order="C")
# def get_model_array_attribute_chunk(mid, aid, array, attribute, **arguments):
# try:
# attribute = int(attribute)
# except:
# raise cherrypy.HTTPError("400 Malformed attribute argument must be a zero-based integer attribute index.")
#
# try:
# ranges = [int(spec) for spec in arguments["ranges"].split(",")]
# i = iter(ranges)
# ranges = list(itertools.izip(i, i))
# except:
# raise cherrypy.HTTPError("400 Malformed ranges argument must be a comma separated collection of half-open index ranges.")
#
# byteorder = arguments.get("byteorder", None)
# if byteorder is not None:
# if byteorder not in ["little", "big"]:
# raise cherrypy.HTTPError("400 Malformed byteorder argument must be 'little' or 'big'.")
# accept = cherrypy.lib.cptools.accept(["application/octet-stream"])
# else:
# accept = cherrypy.lib.cptools.accept(["application/json"])
# cherrypy.response.headers["content-type"] = accept
#
# database = slycat.web.server.database.couchdb.connect()
# model = database.get("model", mid)
# project = database.get("project", model["project"])
# slycat.web.server.authentication.require_project_reader(project)
#
# artifact = model.get("artifact:%s" % aid, None)
# if artifact is None:
# raise cherrypy.HTTPError(404)
# artifact_type = model["artifact-types"][aid]
# if artifact_type not in ["hdf5"]:
# raise cherrypy.HTTPError("400 %s is not an array artifact." % aid)
#
# with slycat.web.server.hdf5.lock:
# with slycat.web.server.hdf5.open(artifact) as file:
# hdf5_arrayset = slycat.hdf5.ArraySet(file)
# hdf5_array = hdf5_arrayset[array]
#
# if not(0 <= attribute and attribute < len(hdf5_array.attributes)):
# raise cherrypy.HTTPError("400 Attribute argument out-of-range.")
# if len(ranges) != hdf5_array.ndim:
# raise cherrypy.HTTPError("400 Ranges argument doesn't contain the correct number of dimensions.")
#
# ranges = [(max(dimension["begin"], range[0]), min(dimension["end"], range[1])) for dimension, range in zip(hdf5_array.dimensions, ranges)]
# index = tuple([slice(begin, end) for begin, end in ranges])
#
# attribute_type = hdf5_array.attributes[attribute]["type"]
# data = hdf5_array.get_data(attribute)[index]
#
# if byteorder is None:
# return json.dumps(data.tolist())
# else:
# if sys.byteorder != byteorder:
# return data.byteswap().tostring(order="C")
# else:
# return data.tostring(order="C")

@cherrypy.tools.json_out(on = True)
def get_model_arrayset_metadata(mid, aid, **kwargs):
Expand Down

0 comments on commit 69bf1bf

Please sign in to comment.