Exemplo n.º 1
0
def to_volumecutout(img,
                    image_type,
                    resolution=None,
                    offset=None,
                    hostname='localhost'):
    from cloudvolume.volumecutout import VolumeCutout
    if type(img) == VolumeCutout:
        try:
            img.dataset_name  # check if it's an intact VolumeCutout
            return img
        except AttributeError:
            pass

    resolution = getresolution(img, resolution)
    offset = getoffset(img, offset)

    return VolumeCutout(
        buf=img,
        path=ExtractedPath('mem', hostname, '/', '', '', '', ''),
        cloudpath='IN MEMORY',
        resolution=resolution,
        mip=-1,
        layer_type=image_type,
        bounds=Bbox(offset, offset + Vec(*(img.shape[:3]))),
        handle=None,
    )
Exemplo n.º 2
0
def view(img,
         segmentation=False,
         resolution=None,
         offset=None,
         hostname="localhost",
         port=DEFAULT_PORT):
    from cloudvolume.volumecutout import VolumeCutout

    img = to3d(img)
    resolution = getresolution(img, resolution)
    offset = getoffset(img, offset)

    # Makes sense for viewing not segmentation
    # which requires uints currently. (Jan. 2019)
    if np.dtype(img.dtype).itemsize == 8 and not np.issubdtype(
            img.dtype, np.float64):
        print(
            yellow("""
Converting {} to float64 for display. 
Javascript does not support native 64-bit integer arrays.
      """.format(img.dtype)))
        img = img.astype(np.float64)

    cutout = VolumeCutout(
        buf=img,
        path=ExtractedPath('mem', hostname, '/', '', '', '', ''),
        cloudpath='IN MEMORY',
        resolution=resolution,
        mip=-1,
        layer_type=('segmentation' if segmentation else 'image'),
        bounds=Bbox(offset, offset + Vec(*(img.shape[:3]))),
        handle=None,
    )
    return run([cutout], hostname=hostname, port=port)
Exemplo n.º 3
0
def view(
    img, segmentation=False, resolution=None, offset=None,
    hostname="localhost", port=DEFAULT_PORT
  ):
  from cloudvolume.volumecutout import VolumeCutout

  img = to3d(img)
  resolution = getresolution(img, resolution)
  offset = getoffset(img, offset)

  cutout = VolumeCutout(
    buf=img,
    path=ExtractedPath('mem', hostname, '/', '', '', '', ''),
    cloudpath='IN MEMORY',
    resolution=resolution,
    mip=-1,
    layer_type=('segmentation' if segmentation else 'image'),
    bounds=Bbox( offset, offset + Vec(*(img.shape[:3])) ),
    handle=None,
  )
  return run([ cutout ], hostname=hostname, port=port)
