return self.resources.create_project(project_name,<EOL>dataset_name,<EOL>hostname,<EOL>is_public,<EOL>s3backend,<EOL>kvserver,<EOL>kvengine,<EOL>mdengine,<EOL>description)<EOL>

Creates a project with the given parameters.

Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on
    hostname (str): Hostname
    s3backend (str): S3 region to save the data in
    is_public (int): 1 is public. 0 is not public.
    kvserver (str): Server to store key value pairs in
    kvengine (str): Database to store key value pairs in
    mdengine (str): ???
    description (str): Description for your project

Returns:
    bool: True if project created, false if not created.


def get_project(self, project_name, dataset_name):

return self.resources.get_project(project_name, dataset_name)<EOL>

Get details regarding a project given its name and dataset its linked
to.

Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on

Returns:
    dict: Project info


def delete_project(self, project_name, dataset_name):

return self.resources.delete_project(project_name, dataset_name)<EOL>

Deletes a project once given its name and its related dataset.

Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on

Returns:
    bool: True if project deleted, False if not.


return self.resources.create_token(token_name,<EOL>project_name,<EOL>dataset_name,<EOL>is_public)<EOL>

Creates a token with the given parameters.
Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on
    token_name (str): Token name
    is_public (int): 1 is public. 0 is not public
Returns:
    bool: True if project created, false if not created.


return self.resources.get_token(token_name,<EOL>project_name,<EOL>dataset_name)<EOL>

Get a token with the given parameters.
Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on
    token_name (str): Token name
Returns:
    dict: Token info


return self.resources.delete_token(token_name,<EOL>project_name,<EOL>dataset_name)<EOL>

Delete a token with the given parameters.
Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on
    token_name (str): Token name
    channel_name (str): Channel name project is based on
Returns:
    bool: True if project deleted, false if not deleted.


return self.resources.list_tokens()<EOL>

Lists a set of tokens that are public in Neurodata.
Arguments:
Returns:
    dict: Public tokens found in Neurodata


return self.resources.list_projects(dataset_name)<EOL>

Lists a set of projects related to a dataset.

Arguments:
    dataset_name (str): Dataset name to search projects for

Returns:
    dict: Projects found based on dataset query


Creates a dataset.

Arguments:
    name (str): Name of dataset
    x_img_size (int): max x coordinate of image size
    y_img_size (int): max y coordinate of image size
    z_img_size (int): max z coordinate of image size
    x_vox_res (float): x voxel resolution
    y_vox_res (float): y voxel resolution
    z_vox_res (float): z voxel resolution
    x_offset (int): x offset amount
    y_offset (int): y offset amount
    z_offset (int): z offset amount
    scaling_levels (int): Level of resolution scaling
    scaling_option (int): Z slices is 0 or Isotropic is 1
    dataset_description (str): Your description of the dataset
    is_public (int): 1 'true' or 0 'false' for viewability of data set
        in public

Returns:
    bool: True if dataset created, False if not


return self.resources.get_dataset(name)<EOL>

Returns info regarding a particular dataset.

Arugments:
    name (str): Dataset name

Returns:
    dict: Dataset information


return self.resources.list_datasets(get_global_public)<EOL>

Lists datasets in resources. Setting 'get_global_public' to 'True'
will retrieve all public datasets in cloud. 'False' will get user's
public datasets.

Arguments:
    get_global_public (bool): True if user wants all public datasets in
                              cloud. False if user wants only their
                              public datasets.

Returns:
    dict: Returns datasets in JSON format


return self.resources.delete_dataset(name)<EOL>

Arguments:
    name (str): Name of dataset to delete

Returns:
    bool: True if dataset deleted, False if not


Create a new channel on the Remote, using channel_data.

Arguments:
    channel_name (str): Channel name
    project_name (str): Project name
    dataset_name (str): Dataset name
    channel_type (str): Type of the channel (e.g. `neurodata.IMAGE`)
    dtype (str): The datatype of the channel's data (e.g. `uint8`)
    startwindow (int): Window to start in
    endwindow (int): Window to end in
    readonly (int): Can others write to this channel?
    propagate (int): Allow propogation? 1 is True, 0 is False
    resolution (int): Resolution scaling
    channel_description (str): Your description of the channel

Returns:
    bool: `True` if successful, `False` otherwise.

Raises:
    ValueError: If your args were bad :(
    RemoteDataUploadError: If the channel data is valid but upload
        fails for some other reason.


def get_channel(self, channel_name, project_name, dataset_name):

return self.resources.get_channel(channel_name, project_name,<EOL>dataset_name)<EOL>

Gets info about a channel given its name, name of its project
, and name of its dataset.

Arguments:
    channel_name (str): Channel name
    project_name (str): Project name
    dataset_name (str): Dataset name

Returns:
    dict: Channel info


def delete_channel(self, channel_name, project_name, dataset_name):

return self.resources.delete_channel(channel_name, project_name,<EOL>dataset_name)<EOL>

Deletes a channel given its name, name of its project
, and name of its dataset.

Arguments:
    channel_name (str): Channel name
    project_name (str): Project name
    dataset_name (str): Dataset name

Returns:
    bool: True if channel deleted, False if not


self.protocol = protocol<EOL>self.hostname = hostname<EOL>

Arguments:
    `hostname`:     Hostname (e.g. google.com)
    `protocol`:     HTTP protocol (e.g. https)


if not endpoint.startswith('<STR_LIT:/>'):<EOL><INDENT>endpoint = "<STR_LIT:/>" + endpoint<EOL><DEDENT>return self.protocol + "<STR_LIT>" + self.hostname + endpoint<EOL>

Get the base URL of the Remote.

Arguments:
    None
Returns:
    `str` base URL


r = requests.get(self.url() + "<STR_LIT:/>" + endpoint)<EOL>return r.status_code<EOL>

Ping the server to make sure that you can access the base URL.

Arguments:
    None
Returns:
    `boolean` Successful access of server (or status code)


super(resources, self).__init__(user_token,<EOL>hostname,<EOL>protocol,<EOL>meta_root,<EOL>meta_protocol, **kwargs)<EOL>

Initializer for resources class.

Arguments:
    hostname (str: "openconnecto.me"): The hostname to connect to
    protocol (str: "http"): The protocol (http or https) to use
    meta_root (str: "http://lims.neurodata.io/"): The metadata server
    meta_protocol (str: "http"): The protocol to use for the md server
    check_tokens (boolean: False): Whether functions that take `token`
        as an argument should check for the existance of that token and
        fail immediately if it is not found. This is a good idea for
        functions that take more time to complete, and might not fail
        until the very end otherwise.
    chunk_threshold (int: 1e9 / 4): The maximum size of a numpy array
        that will be uploaded in one HTTP request. If you find that
        your data requests are commonly timing out, try reducing this.
        Default is 1e9 / 4, or a 0.25GiB.
    suffix (str: "ocp"): The URL suffix to specify ndstore/microns. If
        you aren't sure what to do with this, don't specify one.


url = self.url() + "<STR_LIT>".format(<EOL>dataset_name) + "<STR_LIT>".format(project_name)<EOL>json = {<EOL>"<STR_LIT>": project_name,<EOL>"<STR_LIT:host>": hostname,<EOL>"<STR_LIT>": s3backend,<EOL>"<STR_LIT>": is_public,<EOL>"<STR_LIT>": kvserver,<EOL>"<STR_LIT>": kvengine,<EOL>"<STR_LIT>": mdengine,<EOL>"<STR_LIT>": description<EOL>}<EOL>req = self.remote_utils.post_url(url, json=json)<EOL>if req.status_code is not <NUM_LIT>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req))<EOL><DEDENT>if req.content == "<STR_LIT>" or req.content == b'<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Creates a project with the given parameters.

Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on
    hostname (str): Hostname
    s3backend (str): S3 region to save the data in
    is_public (int): 1 is public. 0 is not public.
    kvserver (str): Server to store key value pairs in
    kvengine (str): Database to store key value pairs in
    mdengine (str): ???
    description (str): Description for your project

Returns:
    bool: True if project created, false if not created.


url = self.url() + "<STR_LIT>".format(dataset_name)+ "<STR_LIT>".format(project_name)<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataNotFoundError('<STR_LIT>'.format(req.text))<EOL><DEDENT>else:<EOL><INDENT>return req.json()<EOL><DEDENT>

Get details regarding a project given its name and dataset its linked
to.

Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on

Returns:
    dict: Project info


url = self.url() + "<STR_LIT>".format(dataset_name)+ "<STR_LIT>".format(project_name)<EOL>req = self.remote_utils.delete_url(url)<EOL>if req.status_code is not <NUM_LIT>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req.text))<EOL><DEDENT>if req.content == "<STR_LIT>" or req.content == b'<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Deletes a project once given its name and its related dataset.

Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on

Returns:
    bool: True if project deleted, False if not.


url = self.url() + "<STR_LIT>".format(dataset_name)+ "<STR_LIT>"<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataNotFoundError('<STR_LIT>'.format(req.text))<EOL><DEDENT>else:<EOL><INDENT>return req.json()<EOL><DEDENT>


url = self.url() + '<STR_LIT>'.format(<EOL>dataset_name) + '<STR_LIT>'.format(project_name) +'<STR_LIT>'.format(token_name)<EOL>json = {<EOL>"<STR_LIT>": token_name,<EOL>"<STR_LIT>": is_public<EOL>}<EOL>req = self.remote_utils.post_url(url, json=json)<EOL>if req.status_code is not <NUM_LIT>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req.text))<EOL><DEDENT>if req.content == "<STR_LIT>" or req.content == b'<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Creates a token with the given parameters.
Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on
    token_name (str): Token name
    is_public (int): 1 is public. 0 is not public
Returns:
    bool: True if project created, false if not created.


url = self.url() + "<STR_LIT>".format(dataset_name)+ "<STR_LIT>".format(project_name)+ "<STR_LIT>".format(token_name)<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req.text))<EOL><DEDENT>else:<EOL><INDENT>return req.json()<EOL><DEDENT>

Get a token with the given parameters.
Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on
    token_name (str): Token name
Returns:
    dict: Token info


url = self.url() + "<STR_LIT>".format(dataset_name)+ "<STR_LIT>".format(project_name)+ "<STR_LIT>".format(token_name)<EOL>req = self.remote_utils.delete_url(url)<EOL>if req.status_code is not <NUM_LIT>:<EOL><INDENT>raise RemoteDataUploadError("<STR_LIT>".format(req.text))<EOL><DEDENT>if req.content == "<STR_LIT>" or req.content == b'<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Delete a token with the given parameters.
Arguments:
    project_name (str): Project name
    dataset_name (str): Dataset name project is based on
    token_name (str): Token name
    channel_name (str): Channel name project is based on
Returns:
    bool: True if project deleted, false if not deleted.


url = self.url() + "<STR_LIT>"<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataNotFoundError('<STR_LIT>'.format(req.text))<EOL><DEDENT>else:<EOL><INDENT>return req.json()<EOL><DEDENT>

Lists a set of tokens that are public in Neurodata.
Arguments:
Returns:
    dict: Public tokens found in Neurodata


url = self.url() + "<STR_LIT>".format(name)<EOL>json = {<EOL>"<STR_LIT>": name,<EOL>"<STR_LIT>": x_img_size,<EOL>"<STR_LIT>": y_img_size,<EOL>"<STR_LIT>": z_img_size,<EOL>"<STR_LIT>": x_vox_res,<EOL>"<STR_LIT>": y_vox_res,<EOL>"<STR_LIT>": z_vox_res,<EOL>"<STR_LIT>": x_offset,<EOL>"<STR_LIT>": y_offset,<EOL>"<STR_LIT>": z_offset,<EOL>"<STR_LIT>": scaling_levels,<EOL>"<STR_LIT>": scaling_option,<EOL>"<STR_LIT>": dataset_description,<EOL>"<STR_LIT>": is_public<EOL>}<EOL>req = self.remote_utils.post_url(url, json=json)<EOL>if req.status_code is not <NUM_LIT>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req.text))<EOL><DEDENT>if req.content == "<STR_LIT>" or req.content == b'<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Creates a dataset.

Arguments:
    name (str): Name of dataset
    x_img_size (int): max x coordinate of image size
    y_img_size (int): max y coordinate of image size
    z_img_size (int): max z coordinate of image size
    x_vox_res (float): x voxel resolution
    y_vox_res (float): y voxel resolution
    z_vox_res (float): z voxel resolution
    x_offset (int): x offset amount
    y_offset (int): y offset amount
    z_offset (int): z offset amount
    scaling_levels (int): Level of resolution scaling
    scaling_option (int): Z slices is 0 or Isotropic is 1
    dataset_description (str): Your description of the dataset
    is_public (int): 1 'true' or 0 'false' for viewability of data set
        in public

Returns:
    bool: True if dataset created, False if not


url = self.url() + "<STR_LIT>".format(name)<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataNotFoundError('<STR_LIT>'.format(req.text))<EOL><DEDENT>else:<EOL><INDENT>return req.json()<EOL><DEDENT>

