autofit.Aggregator#
- class Aggregator[source]#
Bases:
AbstractAggregatorQuery results from an intermediary SQLite database.
Results can be scraped from a directory structure and stored in the database.
- Parameters:
session (
Session) – A session for communicating with the database.filename (
Optional[str]) – The path to the database file. If None, the database is in memory.predicate (
AbstractQuery) – A predicate to filter the results by.offset – The number of results to skip
limit – The maximum number of results to return
order_bys – A list of attributes to order the results by
top_level_only – If True, only return the top level fits
Methods
Recursively search a directory for autofit results and add them to this database.
child_valuesRetrieve the value associated with each fit with the given parameter name
Create an instance from a sqlite database file.
Filter to only grid searches and return an aggregator with grid search specific functionality.
Order the results by a given attribute of the search.
Apply a query on the model.
valuesRetrieve the value associated with each fit with the given parameter name
Attributes
Lazily query the database for a list of Fit objects that match the aggregator's predicate.
Query info associated with the fit in the info dictionary
Facilitates query construction.
An object facilitating queries on fit attributes such as: name unique_tag path_prefix is_complete is_grid_search
- order_by(item, reverse=False)[source]#
Order the results by a given attribute of the search. Can be applied multiple times with the first application taking precedence.
- Parameters:
item (
Attribute) – An attribute of the searchreverse – If True reverse the results
- Return type:
An aggregator with ordering applied
Examples
- aggregator = aggregator.order_by(
aggregator.search.unique_tag
)
- property search: FitQuery#
An object facilitating queries on fit attributes such as: name unique_tag path_prefix is_complete is_grid_search
- property info#
Query info associated with the fit in the info dictionary
- property fits: List[Fit]#
Lazily query the database for a list of Fit objects that match the aggregator’s predicate.
- property model: Query#
Facilitates query construction. If the Fit class has an attribute with the given name then a predicate is generated based on that attribute. Otherwise the query is assumed to apply to the best fit instance.
- Return type:
A query
- query(predicate)[source]#
Apply a query on the model.
- Parameters:
predicate (
AbstractQuery) – A predicate constructed to express which models should be included.- Return type:
A list of objects that match the predicate
Examples
>>> >>> aggregator = Aggregator.from_database( >>> "my_database.sqlite" >>> ) >>> >>> lens = aggregator.galaxies.lens >>> >>> aggregator.filter((lens.bulge == SersicCore) & (lens.disk == Sersic)) >>> aggregator.filter((lens.bulge == SersicCore) | (lens.disk == Sersic))
- add_directory(directory, auto_commit=True, reference=None, completed_only=False)[source]#
Recursively search a directory for autofit results and add them to this database.
Any pickles found in the pickles file are implicitly added to the fit object.
Warning
If a directory is added twice then that will result in duplicate entries in the database.
- Parameters:
auto_commit – If True the session is committed writing the new objects to the database
directory (
str) – A directory containing autofit results embedded in a file structurereference (
Optional[dict]) – A dictionary mapping the names of objects in the model to their class path.completed_only (
bool) – If true only searches that have completed are added