Unverified Commit 4b44bb3b authored by Akke Esa Tapio Viitanen's avatar Akke Esa Tapio Viitanen
Browse files

add focc, tau, sf_inf columns to the datatype

parent 60f07d8e
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ class CatalogAGN:
                ("is_agn_ctn",  bool, "is Compton-thin AGN", ""),
                ("is_agn_ctk",  bool, "is Compton-thick AGN", ""),
                ("is_agn",      bool, "is Compton-thin or Compton-thick AGN", ""),
                ("is_agn_focc", bool, "has MBH and is Compton-thin or Compton-thick AGN", ""),
                ("log_LX_2_10", np.float64, "log10 of 2-10 keV intrinsic X-ray luminosity", "erg/s"),
                (
                    "log_FX_2_10",
@@ -156,14 +157,16 @@ class CatalogAGN:
                ("log_L_2500", np.float64, "Monochromatic 2500keV luminosity", "erg/s/Hz"),
                ("MBH", np.float64, "Black hole mass", "Msun"),
                ("log_L_bol", np.float64, "Bolometric AGN luminosity", "erg/s"),
                ("occupation_fraction", np.float64, "SMBH occupation fraction", ""),
                ("has_bh", bool, "Galaxy contains a SMBH according to the occupation fraction", ""),
                #("occupation_fraction", np.float64, "SMBH occupation fraction", ""),
                #("has_bh", bool, "Galaxy contains a SMBH according to the occupation fraction", ""),
            ]
            + [(b.strip() + "_point", np.float64, f"AGN {b} flux", "uJy") for b in bands]
            + [
                ("magabs_" + b.strip() + "_point", np.float64, f"AGN {b} absolute magnitude", "ABmag")
                for b in bands
            ]
            + [(b.strip() + "_tau",    np.float64, f"AGN damped random walk timescale {b}", "days") for b in bands]
            + [(b.strip() + "_sf_inf", np.float64, f"AGN damped random walk structure function at infinity", "ABmag") for b in bands]
        )

    def get_dtype(self) -> np.dtype:
@@ -725,6 +728,13 @@ class CatalogAGN:
        U = np.random.rand(self["M"].size)
        return self["occupation_fraction"] > U

    def get_is_agn_focc(self):
        """
        Return the joint probability that a galaxy has a BH and the BH is active.

        """
        return self["is_agn"] & self["has_bh"]

    def get_lightcurve(self, i, band, *args, **kwargs):
        """
        Return an AGN lightcurve.
@@ -820,12 +830,12 @@ class CatalogAGN:
            return None
        return np.interp(mjd - mjd0, util.get_mjd_vec(), lc)

    def get_tau(self, band="lsst-r"):
    def get_tau(self, i, band="lsst-r"):
        """Return the Damped Random Walk characteristic timescale tau."""
        ret = self.get_lightcurve(0, band, return_tau_sf_inf=True)
        ret = self.get_lightcurve(i, band, return_tau_sf_inf=True)
        return ret[0]

    def get_sf_inf(self, band="lsst-r", divide_sf_inf_by_z1=False):
    def get_sf_inf(self, i, band="lsst-r", divide_sf_inf_by_z1=False):
        """Return the Damped Random Walk parameter structure function at infinity."""
        ret = self.get_lightcurve(0, band, return_tau_sf_inf=True, divide_sf_inf_by_z1=divide_sf_inf_by_z1)
        ret = self.get_lightcurve(i, band, return_tau_sf_inf=True, divide_sf_inf_by_z1=divide_sf_inf_by_z1)
        return ret[1]
+13 −3
Original line number Diff line number Diff line
@@ -240,9 +240,14 @@ class CatalogCombined:

        return ret

    def write(self):
    def write(self, filename=None):
        """Write the combined catalog to a FITS file."""
        fitsio.write(self.get_filename(), self.catalog_combined, clobber=True)
        if filename is None:
            filename = self.get_filename()
        if hasattr(self.catalog_combined, "write"):
            self.catalog_combined.write(filename, overwrite=True)
        else:
            fitsio.write(filename, self.catalog_combined, clobber=True)
        return self.catalog_combined

    def ingest(self, filename_database, name_table, if_exists="replace"):
@@ -398,6 +403,11 @@ class CatalogCombined:
        """Return combined catalog value corresponding to 'key'."""
        return self.catalog_combined[key]

    def __setitem__(self, key, value):
        """Set combined catalog value to 'key'."""
        self.catalog_combined[key] = value
        return self.catalog_combined[key]

    def get_luminosity_function(
        self,
        key,
@@ -523,7 +533,7 @@ class CatalogCombined:
                    con,
                    index=False,
                    if_exists="append",
                    chunksize=1024,
                    chunksize=512,
                    method="multi",
                )
        return df