Python API¶
AMAD offers a python API to interact with user notebooks and their data directly from python scripts (or JupyterLab).
Installation¶
The API code (labcore.py
) is freely available to all registered users, and is obtained by clicking the download button in the Dashboard/Account panel.
The API source code shoule be placed in the same folder as the python scripts that will use it in order to be importable.
Alternatively, it can be placed in any folder included in the PYTHONPATH
environment variable.
It is also necessary to download the SSL certificate from the Dashboard/Account panel and place it in the same folder as the python code.
Dependencies¶
The API requires the following python packages to be installed in your environment:
asd
Using the API¶
Once properly installed, it is straightforward to use the API by importing the labcore
module and all its content. Here is an example python script that retrieves the list of user notebooks:
from labcore import *
import numpy
# setup the API
LabCore.SERVER = 'https://amad.aalto.fi'
LabCore.APITOKEN = '5fa2847501684136921855a6.1906e26a9c19c68717726f9780651092fdb8bb1f'
# this is only necessary if the file is not in the same folder as this script
# LabCore.CERT = '/path/to/certificate/labcore.pem'
#
# SSL certificate verification can be disabled with:
# LabCore.CERT = False
# but don't come crying to me when you get hacked!
# fetch list of notebooks
nbs = LabCore.notebook_list()
# print notebook titles
for nb in nbs:
print("notebook:",nb['title'])
The important lines are:
from labcore import *
: import all functions and objects from the API moduleLabCore.SERVER = '...'
: tells the API the URL of AMAD serverLabCore.APITOKEN = '...'
: set the API token for this user
The API token can be requested from the Dashboard/Account panel and remains valid for 24 hours after it is last used. When a new token is obtained, just replace the string with the new token. If the token is expired or invalid, all the API functions will return an error.
Note
Issuing a new token will replace the existing one.
The token inlcudes the unique ID of the user, thus every notebook/data interaction done through the API is associated to the user.
Using the API with RSA keys¶
It is also possible to use the API with RSA keys that do not expire. First generate an RSA private key in the PKCS#1 format:
openssl genrsa -traditional -out id_api_private.pem 2048
and the corresponding public key:
openssl rsa -in id_api_private.pem -pubout -out id_api_public.pem
The public key should look like this:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsKDYUOOCVbA347Z7iTeu
mtU6meHYIwmcWF3VfGqo1qlqVQK9o7bADTYlqwUUcsbHmTxydyav1w5BLw8NBq1V
W3Vkjv9fDZwmAl/be7QQf/Qdt+nx0/A/uJ9LAWJ1F9jVhamwWDD7co1EkdVeWui9
Mdjs+RY84m3QkH1meGvD2t0F1kkXmumAksKRuhWL4jvPNZ5pLwvrPh2ywRaHt61J
yMc5miqlnExOuBsPPMQClYoMsKZ80EOyw45Cwm1iqzl3xgSuPHMgeskDMojqzveg
cfGQSMU3az/GYAyh0v+F8rJfr2xbqIgR9wHn+uWQ09DI9dQggEuBfKz0df2gq7yw
tQIDAQAB
-----END PUBLIC KEY-----
Click the add key button in the Dashboard/Account panel and paste the public key in the text area. After uploading the public key, configure the API in your python script as follows:
from labcore import *
f = open('id_api_private.pem', 'rb')
LabCore.SetUserKey('USER ID HERE', f.read())
f.close()
The file to read is the private key corresponding to any of the public keys uploaded in the dashboard. The user ID string is also visible in the Dashboard/Account panel. After the calling labCore.SetUserKey, all API functions can be used as long as the corresponding public key remains in the database.
API Documentation¶
Here is an overview of the API functions.
Enumerators¶
EDataType (enum)¶
This is an Enum with all the basic data types. It masks integer values. The full list of data types can be found here.
Example:
print(int(EDataType.FILE))
EMetaType (enum)¶
This is an Enum for the metadata types. Possible values are:
EMetaTyp.TAG
: simple metadata tagEMetaTyp.VTAG
: value-tagEMetaTyp.ITAG
: inventory tag
See Metadata Systems for more info.
Notebook Interactions¶
LabCore.notebook_list()¶
Returns the full list of notebook documents that the user can acces from the database.
A notebook document is a python dictionary, currently containing the following keys:
key |
value |
---|---|
_id |
dictionary with the notebook ID |
_id.$oid |
hexadecimal notebook ID |
title |
notebook title |
Example:
...
# get a list of notebooks
nbs = LabCore.notebook_list()
# print ID and title of each one
for nb in nbs:
print("notebook[{}] title is:".format(nb['_id']['$oid'], nb['title']))
LabCore.MakeRecord(name, typ, data, units=”1”)¶
name
: record nametyp
: record type from theEDataType
enumdata
: the data payloadunits
: physical units, see Physical Quantities for list of choices
Returns a data record in the proper python dictionary format, with the given data.
Example:
# matrix of random distances
data = numpy.random.random((10,10))
# create a DATA2D record
record = LabCore.MakeRecord("distances", EDataType.DATA2D, data, units="m")
Note
This will not upload anything to the database. It only creates a properly formatted dictionary describing the record.
Metadata Interactions¶
LabCore.metadata_print() and LabCore.metadata_list()¶
Returns the list of all metadata tags in the platform. The metadata_print
version also prints the metadata to the standard output in a nice format.
The output is a complex structure of nested python dictionaries. At the first level the dictionary has three main keys,
and the corresponding values are dictionaries of metadata tags for each of the main types (see Metadata Systems):
tags
: simple metadata tags dictionarykvps
: dictionary of key-value pair metadata (also known as vtags)itags
: dictionary of inventory metadata
Each of the three main dictionaries uses the metadata tag ID as key.
Example:
# get the metadata
metadataDB = LabCore.metadata_print()
# this is a dictionary of only inventory tags
itags = metadataDB['itags']
# show details of a particular item tag
print(tags['6214b0d240c0d996fab705a5'])
Object Oriented API¶
labcore.Notebook¶
-
class
labcore.
Notebook
(ID)¶ Creates a notebook object from the server’s notebook with given ID.
- Parameters
ID (str) – hex ID of the notebook
- Returns
Notebook object with the given ID, if found
- Return type
- Variables
records – list of
labcore.Record
objects for all data records in the notebook
-
CreateCompositeRecord
(master, records)¶ Uploads a composite record and its children to the notebook. The master and children records must be properly formatted dictionaries with the records information.
- Parameters
master (dict) – master COMPOSITE record
records (list of dict) – list of children records for the COMPOSITE
Warning
The API does not check that the master and records are formatted correctly. It is up to the user to make sure the supplied data matches their record types.
Warning
It is better to let the API create proper master and records dictionary using dedicated parsers, e.g. Record.SPM_from_IBW.
Example:
from labcore import * # get a notebook nb = Notebook.Find_byID('60eed666f49103c93f6aa988') # parse SPM data from an ibw master, records = Record.SPM_from_IBW('Mica_in_water.ibw', nameprefix='noisy') # upload the whole composite into the notebook nb.CreateCompositeRecord(master, records)
-
CreateRecord
(name, rectype, data, units='1')¶ Creates a new data record and uploads it into the notebook
- Parameters
name (str) – name of the new record to make
rectype (
labcore.EDataType
) – recrod typedata (variable) – the record data (type depends on rectype)
units (str) – physical units of the data (default is “1” for adimensional)
- Returns
the new record object (without the data)
- Return type
Warning
The API does not check that the data is formatted correctly. It is up to the user to make sure the supplied data matches rectype.
Warning
The record name shall not contain special characters - !@$%^&*?=”’/
Example:
from labcore import * # get a notebook nb = Notebook.Find_byID('60eed666f49103c93f6aa988') # create data for an array record (DATA1D) data = [0,1,1,2,3,5,8,-12] # make the record and save it in the notebook rec = nb.CreateRecord("fribonacchy", EDataType.DATA1D, data, "1") # print the UUID print(rec.uuid)
-
Find
()¶ Retrieves the notebook with given title from the server.
- Parameters
title (str) – title of the notebook
- Returns
Notebook object if found
- Return type
Example:
from labcore import * nb = Notebook.Find('test notebook')
-
FindRecord
(name)¶ Returns the object representing the data record with given name.
- Parameters
name (str) – name of the record to find.
- Returns
labcore.Record
object with given name, or None if not found.- Return type
Example:
from labcore import * nb = Notebook.Find_byID('60eed666f49103c93f6aa988') rec = nb.FindRecord('test array') print(rec.uuid)
-
FindRecord_byID
(uuid)¶ Returns the object representing the data record with given UUID.
- Parameters
uuid (str) – UUID of the record to find.
- Returns
labcore.Record
object with given name, or None if not found.- Return type
Example:
from labcore import * nb = Notebook.Find_byID('60eed666f49103c93f6aa988') rec = nb.FindRecord_byID('trolo-lol-olol') print(rec.name)
-
Find_byID
()¶ Retrieves the notebook with given ID from the server.
- Parameters
ID (str) – hex ID of the notebook.
- Returns
Notebook object if found.
- Return type
Example:
from labcore import * nb = Notebook.Find_byID('60eed666f49103c93f6aa988')
-
FluidElement
(uuid)¶ Returns the notebook fluid element with given uuid.
Raises an exception if the fluid element was not found.
- Parameters
uuid (str) – uuid of the element to find.
- Returns
Dictionary with the fluid element information.
- Return type
dict
Example:
from labcore import * nb = Notebook.Find('test notebook') # we know the uuid corresponds to a table! table = nb.FluidElement('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') # print out the configuration of the table print(table['config'])
-
FluidElements
(uuidOnly=False)¶ Prints the list of fluid elements in the notebook and their uuid.
- Parameters
uuidOnly (bool) – set True to only show referrable elements (tables, figures, …), default is False.
-
GetActiveTable
(uuid)¶ Returns the active table with given uuid (or index). If the argument is integer, it will be interpreted as the index of the table in the list of all active tables (starting from 0). Raises an exception if the uuid/index is wrong.
- Parameters
uuid (str or int) – uuid (or integer index) of the active table to find.
- Returns
Active table object.
- Return type
Example:
from labcore import * nb = Notebook.Find('test notebook') # we know the uuid corresponds to an active table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') # print out the configuration of the active table print(table._src['config'])
-
GetMessages
(printout=False, newfirst=False)¶ Returns the message log for this notebook. Each message is a dictionary with sender, timestamp and text.
- Parameters
printout (bool) – If True prints the messages to the screen (default is False).
newfirst (bool) – If True sorts the messages from newest to oldest (default is False).
- Returns
List of dictionary with the messages details.
- Return type
list
Example:
from labcore import * nb = Notebook.Find('test notebook') messages = nb.GetMessages(printout=True, newfirst=True)
-
property
ID
¶ Notebook’s ID string, e.g. “60eed666f49103c93f6aa988”.
-
Records
(withHidden=False)¶ Returns a List of data record objects in this notebook, optionally including hidden ones.
- Parameters
withHidden (bool) – True if hidden records should be included, False (default) otherwise.
rectype – recrod type
- Returns
the record object list
- Return type
lits of
labcore.Record
Warning
Adding/removing records to the output list will not have any effect on the server!
-
SendMessage
(message, withEmail=False)¶ Send a message to all users on this notebook, optionally via email as well.
Note
Only users with explicit permission will get the email.
- Parameters
message (str) – message text.
withEmail (bool) – set to True to also send the message via email (default is False).
Example:
from labcore import * nb = Notebook.Find_byID('60eed666f49103c93f6aa988') nb.SendMessage('Table 1 was updated with the latest MtG rare prices.', withEmail=True)
-
property
records
¶ List of data record objects in this notebook.
Warning
Adding/removing records to this list will not have any effect on the server!
Note
Hidden records will not be included in the list
-
property
title
¶ Notebook’s title.
labcore.ActiveTable¶
-
class
labcore.
ActiveTable
(src, notebook)¶ Creates an active table object from the notebook source code.
- Parameters
src (dict) – source code of the active table
notebook (
labcore.Notebook
) – Notebook object where the table is found
- Returns
Interface to the active table
- Return type
-
AddColumn
(title='', width=150, units='1')¶ Adds a column to the active table, with given title, width and units.
- Parameters
title (str) – column name (default is “column-X”)
width (int) – column width (default is 150)
units (str) – column physical units (default is “1”)
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') print(table.data()) table.AddColumn(title="BladeLength", units="cm", width=200) print(table.data())
-
AddRow
(title='')¶ Adds a row to the active table, with given title (ID column value).
- Parameters
title (str) – row title (default is “”)
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') print(table.data()) table.AddRow(title="Elm Street") print(table.data())
-
GetColumnIDs
()¶ Returns the list of column names.
- Returns
list of column names
- Return type
list
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') columns = table.GetColumnIDs() print(columns)
-
GetColumnMeta
(column)¶ Get the metadata dictionary attached to a given column (0-based index). The dictionary has three keys (‘tags’, ‘kvps’, ‘itags’) for the three metadata types, and each of the associated values is a list of
labcore.Metadata
objects.- Parameters
column (int) – column number (starting from 0)
- Returns
Metadata dictionary for the column
- Return type
dict
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') colmeta = table.GetColumnMeta(1) print(colmeta)
-
GetColumnUnits
()¶ Returns the list of column physical units.
- Returns
list of column units
- Return type
list
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') colUnits = table.GetColumnUnits() print(colUnits)
-
GetRowIDs
()¶ Returns the list of row names.
- Returns
list of row names
- Return type
list
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') rows = table.GetRowIDs() print(rows)
-
GetRowMeta
(row)¶ Get the metadata dictionary attached to a given row (0-based index). The dictionary has three keys (‘tags’, ‘kvps’, ‘itags’) for the three metadata types, and each of the associated values is a list of
labcore.Metadata
objects.- Parameters
row (int) – row number (starting from 0)
- Returns
Metadata dictionary for the row
- Return type
dict
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') rowmeta = table.GetRowMeta(1) print(rowmeta)
-
LockColumn
(column, lock=True)¶ Sets the lock status of a column.
- Parameters
column (int) – column number (starting from 0)
lock (bool) – lock status, default is True
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') print(table.data()) # lock a column table.LockColumn(2, True) # the next line should raise an error since column 2 is locked table.SetValue(1,2, "Freddy's coming for you")
-
LockRow
(row, lock=True)¶ Sets the lock status of a row.
- Parameters
row (int) – row number (starting from 0)
lock (bool) – lock status, default is True
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') print(table.data()) # lock a row table.LockRow(1, True) # the next line should raise an error since row 1 is locked table.SetValue(1,2, "Freddy's coming for you")
-
property
Notebook
¶ Parent Notebook object.
-
RemoveColumn
(index)¶ Remove the column with given index from the active table.
- Parameters
index (int) – column index, not 0
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') print(table.data()) table.RemoveColumn(1) print(table.data())
-
RemoveRow
(index)¶ Remove the row with given index from the active table.
- Parameters
index (int) – row index
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') print(table.data()) table.RemoveRow(2) print(table.data())
-
SetColumnMeta
(column, metas)¶ Set the metadata dictionary attached to a given column (0-based index). The dictionary should have three keys (‘tags’, ‘kvps’, ‘itags’) for the three metadata types, and each of the associated values has to be a list of
labcore.Metadata
objects. Omitted keys will set the list of corresponding metadata type to empty...note:
The first column cannot be modified.
- Parameters
column (int) – column number (starting from 0)
metas (dict) – metadata dictionary
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the first table in the notebook table = nb.GetActiveTable(0) # get metadata tags from the database tag = Metadata("b4d4557460fd00m", 'tag') kvp = Metadata("57affedf4ff3der", 'kvp', value=1.23) # combine into a dictionary metadict = {'tags': ["b4d4557460fd00m"], 'kvps': [kvp]} # set the metadata for the second column table.SetColumnMeta(1, metadict)
-
SetData
(data, ignoreLock=False)¶ Set the entire data table to the desired matrix.
- Parameters
data (numpy 2D ndarray or list) – matrix (numpy or list), without the ID column
ignoreLock (bool) – True if the operation should ignore any row/column lock (default=False)
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') print(table.data()) table.SetValue(1,2, "Freddy's coming for you") table.SetValue(3,4, "better lock your door") print(table.data())
-
SetRowMeta
(row, metas)¶ Set the metadata dictionary attached to a given row (0-based index). The dictionary should have three keys (‘tags’, ‘kvps’, ‘itags’) for the three metadata types, and each of the associated values has to be a list of
labcore.Metadata
objects. Omitted keys will set the list of corresponding metadata type to empty.- Parameters
row (int) – row number (starting from 0)
metas (dict) – metadata dictionary
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the first table in the notebook table = nb.GetActiveTable(0) # get metadata tags from the database tag = Metadata("b4d4557460fd00m", 'tag') kvp = Metadata("57affedf4ff3der", 'kvp', value=1.23) # combine into a dictionary metadict = {'tags': ["b4d4557460fd00m"], 'kvps': [kvp]} # set the metadata for the first row table.SetRowMeta(0, metadict)
-
SetValue
(i, j, value)¶ Sets the value of the given ActiveTable cell. The cell is specified by i,j coordinates (start from 0). Since the ID column cannot be modified this way, the indexing for columns excludes the true first column (ID).
Note
Element ([i, 0]) is not the ID of the i-th row, but the data in the first data column for i-th row.
- Parameters
i (int) – row number (starting from 0)
j (int) – column number (starting from 0)
value (str or number) – value to write in the cell, or None to clear it.
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') print(table.data()) table.SetValue(1,2, "Freddy's coming for you") table.SetValue(3,4, "better lock your door") print(table.data())
-
SetupColumn
(column, name=None, units=None)¶ Change the name and/or units of a column.
- Parameters
column (int) – column index (0 being the first column after ID)
name (str) – new column name (optional)
units (str) – new column physical units (optional)
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') table.SetupColumn(3, name="SnailSpeed", units="m/fortnight") print(table.data())
-
SetupRow
(row, name)¶ Change the name of a row.
- Parameters
column (int) – row index
name (str) – new row name
Example:
from labcore import * nb = Notebook.Find('test notebook') # get the table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') table.SetupRow(1, name="snail-1") print(table.data())
-
property
UUID
¶ UUID of the active table.
-
data
(withID=False)¶ Returns the data in the as a numpy array.
- Parameters
withID (bool) – include the ID column in the output (default is False)
- Returns
Table data.
- Return type
numpy array
Example:
from labcore import * nb = Notebook.Find('test notebook') # we know the uuid corresponds to an active table table = nb.GetActiveTable('ad788298-3fda8d4b0000000008528643c81ae5bd-55ca5e2d') # print out the active table data (with the ID column) data = table.data(withID=True) print(data())
labcore.Record¶
-
class
labcore.
Record
(notebook, record)¶ Represents a data record.
-
Delete
()¶ Deletes this record from the notebook it belongs to.
- ..warn::
This will permanently delete the data!
Example:
from labcore import * nb = Notebook.Find('test notebook') rec = nb.FindRecord('test array') rec.Delete()
-
GetData
()¶ Downloads the actual data payload of this record and stores it in record.data
Example:
from labcore import * nb = Notebook.Find('test notebook') rec = nb.FindRecord('test array') rec.GetData() print(rec.data)
-
MetadataAdd
(meta)¶ Adds a metadata element to this record, and save the change into the database. If the metadata is already present, prints a message without changing anything.
- Parameters
meta (
labcore.Metadata
) – metadata object to attach
Example:
from labcore import * nb = Notebook.Find('test notebook') rec = nb.FindRecord('test array') # create a key-value pair metadata tag tag = Metadata('bad455000571dd1c34d18411', 'kvp', '30 celsius') # add the tag - also saves on the server rec.MetadataAdd(tag)
-
MetadataPrint
()¶ Prints all metadata in this record.
Example:
from labcore import * nb = Notebook.Find('test notebook') rec = nb.FindRecord('test array') # print metadata attached to record rec.MetadataPrint()
-
MetadataRemove
(meta)¶ Removes the given metadata element from this record, and save the change into the database. If the metadata is not present, prints a message without changing anything.
- Parameters
meta (
labcore.Metadata
) – metadata object to remove
Example:
from labcore import * nb = Notebook.Find('test notebook') rec = nb.FindRecord('test array') # create a key-value pair metadata tag tag = Metadata('bad455000571dd1c34d18411', 'kvp') # remove the tag - also saves on the server rec.MetadataRemove(tag)
-
MetadataSave
()¶ Saves the current state of metadata in this record into the database.
Example:
from labcore import * nb = Notebook.Find('test notebook') rec = nb.FindRecord('test array') # create a key-value pair metadata tag tag = Metadata('bad455000571dd1c34d18411', 'kvp', '30 celsius') # set the list of key-value pairs rec.kvps = [tag] # save rec.MetadataSave()
-
Rename
(newName=None, newUnits=None)¶ Changes the record name and/or physical units.
- Parameters
newName (
labcore.Metadata
) – metadata object to attachnewUnits (
labcore.Metadata
) – metadata object to attach
Example:
from labcore import * nb = Notebook.Find('test notebook') rec = nb.FindRecord('test array') rec.Rename(newName='dis array', newUnits='m/s')
-
SPMCompare
(target, parameters={})¶ Performs SPM image comparison (johnbot v4) between channels of SPM records.
- Parameters
ref (
labcore.Record
) – DATA2D record with the reference channeltarget (
labcore.Record
) – DATA2D record with the target channelparameters (dict) – dictionary of calculation parameters
- Returns
dictionary with comparison metrics results
- Return type
dict
The parameters dictionary should have the following keys: * sigma [float]: stdv of the gaussian filter applied to FFT * kmin [float]: minimum k-space value to consider in the possible range (0-1) * kmax [float]: maximum k-space value to consider in the possible range (0-1) * angscans [int]: number of angular scans * angres [float]: resolution of the angular scans (in degrees)
The function returns a dictionary with the following elements: * PatternMismatch: mismatch factor between the image patterns (absolute error) * PatternMismatchPct: mismatch factor between the image patterns as percentage (relative error) * PowerMismatch’: mismatch between image contrast magnitudes * OffsetMismatch’: mismatch between image offsets
Example:
from labcore import * # get the DATA2D records of two SPM image channels to compare ref = ... trg = ... # compute mismatch metrics results = Record.SPMCompare(ref,trg)
-
SPM_from_IBW
(nameprefix='')¶ Creates an SPM record by parsing an ibw file. Returns the dictionary form of the master record and a list of children. The optional name prefix will be added to the record name, before the original file name.
- Parameters
filename (string) – full path of the ibw file to parse
nameprefix (string) – custom prefix for the output record name
Warning
The nameprefix must not contain special characters - !@$%^&*?=”’/
Example:
from labcore import * # get a notebook nb = Notebook.Find_byID('60eed666f49103c93f6aa988') # parse SPM data from an ibw master, records = Record.SPM_from_IBW('Mica_in_water.ibw', nameprefix='noisy') # upload the whole composite into the notebook nb.CreateCompositeRecord(master, records)
-
STRUCTURE_from_ASE
()¶ Returns the data for a STRUCTURE record for the given ASE system instance.
- Parameters
aseObject (ASE Atoms) – a valid ASE object representing an atomistic structure.
- Returns
STRUCTURE record data field
- Return type
dict
Example:
from labcore import * import ase.io # import an atomistic system with ASE aseobj = ase.io.read('somemolecule.xyz') # create LabCore data representation data = Record.STRUCTURE_from_ASE(aseobj) # add a new STRUCTURE record to a notebook nb = Notebook.Find_byID('60eed666f49103c93f6aa988') # make the record and save it in the notebook rec = nb.CreateRecord("somemolecule", EDataType.STRUCTURE, data, "1")
-
UploadData
()¶ Uploads the content of record.data to the server.
This will effectively overwrite the existing data.
Example:
from labcore import * nb = Notebook.Find('test notebook') rec = nb.FindRecord('test array') # set the new data rec.data = [1,2,3,4,5] # upload to server rec.UploadData()
-
property
children
¶ List of labcore.Record objects that are grouped into this record. If called on a record that is not of type COMPOSITE, the list is empty.
-
property
masterRecord
¶ labcore.Record object of the master COMPOSITE where the current record belongs. Returns None if called by a record that is not a child of a COMPOSITE.
-
property
name
¶ Record’s name.
-
property
notebook
¶ Reference to the
labcore.Notebook
object this record belongs to.
-
property
type
¶ Record’s type as labcore.EDataType enum.
-
property
uuid
¶ Record’s unique ID.
-
labcore.Metadata¶
-
class
labcore.
Metadata
(ID, metaType, value=None)¶ Metadata tag.
Create a Metadata object. The corresponding tag with same ID must exist in the database.
- Parameters
ID (str) – valid ID string of the metadata
metaType (str) – type of metadata [“tag”|”kvp”|”itag”]
value (str|int|float) – value of the tag (only for kvp type)
Example:
from labcore import * # create a key-value pair metadata tag tag = Metadata('bad455000571dd1c34d18411', 'kvp', "123 celsius")
-
property
ID
¶ ID string of this metadata tag.
-
ToString
(withType=False)¶ Returns a string with the metadata details.
- Parameters
withType (bool) – set to True to display the tag type (default False)
- Returns
info string
- Return type
str
from labcore import * # create a key-value pair metadata tag tag = Metadata('bad455000571dd1c34d18411', 'kvp', '30 celsius') # print its string representation (including type) print(tag.ToString(withType=True))
-
property
info
¶ Metadata description.
-
property
name
¶ Name of this metadata tag.
-
property
type
¶ Type of this metadata [“tag”|”kvp”|”itag”].
-
property
value
¶ Metadata value (only for key-value type).