Returns info regarding a particular dataset.

Arugments:
    name (str): Dataset name

Returns:
    dict: Dataset information


appending = "<STR_LIT>"<EOL>if get_global_public:<EOL><INDENT>appending = "<STR_LIT>"<EOL><DEDENT>url = self.url() + "<STR_LIT>".format(appending)<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataNotFoundError('<STR_LIT>'.format(req.text))<EOL><DEDENT>else:<EOL><INDENT>return req.json()<EOL><DEDENT>

Lists datasets in resources. Setting 'get_global_public' to 'True'
will retrieve all public datasets in cloud. 'False' will get user's
public datasets.

Arguments:
    get_global_public (bool): True if user wants all public datasets in
                              cloud. False if user wants only their
                              public datasets.

Returns:
    dict: Returns datasets in JSON format


url = self.url() + "<STR_LIT>".format(name)<EOL>req = self.remote_utils.delete_url(url)<EOL>if req.status_code is not <NUM_LIT>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req.text))<EOL><DEDENT>if req.content == "<STR_LIT>" or req.content == b'<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Arguments:
    name (str): Name of dataset to delete

Returns:
    bool: True if dataset deleted, False if not


self._check_channel(channel_name)<EOL>if channel_type not in ['<STR_LIT:image>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>raise ValueError('<STR_LIT>' +<EOL>'<STR_LIT>')<EOL><DEDENT>if readonly * <NUM_LIT:1> not in [<NUM_LIT:0>, <NUM_LIT:1>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>url = self.url() + "<STR_LIT>".format(dataset_name)+ "<STR_LIT>".format(project_name) +"<STR_LIT>".format(channel_name)<EOL>json = {<EOL>"<STR_LIT>": channel_name,<EOL>"<STR_LIT>": channel_type,<EOL>"<STR_LIT>": dtype,<EOL>"<STR_LIT>": startwindow,<EOL>"<STR_LIT>": endwindow,<EOL>'<STR_LIT>': start_time,<EOL>'<STR_LIT>': end_time,<EOL>'<STR_LIT>': readonly,<EOL>'<STR_LIT>': propagate,<EOL>'<STR_LIT>': resolution,<EOL>'<STR_LIT>': channel_description<EOL>}<EOL>req = self.remote_utils.post_url(url, json=json)<EOL>if req.status_code is not <NUM_LIT>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req.text))<EOL><DEDENT>if req.content == "<STR_LIT>" or req.content == b'<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Create a new channel on the Remote, using channel_data.

Arguments:
    channel_name (str): Channel name
    project_name (str): Project name
    dataset_name (str): Dataset name
    channel_type (str): Type of the channel (e.g. `neurodata.IMAGE`)
    dtype (str): The datatype of the channel's data (e.g. `uint8`)
    startwindow (int): Window to start in
    endwindow (int): Window to end in
    readonly (int): Can others write to this channel?
    propagate (int): Allow propogation? 1 is True, 0 is False
    resolution (int): Resolution scaling
    channel_description (str): Your description of the channel

Returns:
    bool: `True` if successful, `False` otherwise.

Raises:
    ValueError: If your args were bad :(
    RemoteDataUploadError: If the channel data is valid but upload
        fails for some other reason.


url = self.url() + "<STR_LIT>".format(dataset_name)+ "<STR_LIT>".format(project_name) +"<STR_LIT>".format(channel_name)<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataNotFoundError('<STR_LIT>'.format(req.text))<EOL><DEDENT>else:<EOL><INDENT>return req.json()<EOL><DEDENT>

Gets info about a channel given its name, name of its project
, and name of its dataset.

Arguments:
    channel_name (str): Channel name
    project_name (str): Project name
    dataset_name (str): Dataset name

Returns:
    dict: Channel info


url = self.url() + "<STR_LIT>".format(dataset_name)+ "<STR_LIT>".format(project_name) +"<STR_LIT>".format(channel_name)<EOL>req = self.remote_utils.delete_url(url)<EOL>if req.status_code is not <NUM_LIT>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req.text))<EOL><DEDENT>if req.content == "<STR_LIT>" or req.content == b'<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Deletes a channel given its name, name of its project
, and name of its dataset.

Arguments:
    channel_name (str): Channel name
    project_name (str): Project name
    dataset_name (str): Dataset name

Returns:
    bool: True if channel deleted, False if not


self._check_tokens = kwargs.get('<STR_LIT>', False)<EOL>self._chunk_threshold = kwargs.get('<STR_LIT>', <NUM_LIT> / <NUM_LIT:4>)<EOL>self._ext = kwargs.get('<STR_LIT>', DEFAULT_SUFFIX)<EOL>self._known_tokens = []<EOL>self._user_token = user_token<EOL>self.meta_root = meta_root<EOL>if not self.meta_root.endswith('<STR_LIT:/>'):<EOL><INDENT>self.meta_root = self.meta_root + "<STR_LIT:/>"<EOL><DEDENT>if self.meta_root.startswith('<STR_LIT>'):<EOL><INDENT>self.meta_root = self.meta_root[self.meta_root.index('<STR_LIT>') + <NUM_LIT:3>:]<EOL><DEDENT>self.meta_protocol = meta_protocol<EOL>self.remote_utils = remote_utils(self._user_token)<EOL>super(neuroRemote, self).__init__(hostname, protocol)<EOL>

Initializer for the neuroRemote remote class.

Arguments:
    hostname (str: "openconnecto.me"): The hostname to connect to
    protocol (str: "http"): The protocol (http or https) to use
    meta_root (str: "http://lims.neurodata.io/"): The metadata server
    meta_protocol (str: "http"): The protocol to use for the md server
    check_tokens (boolean: False): Whether functions that take `token`
        as an argument should check for the existance of that token and
        fail immediately if it is not found. This is a good idea for
        functions that take more time to complete, and might not fail
        until the very end otherwise.
    chunk_threshold (int: 1e9 / 4): The maximum size of a numpy array
        that will be uploaded in one HTTP request. If you find that
        your data requests are commonly timing out, try reducing this.
        Default is 1e9 / 4, or a 0.25GiB.
    suffix (str: "ocp"): The URL suffix to specify ndstore/microns. If
        you aren't sure what to do with this, don't specify one.


return self.remote_utils.get_url(url)<EOL>

Old getURL method. Use remote_utils.get_url() instead.

Arguments:
    url (str): The url to send get request to.

Returns:
    str: result


return self.remote_utils.ping(super(neuroRemote, self).url(), suffix)<EOL>

Return the status-code of the API (estimated using the public-tokens
lookup page).

Arguments:
    suffix (str : 'public_tokens/'): The url endpoint to check

Returns:
    int: status code


return super(neuroRemote,<EOL>self).url('<STR_LIT>'.format(self._ext) + suffix)<EOL>

Return a constructed URL, appending an optional suffix (uri path).

Arguments:
    suffix (str : ""): The suffix to append to the end of the URL

Returns:
    str: The complete URL


return self.meta_protocol + "<STR_LIT>" + self.meta_root + suffix<EOL>

Return a constructed URL, appending an optional suffix (uri path),
for the metadata server. (Should be temporary, until the LIMS shim
is fixed.)

Arguments:
    suffix (str : ""): The suffix to append to the end of the URL

Returns:
    str: The complete URL


return "<STR_LIT>".format(<EOL>self.hostname,<EOL>self.protocol,<EOL>self.meta_url,<EOL>self.meta_protocol<EOL>)<EOL>

Return a string representation that can be used to reproduce this
instance. `eval(repr(this))` should return an identical copy.

Arguments:
    None

Returns:
    str: Representation of reproducible instance.


@_check_token<EOL><INDENT>def reserve_ids(self, token, channel, quantity):<DEDENT>

quantity = str(quantity)<EOL>url = self.url("<STR_LIT>".format(token, channel, quantity))<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataNotFoundError('<STR_LIT>' + req.status_code)<EOL><DEDENT>out = req.json()<EOL>return [out[<NUM_LIT:0>] + i for i in range(out[<NUM_LIT:1>])]<EOL>

Requests a list of next-available-IDs from the server.

Arguments:
    quantity (int): The number of IDs to reserve

Returns:
    int[quantity]: List of IDs you've been granted


@_check_token<EOL><INDENT>def merge_ids(self, token, channel, ids, delete=False):<DEDENT>

url = self.url() + "<STR_LIT>".format('<STR_LIT:U+002C>'.join([str(i) for i in ids]))<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(<EOL>'<STR_LIT:U+002C>'.join([str(i) for i in ids])))<EOL><DEDENT>if delete:<EOL><INDENT>self.delete_ramon(token, channel, ids[<NUM_LIT:1>:])<EOL><DEDENT>return True<EOL>

Call the restful endpoint to merge two RAMON objects into one.

Arguments:
    token (str): The token to inspect
    channel (str): The channel to inspect
    ids (int[]): the list of the IDs to merge
    delete (bool : False): Whether to delete after merging.

Returns:
    json: The ID as returned by ndstore


@_check_token<EOL><INDENT>def create_channels(self, dataset, token, new_channels_data):<DEDENT>

channels = {}<EOL>for channel_new in new_channels_data:<EOL><INDENT>self._check_channel(channel_new.name)<EOL>if channel_new.channel_type not in ['<STR_LIT:image>', '<STR_LIT>']:<EOL><INDENT>raise ValueError('<STR_LIT>' +<EOL>'<STR_LIT>' +<EOL>'<STR_LIT>')<EOL><DEDENT>if channel_new.readonly * <NUM_LIT:1> not in [<NUM_LIT:0>, <NUM_LIT:1>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>channels[channel_new.name] = {<EOL>"<STR_LIT>": channel_new.name,<EOL>"<STR_LIT>": channel_new.channel_type,<EOL>"<STR_LIT>": channel_new.dtype,<EOL>"<STR_LIT>": channel_new.readonly * <NUM_LIT:1><EOL>}<EOL><DEDENT>req = requests.post(self.url("<STR_LIT>".format(dataset) +<EOL>"<STR_LIT:{}>".format(token)),<EOL>json={"<STR_LIT>": {channels}}, verify=False)<EOL>if req.status_code is not <NUM_LIT>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req.text))<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>

Creates channels given a dictionary in 'new_channels_data'
, 'dataset' name, and 'token' (project) name.

Arguments:
    token (str): Token to identify project
    dataset (str): Dataset name to identify dataset to download from
    new_channels_data (dict): New channel data to upload into new
        channels

Returns:
    bool: Process completed succesfully or not


if self.get_propagate_status(token, channel) != u'<STR_LIT:0>':<EOL><INDENT>return<EOL><DEDENT>url = self.url('<STR_LIT>'.format(token, channel))<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataUploadError('<STR_LIT>'.format(req.text))<EOL><DEDENT>return True<EOL>

Kick off the propagate function on the remote server.

Arguments:
    token (str): The token to propagate
    channel (str): The channel to propagate

Returns:
    boolean: Success


def get_propagate_status(self, token, channel):

url = self.url('<STR_LIT>'.format(token, channel))<EOL>req = self.remote_utils.get_url(url)<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(token, channel))<EOL><DEDENT>return req.text<EOL>

Get the propagate status for a token/channel pair.

Arguments:
    token (str): The token to check
    channel (str): The channel to check

Returns:
    str: The status code


super(Exception, self).__init__(message)<EOL>


super(RemoteError, self).__init__(message)<EOL>


super(data, self).__init__(user_token,<EOL>hostname,<EOL>protocol,<EOL>meta_root,<EOL>meta_protocol, **kwargs)<EOL>

Initializer for the data class.

Arguments:
    hostname (str: "openconnecto.me"): The hostname to connect to
    protocol (str: "http"): The protocol (http or https) to use
    meta_root (str: "http://lims.neurodata.io/"): The metadata server
    meta_protocol (str: "http"): The protocol to use for the md server
    check_tokens (boolean: False): Whether functions that take `token`
        as an argument should check for the existance of that token and
        fail immediately if it is not found. This is a good idea for
        functions that take more time to complete, and might not fail
        until the very end otherwise.
    chunk_threshold (int: 1e9 / 4): The maximum size of a numpy array
        that will be uploaded in one HTTP request. If you find that
        your data requests are commonly timing out, try reducing this.
        Default is 1e9 / 4, or a 0.25GiB.
    suffix (str: "ocp"): The URL suffix to specify ndstore/microns. If
        you aren't sure what to do with this, don't specify one.


return super(data, self).url() + '<STR_LIT>' + suffix<EOL>

Overloaded url method from neuroRemote.

Arugments:
    suffix (str): url extension

Returns:
    str: properly formatted url


def get_block_size(self, token, resolution=None):

cdims = self.get_metadata(token)['<STR_LIT>']['<STR_LIT>']<EOL>if resolution is None:<EOL><INDENT>resolution = min(cdims.keys())<EOL><DEDENT>return cdims[str(resolution)]<EOL>

