Unverified Commit cb17f851 authored by Akke Viitanen's avatar Akke Viitanen
Browse files

add documentation

parent 046e4437
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -113,3 +113,10 @@ repos:
        language: system
        pass_filenames: false
        always_run: true

  # pydocstyle
  - repo: https://github.com/PyCQA/pydocstyle
    rev: 6.3.0
    hooks:
    - id: pydocstyle
      args: ["--ignore=D100,D104,D203,D212"]
+2 −0
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ requires = [
]
build-backend = "setuptools.build_meta"

[tool.pydocstyle]

[tool.setuptools_scm]
write_to = "src/lsst_inaf_agile/_version.py"

+3 −3
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ version_tuple: VERSION_TUPLE
commit_id: COMMIT_ID
__commit_id__: COMMIT_ID

__version__ = version = "0.1.dev42+g5d8957f44.d20250930"
__version_tuple__ = version_tuple = (0, 1, "dev42", "g5d8957f44.d20250930")
__version__ = version = "0.1.dev43+g046e4437a.d20250930"
__version_tuple__ = version_tuple = (0, 1, "dev43", "g046e4437a.d20250930")

__commit_id__ = commit_id = "g5d8957f44"
__commit_id__ = commit_id = "g046e4437a"
+32 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
# Email: akke.viitanen@helsinki.fi
# Date: 2025-07-03 19:47:54

""" """
"""Implement CatalogStar class."""

import logging
import os
@@ -20,7 +20,25 @@ logger = logging.getLogger()


class CatalogStar:
    """
    CatalogStar class.

    Catalog star correspond to the stellar catalog (either star OR binary).
    Refer to dal Tio+ for the details.

    Attributes
    ----------
    dirname: str
        directory name in which to store the catalogs
    catalog_galaxy: CatalogGalaxy
        underlying galaxy catalog (used for determining the area)
    is_binary: bool
        True if is binary star catalog.

    """

    def __init__(self, dirname, catalog_galaxy, is_binary):
        """Init StarCatalog."""
        self.dirname = dirname
        self.catalog_galaxy = catalog_galaxy
        self.is_binary = is_binary
@@ -33,6 +51,7 @@ class CatalogStar:
        self.catalog = self.get_catalog()

    def get_catalog(self):
        """Build the star catalog."""
        vals = []
        dtype = []

@@ -67,9 +86,11 @@ class CatalogStar:
        return self.catalog

    def __getitem__(self, k):
        """Return column corresponding to 'k'."""
        return self.catalog[k]

    def get_stars(self, selection="rmag", maglim=28, fbin=1.0):
        """Query NOIRlab to retrieve the stellar catalogs from LSST-SIM."""
        if os.path.exists(self.filename):
            logger.info(f"Reading {self.filename}")
            return fitsio.read(self.filename)
@@ -100,11 +121,13 @@ class CatalogStar:
        return table

    def is_cepheid(self, i):
        """Return true if star 'i' is a cepheid star."""
        label = self.stars["label"][i]
        pmode = self.stars["pmode"][i]
        return (label >= 4) & (label <= 6) & (pmode >= 0) & (pmode <= 1)

    def is_lpv(self, i, orich=True, crich=True, c_o=None):
        """Return true if star 'i' is a long-period variable star."""
        label = self.stars["label"][i]
        pmode = self.stars["pmode"][i]
        select = (label >= 7) & (label <= 8) & (pmode >= 0) & (pmode <= 4)
@@ -119,6 +142,11 @@ class CatalogStar:
        return select

    def get_lightcurve_mjd(self, i, band, mjd, mjd0):
        """
        Estimate a star lightcurve.

        Convenience function for handling all different classes of stars.
        """
        args = i, band, mjd, mjd0

        # Handle binary stars
