The CoreLayer¶
You can import from ./ or with bfly installed.
from bfly import CoreLayer
Or, in scripts in some directories:
# if './bfly/' in sys.path
import CoreLayer
You can from CoreLayer import All layers.
# if './bfly/' in sys.path
from CoreLayer import DatabaseLayer, AccessLayer
from CoreLayer import QueryLayer, ImageLayer, UtilityLayer
CoreLayer¶
You can import CoreLayer from bfly.
CoreLayer classes¶
-
class
CoreLayer.Core(db)[source]¶ Starts the
CacheParameters: db ( bfly.Butterfly._db_type) – A fully-loaded database-
_db¶ bfly.Butterfly._db_type– Taken from first argumentdb
-
_cache¶ Cache– Able to store images and metadata usingUtilityLayer.RUNTIMEinstance fromdbargument
-
find_tiles(d_query)[source]¶ Load the requested image for a
DataQueryParameters: - d_query (
DataQuery) – Request for a scaled subvolume of a source image - Returns –
- numpy.ndarray – The full image data for the requested region
- d_query (
-
find_unique(d_query)[source]¶ Get unique values for a
DataQueryParameters: - d_query (
DataQuery) – Request for a scaled subvolume of a source image - Returns –
- set – The set of unique values for the request
- d_query (
-
get_data(d_query)[source]¶ dumps answer to
d_queryas a stringCalls
update_query()with more informationfrom the cache or from the properties of a tile. Also callsfind_tiles()to get the completeimage needed to answer thed_query.Parameters: i_query ( QueryLayer.InfoQuery) – A request for informationReturns: Answer for the QueryLayer.InfoQueryReturn type: str
-
get_dataset(i_query)[source]¶ dumps dataset from
i_queryas a stringCalls
update_query()with more informationfrom the cache or from the properties of a tile.Parameters: i_query ( QueryLayer.InfoQuery) – A request for informationReturns: Dataset info for QueryLayer.InfoQueryReturn type: str
-
get_edits(i_query, msg={})[source]¶ dumps websocket updates to
i_queryas a stringCalls
update_query()with more informationfrom the cache or from the properties of a tile.Parameters: i_query ( QueryLayer.InfoQuery) – A request for informationReturns: Wesocket info for QueryLayer.InfoQueryReturn type: str
-
static
get_groups(i_query)[source]¶ dumps group list for
i_queryas a stringParameters: i_query ( QueryLayer.InfoQuery) – A request for a list of groupsReturns: A list of all groups for the i_queryReturn type: str
-
get_info(i_query)[source]¶ dumps answer to
i_queryas a stringCalls
update_query()with more informationfrom the cache or from the properties of a tile.Parameters: i_query ( QueryLayer.InfoQuery) – A request for informationReturns: Channel info for QueryLayer.InfoQueryReturn type: str
-
load_tile(t_query)[source]¶ Load a single tile from the cache or from disk
Parameters: t_query ( TileQuery) – With tile coordinates and volume within the tileReturns: The subregion image data for the requested tile Return type: numpy.ndarray
-
static
make_data_query(i_query)[source]¶ Make a data query from an info query
Parameters: i_query ( InfoQuery) – only needsPATHset inOUTPUT.INFOReturns: takes only the PATH from i_queryReturn type: DataQuery
-
static
make_tile_query(d_query, t_index=array([0, 0, 0], dtype=uint32))[source]¶ Make a
TileQueryfromDataQueryParameters: - d_query (
DataQuery) – only needsPATHset inOUTPUT.INFO - t_index (numpy.ndarray) – The 3x1 count of tiles form the origin
Returns: One tile request in the given data request
Return type: TileQuery- d_query (
-
update_query(query)[source]¶ Finds missing query details from cache or tile
Makes
keywordsfrom either the_cacheor from a newTileQueryto update the givenqueryParameters: query ( Query) – Either anInfoQueryor aDataQueryReturns: keywords – Can pass to Query.update_source()or combine to pass toQuery.update_dataset().Return type: dict
-
-
class
CoreLayer.Cache(_runtime)[source]¶ Cache tiles and preloaded keywords
Parameters: _runtime ( RUNTIME) – Needed to make attributes for each instance-
_max_memory¶ int –
MAXfromRUNTIME.CACHE, and the max bytes of memory to be used.
-
_cach_meta¶ str –
MAXfromRUNTIME.CACHE, and the key for the size of cached keywords
-
_cache¶ Collections.OrderedDict – A Least recently used ordered dictionary
-
_now_memory¶ int – The current bytes of memory used
-
get(key)[source]¶ Get a value from the cache by key
Parameters: key (str) – The key from a Queryto access the cacheReturns: The value stored in the cache, or an empty list Return type: anything
-
DatabaseLayer¶
You can import DatabaseLayer from bfly and CoreLayer.
DatabaseLayer classes¶
Database base class¶
-
class
DatabaseLayer.Database(path, _runtime)[source]¶ Stores tables to respond to
API._feature_info()Parameters: -
add_entries(table, path, t_keys, entries)[source]¶ Add an array or list of entries to a table Must be overridden by derived class.
-
add_entry(table, path, entry, update=1)[source]¶ and a single entry to a table for a path Overides
Database.add_entry()Parameters: - table (str) – The category of table for the database
- path (str) – The dataset path to metadata files
- entry (dict) – The mapping of keys to values for the entry
- update (int) – 1 to update old entries matching keys, and 0 to write new entries ignoring old entries. Default 1.
Returns: The value of the entry
Return type: dict
-
add_neurons(path, neurons)[source]¶ Add all the neurons to the database
Parameters: - path (str) – The dataset path to metadata files
- neurons (numpy.ndarray) – The Nx4 array of id, z, y, x values where N is the number of neurons for the
path.
Returns: A list of dicts from each row of
neuronswith dictionary keys from theNEURON.FULL_LISTfield ofRUNTIME.DBReturn type: list
-
add_path(c_path, d_path)[source]¶ store a link from a
c_pathto ad_pathMust be overridden by derived class.Parameters: - c_path (str) – The path to a given channel with images
- d_path (str) – The path to the dataset with metadata files
-
add_synapses(path, synapses)[source]¶ Add all the synapases to the database
Parameters: - path (str) – The dataset path to metadata files
- synapses (numpy.ndarray) – The Nx5 array of pre, post, z, y, x values where N is the number of synapses for the
path.
Returns: A list of dicts from each row of
synapseswith dictionary keys taken fromSYNAPSE.FULL_LISTfield ofRUNTIME.DBReturn type: list
-
add_table(table, path)[source]¶ Add a table to the database Must be overridden by derived classes
Parameters: - table (str) – The category of table for the database
- path (str) – The dataset path to metadata files
Returns: The table name combining
tableandpathThe derived classes should return whether the table was added successfully.Return type: str or bool
-
add_tables(path)[source]¶ Store all the tables for a given path
Parameters: path (str) – The dataset path to metadata files
-
commit()[source]¶ Save all database changes to the database file. Must be overridden by derived class.
-
get_by_key(table, path, key)[source]¶ Get the entry for the key in the table. Must be overridden by derived class.
Parameters: - table (str) – The category of table for the database
- path (str) – The dataset path to metadata files
- key (int) – The primary key value for any entry
Returns: The object reference from
get_table(). The derived class should give an entry in the table.Return type: object or dict
-
get_path(path)[source]¶ Map a channel path to a dataset path Must be overridden by derived class.
Parameters: path (str) – The path to the given channel Returns: The dataset path for the given pathReturn type: str
-
get_table(table, path)[source]¶ Get the actual table for a given path Must be overridden by derived class.
Parameters: - table (str) – The category of table for the database
- path (str) – The dataset path to metadata files
Returns: Full database name of the table for a path. The derived classes should actually return the python object reference to the real table.
Return type: str or object
-
load_all(source)[source]¶ Load the tables, synapses, and neuron configs :param source: The configuration options for a dataset :type source: dict
-
load_config(config)[source]¶ Loads all files from
configinto databaseParameters: config (dict) – all data from UtilityLayer.rh_configReturns: the derived database class instance Return type: Database
-
load_neurons(path, synapses)[source]¶ Load all the neuron information from files
Parameters: - path (str) – The dataset path to metadata files
- synapses (numpy.ndarray) – The Nx5 array of pre, post, z, y, x values where N is the number of synapses for the
path.
Returns: The Nx4 array of id, z, y, x values where N is the number of neurons for the
path.Return type: numpy.ndarray
-