aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/extragalactic/pointsources/pointsources.py
diff options
context:
space:
mode:
authorJason Ma <zxma_sjtu@qq.com>2016-10-27 12:13:07 +0800
committerAaron LI <liweitianux@users.noreply.github.com>2016-10-27 12:13:07 +0800
commit2f40f984a44c393b72a62b36cf054171dabf169d (patch)
tree5eecb02290e1bf3cca47f90f9db427788d1da2b9 /fg21sim/extragalactic/pointsources/pointsources.py
parente438cde9c3ea4a35dcff974a15ee7b0203ff077f (diff)
downloadfg21sim-2f40f984a44c393b72a62b36cf054171dabf169d.tar.bz2
extragalactic/pointsource (#3)
Merge PR#3: Add new simulation component "extragalactic/pointsources", including SF, SB, RQ, FRI and FRII. * extragalactic/pointsource: add point source simulation module * extracgalactic/pointsource: add point source simulation module * Add configurating spec to extragalgactic point sources. * Modified some variables * base.py: modified * flux.py: modified * fr1.py: modified * fr2.py: modified * pointsources.py: modified * psparams.py: modified * radioquiet.py: modified * starforming.py: modified * starbursting.py: modified * Rewritten the comments. * base.py: modified * flux.py: modified * fr1.py: modified * fr2.py: modified * Modified * psparams.py: modified * radioquiet.py: modified * starforming.py: modified * starbursting.py: modified * Modified * Modified * Modified * Modified * Modified * MOdified * Modified * Modified * Modified * Modified * Modified * Modified * Modified * Modified * Modified * Changed pointsource to pointsources * Fixed some config keywords * Fixed some config keywords * Fixed some config keywords * Fixed some config keywords * Fixed some config keywords * Fixed some config keywords * Fixed some config keywords * base.py:rewrited * fr1.py:rewritten * pointsources.py: rewritten * radioquiet.py: rewritten * Rewritten * Rewritten * base.py: modified * fr1.py: modified * fr2.py: modified * radioquiet.py: modified * starbursting.py: modified * starforming.py: modified * Fix conflicts * fg21sim: fixed conflicts * base.py: modified frequencies loading in _get_configs() * Rewritten as forground.py * fg21sim: fixed conflicts * base.py: deteled loading for frequencies configurations. * fr1.py: modified * fr2.py: modified * pointsources.py: modified * radioquiet.py: modified * starbursting.py: modified * starforming.py: modified * Add new methods to calculate Tb. * Add new methods to calculate Tb. * Add new methods to calculate Tb. * Add new methods to calculate Tb. * Add new methods to calculate Tb. * Add new methods to calculate Tb. * Deleted useless comments. * Add pscomps to deal with multi-type PS problem. * Add a new key. * Fixed permission to 755. * Rejusted PS subsections. * Add methods to calcualte luminosity function and redshift distribution. * Rejusted generation of samples redshift and luminosity. * Fixed mistakes on FRII structure, added hotspots and offsets. * Reajusted generation of samples redshift and luminosity. * Readujsted generation of samples radii, redshifts and luminosity. * Readujsted generation of samples radii, redshifts and luminosity. * Fixed conflicts. * Fixed conficts. * Combined configurations of pointsources. * Removed the older extragalactic configuration file. * Fixed some mistakes. * Fixed mistakes of drawing PS. * Fixed mistakes of drawing PS. * Fixed code style by pep8 checking. * Fixed code style by pep8 checking. * Fixed code style by pep8 checking. * Fixed some coding style. * Reconfigured default redshift interval. * Reconfigured default redshift interval. * Reconfigured default redshift interval. * Fixed mistakes in method calc_single_Tb and changed resolution of grid. * Fixed mistakes in method calc_single_Tb and changed resolution of grid. * Deleted astropy.units style code to accelerate. * Deleted astropy.units style code to accelerate. * Deleted astropy.units style code to accelerate. * Deleted astropy.units style code to accelerate. * Deleted astropy.units style code to accelerate. * Deleted astropy.units style code to accelerate. * Deleted astropy.units style code to accelerate. * Fixed some mistakes. * Fixed some mistakes. * Changed dA from au.Mpc to float64. * Fixed some mistakes. * Fixed some mistakes. * Fixed some mistakes. * Reajusted grid resolution to generate discs. * Reajusted grid resolution to generate discs. * Reajusted loading strategy of parameter resolution. * Reajusted code style of configuration loading. * Reajusted code style of configuration loading. * Reajusted code style of configuration loading. * Reajusted code style of configuration loading. * Reajusted code style of configuration loading.
Diffstat (limited to 'fg21sim/extragalactic/pointsources/pointsources.py')
-rw-r--r--fg21sim/extragalactic/pointsources/pointsources.py126
1 files changed, 126 insertions, 0 deletions
diff --git a/fg21sim/extragalactic/pointsources/pointsources.py b/fg21sim/extragalactic/pointsources/pointsources.py
new file mode 100644
index 0000000..85f6ec4
--- /dev/null
+++ b/fg21sim/extragalactic/pointsources/pointsources.py
@@ -0,0 +1,126 @@
+# Copyright (c) 2016 Zhixian MA <zxma_sjtu@qq.com>
+# MIT license
+
+"""
+Extragalactic point sources (ps) simulation
+"""
+
+import logging
+import numpy as np
+import healpy as hp
+from collections import OrderedDict
+
+from .starforming import StarForming
+from .starbursting import StarBursting
+from .radioquiet import RadioQuiet
+from .fr1 import FRI
+from .fr2 import FRII
+
+
+logger = logging.getLogger(__name__)
+
+
+class PointSources:
+ """
+ This class namely pointsource is designed to generate PS catalogs,
+ read csv format PS lists, calculate the flux and surface brightness
+ of the sources at different frequencies, and then ouput hpmaps
+
+ Parameters
+ ----------
+ configs: ConfigManager object
+ An 'ConfigManager' object contains default and user configurations.
+ For more details, see the example config specification.
+
+ Functions
+ ---------
+ preprocessing
+ Generate the ps catalogs for each type.
+ simulate_frequency
+ Simualte point sources at provivded frequency
+ simulate
+ Simulate and project PSs to the healpix map.
+ postprocessing
+ Save catalogs
+ """
+ PSCOMPONENTS_ALL = OrderedDict([
+ ("starforming", StarForming),
+ ("starbursting", StarBursting),
+ ("radioquiet", RadioQuiet),
+ ("FRI", FRI),
+ ("FRII", FRII),
+ ])
+
+ def __init__(self, configs):
+ self.configs = configs
+ self._set_configs()
+ self.pscomps = OrderedDict()
+ for comp in self.pscomps_id:
+ logger.info("Initlalize PS component: {0}".format(comp))
+ comp_type = self.PSCOMPONENTS_ALL[comp]
+ self.pscomps[comp] = comp_type(configs)
+ logger.info("Done initlalize %d PS components!" %
+ len(self.pscomps))
+
+ def _set_configs(self):
+ """Load configs and set the attributes"""
+ # Prefix of simulated point sources
+ self.pscomps_id = self.configs.getn("extragalactic/pscomponents")
+ if self.pscomps_id is None:
+ self.pscomps_id = ['starforming', 'starbursting', 'radioquiet',
+ 'FRI', 'FRII']
+ print(self.pscomps_id)
+ # nside of the healpix cell
+ self.nside = self.configs.getn("common/nside")
+ # save flag
+ self.save = self.configs.getn("extragalactic/pointsources/save")
+
+ def preprocess(self):
+ """Preprocess and generate the catalogs"""
+ logger.info("Generating PS catalogs...")
+ # Gen ps_catalog
+ for pscomp_obj in self.pscomps.values():
+ pscomp_obj.gen_catalog()
+ logger.info("Generating PS catalogs done!")
+
+ def simulate_frequency(self, freq):
+ """Simulate the point sources and output hpmaps"""
+ npix = hp.nside2npix(self.nside)
+ hpmap_f = np.zeros((npix,))
+ # Projecting
+ logger.info("Generating PS hpmaps...")
+ for pscomp_obj in self.pscomps.values():
+ hpmap_f += pscomp_obj.draw_single_ps(freq)
+ logger.info("Generating PS hpmaps done!")
+
+ return hpmap_f
+
+ def simulate(self, frequencies):
+ """Simulate the emission (HEALPix) maps of all Galactic SNRs for
+ every specified frequency.
+
+ Parameters
+ ----------
+ frequency : list[float]
+ List of frequencies (unit: `self.freq_unit`) where the
+ simulation performed.
+
+ Returns
+ -------
+ hpmaps : list[1D `~numpy.ndarray`]
+ List of HEALPix maps (in RING ordering) at each frequency.
+ """
+ hpmaps = []
+ for f in np.array(frequencies, ndmin=1):
+ hpmap_f = self.simulate_frequency(f)
+ hpmaps.append(hpmap_f)
+ return hpmaps
+
+ def postprocess(self):
+ """Perform the post-simulation operations before the end."""
+ # Save the catalog actually used in the simulation
+ if self.save:
+ logger.info("Saving simulated catalogs...")
+ for pscomp_obj in self.pscomps.values():
+ pscomp_obj.save_as_csv()
+ logger.info("Saving simulated catalogs done!")