Loading src/lsst_inaf_agile/ananna2022.py +5 −7 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ # Email: akke.viitanen@helsinki.fi # Date: 2024-08-01 13:53:22 """ Implements Ananna+2022 """ """Implement Ananna+ 2022.""" import matplotlib.pyplot as plt import numpy as np Loading Loading @@ -69,10 +67,7 @@ parameters = { def get_phi_bh(m, m_star, phi_star, alpha, beta, h=1.0, sample=None): """ Return the Schechter function form of BHMF """ """Return the Schechter function form of BHMF.""" if sample: ## NOTE: errors for sigma=0.50 case # m_star = 10 ** (np.log10(m_star) + np.random.uniform(-0.20, 0.25)) Loading @@ -94,6 +89,7 @@ def get_phi_bh(m, m_star, phi_star, alpha, beta, h=1.0, sample=None): def get_phi_lambda(lambda_edd, lambda_edd_star, xi_star, delta1, epsilon_lambda, h=1.0): """Return phi_lambda following the functional form in Ananna.""" ratio = lambda_edd / lambda_edd_star return ( np.ma.true_divide(xi_star, np.power(ratio, delta1) + np.power(ratio, delta1 + epsilon_lambda)) * h**3 Loading @@ -101,6 +97,7 @@ def get_phi_lambda(lambda_edd, lambda_edd_star, xi_star, delta1, epsilon_lambda, def get_phi_bh_fig10(m, is_type1=True, is_type2=True, log_ledd_gt=-3, h=1.0): """Get phi_bh from Ananna Fig10.""" x = np.log10(m) y = np.zeros_like(m) Loading @@ -116,6 +113,7 @@ def get_phi_bh_fig10(m, is_type1=True, is_type2=True, log_ledd_gt=-3, h=1.0): def get_phi_lambda_fig10(lambda_edd, is_type1=True, is_type2=True, log_mbh_gt=6.5, h=1.0): """Get phi_lambda from Ananna Fig10.""" x = np.log10(lambda_edd) y = np.zeros_like(lambda_edd) Loading src/lsst_inaf_agile/catalog_agn.py +23 −10 Original line number Diff line number Diff line Loading @@ -84,6 +84,7 @@ class CatalogAGN: filename of the EGG filter database (db.dat) catalog: np.ndarray catalog data """ def __init__( Loading Loading @@ -125,6 +126,7 @@ class CatalogAGN: Returns ------- Value of the column. """ if key not in self.catalog.dtype.names: return self.catalog_galaxy[key] Loading @@ -147,6 +149,7 @@ class CatalogAGN: Returns ------- List of 4-tuples of column names, types, descriptions, and units. """ return ( [ Loading Loading @@ -306,6 +309,7 @@ class CatalogAGN: ---------- Gamma: float Assumed power-law index for the band conversion. """ return np.log10(util.convert_flux(10 ** self["log_FX_2_10"], 2.0, 10.0, 2.0, 7.0, Gamma=Gamma)) Loading @@ -329,11 +333,13 @@ class CatalogAGN: return lusso2010.get_log_l_2500(self["log_L_2_keV"], alpha, beta, scatter) def get_is_optical_type2(self, func_get_f_obs=None, use_f_obs_for_ctk_agn=False): """Return boolean vector selecting optical type2 AGN. """ Return boolean vector selecting optical type2 AGN. The optical type2 AGN fraction is evaluated based on Merloni+2014 assuming obscured fraction as a function of intrinsic X-ray luminosity and redshift. """ select_ctk = self["is_agn_ctk"] if func_get_f_obs is None: Loading @@ -359,10 +365,12 @@ class CatalogAGN: mu_type_2=0.3, ebv_ctk=9.0, ): """Return AGN reddening E(B-V) in ABmag. """ Return AGN reddening E(B-V) in ABmag. The E(B-V) is assumed to be different for type1 and type2 AGN, while CTK AGN are assumed to be all type2. """ type_1_ebv = (np.linspace(0, 1, 101),) type_2_ebv = (np.linspace(0, 3, 301),) Loading Loading @@ -462,7 +470,8 @@ class CatalogAGN: return self["is_agn_ctn"] + self["is_agn_ctk"] def get_sed(self, i): """Return an AGN SED. """ Return an AGN SED. Parameters ---------- Loading @@ -475,6 +484,7 @@ class CatalogAGN: Wavelength in microns. flux: array_like observer frame flux in microjanskies. """ filename = f"{self.dirname}/seds/agn-seds-{i}.fits" if not os.path.exists(filename): Loading @@ -484,7 +494,8 @@ class CatalogAGN: return fits["LAMBDA"][0], fits["FLUX"][0] def _get_sed(self, i, ratio_max=0.90, dlog_wav=7.65e-4): """Generate an AGN SED. """ Generate an AGN SED. Parameters ---------- Loading @@ -494,6 +505,7 @@ class CatalogAGN: Maximum allowed ratio flux_agn / flux_total for type2 AGN. dlog_wav: float SED wavelength resolution in dex. """ logger.debug(f"Getting AGN SED {i} {self.catalog.size}") Loading Loading @@ -568,7 +580,8 @@ class CatalogAGN: return agn_sed def _get_flux_single(self, my_sed, band, rest_frame, redshift, distance): """Return a single bandbass flux by integrating the SED. """ Return a single bandbass flux by integrating the SED. Take a rest-frame intrinsic SED and integrate it along a filter passband. The SED is shifted to either rest-frame (10pc) or observer Loading @@ -586,6 +599,7 @@ class CatalogAGN: Redshift of the SED distance: float Distance at which to evaluate the flux. """ # Get the flux in observed frame or rest frame if rest_frame: Loading Loading @@ -636,15 +650,12 @@ class CatalogAGN: def get_MBH( self, sigma_total=0.50, offset=0.00, sigma_intrinsic=False, sigma_observational=None, select=None ): """Return log10 of the supermassive black hole mass in Msun. """ Return log10 of the supermassive black hole mass in Msun. The MBH is assigned in accordance with the continuity equation after which log-normal scatter is added to the final value of the MBH. Parameters ---------- sigma_total: float Magnitude of log-normal scatter in dex. """ # Get MBH log_mbh = get_log_mbh_continuity_new2(self["M"], self["Z"]) Loading Loading @@ -741,6 +752,7 @@ class CatalogAGN: EGG-style passband name. mjd: float or array_like or None MJD of observation. """ if mjd is None: mjd = util.get_mjd_vec() Loading Loading @@ -795,6 +807,7 @@ class CatalogAGN: Returns ------- The value of the lightcurve at given MJD in microjanskies. """ lc = self.get_lightcurve(i, band) return np.interp(mjd - mjd0, util.get_mjd_vec(), lc) src/lsst_inaf_agile/catalog_combined.py +28 −31 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ class CatalogCombined: Single star catalog. catalog_binary: catalog_star.CatalogStar or None Binary star catalog. """ def __init__( Loading @@ -63,6 +64,7 @@ class CatalogCombined: catalog_binary=None, sql_query=None, ): """Initialize CombinedCatalog.""" self.dirname = dirname self.catalog_galaxy = catalog_galaxy self.catalog_agn = catalog_agn Loading Loading @@ -95,7 +97,7 @@ class CatalogCombined: self.write() def get_filename(self): """Return the FITS filename of the combined catalog""" """Return the FITS filename of the combined catalog.""" return f"{self.dirname}/catalog.fits" def get_dtype(self): Loading @@ -105,6 +107,7 @@ class CatalogCombined: Returns ------- List of (name, type) corresponding to the names and types of the columns. """ dtype = {} for catalog in (self.catalog_galaxy, self.catalog_agn, self.catalog_star, self.catalog_binary): Loading @@ -121,8 +124,10 @@ class CatalogCombined: def get_number_galaxy_star_binary(self): """ Return the tuple (N_galaxy, N_star, N_binary) where N is the number of objects in the combined catalog. Return the tuple (N_galaxy, N_star, N_binary). N is the number of objects in the combined catalog. """ return ( len(self.catalog_galaxy.catalog), Loading @@ -132,7 +137,7 @@ class CatalogCombined: def get_catalog_combined(self): r""" Constructs the combined catalog based on the dtype. Construct the combined catalog based on the dtype. For each column in the catalog, the column is looked for in the AGN/galaxy/star/binary catalogs. Upon a match, the corresponding rows Loading @@ -146,8 +151,8 @@ class CatalogCombined: Returns ------- The combined catalog as a numpy ndarray. """ """ n_galaxy, n_star, n_binary = self.get_number_galaxy_star_binary() n_total = n_galaxy + n_star + n_binary catalog_combined = np.full(n_total, np.nan, dtype=self.get_dtype()) Loading Loading @@ -184,10 +189,7 @@ class CatalogCombined: return catalog_combined def postprocess(self): """ Adds columns in post-processing """ """Add columns in post-processing.""" for band in self.catalog_galaxy.bands: logger.info(f"Postprocessing flux {band}") self.catalog_combined[band + "_total"] = self.get_flux_total(band, False) Loading @@ -207,8 +209,8 @@ class CatalogCombined: - galaxy: sum of galaxy bulge and disk fluxes - star: point fluxes - binary star: sum of the component point fluxes """ """ # NOTE: override rest-frame behavior as EGG does not have absmags for # disk/bulge separately keys = ["disk", "bulge", "point"] Loading @@ -230,9 +232,7 @@ class CatalogCombined: return ret def write(self): """ Writes the combined catalog to a FITS file """ """Write the combined catalog to a FITS file.""" fitsio.write(self.get_filename(), self.catalog_combined, clobber=True) return self.catalog_combined Loading @@ -246,8 +246,10 @@ class CatalogCombined: filename of the sqlite3 database name_table: str name of the table in the sqlite3 database """ if_exists: str sqlite3 action to handle an existing table """ import sqlite3 from astropy.table import Table Loading @@ -260,28 +262,23 @@ class CatalogCombined: df.to_sql(name_table, con, index=False, if_exists=if_exists, chunksize=1024, method="multi") def get_is_galaxy(self): """ Return boolean vector selecting galaxies """ """Return boolean vector selecting galaxies.""" return np.isfinite(self.catalog_combined["Z"]) def get_is_star(self): """ Return boolean vector selecting stars """ """Return boolean vector selecting stars.""" return ~self.get_is_galaxy() def get_index_star(self, i): """ Return the index in the stellar catalog corresponding to 'i' in the combined catalog. Return the index in the stellar catalog corresponding to 'i' in the combined catalog. Parameters ---------- i: int ID of the truth catalog object """ """ n_galaxy, n_star, n_binary = self.get_number_galaxy_star_binary() # Handles single star Loading @@ -297,11 +294,12 @@ class CatalogCombined: def write_reference_catalog(self, filename: str, maglim: float, selection_band: str): """ Write a mock LSST reference catalog in CSV format to the given 'filename'. The reference catalog is cut to brighter than the magnitude limit 'maglim' in the band 'selection_band'. """ Write a mock LSST reference catalog in CSV format to the given 'filename'. The reference catalog is cut to brighter than the magnitude limit 'maglim' in the band 'selection_band'. """ logger.info("Writing the reference catalog...") if os.path.exists(filename): logger.info(f"{filename} exists, will not overwrite.") Loading Loading @@ -384,9 +382,7 @@ class CatalogCombined: return 24.0 def __getitem__(self, key): """ Return combined catalog value corresponding to 'key'. """ """Return combined catalog value corresponding to 'key'.""" return self.catalog_combined[key] def get_luminosity_function( Loading Loading @@ -418,6 +414,8 @@ class CatalogCombined: maximum redshift select: array_like boolean vector for selecting values values: array_like values to use instead of the value corresponding to 'key' nmin: int minimum allowed counts per bin deredden: bool Loading @@ -426,7 +424,6 @@ class CatalogCombined: weight LF by occupation fraction """ # select in redshift z = self["Z"] if select is None: Loading src/lsst_inaf_agile/convert_agile_manager.py +6 −6 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ # Email: akke.viitanen@helsinki.fi # Date: 2025-09-12 00:39:53 """ Middleware for reference catalog config """ """Middleware for reference catalog config.""" import numpy as np import util Loading @@ -14,9 +12,11 @@ from lsst.meas.algorithms.convertRefcatManager import ConvertGaiaManager class ConvertAgileManager(ConvertGaiaManager): """ Convert from AGILE to the reference catalog format. This class is piggybacking on the existing Gaia converter (proper motions, covariances), but only overloads the way fluxes are handled. Convert from AGILE to the reference catalog format. The class is piggybacking on the existing Gaia converter (proper motions, covariances), but only overloads the way fluxes are handled. """ def _getFluxes(self, input): Loading src/lsst_inaf_agile/egg.py +30 −6 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ # Email: akke.viitanen@helsinki.fi # Date: 2023-04-12 22:44:16 """ Wrapper for calling egg """ """Impelement wrapper for calling egg.""" import logging import os Loading @@ -26,15 +24,36 @@ if not shutil.which("egg-gencat"): class Egg: """ EGG class. Provie a wrapper for the EGG command-line software. Attributes ---------- egg_kwargs: dict list of EGG key value pairs used to construct the EGG command-line arguments. Examples -------- >>> # Create an EGG object with 1deg2 area and logM > 9.5 (Chabrier) >>> # follow-it by calling egg.run() ... >>> egg = Egg({'area': 1, 'mmin': 9.5}) """ def __init__(self, egg_kwargs): """Initialize EGG.""" self.egg_kwargs = egg_kwargs def get_argument_line(self): """Get the EGG argument line for calling it from the terminal.""" exclude = [] egg_kwargs = {k: v for k, v in self.egg_kwargs.items()} return sorted([f"{k}={str(v)}" for k, v in egg_kwargs.items() if k not in exclude]) def get_filename(self): """Return an example filename constructed from the kwargs.""" if "out" in self.egg_kwargs: return self.egg_kwargs["out"] Loading @@ -46,9 +65,11 @@ class Egg: return filename def get_area(self): """Return EGG catalog area.""" return self.egg_kwargs["area"] def run(self, overwrite=False): """Run EGG using the kwargs supplied.""" cmd = " ".join(["egg-gencat"] + self.get_argument_line()) filename = self.get_filename() if not overwrite and os.path.exists(filename): Loading @@ -62,7 +83,7 @@ class Egg: return os.system(cmd) def get_sed(self, i): """Return a EGG SED""" """Return an EGG SED.""" import fitsio dirname = os.path.dirname(self.egg_kwargs["save_sed"]) Loading @@ -78,6 +99,8 @@ class Egg: @staticmethod def read(filename): """ Read an EGG catalog from the filename. Note that usually and for small files, loading EGG through astropy/fitsio works fine. For large files (n_bands * n_galaxies >= 2 ** 28) these routines fail due to the dtype not fitting into a C Loading @@ -90,7 +113,6 @@ class Egg: This is a dirty hack, but the alternative is to change completely how EGG writes the FITS files. """ import fitsio import numpy as np Loading Loading @@ -154,6 +176,7 @@ class Egg: @staticmethod def get_smf(z, key, filename): """Read an EGG-like stellar mass function from a file.""" import fitsio import numpy as np Loading @@ -174,8 +197,8 @@ class Egg: Run EGG for the given configuration file. Returns the EGG catalog using Egg.read. """ """ logger.info(f"Reading {config}") config = ConfigParser() config.read("etc/config_egg.ini") Loading @@ -186,6 +209,7 @@ class Egg: def main(): """Run EGG using an example config file.""" Egg.run_config("etc/config_egg.ini") Loading Loading
src/lsst_inaf_agile/ananna2022.py +5 −7 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ # Email: akke.viitanen@helsinki.fi # Date: 2024-08-01 13:53:22 """ Implements Ananna+2022 """ """Implement Ananna+ 2022.""" import matplotlib.pyplot as plt import numpy as np Loading Loading @@ -69,10 +67,7 @@ parameters = { def get_phi_bh(m, m_star, phi_star, alpha, beta, h=1.0, sample=None): """ Return the Schechter function form of BHMF """ """Return the Schechter function form of BHMF.""" if sample: ## NOTE: errors for sigma=0.50 case # m_star = 10 ** (np.log10(m_star) + np.random.uniform(-0.20, 0.25)) Loading @@ -94,6 +89,7 @@ def get_phi_bh(m, m_star, phi_star, alpha, beta, h=1.0, sample=None): def get_phi_lambda(lambda_edd, lambda_edd_star, xi_star, delta1, epsilon_lambda, h=1.0): """Return phi_lambda following the functional form in Ananna.""" ratio = lambda_edd / lambda_edd_star return ( np.ma.true_divide(xi_star, np.power(ratio, delta1) + np.power(ratio, delta1 + epsilon_lambda)) * h**3 Loading @@ -101,6 +97,7 @@ def get_phi_lambda(lambda_edd, lambda_edd_star, xi_star, delta1, epsilon_lambda, def get_phi_bh_fig10(m, is_type1=True, is_type2=True, log_ledd_gt=-3, h=1.0): """Get phi_bh from Ananna Fig10.""" x = np.log10(m) y = np.zeros_like(m) Loading @@ -116,6 +113,7 @@ def get_phi_bh_fig10(m, is_type1=True, is_type2=True, log_ledd_gt=-3, h=1.0): def get_phi_lambda_fig10(lambda_edd, is_type1=True, is_type2=True, log_mbh_gt=6.5, h=1.0): """Get phi_lambda from Ananna Fig10.""" x = np.log10(lambda_edd) y = np.zeros_like(lambda_edd) Loading
src/lsst_inaf_agile/catalog_agn.py +23 −10 Original line number Diff line number Diff line Loading @@ -84,6 +84,7 @@ class CatalogAGN: filename of the EGG filter database (db.dat) catalog: np.ndarray catalog data """ def __init__( Loading Loading @@ -125,6 +126,7 @@ class CatalogAGN: Returns ------- Value of the column. """ if key not in self.catalog.dtype.names: return self.catalog_galaxy[key] Loading @@ -147,6 +149,7 @@ class CatalogAGN: Returns ------- List of 4-tuples of column names, types, descriptions, and units. """ return ( [ Loading Loading @@ -306,6 +309,7 @@ class CatalogAGN: ---------- Gamma: float Assumed power-law index for the band conversion. """ return np.log10(util.convert_flux(10 ** self["log_FX_2_10"], 2.0, 10.0, 2.0, 7.0, Gamma=Gamma)) Loading @@ -329,11 +333,13 @@ class CatalogAGN: return lusso2010.get_log_l_2500(self["log_L_2_keV"], alpha, beta, scatter) def get_is_optical_type2(self, func_get_f_obs=None, use_f_obs_for_ctk_agn=False): """Return boolean vector selecting optical type2 AGN. """ Return boolean vector selecting optical type2 AGN. The optical type2 AGN fraction is evaluated based on Merloni+2014 assuming obscured fraction as a function of intrinsic X-ray luminosity and redshift. """ select_ctk = self["is_agn_ctk"] if func_get_f_obs is None: Loading @@ -359,10 +365,12 @@ class CatalogAGN: mu_type_2=0.3, ebv_ctk=9.0, ): """Return AGN reddening E(B-V) in ABmag. """ Return AGN reddening E(B-V) in ABmag. The E(B-V) is assumed to be different for type1 and type2 AGN, while CTK AGN are assumed to be all type2. """ type_1_ebv = (np.linspace(0, 1, 101),) type_2_ebv = (np.linspace(0, 3, 301),) Loading Loading @@ -462,7 +470,8 @@ class CatalogAGN: return self["is_agn_ctn"] + self["is_agn_ctk"] def get_sed(self, i): """Return an AGN SED. """ Return an AGN SED. Parameters ---------- Loading @@ -475,6 +484,7 @@ class CatalogAGN: Wavelength in microns. flux: array_like observer frame flux in microjanskies. """ filename = f"{self.dirname}/seds/agn-seds-{i}.fits" if not os.path.exists(filename): Loading @@ -484,7 +494,8 @@ class CatalogAGN: return fits["LAMBDA"][0], fits["FLUX"][0] def _get_sed(self, i, ratio_max=0.90, dlog_wav=7.65e-4): """Generate an AGN SED. """ Generate an AGN SED. Parameters ---------- Loading @@ -494,6 +505,7 @@ class CatalogAGN: Maximum allowed ratio flux_agn / flux_total for type2 AGN. dlog_wav: float SED wavelength resolution in dex. """ logger.debug(f"Getting AGN SED {i} {self.catalog.size}") Loading Loading @@ -568,7 +580,8 @@ class CatalogAGN: return agn_sed def _get_flux_single(self, my_sed, band, rest_frame, redshift, distance): """Return a single bandbass flux by integrating the SED. """ Return a single bandbass flux by integrating the SED. Take a rest-frame intrinsic SED and integrate it along a filter passband. The SED is shifted to either rest-frame (10pc) or observer Loading @@ -586,6 +599,7 @@ class CatalogAGN: Redshift of the SED distance: float Distance at which to evaluate the flux. """ # Get the flux in observed frame or rest frame if rest_frame: Loading Loading @@ -636,15 +650,12 @@ class CatalogAGN: def get_MBH( self, sigma_total=0.50, offset=0.00, sigma_intrinsic=False, sigma_observational=None, select=None ): """Return log10 of the supermassive black hole mass in Msun. """ Return log10 of the supermassive black hole mass in Msun. The MBH is assigned in accordance with the continuity equation after which log-normal scatter is added to the final value of the MBH. Parameters ---------- sigma_total: float Magnitude of log-normal scatter in dex. """ # Get MBH log_mbh = get_log_mbh_continuity_new2(self["M"], self["Z"]) Loading Loading @@ -741,6 +752,7 @@ class CatalogAGN: EGG-style passband name. mjd: float or array_like or None MJD of observation. """ if mjd is None: mjd = util.get_mjd_vec() Loading Loading @@ -795,6 +807,7 @@ class CatalogAGN: Returns ------- The value of the lightcurve at given MJD in microjanskies. """ lc = self.get_lightcurve(i, band) return np.interp(mjd - mjd0, util.get_mjd_vec(), lc)
src/lsst_inaf_agile/catalog_combined.py +28 −31 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ class CatalogCombined: Single star catalog. catalog_binary: catalog_star.CatalogStar or None Binary star catalog. """ def __init__( Loading @@ -63,6 +64,7 @@ class CatalogCombined: catalog_binary=None, sql_query=None, ): """Initialize CombinedCatalog.""" self.dirname = dirname self.catalog_galaxy = catalog_galaxy self.catalog_agn = catalog_agn Loading Loading @@ -95,7 +97,7 @@ class CatalogCombined: self.write() def get_filename(self): """Return the FITS filename of the combined catalog""" """Return the FITS filename of the combined catalog.""" return f"{self.dirname}/catalog.fits" def get_dtype(self): Loading @@ -105,6 +107,7 @@ class CatalogCombined: Returns ------- List of (name, type) corresponding to the names and types of the columns. """ dtype = {} for catalog in (self.catalog_galaxy, self.catalog_agn, self.catalog_star, self.catalog_binary): Loading @@ -121,8 +124,10 @@ class CatalogCombined: def get_number_galaxy_star_binary(self): """ Return the tuple (N_galaxy, N_star, N_binary) where N is the number of objects in the combined catalog. Return the tuple (N_galaxy, N_star, N_binary). N is the number of objects in the combined catalog. """ return ( len(self.catalog_galaxy.catalog), Loading @@ -132,7 +137,7 @@ class CatalogCombined: def get_catalog_combined(self): r""" Constructs the combined catalog based on the dtype. Construct the combined catalog based on the dtype. For each column in the catalog, the column is looked for in the AGN/galaxy/star/binary catalogs. Upon a match, the corresponding rows Loading @@ -146,8 +151,8 @@ class CatalogCombined: Returns ------- The combined catalog as a numpy ndarray. """ """ n_galaxy, n_star, n_binary = self.get_number_galaxy_star_binary() n_total = n_galaxy + n_star + n_binary catalog_combined = np.full(n_total, np.nan, dtype=self.get_dtype()) Loading Loading @@ -184,10 +189,7 @@ class CatalogCombined: return catalog_combined def postprocess(self): """ Adds columns in post-processing """ """Add columns in post-processing.""" for band in self.catalog_galaxy.bands: logger.info(f"Postprocessing flux {band}") self.catalog_combined[band + "_total"] = self.get_flux_total(band, False) Loading @@ -207,8 +209,8 @@ class CatalogCombined: - galaxy: sum of galaxy bulge and disk fluxes - star: point fluxes - binary star: sum of the component point fluxes """ """ # NOTE: override rest-frame behavior as EGG does not have absmags for # disk/bulge separately keys = ["disk", "bulge", "point"] Loading @@ -230,9 +232,7 @@ class CatalogCombined: return ret def write(self): """ Writes the combined catalog to a FITS file """ """Write the combined catalog to a FITS file.""" fitsio.write(self.get_filename(), self.catalog_combined, clobber=True) return self.catalog_combined Loading @@ -246,8 +246,10 @@ class CatalogCombined: filename of the sqlite3 database name_table: str name of the table in the sqlite3 database """ if_exists: str sqlite3 action to handle an existing table """ import sqlite3 from astropy.table import Table Loading @@ -260,28 +262,23 @@ class CatalogCombined: df.to_sql(name_table, con, index=False, if_exists=if_exists, chunksize=1024, method="multi") def get_is_galaxy(self): """ Return boolean vector selecting galaxies """ """Return boolean vector selecting galaxies.""" return np.isfinite(self.catalog_combined["Z"]) def get_is_star(self): """ Return boolean vector selecting stars """ """Return boolean vector selecting stars.""" return ~self.get_is_galaxy() def get_index_star(self, i): """ Return the index in the stellar catalog corresponding to 'i' in the combined catalog. Return the index in the stellar catalog corresponding to 'i' in the combined catalog. Parameters ---------- i: int ID of the truth catalog object """ """ n_galaxy, n_star, n_binary = self.get_number_galaxy_star_binary() # Handles single star Loading @@ -297,11 +294,12 @@ class CatalogCombined: def write_reference_catalog(self, filename: str, maglim: float, selection_band: str): """ Write a mock LSST reference catalog in CSV format to the given 'filename'. The reference catalog is cut to brighter than the magnitude limit 'maglim' in the band 'selection_band'. """ Write a mock LSST reference catalog in CSV format to the given 'filename'. The reference catalog is cut to brighter than the magnitude limit 'maglim' in the band 'selection_band'. """ logger.info("Writing the reference catalog...") if os.path.exists(filename): logger.info(f"{filename} exists, will not overwrite.") Loading Loading @@ -384,9 +382,7 @@ class CatalogCombined: return 24.0 def __getitem__(self, key): """ Return combined catalog value corresponding to 'key'. """ """Return combined catalog value corresponding to 'key'.""" return self.catalog_combined[key] def get_luminosity_function( Loading Loading @@ -418,6 +414,8 @@ class CatalogCombined: maximum redshift select: array_like boolean vector for selecting values values: array_like values to use instead of the value corresponding to 'key' nmin: int minimum allowed counts per bin deredden: bool Loading @@ -426,7 +424,6 @@ class CatalogCombined: weight LF by occupation fraction """ # select in redshift z = self["Z"] if select is None: Loading
src/lsst_inaf_agile/convert_agile_manager.py +6 −6 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ # Email: akke.viitanen@helsinki.fi # Date: 2025-09-12 00:39:53 """ Middleware for reference catalog config """ """Middleware for reference catalog config.""" import numpy as np import util Loading @@ -14,9 +12,11 @@ from lsst.meas.algorithms.convertRefcatManager import ConvertGaiaManager class ConvertAgileManager(ConvertGaiaManager): """ Convert from AGILE to the reference catalog format. This class is piggybacking on the existing Gaia converter (proper motions, covariances), but only overloads the way fluxes are handled. Convert from AGILE to the reference catalog format. The class is piggybacking on the existing Gaia converter (proper motions, covariances), but only overloads the way fluxes are handled. """ def _getFluxes(self, input): Loading
src/lsst_inaf_agile/egg.py +30 −6 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ # Email: akke.viitanen@helsinki.fi # Date: 2023-04-12 22:44:16 """ Wrapper for calling egg """ """Impelement wrapper for calling egg.""" import logging import os Loading @@ -26,15 +24,36 @@ if not shutil.which("egg-gencat"): class Egg: """ EGG class. Provie a wrapper for the EGG command-line software. Attributes ---------- egg_kwargs: dict list of EGG key value pairs used to construct the EGG command-line arguments. Examples -------- >>> # Create an EGG object with 1deg2 area and logM > 9.5 (Chabrier) >>> # follow-it by calling egg.run() ... >>> egg = Egg({'area': 1, 'mmin': 9.5}) """ def __init__(self, egg_kwargs): """Initialize EGG.""" self.egg_kwargs = egg_kwargs def get_argument_line(self): """Get the EGG argument line for calling it from the terminal.""" exclude = [] egg_kwargs = {k: v for k, v in self.egg_kwargs.items()} return sorted([f"{k}={str(v)}" for k, v in egg_kwargs.items() if k not in exclude]) def get_filename(self): """Return an example filename constructed from the kwargs.""" if "out" in self.egg_kwargs: return self.egg_kwargs["out"] Loading @@ -46,9 +65,11 @@ class Egg: return filename def get_area(self): """Return EGG catalog area.""" return self.egg_kwargs["area"] def run(self, overwrite=False): """Run EGG using the kwargs supplied.""" cmd = " ".join(["egg-gencat"] + self.get_argument_line()) filename = self.get_filename() if not overwrite and os.path.exists(filename): Loading @@ -62,7 +83,7 @@ class Egg: return os.system(cmd) def get_sed(self, i): """Return a EGG SED""" """Return an EGG SED.""" import fitsio dirname = os.path.dirname(self.egg_kwargs["save_sed"]) Loading @@ -78,6 +99,8 @@ class Egg: @staticmethod def read(filename): """ Read an EGG catalog from the filename. Note that usually and for small files, loading EGG through astropy/fitsio works fine. For large files (n_bands * n_galaxies >= 2 ** 28) these routines fail due to the dtype not fitting into a C Loading @@ -90,7 +113,6 @@ class Egg: This is a dirty hack, but the alternative is to change completely how EGG writes the FITS files. """ import fitsio import numpy as np Loading Loading @@ -154,6 +176,7 @@ class Egg: @staticmethod def get_smf(z, key, filename): """Read an EGG-like stellar mass function from a file.""" import fitsio import numpy as np Loading @@ -174,8 +197,8 @@ class Egg: Run EGG for the given configuration file. Returns the EGG catalog using Egg.read. """ """ logger.info(f"Reading {config}") config = ConfigParser() config.read("etc/config_egg.ini") Loading @@ -186,6 +209,7 @@ class Egg: def main(): """Run EGG using an example config file.""" Egg.run_config("etc/config_egg.ini") Loading