Manage database¶
Functions to import and export Bluesky data.
|
Exports databroker database into msgpack files. |
|
Exports scans into .csv and .json files. |
|
Load the exported databroker database. |
|
Removes a catalog created by to_databroker. |
- polartools.manage_database.from_databroker_inplace(folder, name, catalog, merge=False)[source]¶
Load the exported databroker database.
This is a narrow usage of the databroker-pack package. Note that this package includes a convenient command line tool.
- Parameters:
- folderstr
Folder with files exported by
polartools.manage_database.to_databroker().- namestr
Unique name that will be set in the databroker catalog.
- mergebool, optional
Flag to decide if this data will be merged into an existing catalog.
Example
from databroker import catalog from polartools.manage_database import from_databroker_inplace from_databroker_inplace('folder/to/files', 'my_data') db = catalog['my_data']
- polartools.manage_database.remove_catalog(name, catalog=None)[source]¶
Removes a catalog created by to_databroker.
- Parameters:
- namestr
Catalog name
Notes
This will not remove the data files, only the catalog, which will not be discoverable using databroker.catalog.
It assumes that the catalog was created by to_databroker or databroker_pack. The actual name of the file is ‘databroker_unpack_NAME.yml’.
- polartools.manage_database.to_csv_json(db, folder, query=None, fname_format='scan_{}_', overwrite=False, max_attempts=100)[source]¶
Exports scans into .csv and .json files.
The scans will be labeled by their scan_id metadata. If two or more scans have the same scan_id, it will write the new scan with a -number suffix where number will be the first available integer starting with 2.
WARNING: While you can pass a query dictionary here, it is advised to run the query and check the results before running this function as you may inadvertely export a very large number of scans. See
polartools.load_data.db_query().- Parameters:
- db
Databroker database.
- folderstr
Destination directory.
- querydict, optional
Search parameters to select a subsection of db. See
polartools.load_data.db_query()for more details.- fname_formatstr, optional
Format of the string to be used for the file names. Note that one has to be able to add the scan numbers into this string by doing: fname_format.format(scan_number).
- overwritebool, optional
Flag to determine if an existing folder should be overwritten.
- max_attemptsint, optional
Maximum number of times that a new suffix will be added to the file name. Once it reaches this maximum, it will overwrite the last file.
See also
polartools.load_data.db_query()suitcase.csv.export()suitcase.json_metadata.export()
Notes
Each scan has one json “-metadata.json” file, plus ome csv file for each data stream, for instance “-primary.csv”.
- polartools.manage_database.to_databroker(db, folder, query=None, external=False)[source]¶
Exports databroker database into msgpack files. WARNING: While you can pass a query dictionary here, it is advised to run the query and check the results before running this function as you may inadvertely export a very large number of scans. See
polartools.load_data.db_query(). This is a narrow usage of the databroker-pack package. Note that this package includes a convenient command line tool.- Parameters:
- db
Databroker database.
- folderstr
Destination directory.
- querydict, optional
Search parameters to select a subsection of db. See
polartools.load_data.db_query()for more details.
See also
polartools.load_data.db_query()databroker-pack.export_catalog()databroker-pack.write_documents_manifest()databroker-pack.write_msgpack_catalog_file()
Notes
The scans are saved in msgpack files placed in the folder/documents folder.
catalog.yml and documents_manifest.txt are located in folder.