datajoint / datajoint-docs-original

https://docs.datajoint.org
Other
2 stars 13 forks source link

external storage: add examples of working with external tracking table: getting uuid / fetching raw blobs #252

Open ixcat opened 3 years ago

ixcat commented 3 years ago

should have some basic examples of how to get the UUID for a given external attribute, and how to fetch the corresponding blob value via the external table for debugging/testing purposes on external storage

ex 1 python:

import numpy as np
import datajoint as dj
from pipeline import ephys # schema module

key = {'subject': 1234}
external_table = ephys.schema.external['store_name']

external_rec = (external_table & (real_table & key).proj(
    hash='my_field_name')).fetch1()

print(external_rec['hash'])  # UUID hash

with open('myblob.bin', 'wb') as outf:
    outf.write(et.get(external_rec['hash']))  # .get from external table of that UUID hash

with open('myblob.bin', 'rb') as inf:
    data = dj.blob.unpack(inf.read()) # should work or fail in same place

ex2 python: also the 'proj trick' for raw blob (if this is desired functionality and not a bug ...)

type((analysis.GridScore & key).proj(v='grid_ellipse').fetch1('v')) == np.ndarray
type((analysis.GridScore & key).proj(v='(grid_ellipse)').fetch1('v')) == bytes