Gets the block-size for a given token at a given resolution.

Arguments:
    token (str): The token to inspect
    resolution (int : None): The resolution at which to inspect data.
        If none is specified, uses the minimum available.

Returns:
    int[3]: The xyz blocksize.


def get_image_offset(self, token, resolution=<NUM_LIT:0>):

info = self.get_proj_info(token)<EOL>res = str(resolution)<EOL>if res not in info['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>raise RemoteDataNotFoundError("<STR_LIT>" + res +<EOL>"<STR_LIT>")<EOL><DEDENT>return info['<STR_LIT>']['<STR_LIT>'][str(resolution)]<EOL>

Gets the image offset for a given token at a given resolution. For
instance, the `kasthuri11` dataset starts at (0, 0, 1), so its 1850th
slice is slice 1850, not 1849. When downloading a full dataset, the
result of this function should be your x/y/z starts.

Arguments:
    token (str): The token to inspect
    resolution (int : 0): The resolution at which to gather the offset

Returns:
    int[3]: The origin of the dataset, as a list


def get_xy_slice(self, token, channel,<EOL>x_start, x_stop,<EOL>y_start, y_stop,<EOL>z_index,<EOL>resolution=<NUM_LIT:0>):

vol = self.get_cutout(token, channel, x_start, x_stop, y_start,<EOL>y_stop, z_index, z_index + <NUM_LIT:1>, resolution)<EOL>vol = numpy.squeeze(vol)  <EOL>return vol<EOL>

Return a binary-encoded, decompressed 2d image. You should
specify a 'token' and 'channel' pair.  For image data, users
should use the channel 'image.'

Arguments:
    token (str): Token to identify data to download
    channel (str): Channel
    resolution (int): Resolution level
    Q_start (int):` The lower bound of dimension 'Q'
    Q_stop (int): The upper bound of dimension 'Q'
    z_index (int): The z-slice to image

Returns:
    str: binary image data


def get_image(self, token, channel,<EOL>x_start, x_stop,<EOL>y_start, y_stop,<EOL>z_index,<EOL>resolution=<NUM_LIT:0>):

return self.get_xy_slice(token, channel,<EOL>x_start, x_stop,<EOL>y_start, y_stop,<EOL>z_index,<EOL>resolution)<EOL>

Alias for the `get_xy_slice` function for backwards compatibility.


def get_volume(self, token, channel,<EOL>x_start, x_stop,<EOL>y_start, y_stop,<EOL>z_start, z_stop,<EOL>resolution=<NUM_LIT:1>,<EOL>block_size=DEFAULT_BLOCK_SIZE,<EOL>neariso=False):

size = (x_stop - x_start) * (y_stop - y_start) * (z_stop - z_start)<EOL>volume = ramon.RAMONVolume()<EOL>volume.xyz_offset = [x_start, y_start, z_start]<EOL>volume.resolution = resolution<EOL>volume.cutout = self.get_cutout(token, channel, x_start,<EOL>x_stop, y_start, y_stop,<EOL>z_start, z_stop,<EOL>resolution=resolution,<EOL>block_size=block_size,<EOL>neariso=neariso)<EOL>return volume<EOL>

Get a RAMONVolume volumetric cutout from the neurodata server.

Arguments:
    token (str): Token to identify data to download
    channel (str): Channel
    resolution (int): Resolution level
    Q_start (int): The lower bound of dimension 'Q'
    Q_stop (int): The upper bound of dimension 'Q'
    block_size (int[3]): Block size of this dataset
    neariso (bool : False): Passes the 'neariso' param to the cutout.
        If you don't know what this means, ignore it!

Returns:
    ndio.ramon.RAMONVolume: Downloaded data.


def get_cutout(self, token, channel,<EOL>x_start, x_stop,<EOL>y_start, y_stop,<EOL>z_start, z_stop,<EOL>t_start=<NUM_LIT:0>, t_stop=<NUM_LIT:1>,<EOL>resolution=<NUM_LIT:1>,<EOL>block_size=DEFAULT_BLOCK_SIZE,<EOL>neariso=False):

if block_size is None:<EOL><INDENT>block_size = self.get_block_size(token, resolution)<EOL><DEDENT>origin = self.get_image_offset(token, resolution)<EOL>if (z_stop - z_start) < <NUM_LIT:16>:<EOL><INDENT>z_slices = <NUM_LIT:16><EOL><DEDENT>else:<EOL><INDENT>z_slices = z_stop - z_start<EOL><DEDENT>size = (x_stop - x_start) * (y_stop - y_start) * z_slices * <NUM_LIT:4><EOL>if six.PY2:<EOL><INDENT>dl_func = self._get_cutout_blosc_no_chunking<EOL><DEDENT>elif six.PY3:<EOL><INDENT>dl_func = self._get_cutout_no_chunking<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if size < self._chunk_threshold:<EOL><INDENT>vol = dl_func(token, channel, resolution,<EOL>x_start, x_stop,<EOL>y_start, y_stop,<EOL>z_start, z_stop,<EOL>t_start, t_stop,<EOL>neariso=neariso)<EOL>vol = numpy.rollaxis(vol, <NUM_LIT:1>)<EOL>vol = numpy.rollaxis(vol, <NUM_LIT:2>)<EOL>return vol<EOL><DEDENT>else:<EOL><INDENT>from ndio.utils.parallel import block_compute<EOL>blocks = block_compute(x_start, x_stop,<EOL>y_start, y_stop,<EOL>z_start, z_stop,<EOL>origin, block_size)<EOL>vol = numpy.zeros(((z_stop - z_start),<EOL>(y_stop - y_start),<EOL>(x_stop - x_start)))<EOL>for b in blocks:<EOL><INDENT>data = dl_func(token, channel, resolution,<EOL>b[<NUM_LIT:0>][<NUM_LIT:0>], b[<NUM_LIT:0>][<NUM_LIT:1>],<EOL>b[<NUM_LIT:1>][<NUM_LIT:0>], b[<NUM_LIT:1>][<NUM_LIT:1>],<EOL>b[<NUM_LIT:2>][<NUM_LIT:0>], b[<NUM_LIT:2>][<NUM_LIT:1>],<EOL><NUM_LIT:0>, <NUM_LIT:1>,<EOL>neariso=neariso)<EOL>if b == blocks[<NUM_LIT:0>]:  <EOL><INDENT>vol = numpy.zeros(((z_stop - z_start),<EOL>(y_stop - y_start),<EOL>(x_stop - x_start)), dtype=data.dtype)<EOL><DEDENT>vol[b[<NUM_LIT:2>][<NUM_LIT:0>] - z_start: b[<NUM_LIT:2>][<NUM_LIT:1>] - z_start,<EOL>b[<NUM_LIT:1>][<NUM_LIT:0>] - y_start: b[<NUM_LIT:1>][<NUM_LIT:1>] - y_start,<EOL>b[<NUM_LIT:0>][<NUM_LIT:0>] - x_start: b[<NUM_LIT:0>][<NUM_LIT:1>] - x_start] = data<EOL><DEDENT>vol = numpy.rollaxis(vol, <NUM_LIT:1>)<EOL>vol = numpy.rollaxis(vol, <NUM_LIT:2>)<EOL>return vol<EOL><DEDENT>

Get volumetric cutout data from the neurodata server.

Arguments:
    token (str): Token to identify data to download
    channel (str): Channel
    resolution (int): Resolution level
    Q_start (int): The lower bound of dimension 'Q'
    Q_stop (int): The upper bound of dimension 'Q'
    block_size (int[3]): Block size of this dataset. If not provided,
        ndio uses the metadata of this tokenchannel to set. If you find
        that your downloads are timing out or otherwise failing, it may
        be wise to start off by making this smaller.
    neariso (bool : False): Passes the 'neariso' param to the cutout.
        If you don't know what this means, ignore it!

Returns:
    numpy.ndarray: Downloaded data.


def post_cutout(self, token, channel,<EOL>x_start,<EOL>y_start,<EOL>z_start,<EOL>data,<EOL>resolution=<NUM_LIT:0>):

datatype = self.get_proj_info(token)['<STR_LIT>'][channel]['<STR_LIT>']<EOL>if data.dtype.name != datatype:<EOL><INDENT>data = data.astype(datatype)<EOL><DEDENT>data = numpy.rollaxis(data, <NUM_LIT:1>)<EOL>data = numpy.rollaxis(data, <NUM_LIT:2>)<EOL>if six.PY3 or data.nbytes > <NUM_LIT>:<EOL><INDENT>ul_func = self._post_cutout_no_chunking_npz<EOL><DEDENT>else:<EOL><INDENT>ul_func = self._post_cutout_no_chunking_blosc<EOL><DEDENT>if data.size < self._chunk_threshold:<EOL><INDENT>return ul_func(token, channel, x_start,<EOL>y_start, z_start, data,<EOL>resolution)<EOL><DEDENT>return self._post_cutout_with_chunking(token, channel,<EOL>x_start, y_start, z_start, data,<EOL>resolution, ul_func)<EOL>

Post a cutout to the server.

Arguments:
    token (str)
    channel (str)
    x_start (int)
    y_start (int)
    z_start (int)
    data (numpy.ndarray): A numpy array of data. Pass in (x, y, z)
    resolution (int : 0): Resolution at which to insert the data

Returns:
    bool: True on success

Raises:
    RemoteDataUploadError: if there's an issue during upload.


def _post_cutout_no_chunking_blosc(self, token, channel,<EOL>x_start, y_start, z_start,<EOL>data, resolution):

data = numpy.expand_dims(data, axis=<NUM_LIT:0>)<EOL>blosc_data = blosc.pack_array(data)<EOL>url = self.url("<STR_LIT>".format(<EOL>token, channel,<EOL>resolution,<EOL>x_start, x_start + data.shape[<NUM_LIT:3>],<EOL>y_start, y_start + data.shape[<NUM_LIT:2>],<EOL>z_start, z_start + data.shape[<NUM_LIT:1>]<EOL>))<EOL>req = self.remote_utils.post_url(url, data=blosc_data, headers={<EOL>'<STR_LIT:Content-Type>': '<STR_LIT>'<EOL>})<EOL>if req.status_code is not <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataUploadError(req.text)<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>


self.remote_utils = remote_utils(user_token)<EOL>

Initializes metadata.

Arguments:
    user_token (str): Authentication token for user.


r = self.remote_utils.get_url(self.url() + "<STR_LIT>")<EOL>return r.json()<EOL>

Get a list of public tokens available on this server.

Arguments:
    None

Returns:
    str[]: list of public tokens


return list(self.get_public_datasets_and_tokens().keys())<EOL>

NOTE: VERY SLOW!
Get a list of public datasets. Different than public tokens!

Arguments:
    None

Returns:
    str[]: list of public datasets


datasets = {}<EOL>tokens = self.get_public_tokens()<EOL>for t in tokens:<EOL><INDENT>dataset = self.get_token_dataset(t)<EOL>if dataset in datasets:<EOL><INDENT>datasets[dataset].append(t)<EOL><DEDENT>else:<EOL><INDENT>datasets[dataset] = [t]<EOL><DEDENT><DEDENT>return datasets<EOL>

NOTE: VERY SLOW!
Get a dictionary relating key:dataset to value:[tokens] that rely
on that dataset.

Arguments:
    None

Returns:
    dict: relating key:dataset to value:[tokens]


return self.get_proj_info(token)['<STR_LIT>']['<STR_LIT:description>']<EOL>

Get the dataset for a given token.

Arguments:
    token (str): The token to inspect

Returns:
    str: The name of the dataset


r = self.remote_utils.get_url(self.url() + "<STR_LIT>".format(token))<EOL>return r.json()<EOL>

Return the project info for a given token.

Arguments:
    token (str): Token to return information for

Returns:
    JSON: representation of proj_info


return self.get_proj_info(token)<EOL>


return self.get_proj_info(token)['<STR_LIT>']<EOL>

Wraps get_proj_info to return a dictionary of just the channels of
a given project.

Arguments:
    token (str): Token to return channels for

Returns:
    JSON: dictionary of channels.


def get_image_size(self, token, resolution=<NUM_LIT:0>):

Return the size of the volume (3D). Convenient for when you want
to download the entirety of a dataset.

Arguments:
    token (str): The token for which to find the dataset image bounds
    resolution (int : 0): The resolution at which to get image bounds.
        Defaults to 0, to get the largest area available.

Returns:
    int[3]: The size of the bounds. Should == get_volume.shape

Raises:
    RemoteDataNotFoundError: If the token is invalid, or if the
        metadata at that resolution is unavailable in projinfo.


req = requests.post(self.meta_url("<STR_LIT>" + token),<EOL>json=data, verify=False)<EOL>if req.status_code != <NUM_LIT:200>:<EOL><INDENT>raise RemoteDataUploadError(<EOL>"<STR_LIT>" + req.json()['<STR_LIT:message>']<EOL>)<EOL><DEDENT>return req.json()<EOL>

Insert new metadata into the OCP metadata database.

Arguments:
    token (str): Token of the datum to set
    data (str): A dictionary to insert as metadata. Include `secret`.

Returns:
    json: Info of the inserted ID (convenience) or an error message.

Throws:
    RemoteDataUploadError: If the token is already populated, or if
        there is an issue with your specified `secret` key.


md = self.get_metadata(token)['<STR_LIT>']<EOL>if '<STR_LIT>' in md:<EOL><INDENT>return md['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Return a list of subvolumes taken from LIMS, if available.

Arguments:
    token (str): The token to read from in LIMS

Returns:
    dict: or None if unavailable


def add_subvolume(self, token, channel, secret,<EOL>x_start, x_stop,<EOL>y_start, y_stop,<EOL>z_start, z_stop,<EOL>resolution, title, notes):

md = self.get_metadata(token)['<STR_LIT>']<EOL>if '<STR_LIT>' in md:<EOL><INDENT>subvols = md['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>subvols = []<EOL><DEDENT>subvols.append({<EOL>'<STR_LIT>': token,<EOL>'<STR_LIT>': channel,<EOL>'<STR_LIT>': x_start,<EOL>'<STR_LIT>': x_stop,<EOL>'<STR_LIT>': y_start,<EOL>'<STR_LIT>': y_stop,<EOL>'<STR_LIT>': z_start,<EOL>'<STR_LIT>': z_stop,<EOL>'<STR_LIT>': resolution,<EOL>'<STR_LIT:title>': title,<EOL>'<STR_LIT>': notes<EOL>})<EOL>return self.set_metadata(token, {<EOL>'<STR_LIT>': secret,<EOL>'<STR_LIT>': subvols<EOL>})<EOL>

Adds a new subvolume to a token/channel.

Arguments:
    token (str): The token to write to in LIMS
    channel (str): Channel to add in the subvolume. Can be `None`
    x_start (int): Start in x dimension
    x_stop (int): Stop in x dimension
    y_start (int): Start in y dimension
    y_stop (int): Stop in y dimension
    z_start (int): Start in z dimension
    z_stop (int): Stop in z dimension
    resolution (int): The resolution at which this subvolume is seen
    title (str): The title to set for the subvolume
    notes (str): Optional extra thoughts on the subvolume

Returns:
    boolean: success


super(grute, self).__init__(hostname, protocol)<EOL>self.email = email<EOL>

Initialize a new grute remote.

Arguments:
    hostname (str: "openconnecto.me"): The hostname where grute lives
    protocol (str: "http"): The protocol over which to access grute
    email (str: ""): The email to which completion notifications should
        be sent (unless overridden in individual calls). Note that the
        completion URLs are also accessible via this Python API.


return "<STR_LIT>".format(<EOL>self.hostname,<EOL>self.protocol,<EOL>self.email<EOL>)<EOL>

Returns a string representation that can be used to reproduce this
instance. `eval(repr(this))` should return an identical copy.

Arguments:
    None

Returns:
    str: Representation of reproducible instance.


return super(grute, self).ping()<EOL>


return super(grute, self).url('<STR_LIT>' + suffix)<EOL>

Construct a valid URL from the base grutedb url.

Arguments:
    suffix (str: ""): The suffix that should be appended to the base

Returns:
    str: Fully formed absolute URL


if "<STR_LIT:@>" not in email:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>self.email = email<EOL>

Sets the default email to use for notifications if none is specified.
Does only basic error-checking.

Arguments:
    email (str): The email to notify for all server graph services.

Returns:
    None

Raises:
    ValueError: If an invalid email is supplied.


def build_graph(self, project, site, subject, session, scan,<EOL>size, email=None, invariants=Invariants.ALL,<EOL>fiber_file=DEFAULT_FIBER_FILE, atlas_file=None,<EOL>use_threads=False, callback=None):

if email is None:<EOL><INDENT>email = self.email<EOL><DEDENT>if not set(invariants) <= set(Invariants.ALL):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if use_threads and callback is not None:<EOL><INDENT>if not hasattr(callback, '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(inspect.getargspec(callback).args) != <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if size not in [self.BIG, self.SMALL]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>url = "<STR_LIT>".format(<EOL>project,<EOL>site,<EOL>subject,<EOL>session,<EOL>scan,<EOL>size,<EOL>email,<EOL>"<STR_LIT:/>".join(invariants)<EOL>)<EOL>if "<STR_LIT:U+0020>" in url:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if use_threads:<EOL><INDENT>download_thread = threading.Thread(<EOL>target=self._run_build_graph,<EOL>args=[url, fiber_file, atlas_file, callback]<EOL>)<EOL>download_thread.start()<EOL><DEDENT>else:<EOL><INDENT>return self._run_build_graph(url, fiber_file, atlas_file)<EOL><DEDENT>return<EOL>

Builds a graph using the graph-services endpoint.

Arguments:
    project (str): The project to use
    site (str): The site in question
    subject (str): The subject's identifier
    session (str): The session (per subject)
    scan (str): The scan identifier
    size (str): Whether to return a big (grute.BIG) or small
        (grute.SMALL) graph. For a better explanation, see m2g.io.
    email (str : self.email)*: An email to notify
    invariants (str[]: Invariants.ALL)*: An array of invariants to
        compute. You can use the grute.Invariants class to construct a
        list, or simply pass grute.Invariants.ALL to compute them all.
    fiber_file (str: DEFAULT_FIBER_FILE)*: A local filename of an
        MRI Studio .dat file
    atlas_file (str: None)*: A local atlas file, in NIFTI .nii format.
        If none is specified, the Desikan atlas is used by default.
    use_threads (bool: False)*: Whether to run the download in a Python
        thread. If set to True, the call to `build_graph` will end
        quickly, and the `callback` will be called with the returned
        status-code of the restful call as its only argument.
    callback (function: None)*: The function to run upon completion of
        the call, if using threads. (Will not be called if use_threads
        is set to False.)

Returns:
    HTTP Response if use_threads is False. Otherwise, None

Raises:
    ValueError: When the supplied values are invalid (contain invalid
        characters, bad email address supplied, etc.)
    RemoteDataNotFoundError: When the data cannot be processed due to
        a server error.


def compute_invariants(self, graph_file, input_format,<EOL>invariants=Invariants.ALL, email=None,<EOL>use_threads=False, callback=None):

if email is None:<EOL><INDENT>email = self.email<EOL><DEDENT>if input_format not in GraphFormats._any:<EOL><INDENT>raise ValueError("<STR_LIT>".format(input_format))<EOL><DEDENT>if not set(invariants) <= set(Invariants.ALL):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if use_threads and callback is not None:<EOL><INDENT>if not hasattr(callback, '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(inspect.getargspec(callback).args) != <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>url = "<STR_LIT>".format(<EOL>email,<EOL>input_format,<EOL>"<STR_LIT:/>".join(invariants)<EOL>)<EOL>if "<STR_LIT:U+0020>" in url:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not (os.path.exists(graph_file)):<EOL><INDENT>raise ValueError("<STR_LIT>".format(graph_file))<EOL><DEDENT>if use_threads:<EOL><INDENT>upload_thread = threading.Thread(<EOL>target=self._run_compute_invariants,<EOL>args=[url, graph_file, callback]<EOL>)<EOL>upload_thread.start()<EOL><DEDENT>else:<EOL><INDENT>return self._run_compute_invariants(url, graph_file)<EOL><DEDENT>return<EOL>

Compute invariants from an existing GraphML file using the remote
grute graph services.

Arguments:
    graph_file (str): The filename of the graphml file
    input_format (str): One of grute.GraphFormats
    invariants (str[]: Invariants.ALL)*: An array of grute.Invariants
        to compute on the graph
    email (str: self.email)*: The email to notify upon completion
    use_threads (bool: False)*: Whether to use Python threads to run
        computation in the background when waiting for the server to
        return the invariants
    callback (function: None)*: The function to run upon completion of
        the call, if using threads. (Will not be called if use_threads
        is set to False.)

Returns:
    HTTP Response if use_threads is False. Otherwise, None

Raises:
    ValueError: If the graph file does not exist, or if there are
        issues with the passed arguments
    RemoteDataUploadError: If there is an issue packing the file
    RemoteError: If the server experiences difficulty computing invs


def convert_graph(self, graph_file, input_format, output_formats,<EOL>email=None, use_threads=False, callback=None):

if email is None:<EOL><INDENT>email = self.email<EOL><DEDENT>if input_format not in GraphFormats._any:<EOL><INDENT>raise ValueError("<STR_LIT>".format(input_format))<EOL><DEDENT>if not set(output_formats) <= set(GraphFormats._any):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if use_threads and callback is not None:<EOL><INDENT>if not hasattr(callback, '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(inspect.getargspec(callback).args) != <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if not (os.path.exists(graph_file)):<EOL><INDENT>raise ValueError("<STR_LIT>".format(graph_file))<EOL><DEDENT>url = "<STR_LIT>".format(<EOL>email,<EOL>input_format,<EOL>'<STR_LIT:U+002C>'.join(output_formats)<EOL>)<EOL>if "<STR_LIT:U+0020>" in url:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if use_threads:<EOL><INDENT>convert_thread = threading.Thread(<EOL>target=self._run_convert_graph,<EOL>args=[url, graph_file, callback]<EOL>)<EOL>convert_thread.start()<EOL><DEDENT>else:<EOL><INDENT>return self._run_convert_graph(url, graph_file)<EOL><DEDENT>return<EOL>

Convert a graph from one GraphFormat to another.

Arguments:
    graph_file (str): Filename of the file to convert
    input_format (str): A grute.GraphFormats
    output_formats (str[]): A grute.GraphFormats
    email (str: self.email)*: The email to notify
    use_threads (bool: False)*: Whether to use Python threads to run
        computation in the background when waiting for the server
    callback (function: None)*: The function to run upon completion of
        the call, if using threads. (Will not be called if use_threads
        is set to False.)

Returns:
    HTTP Response if use_threads=False. Else, no return value.

Raises:
    RemoteDataUploadError: If there's an issue uploading the data
    RemoteError: If there's a server-side issue
    ValueError: If there's a problem with the supplied arguments


import requests<EOL>r = requests.get('<STR_LIT>').json()<EOL>r = r['<STR_LIT:info>']['<STR_LIT:version>']<EOL>if r != version:<EOL><INDENT>print("<STR_LIT>" +<EOL>"<STR_LIT>")<EOL><DEDENT>return r<EOL>

Tells you if you have an old version of ndio.


self.segments = segments<EOL>RAMONBase.__init__(self,<EOL>id=id,<EOL>confidence=confidence,<EOL>kvpairs=kvpairs,<EOL>status=status,<EOL>author=author)<EOL>

Initialize a new `RAMONNeuron`. Neurons take all of the arguments of
`RAMONBase`.

Arguments:
    segments (int[]: None): A list of RAMON IDs that make up the neuron


self.msg = msg<EOL>


return self.msg<EOL>

String parser for the casted representation.


self.segmentclass = segmentclass<EOL>self.neuron = neuron<EOL>self.synapses = synapses<EOL>self.organelles = organelles<EOL>RAMONVolume.__init__(self,<EOL>xyz_offset=xyz_offset,<EOL>resolution=resolution,<EOL>cutout=cutout,<EOL>voxels=voxels,<EOL>id=id,<EOL>confidence=confidence,<EOL>kvpairs=kvpairs,<EOL>status=status,<EOL>author=author)<EOL>

Initialize a new `RAMONSegment`. Takes all arguments of `RAMONVolume`.

Arguments:
    segmentclass (int: 0): The type of segment this is. See the online
        ndstore documentation for more details.
    neuron (int: 0): The neuron that this segment belongs to.
    synapses (int[]: []): List of synapses that fall in this segment
    organelles (int[]: []): List of organelles that fall in this seg


enums = dict(list(zip(sequential, list(range(len(sequential))))), **named)<EOL>reverse = dict((value, key) for key, value in six.iteritems(enums))<EOL>enums['<STR_LIT>'] = reverse<EOL>return type('<STR_LIT>', (), enums)<EOL>

A helper function to make enums in Python 2.


return self.msg<EOL>

String representation of the InvalidEnumerationException


if type(ramons) is not list:<EOL><INDENT>ramons = [ramons]<EOL><DEDENT>out_ramons = {}<EOL>for r in ramons:<EOL><INDENT>out_ramons[r.id] = {<EOL>"<STR_LIT:id>": r.id,<EOL>"<STR_LIT:type>": _reverse_ramon_types[type(r)],<EOL>"<STR_LIT>": vars(r)<EOL>}<EOL><DEDENT>return out_ramons<EOL>

Converts a RAMON object list to a JSON-style dictionary. Useful for going
from an array of RAMONs to a dictionary, indexed by ID.

Arguments:
    ramons (RAMON[]): A list of RAMON objects
    flatten (boolean: False): Not implemented

Returns:
    dict: A python dictionary of RAMON objects.


if type(ramons) is not list:<EOL><INDENT>ramons = [ramons]<EOL><DEDENT>out_ramons = {}<EOL>for r in ramons:<EOL><INDENT>out_ramons[r.id] = {<EOL>"<STR_LIT:id>": r.id,<EOL>"<STR_LIT:type>": _reverse_ramon_types[type(r)],<EOL>"<STR_LIT>": vars(r)<EOL>}<EOL><DEDENT>if flatten:<EOL><INDENT>return jsonlib.dumps(out_ramons.values()[<NUM_LIT:0>])<EOL><DEDENT>return jsonlib.dumps(out_ramons)<EOL>

Converts RAMON objects into a JSON string which can be directly written out
to a .json file. You can pass either a single RAMON or a list. If you pass
a single RAMON, it will still be exported with the ID as the key. In other
words:

    type(from_json(to_json(ramon))) # ALWAYS returns a list

...even if `type(ramon)` is a RAMON, not a list.

Arguments:
    ramons (RAMON or list): The RAMON object(s) to convert to JSON.
    flatten (bool : False): If ID should be used as a key. If not, then
        a single JSON document is returned.

Returns:
    str: The JSON representation of the RAMON objects, in the schema:
        ```
        {
            <id>: {
                type: . . . ,
                metadata: {
                    . . .
                }
            },
        }
        ```

Raises:
    ValueError: If an invalid RAMON is passed.


if type(json) is str:<EOL><INDENT>json = jsonlib.loads(json)<EOL><DEDENT>out_ramons = []<EOL>for (rid, rdata) in six.iteritems(json):<EOL><INDENT>_md = rdata['<STR_LIT>']<EOL>r = AnnotationType.RAMON(rdata['<STR_LIT:type>'])(<EOL>id=rid,<EOL>author=_md['<STR_LIT>'],<EOL>status=_md['<STR_LIT:status>'],<EOL>confidence=_md['<STR_LIT>'],<EOL>kvpairs=copy.deepcopy(_md['<STR_LIT>'])<EOL>)<EOL>if rdata['<STR_LIT:type>'] == '<STR_LIT>':<EOL><INDENT>r.segmentclass = _md.get('<STR_LIT>')<EOL>r.neuron = _md.get('<STR_LIT>')<EOL>if '<STR_LIT>' in _md:<EOL><INDENT>r.synapses = _md['<STR_LIT>'][:]<EOL><DEDENT>if '<STR_LIT>' in _md:<EOL><INDENT>r.organelles = _md['<STR_LIT>'][:]<EOL><DEDENT><DEDENT>elif rdata['<STR_LIT:type>'] in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if '<STR_LIT>' in _md:<EOL><INDENT>r.segments = _md['<STR_LIT>'][:]<EOL><DEDENT><DEDENT>elif rdata['<STR_LIT:type>'] == '<STR_LIT>':<EOL><INDENT>r.organelle_class = _md['<STR_LIT>'][:]<EOL><DEDENT>elif rdata['<STR_LIT:type>'] == '<STR_LIT>':<EOL><INDENT>r.synapse_type = _md.get('<STR_LIT>')<EOL>r.weight = _md.get('<STR_LIT>')<EOL><DEDENT>out_ramons.append(r)<EOL><DEDENT>return out_ramons<EOL>

Converts JSON to a python list of RAMON objects. if `cutout` is provided,
the `cutout` attribute of the RAMON object is populated. Otherwise, it's
left empty. `json` should be an ID-level dictionary, like so:

    {
        16: {
            type: "segment",
            metadata: {
                . . .
            }
        },
    }

NOTE: If more than one item is in the dictionary, then a Python list of
RAMON objects is returned instead of a single RAMON.

Arguments:
    json (str or dict): The JSON to import to RAMON objects
    cutout: Currently not supported.

Returns:
    [RAMON]


if anno_id is None:<EOL><INDENT>return from_hdf5(hdf5, list(hdf5.keys())[<NUM_LIT:0>])<EOL><DEDENT>anno_id = str(anno_id)<EOL>if anno_id not in list(hdf5.keys()):<EOL><INDENT>raise ValueError("<STR_LIT>".format(<EOL>anno_id,<EOL>"<STR_LIT:U+002CU+0020>".join(list(hdf5.keys()))<EOL>))<EOL><DEDENT>anno = hdf5[anno_id]<EOL>try:<EOL><INDENT>r = AnnotationType.get_class(anno['<STR_LIT>'][<NUM_LIT:0>])()<EOL><DEDENT>except:<EOL><INDENT>raise InvalidRAMONError("<STR_LIT>")<EOL><DEDENT>metadata = anno['<STR_LIT>']<EOL>r.author = metadata['<STR_LIT>'][<NUM_LIT:0>]<EOL>r.confidence = metadata['<STR_LIT>'][<NUM_LIT:0>]<EOL>r.status = metadata['<STR_LIT>'][<NUM_LIT:0>]<EOL>r.id = anno_id<EOL>if type(r) in [RAMONNeuron, RAMONSynapse]:<EOL><INDENT>r.segments = metadata['<STR_LIT>'][()]<EOL><DEDENT>if '<STR_LIT>' in metadata:<EOL><INDENT>kvs = metadata['<STR_LIT>'][()][<NUM_LIT:0>].split()<EOL>if len(kvs) != <NUM_LIT:0>:<EOL><INDENT>for i in kvs:<EOL><INDENT>k, v = str(i).split('<STR_LIT:U+002C>')<EOL>r.kvpairs[str(k)] = str(v)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>r.kvpairs = {}<EOL><DEDENT><DEDENT>if issubclass(type(r), RAMONVolume):<EOL><INDENT>if '<STR_LIT>' in anno:<EOL><INDENT>r.cutout = anno['<STR_LIT>'][()]<EOL><DEDENT>if '<STR_LIT>' in anno:<EOL><INDENT>r.cutout = anno['<STR_LIT>'][()]<EOL><DEDENT>if '<STR_LIT>' in anno:<EOL><INDENT>r.cutout = anno['<STR_LIT>'][()]<EOL><DEDENT><DEDENT>if type(r) is RAMONSynapse:<EOL><INDENT>r.synapse_type = metadata['<STR_LIT>'][<NUM_LIT:0>]<EOL>r.weight = metadata['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>if type(r) is RAMONSegment:<EOL><INDENT>if '<STR_LIT>' in metadata:<EOL><INDENT>r.neuron = metadata['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>if '<STR_LIT>' in metadata:<EOL><INDENT>r.parent_seed = metadata['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>if '<STR_LIT>' in metadata:<EOL><INDENT>r.segmentclass = metadata['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>if '<STR_LIT>' in metadata:<EOL><INDENT>r.synapses = metadata['<STR_LIT>'][()]<EOL><DEDENT>if '<STR_LIT>' in metadata:<EOL><INDENT>r.organelles = metadata['<STR_LIT>'][()]<EOL><DEDENT><DEDENT>if type(r) is RAMONOrganelle:<EOL><INDENT>r.organelle_class = metadata['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>return r<EOL>

Converts an HDF5 file to a RAMON object. Returns an object that is a child-
-class of RAMON (though it's determined at run-time what type is returned).

Accessing multiple IDs from the same file is not supported, because it's
not dramatically faster to access each item in the hdf5 file at the same
time It's semantically and computationally easier to run this function
several times on the same file.

Arguments:
    hdf5 (h5py.File): A h5py File object that holds RAMON data
    anno_id (int): The ID of the RAMON obj to extract from the file. This
        defaults to the first one (sorted) if none is specified.

Returns:
    ndio.RAMON object


if issubclass(type(ramon), RAMONBase) is False:<EOL><INDENT>raise InvalidRAMONError("<STR_LIT>")<EOL><DEDENT>import h5py<EOL>import numpy<EOL>if hdf5 is None:<EOL><INDENT>tmpfile = tempfile.NamedTemporaryFile(delete=False)<EOL><DEDENT>else:<EOL><INDENT>tmpfile = hdf5<EOL><DEDENT>with h5py.File(tmpfile.name, "<STR_LIT:a>") as hdf5:<EOL><INDENT>grp = hdf5.create_group(str(ramon.id))<EOL>grp.create_dataset("<STR_LIT>", (<NUM_LIT:1>,),<EOL>numpy.uint32,<EOL>data=AnnotationType.get_int(type(ramon)))<EOL>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>if ramon.cutout is not None:<EOL><INDENT>grp.create_dataset('<STR_LIT>', ramon.cutout.shape,<EOL>ramon.cutout.dtype, data=ramon.cutout)<EOL>grp.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>numpy.uint32, data=ramon.resolution)<EOL>grp.create_dataset('<STR_LIT>', (<NUM_LIT:3>,),<EOL>numpy.uint32, data=ramon.xyz_offset)<EOL><DEDENT><DEDENT>metadata = grp.create_group('<STR_LIT>')<EOL>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>dtype=h5py.special_dtype(vlen=str),<EOL>data=ramon.author)<EOL>fstring = StringIO()<EOL>csvw = csv.writer(fstring, delimiter='<STR_LIT:U+002C>')<EOL>csvw.writerows([r for r in six.iteritems(ramon.kvpairs)])<EOL>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>dtype=h5py.special_dtype(vlen=str),<EOL>data=fstring.getvalue())<EOL>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,), numpy.float,<EOL>data=ramon.confidence)<EOL>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,), numpy.uint32,<EOL>data=ramon.status)<EOL>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>',<EOL>data=numpy.asarray(ramon.segments,<EOL>dtype=numpy.uint32))<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,), numpy.uint32,<EOL>data=ramon.synapse_type)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>numpy.float, data=ramon.weight)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>numpy.uint32, data=ramon.neuron)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,), numpy.uint32,<EOL>data=ramon.segmentclass)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (len(ramon.synapses),),<EOL>numpy.uint32, data=ramon.synapses)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>',<EOL>(len(ramon.organelles),),<EOL>numpy.uint32,<EOL>data=ramon.organelles)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>numpy.uint32,<EOL>data=ramon.organelle_class)<EOL><DEDENT>hdf5.flush()<EOL>tmpfile.seek(<NUM_LIT:0>)<EOL>return tmpfile<EOL><DEDENT>return False<EOL>

Exports a RAMON object to an HDF5 file object.

Arguments:
    ramon (RAMON): A subclass of RAMONBase
    hdf5 (str): Export filename

Returns:
    hdf5.File

Raises:
    InvalidRAMONError: if you pass a non-RAMON object


return _reverse_types[typ]<EOL>

From an integer, gets the string representation of a RAMON type.

Arguments:
    typ (int): The type as an integer

Returns:
    str: The type as a string


return _ramon_types[typ]<EOL>

From an integer, gets the ndio class of a RAMON type.

Arguments:
    typ (int): The type as an integer

Returns:
    type: The type of RAMON object


return _reverse_ramon_types[typ]<EOL>

From a string, gets the integer representation of a RAMON type.

Arguments:
    typ (str): The type as an string

Returns:
    int: The type as a integer


if six.PY2:<EOL><INDENT>lookup = [str, unicode]<EOL><DEDENT>elif six.PY3:<EOL><INDENT>lookup = [str]<EOL><DEDENT>if type(typ) is int:<EOL><INDENT>return _ramon_types[typ]<EOL><DEDENT>elif type(typ) in lookup:<EOL><INDENT>return _ramon_types[_types[typ]]<EOL><DEDENT>


self.synapse_type = synapse_type<EOL>self.weight = weight<EOL>self.segments = segments<EOL>RAMONVolume.__init__(self,<EOL>xyz_offset=xyz_offset,<EOL>resolution=resolution,<EOL>cutout=cutout,<EOL>voxels=voxels,<EOL>id=id,<EOL>confidence=confidence,<EOL>kvpairs=kvpairs,<EOL>status=status,<EOL>author=author)<EOL>

Initialize a new `RAMONSynapse` object. Takes all arguments of the
`RAMONVolume` parent class.

Arguments:
    synapse_type (int: 0): The synapse type. See the online ndstore
        documentation for more details.
    weight (int: 0): The weight of this synapse (arbitrarily defined)
    segments (int[]: None): A list of segments that belong to this obj


self.xyz_offset = xyz_offset<EOL>self.resolution = resolution<EOL>self.cutout = cutout<EOL>self.voxels = voxels<EOL>RAMONBase.__init__(self, id=id, confidence=confidence,<EOL>kvpairs=kvpairs,<EOL>status=status, author=author)<EOL>

Initialize a new RAMONVolume object. Inherits attributes from RAMONBase
as well as:

Arguments:
    xyz_offset (int[3] : (0, 0, 0)): x,y,z coordinates of the minimum
        corner of the cube (if data is a cutout), otherwise empty
    resolution (int : 0): level in the database resolution hierarchy
    cutout (numpy.ndarray): dense matrix of data
    voxels: Unused for now


if self.cutout:<EOL><INDENT>return self.cutout<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT>

Gets the data from the volume and pumps it into a numpy.ndarray format,
regardless of whether it's stored in `cutout` or `voxels`. Returns it
as though it were stored in `cutout`.

This is useful for cases where you need to operate on a 3D matrix.

Arguments:
    None

Returns:
    numpy.ndarray


self.id = id<EOL>self.confidence = confidence<EOL>self.kvpairs = kvpairs<EOL>self.status = status<EOL>self.author = author<EOL>

Initialize a new RAMONBase object with default attributes.

Arguments:
    id (int): Unique 32-bit ID value assigned by OCP database
    confidence (float): Value 0-1 indicating confidence in annotation
    kvpairs (dict): A collection of key-value pairs
    status (string): Status of annotation in database
    author (string): Username of the person who created the annotation


return "<STR_LIT>".format(type(self), self.id)<EOL>

String representation of a RAMON object for convenience.


Initialize a new `RAMONOrganelle`. Organelles take all of the arguments
of their parent `RAMONVolume` class.

Arguments:
    organelle_class (int: 0): The organelle class to which this object
        belongs. For more details, see the online ndstore documentation


Initialize a new `RAMONVolume`.

Arguments:
    xyz_offset (int[3]: (0, 0, 0)): The offset at which a RAMON object
        is located.
    resolution (int: 0): The native resolution of the RAMON objec
    cutout (numpy.ndarray: None): The dense representation of volume
    voxels (iterable: None): The sparse representation of volume

> `RAMONGeneric` also takes all of the arguments of `RAMONVolume`.


if type(array) is not numpy.ndarray:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return numpy.argwhere(array)<EOL>

Converts an array to its voxel list.

Arguments:
    array (numpy.ndarray): A numpy nd array. This must be boolean!

Returns:
    A list of n-tuples


dimensions = len(voxels[<NUM_LIT:0>])<EOL>for d in range(len(dimensions)):<EOL><INDENT>size.append(max([i[d] for i in voxels]))<EOL><DEDENT>result = numpy.zeros(dimensions)<EOL>for v in voxels:<EOL><INDENT>result[v] = <NUM_LIT:1><EOL><DEDENT>return result<EOL>

Converts a voxel list to an ndarray.

Arguments:
    voxels (tuple[]): A list of coordinates indicating coordinates of
        populated voxels in an ndarray.

Returns:
    numpy.ndarray The result of the transformation.


raise ValueError("<STR_LIT>" +<EOL>"<STR_LIT>".format(i, o))<EOL>

Helper-function to print failure and pass back False.


if fmt in FILE_FORMATS:<EOL><INDENT>return FILE_FORMATS[fmt][<NUM_LIT:0>]<EOL><DEDENT>return False<EOL>

Get the appropriate file extension for a given format.

Arguments:
    fmt:        The format to find an extension for

Returns:
    String. The format (without leading period),
            or False if none was found.


ext = ext.strip('<STR_LIT:.>')<EOL>formats = []<EOL>for fmt in FILE_FORMATS:<EOL><INDENT>if ext in FILE_FORMATS[fmt]:<EOL><INDENT>formats.append(fmt)<EOL><DEDENT><DEDENT>if formats == [] or len(formats) > <NUM_LIT:1>:<EOL><INDENT>return False<EOL><DEDENT>return formats[<NUM_LIT:0>]<EOL>

Guess the appropriate data type from file extension.

Arguments:
    ext:        The file extension (period optional)

Returns:
    String. The format (without leading period),
            or False if none was found or couldn't be guessed


fmt = in_file.split('<STR_LIT:.>')[-<NUM_LIT:1>]<EOL>if in_fmt:<EOL><INDENT>fmt = in_fmt<EOL><DEDENT>fmt = fmt.lower()<EOL>if fmt in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>return Image.open(in_file)<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>".format(fmt))<EOL><DEDENT>

Reads in a file from disk.

Arguments:
    in_file: The name of the file to read in
    in_fmt: The format of in_file, if you want to be explicit

Returns:
    numpy.ndarray


def convert(in_file, out_file, in_fmt="<STR_LIT>", out_fmt="<STR_LIT>"):

<EOL>in_file = os.path.expanduser(in_file)<EOL>out_file = os.path.expanduser(out_file)<EOL>if not os.path.exists(in_file):<EOL><INDENT>raise IOError("<STR_LIT>"<EOL>.format(in_file))<EOL><DEDENT>in_fmt = in_fmt.lower() or _guess_format_from_extension(<EOL>in_file.split('<STR_LIT:.>')[-<NUM_LIT:1>].lower())<EOL>out_fmt = out_fmt.lower() or _guess_format_from_extension(<EOL>out_file.split('<STR_LIT:.>')[-<NUM_LIT:1>].lower())<EOL>if not in_fmt or not out_fmt:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL>return False<EOL><DEDENT>if in_fmt is out_fmt:<EOL><INDENT>shutil.copyfileobj(in_file, out_file)<EOL>return out_file<EOL><DEDENT>if in_fmt == '<STR_LIT>':<EOL><INDENT>from . import hdf5<EOL>data = hdf5.load(in_file)<EOL><DEDENT>elif in_fmt == '<STR_LIT>':<EOL><INDENT>from . import tiff<EOL>data = tiff.load(in_file)<EOL><DEDENT>elif in_fmt == '<STR_LIT>':<EOL><INDENT>from . import png<EOL>data = png.load(in_file)<EOL><DEDENT>else:<EOL><INDENT>return _fail_pair_conversion(in_fmt, out_fmt)<EOL><DEDENT>if out_fmt == '<STR_LIT>':<EOL><INDENT>from . import hdf5<EOL>return hdf5.save(out_file, data)<EOL><DEDENT>elif out_fmt == '<STR_LIT>':<EOL><INDENT>from . import tiff<EOL>return tiff.save(out_file, data)<EOL><DEDENT>elif out_fmt == '<STR_LIT>':<EOL><INDENT>from . import png<EOL>return png.export_png(out_file, data)<EOL><DEDENT>else:<EOL><INDENT>return _fail_pair_conversion(in_fmt, out_fmt)<EOL><DEDENT>return _fail_pair_conversion(in_fmt, out_fmt)<EOL>

Converts in_file to out_file, guessing datatype in the absence of
in_fmt and out_fmt.

Arguments:
    in_file:    The name of the (existing) datafile to read
    out_file:   The name of the file to create with converted data
    in_fmt:     Optional. The format of incoming data, if not guessable
    out_fmt:    Optional. The format of outgoing data, if not guessable

Returns:
    String. Output filename


<EOL>nifti_filename = os.path.expanduser(nifti_filename)<EOL>try:<EOL><INDENT>data = nib.load(nifti_filename)<EOL>img = data.get_data()<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>.format(nifti_filename))<EOL>raise<EOL><DEDENT>return img<EOL>

Import a nifti file into a numpy array. TODO:  Currently only
transfers raw data for compatibility with annotation and ND formats

Arguments:
    nifti_filename (str):  A string filename of a nifti datafile

Returns:
    A numpy array with data from the nifti file


<EOL>nifti_filename = os.path.expanduser(nifti_filename)<EOL>try:<EOL><INDENT>nifti_img = nib.Nifti1Image(numpy_data, numpy.eye(<NUM_LIT:4>))<EOL>nib.save(nifti_img, nifti_filename)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>".format(nifti_filename))<EOL><DEDENT>return nifti_filename<EOL>

Export a numpy array to a nifti file.  TODO: currently using dummy
headers and identity matrix affine transform. This can be expanded.

Arguments:
    nifti_filename (str): A filename to which to save the nifti data
    numpy_data (numpy.ndarray): The numpy array to save to nifti

Returns:
    String. The expanded filename that now holds the nifti data


<EOL>hdf5_filename = os.path.expanduser(hdf5_filename)<EOL>try:<EOL><INDENT>f = h5py.File(hdf5_filename, "<STR_LIT:r>")<EOL>data_layers = f.get('<STR_LIT:image>').get('<STR_LIT>')<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>".format(<EOL>hdf5_filename, e))<EOL>raise<EOL><DEDENT>return numpy.array(data_layers)<EOL>

Import a HDF5 file into a numpy array.

Arguments:
    hdf5_filename:  A string filename of a HDF5 datafile

Returns:
    A numpy array with data from the HDF5 file


<EOL>hdf5_filename = os.path.expanduser(hdf5_filename)<EOL>try:<EOL><INDENT>h = h5py.File(hdf5_filename, "<STR_LIT:w>")<EOL>h.create_dataset('<STR_LIT>', data=array)<EOL>h.close()<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>".format(hdf5_filename))<EOL><DEDENT>return hdf5_filename<EOL>

Export a numpy array to a HDF5 file.

Arguments:
    hdf5_filename (str): A filename to which to save the HDF5 data
    array (numpy.ndarray): The numpy array to save to HDF5

Returns:
    String. The expanded filename that now holds the HDF5 data


<EOL>png_filename = os.path.expanduser(png_filename)<EOL>try:<EOL><INDENT>img = Image.open(png_filename)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>.format(png_filename))<EOL>raise<EOL><DEDENT>return numpy.array(img)<EOL>

Import a png file into a numpy array.

Arguments:
    png_filename (str): A string filename of a png datafile

Returns:
    A numpy array with data from the png file


<EOL>png_filename = os.path.expanduser(filename)<EOL>if type(numpy_data) is str:<EOL><INDENT>fp = open(png_filename, "<STR_LIT:wb>")<EOL>fp.write(numpy_data)<EOL>fp.close()<EOL>return png_filename<EOL><DEDENT>try:<EOL><INDENT>if numpy_data.dtype.name != '<STR_LIT>':<EOL><INDENT>m = '<STR_LIT:I>'<EOL>img = Image.fromarray(numpy_data, mode=m)<EOL><DEDENT>else:<EOL><INDENT>img = Image.fromarray(numpy_data)<EOL><DEDENT>img.save(png_filename)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>".format(png_filename))<EOL><DEDENT>return png_filename<EOL>

Export a numpy array to a png file.

Arguments:
    filename (str): A filename to which to save the png data
    numpy_data (numpy.ndarray OR str): The numpy array to save to png.
        OR a string: If a string is provded, it should be a binary png str

Returns:
    str. The expanded filename that now holds the png data

Raises:
    ValueError: If the save fails; for instance if the binary string data
        cannot be coerced into a png, or perhaps your numpy.ndarray is
        ill-formed?


def save_collection(png_filename_base, numpy_data, start_layers_at=<NUM_LIT:1>):

file_ext = png_filename_base.split('<STR_LIT:.>')[-<NUM_LIT:1>]<EOL>if file_ext in ['<STR_LIT>']:<EOL><INDENT>file_base = '<STR_LIT:.>'.join(png_filename_base.split('<STR_LIT:.>')[:-<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>file_base = png_filename_base<EOL>file_ext = "<STR_LIT>"<EOL><DEDENT>file_base_array = file_base.split('<STR_LIT:*>')<EOL>output_files = []<EOL>i = start_layers_at<EOL>for layer in numpy_data:<EOL><INDENT>layer_filename = (str(i).zfill(<NUM_LIT:6>)).join(file_base_array) + file_ext<EOL>output_files.append(save(layer_filename, layer))<EOL>i += <NUM_LIT:1><EOL><DEDENT>return output_files<EOL>

Export a numpy array to a set of png files, with each Z-index 2D
array as its own 2D file.

Arguments:
    png_filename_base:     A filename template, such as "my-image-*.png"
                            which will lead to a collection of files named
                            "my-image-0.png", "my-image-1.png", etc.
    numpy_data:             The numpy array data to save to png.

Returns:
    Array. A list of expanded filenames that hold png data.


<EOL>files = glob.glob(png_filename_base)<EOL>files.sort()<EOL>numpy_data = []<EOL>for f in files:<EOL><INDENT>numpy_data.append(load(f))<EOL><DEDENT>return numpy.concatenate(numpy_data)<EOL>

Import all files matching the filename base given with `png_filename_base`.
Images are ordered by alphabetical order, which means that you *MUST* 0-pad
your numbers if they span a power of ten (e.g. 0999-1000 or 09-10). This is
handled automatically by its complementary function, `png.save_collection`.
Also, look at how nicely these documentation lines are all the same length!

Arguments:
    png_filename_base (str): An asterisk-wildcard string that should refer
        to all PNGs in the stack. All *s are replaced according to regular
        cmd-line expansion rules. See the 'glob' documentation for details
Returns:
    A numpy array holding a 3D dataset


try:<EOL><INDENT>numpy_data = blosc.unpack_array(data)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>".format(e))<EOL><DEDENT>return numpy_data<EOL>

Import a blosc array into a numpy array.

Arguments:
    data: A blosc packed numpy array

Returns:
    A numpy array with data from a blosc compressed array


try:<EOL><INDENT>raw_data = blosc.pack_array(array)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>".format(e))<EOL><DEDENT>return raw_data<EOL>

Export a numpy array to a blosc array.

Arguments:
    array: The numpy array to compress to blosc array

Returns:
    Bytes/String. A blosc compressed array


<EOL>tiff_filename = os.path.expanduser(tiff_filename)<EOL>try:<EOL><INDENT>img = tiff.imread(tiff_filename)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>.format(tiff_filename))<EOL>raise<EOL><DEDENT>return numpy.array(img)<EOL>

Import a TIFF file into a numpy array.

Arguments:
    tiff_filename:  A string filename of a TIFF datafile

Returns:
    A numpy array with data from the TIFF file


<EOL>tiff_filename = os.path.expanduser(tiff_filename)<EOL>if type(numpy_data) is str:<EOL><INDENT>fp = open(png_filename, "<STR_LIT:wb>")<EOL>fp.write(numpy_data)<EOL>fp.close()<EOL>return png_filename<EOL><DEDENT>try:<EOL><INDENT>img = tiff.imsave(tiff_filename, numpy_data)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError("<STR_LIT>".format(tiff_filename))<EOL><DEDENT>return tiff_filename<EOL>

Export a numpy array to a TIFF file.

Arguments:
    tiff_filename:  A filename to which to save the TIFF data
    numpy_data:     The numpy array to save to TIFF

Returns:
    String. The expanded filename that now holds the TIFF data


def save_collection(tiff_filename_base, numpy_data, start_layers_at=<NUM_LIT:1>):

file_ext = tiff_filename_base.split('<STR_LIT:.>')[-<NUM_LIT:1>]<EOL>if file_ext in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>file_base = '<STR_LIT:.>'.join(tiff_filename_base.split('<STR_LIT:.>')[:-<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>file_base = tiff_filename_base<EOL>file_ext = "<STR_LIT>"<EOL><DEDENT>file_base_array = file_base.split('<STR_LIT:*>')<EOL>output_files = []<EOL>i = start_layers_at<EOL>for layer in numpy_data:<EOL><INDENT>layer_filename = (str(i).zfill(<NUM_LIT:6>)).join(file_base_array) + file_ext<EOL>output_files.append(save(layer_filename, layer))<EOL>i += <NUM_LIT:1><EOL><DEDENT>return output_files<EOL>

Export a numpy array to a set of TIFF files, with each Z-index 2D
array as its own 2D file.

Arguments:
    tiff_filename_base:     A filename template, such as "my-image-*.tiff"
                            which will lead to a collection of files named
                            "my-image-0.tiff", "my-image-1.tiff", etc.
    numpy_data:             The numpy array data to save to TIFF.

Returns:
    Array. A list of expanded filenames that hold TIFF data.


if not os.path.isfile(tiff_filename):<EOL><INDENT>raise RuntimeError('<STR_LIT>' % tiff_filename)<EOL><DEDENT>data = tiff.imread(tiff_filename)<EOL>im = []<EOL>while True:<EOL><INDENT>Xi = numpy.array(data, dtype=dtype)<EOL>if Xi.ndim == <NUM_LIT:2>:<EOL><INDENT>Xi = Xi[numpy.newaxis, ...]  <EOL><DEDENT>im.append(Xi)<EOL>try:<EOL><INDENT>data.seek(data.tell()+<NUM_LIT:1>)<EOL><DEDENT>except EOFError:<EOL><INDENT>break  <EOL><DEDENT><DEDENT>im = numpy.concatenate(im, axis=<NUM_LIT:0>)  <EOL>im = numpy.rollaxis(im, <NUM_LIT:1>)<EOL>im = numpy.rollaxis(im, <NUM_LIT:2>)<EOL>return im<EOL>

Load a multipage tiff into a single variable in x,y,z format.

Arguments:
    tiff_filename:     Filename of source data
    dtype:             data type to use for the returned tensor

Returns:
    Array containing contents from input tiff file in xyz order


<EOL>files = glob.glob(tiff_filename_base)<EOL>files.sort()<EOL>numpy_data = []<EOL>for f in files:<EOL><INDENT>numpy_data.append(load(f))<EOL><DEDENT>return numpy.concatenate(numpy_data)<EOL>

Import all files matching the filename base given via `tiff_filename_base`.
Images are ordered by alphabetical order, which means that you *MUST* 0-pad
your numbers if they span a power of ten (e.g. 0999-1000 or 09-10). This is
handled automatically by the complement function, `save_collection`.
Also, look at how nicely these documentation lines are all the same length!

Arguments:
    tiff_filename_base:     An asterisk-wildcard string that should refer
                            to all TIFFs in the stack. All * are replaced
                            according to command-line expansion rules.

Returns:
    A numpy array holding a 3D dataset


d={'<STR_LIT>':frame}         <EOL>d.update(frame.f_globals)  <EOL>d.update(frame.f_locals)<EOL>i = code.InteractiveConsole(d)<EOL>message  = "<STR_LIT>"<EOL>message += '<STR_LIT>'.join(traceback.format_stack(frame))<EOL>i.interact(message)<EOL>

Interrupt running process, and provide a python prompt for
    interactive debugging.

    source: http://stackoverflow.com/questions/132058/showing-the-stack-trace-from-a-running-python-application


def render_template(template_file, dst_file, **kwargs):

with open(template_file) as f:<EOL><INDENT>template_text = f.read()<EOL><DEDENT>dst_text = template_text<EOL>for key, value in kwargs.iteritems():<EOL><INDENT>dst_text = dst_text .replace("<STR_LIT>" + key + "<STR_LIT>", value)<EOL><DEDENT>with open(dst_file, "<STR_LIT>") as f:<EOL><INDENT>f.write(dst_text)<EOL><DEDENT>

Copy template and substitute template strings

    File `template_file` is copied to `dst_file`. Then, each template variable
    is replaced by a value. Template variables are of the form

        {{val}}

    Example:

    Contents of template_file:

        VAR1={{val1}}
        VAR2={{val2}}
        VAR3={{val3}}

    render_template(template_file, output_file, val1="hello", val2="world")

    Contents of output_file:

        VAR1=hello
        VAR2=world
        VAR3={{val3}}

    :param template_file: Path to the template file.
    :param dst_file: Path to the destination file.
    :param kwargs: Keys correspond to template variables.
    :return:


def add_task(self, func, *args, **kargs):

self.tasks.put((func, args, kargs))<EOL>


Run this function inside a different thread.

    :param transport: transport handler. We need to pass it in since any
        assertion we do inside this thread gets silently swallowed, so we
        need a way to return the results to the main thread.
    :type transport: MockTransportHandler


<EOL>self.start_timestamp = time.time()<EOL>return self<EOL>

Actions to be taken before request is handled.


Actions to be taken post request handling.


Main function to log all the annotations stored during the entire
        request. This is done if the request is sampled and the response was
        a success. It also logs the service (`ss` and `sr`) or the client
        ('cs' and 'cr') annotations.


return '<STR_LIT>'.format(random.getrandbits(<NUM_LIT:64>))<EOL>

Returns a 64 bit UTF-8 encoded string. In the interests of simplicity,
    this is always cast to a `str` instead of (in py2 land) a unicode string.
    Certain clients (I'm looking at you, Twisted) don't enjoy unicode headers.

    :returns: random 16-character string


t = int(time.time())<EOL>lower_96 = random.getrandbits(<NUM_LIT>)<EOL>return '<STR_LIT>'.format((t << <NUM_LIT>) | lower_96)<EOL>

Returns a 128 bit UTF-8 encoded string. Follows the same conventions
    as generate_random_64bit_string().

    The upper 32 bits are the current time in epoch seconds, and the
    lower 96 bits are random. This allows for AWS X-Ray `interop
    <https://github.com/openzipkin/zipkin/issues/1754>`_

    :returns: 32-character hex string


return struct.unpack('<STR_LIT:q>', struct.pack('<STR_LIT>', int(hex_string, <NUM_LIT:16>)))[<NUM_LIT:0>]<EOL>

Converts a 64-bit hex string to a signed int value.

    This is due to the fact that Apache Thrift only has signed values.

    Examples:
        '17133d482ba4f605' => 1662740067609015813
        'b6dbb1c2b362bf51' => -5270423489115668655

    :param hex_string: the string representation of a zipkin ID
    :returns: signed int representation


hex_string = hex(struct.unpack('<STR_LIT>', struct.pack('<STR_LIT:q>', signed_int))[<NUM_LIT:0>])[<NUM_LIT:2>:]<EOL>if hex_string.endswith('<STR_LIT:L>'):<EOL><INDENT>return hex_string[:-<NUM_LIT:1>]<EOL><DEDENT>return hex_string<EOL>

Converts a signed int value to a 64-bit hex string.

    Examples:
        1662740067609015813  => '17133d482ba4f605'
        -5270423489115668655 => 'b6dbb1c2b362bf51'

    :param signed_int: an int to convert
    :returns: unsigned hex string


log.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>return get_default_tracer()._context_stack._storage<EOL>

A wrapper to return _thread_local.zipkin_attrs

    Returns a list of ZipkinAttrs objects, used for intra-process context
    propagation.

    .. deprecated::
       Use the Tracer interface which offers better multi-threading support.
       get_thread_local_zipkin_attrs will be removed in version 1.0.

    :returns: list that may contain zipkin attribute tuples
    :rtype: list


log.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>return get_default_tracer()._span_storage<EOL>

A wrapper to return _thread_local.span_storage

    Returns a SpanStorage object used to temporarily store all spans created in
    the current process. The transport handlers will pull from this storage when
    they emit the spans.

    .. deprecated::
       Use the Tracer interface which offers better multi-threading support.
       get_thread_local_span_storage will be removed in version 1.0.

    :returns: SpanStore object containing all non-root spans.
    :rtype: py_zipkin.storage.SpanStore


from py_zipkin.storage import ThreadLocalStack<EOL>log.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>return ThreadLocalStack().get()<EOL>

Get the topmost level zipkin attributes stored.

    .. deprecated::
       Use the Tracer interface which offers better multi-threading support.
       get_zipkin_attrs will be removed in version 1.0.

    :returns: tuple containing zipkin attrs
    :rtype: :class:`zipkin.ZipkinAttrs`


from py_zipkin.storage import ThreadLocalStack<EOL>log.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>return ThreadLocalStack().pop()<EOL>

Pop the topmost level zipkin attributes, if present.

    .. deprecated::
       Use the Tracer interface which offers better multi-threading support.
       pop_zipkin_attrs will be removed in version 1.0.

    :returns: tuple containing zipkin attrs
    :rtype: :class:`zipkin.ZipkinAttrs`


from py_zipkin.storage import ThreadLocalStack<EOL>log.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>return ThreadLocalStack().push(zipkin_attr)<EOL>

Stores the zipkin attributes to thread local.

    .. deprecated::
       Use the Tracer interface which offers better multi-threading support.
       push_zipkin_attrs will be removed in version 1.0.

    :param zipkin_attr: tuple containing zipkin related attrs
    :type zipkin_attr: :class:`zipkin.ZipkinAttrs`


<EOL>if trace_id is None:<EOL><INDENT>if use_128bit_trace_id:<EOL><INDENT>trace_id = generate_random_128bit_string()<EOL><DEDENT>else:<EOL><INDENT>trace_id = generate_random_64bit_string()<EOL><DEDENT><DEDENT>if span_id is None:<EOL><INDENT>span_id = generate_random_64bit_string()<EOL><DEDENT>if sample_rate == <NUM_LIT:0.0>:<EOL><INDENT>is_sampled = False<EOL><DEDENT>else:<EOL><INDENT>is_sampled = (random.random() * <NUM_LIT:100>) < sample_rate<EOL><DEDENT>return ZipkinAttrs(<EOL>trace_id=trace_id,<EOL>span_id=span_id,<EOL>parent_span_id=None,<EOL>flags='<STR_LIT:0>',<EOL>is_sampled=is_sampled,<EOL>)<EOL>

Creates a set of zipkin attributes for a span.

    :param sample_rate: Float between 0.0 and 100.0 to determine sampling rate
    :type sample_rate: float
    :param trace_id: Optional 16-character hex string representing a trace_id.
                    If this is None, a random trace_id will be generated.
    :type trace_id: str
    :param span_id: Optional 16-character hex string representing a span_id.
                    If this is None, a random span_id will be generated.
    :type span_id: str
    :param use_128bit_trace_id: If true, generate 128-bit trace_ids
    :type use_128bit_trace_id: boolean


if tracer:<EOL><INDENT>zipkin_attrs = tracer.get_zipkin_attrs()<EOL><DEDENT>elif context_stack:<EOL><INDENT>zipkin_attrs = context_stack.get()<EOL><DEDENT>else:<EOL><INDENT>zipkin_attrs = get_default_tracer().get_zipkin_attrs()<EOL><DEDENT>if not zipkin_attrs:<EOL><INDENT>return {}<EOL><DEDENT>return {<EOL>'<STR_LIT>': zipkin_attrs.trace_id,<EOL>'<STR_LIT>': generate_random_64bit_string(),<EOL>'<STR_LIT>': zipkin_attrs.span_id,<EOL>'<STR_LIT>': '<STR_LIT:0>',<EOL>'<STR_LIT>': '<STR_LIT:1>' if zipkin_attrs.is_sampled else '<STR_LIT:0>',<EOL>}<EOL>

Generate the headers for a new zipkin span.

.. note::

    If the method is not called from within a zipkin_trace context,
    empty dict will be returned back.

:returns: dict containing (X-B3-TraceId, X-B3-SpanId, X-B3-ParentSpanId,
            X-B3-Flags and X-B3-Sampled) keys OR an empty dict.


self.service_name = service_name<EOL>self.span_name = span_name<EOL>self.zipkin_attrs_override = zipkin_attrs<EOL>self.transport_handler = transport_handler<EOL>self.max_span_batch_size = max_span_batch_size<EOL>self.annotations = annotations or {}<EOL>self.binary_annotations = binary_annotations or {}<EOL>self.port = port<EOL>self.sample_rate = sample_rate<EOL>self.add_logging_annotation = add_logging_annotation<EOL>self.report_root_timestamp_override = report_root_timestamp<EOL>self.use_128bit_trace_id = use_128bit_trace_id<EOL>self.host = host<EOL>self._context_stack = context_stack<EOL>self._span_storage = span_storage<EOL>self.firehose_handler = firehose_handler<EOL>self.kind = self._generate_kind(kind, include)<EOL>self.timestamp = timestamp<EOL>self.duration = duration<EOL>self.encoding = encoding<EOL>self._tracer = _tracer<EOL>self._is_local_root_span = False<EOL>self.logging_context = None<EOL>self.do_pop_attrs = False<EOL>self.remote_endpoint = None<EOL>self.zipkin_attrs = None<EOL>if '<STR_LIT>' in self.annotations and '<STR_LIT>' in self.annotations:<EOL><INDENT>self.duration = self.annotations['<STR_LIT>'] - self.annotations['<STR_LIT>']<EOL>self.timestamp = self.annotations['<STR_LIT>']<EOL>log.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if '<STR_LIT>' in self.annotations and '<STR_LIT>' in self.annotations:<EOL><INDENT>self.duration = self.annotations['<STR_LIT>'] - self.annotations['<STR_LIT>']<EOL>self.timestamp = self.annotations['<STR_LIT>']<EOL>log.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if self.zipkin_attrs_override or self.sample_rate is not None:<EOL><INDENT>if self.transport_handler is None:<EOL><INDENT>raise ZipkinError(<EOL>'<STR_LIT>')<EOL><DEDENT>self._is_local_root_span = True<EOL><DEDENT>if self.firehose_handler:<EOL><INDENT>self._is_local_root_span = True<EOL><DEDENT>if self.sample_rate is not None and not (<NUM_LIT:0.0> <= self.sample_rate <= <NUM_LIT>):<EOL><INDENT>raise ZipkinError('<STR_LIT>')<EOL><DEDENT>if self._span_storage is not None andnot isinstance(self._span_storage, storage.SpanStorage):<EOL><INDENT>raise ZipkinError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if self._span_storage is not None:<EOL><INDENT>log.warning('<STR_LIT>')<EOL>self.get_tracer()._span_storage = self._span_storage<EOL><DEDENT>if self._context_stack is not None:<EOL><INDENT>log.warning('<STR_LIT>')<EOL>self.get_tracer()._context_stack = self._context_stack<EOL><DEDENT>

Logs a zipkin span. If this is the root span, then a zipkin
        trace is started as well.

        :param service_name: The name of the called service
        :type service_name: string
        :param span_name: Optional name of span, defaults to 'span'
        :type span_name: string
        :param zipkin_attrs: Optional set of zipkin attributes to be used
        :type zipkin_attrs: ZipkinAttrs
        :param transport_handler: Callback function that takes a message parameter
            and handles logging it
        :type transport_handler: BaseTransportHandler
        :param max_span_batch_size: Spans in a trace are sent in batches,
            max_span_batch_size defines max size of one batch
        :type max_span_batch_size: int
        :param annotations: Optional dict of str -> timestamp annotations
        :type annotations: dict of str -> int
        :param binary_annotations: Optional dict of str -> str span attrs
        :type binary_annotations: dict of str -> str
        :param port: The port number of the service. Defaults to 0.
        :type port: int
        :param sample_rate: Rate at which to sample; 0.0 - 100.0. If passed-in
            zipkin_attrs have is_sampled=False and the sample_rate param is > 0,
            a new span will be generated at this rate. This means that if you
            propagate sampling decisions to downstream services, but still have
            sample_rate > 0 in those services, the actual rate of generated
            spans for those services will be > sampling_rate.
        :type sample_rate: float
        :param include: which annotations to include
            can be one of {'client', 'server'}
            corresponding to ('cs', 'cr') and ('ss', 'sr') respectively.
            DEPRECATED: use kind instead. `include` will be removed in 1.0.
        :type include: iterable
        :param add_logging_annotation: Whether to add a 'logging_end'
            annotation when py_zipkin finishes logging spans
        :type add_logging_annotation: boolean
        :param report_root_timestamp: Whether the span should report timestamp
            and duration. Only applies to "root" spans in this local context,
            so spans created inside other span contexts will always log
            timestamp/duration. Note that this is only an override for spans
            that have zipkin_attrs passed in. Spans that make their own
            sampling decisions (i.e. are the root spans of entire traces) will
            always report timestamp/duration.
        :type report_root_timestamp: boolean
        :param use_128bit_trace_id: If true, generate 128-bit trace_ids.
        :type use_128bit_trace_id: boolean
        :param host: Contains the ipv4 or ipv6 value of the host. The ip value
            isn't automatically determined in a docker environment.
        :type host: string
        :param context_stack: explicit context stack for storing
            zipkin attributes
        :type context_stack: object
        :param span_storage: explicit Span storage for storing zipkin spans
            before they're emitted.
        :type span_storage: py_zipkin.storage.SpanStorage
        :param firehose_handler: [EXPERIMENTAL] Similar to transport_handler,
            except that it will receive 100% of the spans regardless of trace
            sampling rate.
        :type firehose_handler: BaseTransportHandler
        :param kind: Span type (client, server, local, etc...).
        :type kind: Kind
        :param timestamp: Timestamp in seconds, defaults to `time.time()`.
            Set this if you want to use a custom timestamp.
        :type timestamp: float
        :param duration: Duration in seconds, defaults to the time spent in the
            context. Set this if you want to use a custom duration.
        :type duration: float
        :param encoding: Output encoding format, defaults to V1 thrift spans.
        :type encoding: Encoding
        :param _tracer: Current tracer object. This argument is passed in
            automatically when you create a zipkin_span from a Tracer.
        :type _tracer: Tracer


<EOL>if self._is_local_root_span:<EOL><INDENT>if self.sample_rate is not None:<EOL><INDENT>if self.zipkin_attrs_override andnot self.zipkin_attrs_override.is_sampled:<EOL><INDENT>return True, create_attrs_for_span(<EOL>sample_rate=self.sample_rate,<EOL>trace_id=self.zipkin_attrs_override.trace_id,<EOL>)<EOL><DEDENT>elif not self.zipkin_attrs_override:<EOL><INDENT>return True, create_attrs_for_span(<EOL>sample_rate=self.sample_rate,<EOL>use_128bit_trace_id=self.use_128bit_trace_id,<EOL>)<EOL><DEDENT><DEDENT>if self.firehose_handler and not self.zipkin_attrs_override:<EOL><INDENT>return True, create_attrs_for_span(<EOL>sample_rate=<NUM_LIT:0.0>,<EOL>use_128bit_trace_id=self.use_128bit_trace_id,<EOL>)<EOL><DEDENT>return False, self.zipkin_attrs_override<EOL><DEDENT>else:<EOL><INDENT>existing_zipkin_attrs = self.get_tracer().get_zipkin_attrs()<EOL>if existing_zipkin_attrs:<EOL><INDENT>return False, ZipkinAttrs(<EOL>trace_id=existing_zipkin_attrs.trace_id,<EOL>span_id=generate_random_64bit_string(),<EOL>parent_span_id=existing_zipkin_attrs.span_id,<EOL>flags=existing_zipkin_attrs.flags,<EOL>is_sampled=existing_zipkin_attrs.is_sampled,<EOL>)<EOL><DEDENT><DEDENT>return False, None<EOL>

Returns the current ZipkinAttrs and generates new ones if needed.

        :returns: (report_root_timestamp, zipkin_attrs)
        :rtype: (bool, ZipkinAttrs)


self.do_pop_attrs = False<EOL>report_root_timestamp, self.zipkin_attrs = self._get_current_context()<EOL>if not self.zipkin_attrs:<EOL><INDENT>return self<EOL><DEDENT>self.get_tracer().push_zipkin_attrs(self.zipkin_attrs)<EOL>self.do_pop_attrs = True<EOL>self.start_timestamp = time.time()<EOL>if self._is_local_root_span:<EOL><INDENT>if not self.zipkin_attrs.is_sampled and not self.firehose_handler:<EOL><INDENT>return self<EOL><DEDENT>if self.get_tracer().is_transport_configured():<EOL><INDENT>log.info('<STR_LIT>'<EOL>'<STR_LIT>'.format(self.span_name))<EOL>return self<EOL><DEDENT>endpoint = create_endpoint(self.port, self.service_name, self.host)<EOL>self.logging_context = ZipkinLoggingContext(<EOL>self.zipkin_attrs,<EOL>endpoint,<EOL>self.span_name,<EOL>self.transport_handler,<EOL>report_root_timestamp or self.report_root_timestamp_override,<EOL>self.get_tracer,<EOL>self.service_name,<EOL>binary_annotations=self.binary_annotations,<EOL>add_logging_annotation=self.add_logging_annotation,<EOL>client_context=self.kind == Kind.CLIENT,<EOL>max_span_batch_size=self.max_span_batch_size,<EOL>firehose_handler=self.firehose_handler,<EOL>encoding=self.encoding,<EOL>)<EOL>self.logging_context.start()<EOL>self.get_tracer().set_transport_configured(configured=True)<EOL><DEDENT>return self<EOL>

Enter the new span context. All annotations logged inside this
        context will be attributed to this span. All new spans generated
        inside this context will have this span as their parent.

        In the unsampled case, this context still generates new span IDs and
        pushes them onto the threadlocal stack, so downstream services calls
        made will pass the correct headers. However, the logging handler is
        never attached in the unsampled case, so the spans are never logged.


def stop(self, _exc_type=None, _exc_value=None, _exc_traceback=None):

if self.do_pop_attrs:<EOL><INDENT>self.get_tracer().pop_zipkin_attrs()<EOL><DEDENT>if not self.get_tracer().is_transport_configured():<EOL><INDENT>return<EOL><DEDENT>if any((_exc_type, _exc_value, _exc_traceback)):<EOL><INDENT>error_msg = u'<STR_LIT>'.format(_exc_type.__name__, _exc_value)<EOL>self.update_binary_annotations({<EOL>ERROR_KEY: error_msg,<EOL>})<EOL><DEDENT>if self.logging_context:<EOL><INDENT>try:<EOL><INDENT>self.logging_context.stop()<EOL><DEDENT>except Exception as ex:<EOL><INDENT>err_msg = '<STR_LIT>'.format(<EOL>repr(ex),<EOL>)<EOL>log.error(err_msg)<EOL><DEDENT>finally:<EOL><INDENT>self.logging_context = None<EOL>self.get_tracer().clear()<EOL>self.get_tracer().set_transport_configured(configured=False)<EOL>return<EOL><DEDENT><DEDENT>end_timestamp = time.time()<EOL>if self.duration:<EOL><INDENT>duration = self.duration<EOL><DEDENT>else:<EOL><INDENT>duration = end_timestamp - self.start_timestamp<EOL><DEDENT>endpoint = create_endpoint(self.port, self.service_name, self.host)<EOL>self.get_tracer().add_span(Span(<EOL>trace_id=self.zipkin_attrs.trace_id,<EOL>name=self.span_name,<EOL>parent_id=self.zipkin_attrs.parent_span_id,<EOL>span_id=self.zipkin_attrs.span_id,<EOL>kind=self.kind,<EOL>timestamp=self.timestamp if self.timestamp else self.start_timestamp,<EOL>duration=duration,<EOL>annotations=self.annotations,<EOL>local_endpoint=endpoint,<EOL>remote_endpoint=self.remote_endpoint,<EOL>tags=self.binary_annotations,<EOL>))<EOL>

Exit the span context. Zipkin attrs are pushed onto the
        threadlocal stack regardless of sampling, so they always need to be
        popped off. The actual logging of spans depends on sampling and that
        the logging was correctly set up.


if not self.logging_context:<EOL><INDENT>self.binary_annotations.update(extra_annotations)<EOL><DEDENT>else:<EOL><INDENT>self.logging_context.tags.update(extra_annotations)<EOL><DEDENT>

Updates the binary annotations for the current span.