Coverage for src/galsbi/ucat/plugins/write_catalog_photo.py: 92%
25 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-13 03:24 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-13 03:24 +0000
1# Copyright (C) 2019 ETH Zurich, Institute for Particle Physics and Astrophysics
3"""
4Created on Aug 2021
5author: Tomasz Kacprzak
6"""
8import os
10import h5py
11from cosmic_toolbox import logger
12from ivy.plugin.base_plugin import BasePlugin
14LOGGER = logger.get_logger(__file__)
15KW_COMPRESS = dict(compression="lzf", shuffle=True)
18def get_ucat_catalog_filename():
19 return "ucat_photo.h5"
22class Plugin(BasePlugin):
23 def __call__(self):
24 par = self.ctx.parameters
26 # columns independent of band
27 cols_base = [
28 "z",
29 "z_noisy",
30 "galaxy_type",
31 "template_coeffs",
32 "template_coeffs_abs",
33 ]
35 # make output dirs if needed
36 if not os.path.isdir(par.filepath_tile):
37 os.makedirs(par.filepath_tile)
39 # write catalogs
40 filepath_out = os.path.join(par.filepath_tile, get_ucat_catalog_filename())
41 with h5py.File(filepath_out, "w") as f:
42 for col in cols_base:
43 if hasattr(self.ctx.galaxies, col):
44 f.create_dataset(
45 name=col, data=getattr(self.ctx.galaxies, col), **KW_COMPRESS
46 )
48 for b in par.filters:
49 f.create_dataset(
50 name=f"int_mag_{b}",
51 data=self.ctx.galaxies.int_magnitude_dict[b],
52 **KW_COMPRESS,
53 )
54 f.create_dataset(
55 name=f"abs_mag_{b}",
56 data=self.ctx.galaxies.abs_magnitude_dict[b],
57 **KW_COMPRESS,
58 )
59 f.create_dataset(
60 name=f"mag_{b}",
61 data=self.ctx.galaxies.magnitude_dict[b],
62 **KW_COMPRESS,
63 )
65 def __str__(self):
66 return "write ucat photo to file"