Exemplo n.º 4
0
def test_path_extraction():
  extract = paths.extract(r'file://C:\wow\this\is\a\cool\path', windows=True, disable_toabs=True)
  print(extract)
  assert extract.protocol == 'file'
  assert extract.bucket == 'C:\\wow\\'

  # on linux the toabs prepends the current path because it
  # doesn't understand C:\... so we can't test that here.
  # assert extract.path == 'this\\is\\a\\cool\\path' 

  try:
    extract = paths.strict_extract(r'file://C:\wow\this\is\a\cool\path', windows=False, disable_toabs=True)
    assert False 
  except UnsupportedProtocolError:
    pass

  def shoulderror(url):
    try:
        paths.strict_extract(url)
        assert False, url
    except:
        pass

  def okgoogle(url):
    path = paths.strict_extract(url)
    assert path.protocol == 'gs', url
    assert path.bucket == 'bucket', url
    assert path.intermediate_path == '', url
    assert path.dataset == 'dataset', url
    assert path.layer == 'layer', url

  okgoogle('gs://bucket/dataset/layer') 
  shoulderror('s4://dataset/layer')
  shoulderror('dataset/layer')
  shoulderror('s3://dataset')

  firstdir = lambda x: '/' + x.split('/')[1]

  homepath = lib.toabs('~')
  homerintermediate = homepath.replace(firstdir(homepath), '')[1:]

  curpath = lib.toabs('.')
  curintermediate = curpath.replace(firstdir(curpath), '')[1:]

  print(curintermediate)

  assert (paths.extract('s3://seunglab-test/intermediate/path/dataset/layer') 
      == ExtractedPath(
        'precomputed', 's3', 'seunglab-test', 
        'intermediate/path/dataset/layer', 'intermediate/path/', 
        'dataset', 'layer'
      ))

  assert (paths.extract('file:///tmp/dataset/layer') 
      == ExtractedPath('precomputed', 'file', "/tmp", 'dataset/layer', '', 'dataset', 'layer'))

  assert (paths.extract('file://seunglab-test/intermediate/path/dataset/layer') 
      == ExtractedPath(
        'precomputed', 'file', firstdir(curpath), 
        os.path.join(curintermediate, 'seunglab-test/intermediate/path/dataset/layer'),   
        os.path.join(curintermediate, 'seunglab-test', 'intermediate/path/'), 
       'dataset', 'layer'))

  assert (paths.extract('gs://seunglab-test/intermediate/path/dataset/layer') 
      == ExtractedPath(
        'precomputed', 'gs', 
        'seunglab-test', 'intermediate/path/dataset/layer', 
        'intermediate/path/', 'dataset', 'layer'
      ))

  assert (paths.extract('file://~/seunglab-test/intermediate/path/dataset/layer') 
      == ExtractedPath(
        'precomputed', 'file', 
        firstdir(homepath), 
        os.path.join(homerintermediate, 'seunglab-test', 'intermediate/path/dataset/layer'),
        os.path.join(homerintermediate, 'seunglab-test', 'intermediate/path/'),  
        'dataset', 
        'layer'
      )
  )

  assert (paths.extract('file:///User/me/.cloudvolume/cache/gs/bucket/dataset/layer') 
      == ExtractedPath(
        'precomputed', 'file', 
        '/User', 'me/.cloudvolume/cache/gs/bucket/dataset/layer', 
        'me/.cloudvolume/cache/gs/bucket/', 'dataset', 'layer'
      ))

  shoulderror('s3://dataset/layer/')

  shoulderror('ou3bouqjsa fkj aojsf oaojf ojsaf')

  okgoogle('gs://bucket/dataset/layer/')
  shoulderror('gs://bucket/dataset/layer/info')

  path = paths.extract('s3://bucketxxxxxx/datasetzzzzz91h8__3/layer1br9bobasjf/')
  assert path.format == 'precomputed'
  assert path.protocol == 's3'
  assert path.bucket == 'bucketxxxxxx'
  assert path.dataset == 'datasetzzzzz91h8__3'
  assert path.layer == 'layer1br9bobasjf'

  path = paths.extract('file:///bucket/dataset/layer/')
  assert path.format == 'precomputed'
  assert path.protocol == 'file'
  assert path.bucket == '/bucket'
  assert path.dataset == 'dataset'
  assert path.layer == 'layer'

  shoulderror('lucifer://bucket/dataset/layer/')
  shoulderror('gs://///')
  shoulderror('gs://seunglab-test//segmentation')

  path = paths.extract('file:///tmp/removeme/layer/')
  assert path.format == 'precomputed'
  assert path.protocol == 'file'
  assert path.bucket == '/tmp'
  assert path.dataset == 'removeme'
  assert path.layer == 'layer'
