Database access (ctapointing.database)
API
ctapointing.database Package
- class ctapointing.database.MongoDBTableReader(**kwargs: Any)
Class for reading a ctapipe.core.Container object from a Mongo database table.
- __init__(database_name, **kwargs)
- Parameters:
database_name (str) – name of database table
kwargs – any other arguments that will be passed through
- read(collection_name, containers, prefixes=None, selection_dict={}, limit=0)
Returns a generator that reads the next row from the table into the given container. The generator returns the same container. Note that no containers are copied, the data are overwritten inside.
- Parameters:
table_name (str) – name of table to read from
containers (ctapipe.core.Container or iterable thereof) – Container instance(s) to fill
prefixes (bool, str or iterable of str) – prefixes used during writing of the table
- class ctapointing.database.MongoDBTableWriter(**kwargs: Any)
Class for writing ~ctapipe.core.Container objects to a mongo database table
- __init__(database_name, add_prefix=False, parent=None, config=None)
- Parameters:
config (traitlets.loader.Config) – Configuration specified by config file or cmdline arguments. Used to set traitlet values.
parent (Tool or Component) – If a Component is created by another Component or Tool, you need to pass the creating Component as parent, e.g. parent=self. This makes sure the config is correctly handed down to the child components. Do not pass config in this case.
kwargs – Traitlets to be overridden. TraitError is raised if kwargs contains a key that does not correspond to a traitlet.
- close()
Close open writer
- open(filename, **kwargs)
open an output file
- Parameters:
filename (str) – output file name
kwargs – any extra args to pass to the subclass open method
- write(collection_name, containers, replace=False)
Write the contents of the given container or containers to a MongoDB table. :param collection_name: name of collection within the database to write to :type collection_name: str :param containers: container to write :type containers: ctapipe.core.Container or Iterable[ctapipe.core.Container] :param replace: :type replace: replace table entry in database if already existing
- ctapointing.database.check_collection_exists(database_name: str, collection_name: str) bool
Check if collection collection exists in database database
- Parameters:
database_name (str) – name of the database
collection_name (str) – name of the collection
- Returns:
does_exist – True if collection exists, False otherwise
- Return type:
Bool
- ctapointing.database.get_known_configurations(database, collection_name)
Lists all available database entries in this database
- Returns:
config_names – list of tuples with name and UUID of configurations
- Return type:
list
- ctapointing.database.provide_camera_db(*, database='camera_config', access_role='read')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_camera_db_write(*, database='camera_config', access_role='readWrite')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_config_db(*, database='ctapointing_config', access_role='read')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_config_db_write(*, database='ctapointing_config', access_role='readWrite')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_image_db(*, database='images', access_role='read')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_image_db_write(*, database='images', access_role='readWrite')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_mongo_db(database, access_role='read')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_solutions_db(*, database='image_solutions', access_role='read')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_solutions_db_write(*, database='image_solutions', access_role='readWrite')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_solver_db(*, database='solver_config', access_role='read')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.provide_solver_db_write(*, database='solver_config', access_role='readWrite')
Provide a context for a certain mongodb database.
Usage example: with provide_image_db() as db:
[operate on db]
- ctapointing.database.read_configuration(name, database, collection_name, read_from_file)
Read a configuration from either database or file.
- Parameters:
name (str) – name of the configuration (or filename)
database (str) – name of the database to read from
read_from_file (bool) – read from database if False, from file if True
collection_name (str) – mongo database collection to read from
- Returns:
configuration – (nested) dictionary of configuration parameters or None in case of unsuccessful reading
- Return type:
dict
- ctapointing.database.write_configuration(data, database, collection_name, replace=False, write_to_file=False, filepath=None)
Write a configuration to either database or file.
- Parameters:
data (dict) – (nested) dictionary of data to write
database (str) – name of the database to write to
replace (bool) – if True, replace file or database entry
write_to_file (bool) – write to database if False, to file if True
collection_name (str) – mongo database collection to write to
filepath (str or None) – directory to which file gets written
- Returns:
result
- Return type:
path to output file or database storage result
Functions
|
Provide a context for a certain mongodb database. |
|
Check if collection collection exists in database database |
|
Read a configuration from either database or file. |
|
Write a configuration to either database or file. |
|
Lists all available database entries in this database |
Classes
|
Class for writing ~ctapipe.core.Container objects to a mongo database table |
|
Class for reading a ctapipe.core.Container object from a Mongo database table. |
Class Inheritance Diagram
