Loading tests/lsst_inaf_agile/test_catalog_combined.py +103 −49 Original line number Diff line number Diff line #!/usr/bin/env python3 # Author: Akke Viitanen # Email: akke.viitanen@helsinki.fi # Date: 2025-07-03 19:33:15 # Date: 2025-12-11 17:12:44 """Test the combined catalog.""" """Test the combined catalog of AGNs, galaxies, and stars.""" import logging import os from unittest import TestCase import numpy as np from lsst_inaf_agile.catalog_agn import CatalogAGN from lsst_inaf_agile.catalog_combined import CatalogCombined from lsst_inaf_agile.catalog_galaxy import CatalogGalaxy from lsst_inaf_agile.catalog_star import CatalogStar from lsst_inaf_agile.egg import Egg from lsst_inaf_agile.image_simulator import ImageSimulator from lsst_inaf_agile.merloni2014 import Merloni2014 logger = logging.getLogger(__name__) def create_combined_catalog(): dirname = "data/tests/test_catalog_combined" def get_catalog_combined(dirname): """Return a test CatalogCombined object.""" os.makedirs(dirname, exist_ok=True) # Galaxy filename = f"{dirname}/egg.fits" egg_kwargs = Egg.get_example_egg_kwargs(filename) egg = Egg(egg_kwargs) egg.run() catalog_egg = egg.read(filename) catalog_galaxy = CatalogGalaxy(dirname, catalog_egg) # Initialize EGG egg = Egg.run_config("etc/config_egg.ini") # Create the individual catalogs catalog_galaxy = CatalogGalaxy(dirname, egg) # AGN catalog_agn = CatalogAGN( dirname=dirname, catalog_galaxy=catalog_galaxy, dirname, catalog_galaxy, type_plambda="zou+2024", save_sed=1, seed=20250621, seed=20251211, merloni2014=Merloni2014(1, 0, 0.05, 0.95), filter_db="data/egg/share/filter-db/db.dat", ) # Stars catalog_star = CatalogStar(dirname, catalog_galaxy, is_binary=False) catalog_binary = CatalogStar(dirname, catalog_galaxy, is_binary=True) # Create the combined catalog catalog_combined = CatalogCombined(dirname, catalog_galaxy, catalog_agn, catalog_star, catalog_binary) assert np.isclose(catalog_combined.get_area(), 0.01) return catalog_combined def main(): # Setup the dirname dirname = "data/catalog/test" # Get the combined catalog catalog_combined = get_catalog_combined(dirname) # Create the reference catalog maglim = 24 selection_band = "lsst-r" catalog_combined.write_reference_catalog(f"{dirname}/reference_catalog.csv", maglim, selection_band) # Simulate images image_simulator = ImageSimulator( f"{dirname}/imsim", catalog_combined, "data/baseline/baseline_v4.0_10yrs.db" ) # NOTE: select the first visit from COSMOS DDF visits = image_simulator.get_visit() select = visits["target_name"] == "DD:COSMOS" observation_id = visits["observationId"][select].iloc[0] ra_dec = +150.11916667, +2.20583333 image_simulator.write_instance_catalog(observation_id, ra_dec=ra_dec) image_simulator.simulate_image(observation_id, detector=94) if __name__ == "__main__": main() class TestCatalogCombined(TestCase): def test_init(self): # non-existing init # existing truth catalog # existing database ... def test_get_filename(self): # make sure makes sense ... def test_get_dtype(self): # check for some obvious columns ... def test_get_number_galaxy_star_binary(self): # not much to check here honestly ... def test_get_catalog_combined(self): # check id # check galaxy columns # check agn columns # check stellar flags are false ... def test_postprocess(self): # check has _total fluxes # check has _total magabs # range check fluxed and magabs ... def test_get_flux_total(self): # bands # observed flux # restframe absolute magnitude ... def test_write(self): # check exists ... def test_ingest(self): # ingest to a database and a table # ingest to another table # check few if_exists ... def test_get_is_galaxy(self): # check ID # check Ngalaxy ... def test_get_is_star(self): # check ID # check Nstar ... def test_get_index_star(self): # check against star table ... def test_write_reference_catalog(self): # write reference catalog # write it again -> NOP # redo the above with an existing reference_catalog dirname # make sure rm -rfv is called ... def test_get_area(self): # try with egg.fits # try without egg.fts ... def test_getitem(self, key): # try items compared against their catalog values ... def test_get_luminosity_function(self): # try select None or some vector # try values None or some vector # try deredden None or some vector # try occupation fraction None or some vector # try overflowing z ranges ... Loading
tests/lsst_inaf_agile/test_catalog_combined.py +103 −49 Original line number Diff line number Diff line #!/usr/bin/env python3 # Author: Akke Viitanen # Email: akke.viitanen@helsinki.fi # Date: 2025-07-03 19:33:15 # Date: 2025-12-11 17:12:44 """Test the combined catalog.""" """Test the combined catalog of AGNs, galaxies, and stars.""" import logging import os from unittest import TestCase import numpy as np from lsst_inaf_agile.catalog_agn import CatalogAGN from lsst_inaf_agile.catalog_combined import CatalogCombined from lsst_inaf_agile.catalog_galaxy import CatalogGalaxy from lsst_inaf_agile.catalog_star import CatalogStar from lsst_inaf_agile.egg import Egg from lsst_inaf_agile.image_simulator import ImageSimulator from lsst_inaf_agile.merloni2014 import Merloni2014 logger = logging.getLogger(__name__) def create_combined_catalog(): dirname = "data/tests/test_catalog_combined" def get_catalog_combined(dirname): """Return a test CatalogCombined object.""" os.makedirs(dirname, exist_ok=True) # Galaxy filename = f"{dirname}/egg.fits" egg_kwargs = Egg.get_example_egg_kwargs(filename) egg = Egg(egg_kwargs) egg.run() catalog_egg = egg.read(filename) catalog_galaxy = CatalogGalaxy(dirname, catalog_egg) # Initialize EGG egg = Egg.run_config("etc/config_egg.ini") # Create the individual catalogs catalog_galaxy = CatalogGalaxy(dirname, egg) # AGN catalog_agn = CatalogAGN( dirname=dirname, catalog_galaxy=catalog_galaxy, dirname, catalog_galaxy, type_plambda="zou+2024", save_sed=1, seed=20250621, seed=20251211, merloni2014=Merloni2014(1, 0, 0.05, 0.95), filter_db="data/egg/share/filter-db/db.dat", ) # Stars catalog_star = CatalogStar(dirname, catalog_galaxy, is_binary=False) catalog_binary = CatalogStar(dirname, catalog_galaxy, is_binary=True) # Create the combined catalog catalog_combined = CatalogCombined(dirname, catalog_galaxy, catalog_agn, catalog_star, catalog_binary) assert np.isclose(catalog_combined.get_area(), 0.01) return catalog_combined def main(): # Setup the dirname dirname = "data/catalog/test" # Get the combined catalog catalog_combined = get_catalog_combined(dirname) # Create the reference catalog maglim = 24 selection_band = "lsst-r" catalog_combined.write_reference_catalog(f"{dirname}/reference_catalog.csv", maglim, selection_band) # Simulate images image_simulator = ImageSimulator( f"{dirname}/imsim", catalog_combined, "data/baseline/baseline_v4.0_10yrs.db" ) # NOTE: select the first visit from COSMOS DDF visits = image_simulator.get_visit() select = visits["target_name"] == "DD:COSMOS" observation_id = visits["observationId"][select].iloc[0] ra_dec = +150.11916667, +2.20583333 image_simulator.write_instance_catalog(observation_id, ra_dec=ra_dec) image_simulator.simulate_image(observation_id, detector=94) if __name__ == "__main__": main() class TestCatalogCombined(TestCase): def test_init(self): # non-existing init # existing truth catalog # existing database ... def test_get_filename(self): # make sure makes sense ... def test_get_dtype(self): # check for some obvious columns ... def test_get_number_galaxy_star_binary(self): # not much to check here honestly ... def test_get_catalog_combined(self): # check id # check galaxy columns # check agn columns # check stellar flags are false ... def test_postprocess(self): # check has _total fluxes # check has _total magabs # range check fluxed and magabs ... def test_get_flux_total(self): # bands # observed flux # restframe absolute magnitude ... def test_write(self): # check exists ... def test_ingest(self): # ingest to a database and a table # ingest to another table # check few if_exists ... def test_get_is_galaxy(self): # check ID # check Ngalaxy ... def test_get_is_star(self): # check ID # check Nstar ... def test_get_index_star(self): # check against star table ... def test_write_reference_catalog(self): # write reference catalog # write it again -> NOP # redo the above with an existing reference_catalog dirname # make sure rm -rfv is called ... def test_get_area(self): # try with egg.fits # try without egg.fts ... def test_getitem(self, key): # try items compared against their catalog values ... def test_get_luminosity_function(self): # try select None or some vector # try values None or some vector # try deredden None or some vector # try occupation fraction None or some vector # try overflowing z ranges ...