20
20
from ...locations import boundingbox as _boundingbox
21
21
22
22
from neuroglancer_scripts .precomputed_io import get_IO_for_existing_dataset
23
- from neuroglancer_scripts .accessor import get_accessor_for_url
23
+ from neuroglancer_scripts .http_accessor import HttpAccessor
24
24
from neuroglancer_scripts .mesh import read_precomputed_mesh , affine_transform_mesh
25
25
from io import BytesIO
26
26
import nibabel as nib
27
27
import os
28
28
import numpy as np
29
29
from typing import Union , Dict , Tuple
30
+ import json
30
31
31
32
32
33
class NeuroglancerProvider (_provider .VolumeProvider , srctype = "neuroglancer/precomputed" ):
@@ -210,8 +211,9 @@ def __init__(self, url: str):
210
211
assert isinstance (url , str )
211
212
self .url = url
212
213
self ._scales_cached = None
213
- self ._io = None
214
+ self ._info = None
214
215
self ._transform_nm = None
216
+ self ._io = None
215
217
216
218
@property
217
219
def transform_nm (self ):
@@ -234,34 +236,40 @@ def transform_nm(self, val):
234
236
self ._transform_nm = val
235
237
236
238
@property
237
- def map_type (self ):
239
+ def io (self ):
238
240
if self ._io is None :
241
+ accessor = HttpAccessor (self .url )
242
+ self ._io = get_IO_for_existing_dataset (accessor )
243
+ return self ._io
244
+
245
+ @property
246
+ def map_type (self ):
247
+ if self ._info is None :
239
248
self ._bootstrap ()
240
249
return (
241
250
MapType .LABELLED
242
- if self ._io . info .get ("type" ) == "segmentation"
251
+ if self ._info .get ("type" ) == "segmentation"
243
252
else MapType .STATISTICAL
244
253
)
245
254
246
255
@map_type .setter
247
256
def map_type (self , val ):
248
257
if val is not None :
249
258
logger .debug (
250
- "NeuroglancerVolume can determine its own maptype from self._io.info .get('type')"
259
+ "NeuroglancerVolume can determine its own maptype from self._info .get('type')"
251
260
)
252
261
253
262
def _bootstrap (self ):
254
- accessor = get_accessor_for_url (self .url )
255
- self ._io = get_IO_for_existing_dataset (accessor )
263
+ self ._info = requests .HttpRequest (f"{ self .url } /info" , func = lambda b : json .loads (b .decode ())).get ()
256
264
self ._scales_cached = sorted (
257
- [NeuroglancerScale (self , i ) for i in self ._io . info ["scales" ]]
265
+ [NeuroglancerScale (self , i ) for i in self ._info ["scales" ]]
258
266
)
259
267
260
268
@property
261
269
def dtype (self ):
262
- if self ._io is None :
270
+ if self ._info is None :
263
271
self ._bootstrap ()
264
- return np .dtype (self ._io . info ["data_type" ])
272
+ return np .dtype (self ._info ["data_type" ])
265
273
266
274
@property
267
275
def scales (self ):
@@ -422,7 +430,7 @@ def _read_chunk(self, gx, gy, gz):
422
430
y0 = gy * self .chunk_sizes [1 ]
423
431
z0 = gz * self .chunk_sizes [2 ]
424
432
x1 , y1 , z1 = np .minimum (self .chunk_sizes + [x0 , y0 , z0 ], self .size )
425
- chunk_czyx = self .volume ._io .read_chunk (self .key , (x0 , x1 , y0 , y1 , z0 , z1 ))
433
+ chunk_czyx = self .volume .io .read_chunk (self .key , (x0 , x1 , y0 , y1 , z0 , z1 ))
426
434
if not chunk_czyx .shape [0 ] == 1 and not self .color_warning_issued :
427
435
logger .warning (
428
436
"Color channel data is not yet supported. Returning first channel only."
0 commit comments