Skip to content

Commit 1de4b0d

Browse files
committed
Add demo and gitignore file
1 parent 9838123 commit 1de4b0d

File tree

5 files changed

+364
-20
lines changed

5 files changed

+364
-20
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__/
2+
.ipynb_checkpoints/

Demo 1.ipynb

+212
Large diffs are not rendered by default.

Pipfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[[source]]
2+
3+
url = "https://pypi.python.org/simple"
4+
verify_ssl = true
5+
name = "pypi"
6+
7+
8+
[packages]
9+
10+
flask = "*"
11+
numpy = "*"
12+
13+
14+
[dev-packages]
15+

Pipfile.lock

+100
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bosslet/__init__.py

+35-20
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,13 @@
88

99
from flask import Flask, request, Response, send_file, jsonify
1010
import numpy as np
11-
# from intern.remote.boss import BossRemote
12-
# from intern.resource.boss.resource import ChannelResource
13-
# from intern.utils.parallel import block_compute
14-
# from requests import codes, post
1511

1612
APP = Flask(__name__)
1713

1814
UPLOADS_PATH = "./uploads"
1915
BLOCK_SIZE = (256, 256, 256)
2016

2117

22-
"""
23-
https://api.theboss.io/v1/cutout/:collection/:experiment/:channel/:resolution/:x_range/:y_range/:z_range/:time_range/?iso=:iso
24-
"""
25-
26-
2718
def file_compute(x_start, x_stop,
2819
y_start, y_stop,
2920
z_start, z_stop,
@@ -59,6 +50,20 @@ def file_compute(x_start, x_stop,
5950

6051

6152
def blockfile_indices(xs, ys, zs, origin=(0, 0, 0), block_size=(256, 256, 256)):
53+
"""
54+
Returns the indices PER BLOCK for each file required.
55+
56+
Returns the indices of the offset PER BLOCK of each file that is
57+
required in order to construct the final volume.
58+
59+
For instance, in 1D:
60+
61+
Blocksize is 100, origin is 0.
62+
63+
Request of (10, 50) returns (10, 50)
64+
Request of (10, 150) returns (10, 100), (0, 50)
65+
Request of (10, 250) returns (10, 100), (0, 100), (100, 50)
66+
"""
6267
blocks = block_compute(
6368
xs[0], xs[1], ys[0], ys[1], zs[0], zs[1],
6469
origin, block_size
@@ -163,7 +168,7 @@ def getdata(self, col, exp, chan, res, xs, ys, zs):
163168
f[2] + i[2][0]: f[2] + i[2][1],
164169
] = data_partial
165170

166-
except:
171+
except ValueError:
167172
payload[
168173
f[0] + i[0][0]: f[0] + i[0][1],
169174
f[1] + i[1][0]: f[1] + i[1][1],
@@ -189,6 +194,17 @@ def store(self, data, col, exp, chan, res, b):
189194
return np.save(fname, data)
190195

191196
def retrieve(self, col, exp, chan, res, b):
197+
if not (
198+
os.path.isdir("{}/{}".format(UPLOADS_PATH, col)) and
199+
os.path.isdir("{}/{}/{}".format(UPLOADS_PATH, col, exp)) and
200+
os.path.isdir("{}/{}/{}/{}".format(
201+
UPLOADS_PATH, col, exp, chan
202+
))
203+
):
204+
raise IOError("{}/{}/{} not found.".format(
205+
col, exp, chan
206+
))
207+
# return np.zeros(self.block_size, dtype="uint8")
192208
fname = "{}/{}/{}/{}/{}-{}-{}-{}.npy".format(
193209
UPLOADS_PATH,
194210
col, exp, chan,
@@ -206,8 +222,9 @@ def retrieve(self, col, exp, chan, res, b):
206222
@APP.route("/v1/cutout/<collection>/<experiment>/<channel>/<resolution>/<x_range>/<y_range>/<z_range>/", methods=["POST"])
207223
def upload_cutout_xyz(collection, experiment, channel, resolution, x_range, y_range, z_range):
208224
"""
209-
Upload a volume
225+
Upload a volume.
210226
227+
Uses bossURI format.
211228
"""
212229
for _, f in request.files.items():
213230
memfile = io.BytesIO()
@@ -224,25 +241,23 @@ def upload_cutout_xyz(collection, experiment, channel, resolution, x_range, y_ra
224241
@APP.route("/v1/cutout/<collection>/<experiment>/<channel>/<resolution>/<x_range>/<y_range>/<z_range>/", methods=["GET"])
225242
def get_cutout_xyz(collection, experiment, channel, resolution, x_range, y_range, z_range):
226243
"""
227-
Download a volume
244+
Download a volume.
245+
246+
Returns 404 if the bossURI is not found.
228247
"""
229248
xs = [int(i) for i in x_range.split(":")]
230249
ys = [int(i) for i in y_range.split(":")]
231250
zs = [int(i) for i in z_range.split(":")]
232-
if (
233-
os.path.isdir("{}/{}".format(UPLOADS_PATH, collection)) and
234-
os.path.isdir("{}/{}/{}".format(UPLOADS_PATH, collection, experiment)) and
235-
os.path.isdir("{}/{}/{}/{}".format(UPLOADS_PATH, collection, experiment, channel))
236-
):
251+
try:
237252
data = MANAGER.getdata(collection, experiment, channel, resolution, xs, ys, zs)
238253
res = {}
239254
res["dtype"] = str(data.dtype)
240255
res["data"] = data.tolist()
241256
return jsonify(res)
242-
else:
257+
except IOError as e:
243258
return Response(
244-
json.dumps({"message": "DNE"}),
245-
status=402,
259+
json.dumps({"message": str(e)}),
260+
status=404,
246261
mimetype="application/json"
247262
)
248263

0 commit comments

Comments
 (0)