@@ -136,6 +164,7 @@ class CatalogStar:
        return self.catalog[f"{band}_point"][i]

    def get_lightcurve_mjd_cepheid(self, i, band, mjd, mjd0):
        """Estimate a cepheid star lightcurve."""
        pmode = self.stars["pmode"][i]
        period = self.stars[f"period{pmode}"][i]
        kwargs = {
@@ -155,6 +184,7 @@ class CatalogStar:
        return lightcurve.get_lightcurve_cepheid(**kwargs)

    def get_lightcurve_mjd_lpv(self, i, band, mjd, mjd0, is_c_rich):
        """Estimate a long-period variable star lightcurve."""
        pmode = self.stars["pmode"][i]
        period = self.stars[f"period{pmode}"][i]
        kwargs = {
@@ -169,6 +199,7 @@ class CatalogStar:
        return lightcurve.get_lightcurve_lpv(**kwargs)

    def get_lightcurve_mjd_binary(self, i, band, mjd, mjd0):
        """Estimate a binary star lightcurve."""
        s = self.stars[i]

        def get_radius_star(mass, log_gravity_surface):
+51 −5
Original line number Diff line number Diff line
@@ -3,9 +3,7 @@
# Email: akke.viitanen@helsinki.fi
# Date: 2025-07-04 20:39:49

"""
Image simulation tools
"""
"""Image simulation tools."""

import logging
import os
@@ -19,7 +17,27 @@ logger = logging.getLogger(__name__)


class ImageSimulator:
    """
    ImageSimulator class.

    ImageSimulator interfaces with CatalogCombined in order to write instance
    catalogs and produce simulated images starting from the truth catalog. The
    class may further wrap around external image simulation software like
    galsim.

    Attributes
    ----------
    dirnane: str
        directory name to write output products to
    catalog: CatalogCombined
        underlying combined catalog
    filename_baseline: str
        filename of the baseline sqlite3 database to read input values from

    """

    def __init__(self, dirname, catalog, filename_baseline):
        """Initialize ImageSimulator."""
        self.dirname = dirname
        self.catalog = catalog
        self.filename_baseline = filename_baseline
@@ -31,6 +49,7 @@ class ImageSimulator:
        logger.info(f"First MJD is {self.mjd0=}")

    def get_visit(self, observation_id=None):
        """Get the visit corresponding to the observation_id."""
        # Build the query
        query = "SELECT * FROM observations"
        if observation_id is not None:
@@ -46,6 +65,7 @@ class ImageSimulator:
        return df

    def get_header(self, observation_id, ra_dec=None):
        """Return the instance catalog header as a dictionary."""
        visit = self.get_visit(observation_id)

        if ra_dec is None:
@@ -79,10 +99,11 @@ class ImageSimulator:

    def write_instance_catalog(
        self,
        observation_id,
        exptime="38 29.2 29.2 29.2 29.2 29.2",
        observation_id: int,
        exptime: str = "38 29.2 29.2 29.2 29.2 29.2",
        ra_dec=None,  # override ra_dec?
    ):
        """Write an instance catalog to a file."""
        # Get the header and the catalog
        header = self.get_header(observation_id, ra_dec)
        b = "ugrizy"[header["filter"]]
@@ -130,6 +151,17 @@ class ImageSimulator:
                print(imsim_yaml, file=f)

    def get_catalog(self, band, mjd):
        """
        Return the instance catalog corresponding to band and mjd.

        Parameters
        ----------
        band: str
            flux band detection e.g. 'lsst-g'
        mjd: int
            MJD of observation

        """
        is_agn = self.catalog["is_agn"]
        is_galaxy = self.catalog["Z"] > 0
        is_star = ~is_galaxy
@@ -202,6 +234,20 @@ class ImageSimulator:
        return catalog

    def simulate_image(self, observation_id, detector):
        """
        Simulate a single image.

        Runs 'galsim' on a single yaml configuration file to simulate a single
        image.

        Parameters
        ----------
        observation_id: int
            observation ID to be simulated from the baseline
        detector: int
            which of the 189 detectors to simulate

        """
        dirname = f"{self.dirname}/{observation_id}"
        filename_yaml = f"{dirname}/imsim-user-instcat_{detector}.yaml"
        filename_log = filename_yaml.replace(".yaml", ".log")
Loading