Unverified Commit 4ed7f0f5 authored by Akke Viitanen's avatar Akke Viitanen
Browse files

add option for caching

parent 1b5ec308
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -39,7 +39,11 @@ class CatalogCombined:
        Single star catalog.
    catalog_binary: catalog_star.CatalogStar or None
        Binary star catalog.

    sql_query: str
        Input SQL query if a database file is read.
    cache: bool
        Use an existing catalog whenever available. Otherwise, always overwrite
        the one in disk.
    """

    def __init__(
@@ -50,6 +54,7 @@ class CatalogCombined:
        catalog_star=None,
        catalog_binary=None,
        sql_query=None,
        cache=True,
    ):
        """
        Initialize CombinedCatalog.
@@ -61,14 +66,16 @@ class CatalogCombined:
        self.catalog_binary = catalog_binary

        # NOTE: short-circuit for an existing truth catalog
        if os.path.exists(filename := self.get_filename()):
        if cache and os.path.exists(filename := self.get_filename()):
            logger.info(f"Found catalog FITS file {filename}")
            self.catalog_combined = util.read_fits(filename)
            return

        # NOTE: short-circuit for an existing database truth catalog
        if sql_query is not None and (
            filenames := glob.glob(f"{self.dirname}/db/**/master.db", recursive=True)
        if (
            cache
            and sql_query is not None
            and (filenames := glob.glob(f"{self.dirname}/db/**/master.db", recursive=True))
        ):
            import sqlite3