Exemplo n.º 5
0
def test_path_extraction():
    def shoulderror(url):
        try:
            paths.strict_extract(url)
            assert False, url
        except:
            pass

    def okgoogle(url):
        path = paths.extract(url)
        assert path.protocol == 'gs', url
        assert path.bucket == 'bucket', url
        assert path.basepath == 'bucket/dataset', url
        assert path.no_bucket_basepath == 'dataset', url
        assert path.dataset == 'dataset', url
        assert path.layer == 'layer', url

    okgoogle('gs://bucket/dataset/layer')
    shoulderror('s4://dataset/layer')
    shoulderror('dataset/layer')
    shoulderror('s3://dataset')

    # don't error
    assert (strict_extract(
        'graphene://http://localhost:8080/segmentation/1.0/testvol') ==
            ExtractedPath('graphene', 'http', 'localhost:8080',
                          'localhost:8080/segmentation/1.0',
                          'segmentation/1.0', '1.0', 'testvol'))

    assert (strict_extract('precomputed://gs://fafb-ffn1-1234567/segmentation')
            == ExtractedPath('precomputed', 'gs', 'fafb-ffn1-1234567',
                             'fafb-ffn1-1234567', '', 'fafb-ffn1-1234567',
                             'segmentation'))

    firstdir = lambda x: '/' + x.split('/')[1]

    homepath = lib.toabs('~')
    homerintermediate = homepath.replace(firstdir(homepath), '')[1:]

    curpath = lib.toabs('.')
    curintermediate = curpath.replace(firstdir(curpath), '')[1:]

    match = re.match(r'((?:(?:\w:\\\\)|/).+?)\b', lib.toabs('.'))
    bucket, = match.groups()

    print(bucket, curintermediate)

    assert (paths.extract('s3://seunglab-test/intermediate/path/dataset/layer')
            == ExtractedPath('precomputed', 's3', 'seunglab-test',
                             'seunglab-test/intermediate/path/dataset',
                             'intermediate/path/dataset', 'dataset', 'layer'))

    assert (paths.extract('file:///tmp/dataset/layer') == ExtractedPath(
        'precomputed', 'file', "/tmp", '/tmp/dataset', 'dataset', 'dataset',
        'layer'))

    assert (
        paths.extract('file://seunglab-test/intermediate/path/dataset/layer')
        == ExtractedPath(
            'precomputed', 'file', firstdir(curpath),
            os.path.join(bucket, curintermediate,
                         'seunglab-test/intermediate/path/dataset'),
            os.path.join(curintermediate, 'seunglab-test',
                         'intermediate/path/dataset'), 'dataset', 'layer'))

    assert (paths.extract('gs://seunglab-test/intermediate/path/dataset/layer')
            == ExtractedPath('precomputed', 'gs', 'seunglab-test',
                             'seunglab-test/intermediate/path/dataset',
                             'intermediate/path/dataset', 'dataset', 'layer'))

    assert (
        paths.extract('file://~/seunglab-test/intermediate/path/dataset/layer')
        == ExtractedPath(
            'precomputed', 'file', firstdir(homepath),
            os.path.join(bucket, homerintermediate, 'seunglab-test',
                         'intermediate/path/dataset'),
            os.path.join(homerintermediate, 'seunglab-test',
                         'intermediate/path/dataset'), 'dataset', 'layer'))

    assert (paths.extract(
        'file:///User/me/.cloudvolume/cache/gs/bucket/dataset/layer') ==
            ExtractedPath('precomputed', 'file', '/User',
                          '/User/me/.cloudvolume/cache/gs/bucket/dataset',
                          'me/.cloudvolume/cache/gs/bucket/dataset', 'dataset',
                          'layer'))

    shoulderror('ou3bouqjsa fkj aojsf oaojf ojsaf')

    okgoogle('gs://bucket/dataset/layer/')
    shoulderror('gs://bucket/dataset/layer/info')

    path = paths.extract(
        's3://bucketxxxxxx/datasetzzzzz91h8__3/layer1br9bobasjf/')
    assert path.format == 'precomputed'
    assert path.protocol == 's3'
    assert path.bucket == 'bucketxxxxxx'
    assert path.dataset == 'datasetzzzzz91h8__3'
    assert path.layer == 'layer1br9bobasjf'

    path = paths.extract('file:///bucket/dataset/layer/')
    assert path.format == 'precomputed'
    assert path.protocol == 'file'
    assert path.bucket == '/bucket'
    assert path.dataset == 'dataset'
    assert path.layer == 'layer'

    shoulderror('lucifer://bucket/dataset/layer/')
    shoulderror('gs://///')
    shoulderror('gs://seunglab-test//segmentation')

    path = paths.extract('file:///tmp/removeme/layer/')
    assert path.format == 'precomputed'
    assert path.protocol == 'file'
    assert path.bucket == '/tmp'
    assert path.dataset == 'removeme'
    assert path.layer == 'layer'