-
Notifications
You must be signed in to change notification settings - Fork 0
Boss Project Metadata Tutorial
Metadata is stored as key-value pairs. ndio uses Python dictionaries to specify these key-value pairs.
This tutorial assumes the data hierarchy demonstrated in the [Boss Project Auth](https://github.com/jhuapl-boss/ndio/wiki/Boss Project Auth Tutorial) tutorial, exists.
First, begin with the standard import statements and an instance of the
Boss' Remote
class.
from ndio.remote.boss.remote import Remote
from ndio.ndresource.boss.resource import *
rmt = Remote()
Since we already created these resources, we can instantiate the corresponding resource classes with the bare minimum arguments. The bare minimum is the resource's name and the names of any parents.
collection = CollectionResource('JHUAPL')
experiment = ExperimentResource('Mouse17', 'JHUAPL')
channel = ChannelResource('EM', 'JHUAPL', 'Mouse17')
layer = LayerResource('Algorithm1', 'JHUAPL', 'Mouse17')
Add initial metadata using metadata_create()
.
coll_data = {'poc': 'Jane Doe'}
rmt.metadata_create(collection, coll_data)
exp_data = {'weight': '20g', 'diet': 'C2', 'date': '23-May-2016'}
rmt.metadata_create(experiment, exp_data)
chan_data = {'channel_prep': '342', 'microscope': 'sem4'}
rmt.metadata_create(channel, chan_data)
layer_data = {'confidence': '57', 'date': '27-May-2016', 'tolerance': '4'}
rmt.metadata_create(layer, layer_data)
metadata_list()
gets the keys associated with a resource. The keys are
returned as a list.
layer_keys = rmt.metadata_list(layer)
print(layer_keys)
Use metadata_get()
to retrieve existing key-value pairs. This method
takes a list of keys, so multiple key-value pairs may be retrieved with
a single call.
layer_kvals = rmt.metadata_get(layer, ['confidence', 'tolerance'])
print(layer_kvals)
To get all key-value pairs associated with a resource, the output of
metadata_list()
can be passed to metadata_get()
.
all_layer_kvals = rmt.metadata_get(layer, rmt.metadata_list(layer))
print(all_layer_kvals)
Change the values of existing keys using metadata_update()
. This method
takes a Python dictionary just like metadata_create()
. Let's change the
values stored for the channel.
chan_new_data = {'channel_prep': '345', 'microscope': 'sem3'}
rmt.metadata_update(channel, chan_new_data)
Finally, let's remove the POC information associated with the collection using
metadata_delete()
. Like metadata_get()
, this method takes a list of
keys. In this case, we'll provide a list with just one element.
rmt.metadata_delete(collection, ['poc'])