From 8adeeb51cca40337cce36f94d00bacc84c33731d Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 21 Nov 2016 10:16:57 +0800 Subject: Update "simulate_frequency()" to also return the output file path * Update "output()" method to return the output file path * Update "simulate()" to also return the list of output file paths --- fg21sim/extragalactic/clusters.py | 25 ++++++++++++++++++++----- fg21sim/foregrounds.py | 6 ++++++ fg21sim/galactic/freefree.py | 36 +++++++++++++++++++++++++++++++----- fg21sim/galactic/snr.py | 25 ++++++++++++++++++++----- fg21sim/galactic/synchrotron.py | 36 +++++++++++++++++++++++++++++++----- 5 files changed, 108 insertions(+), 20 deletions(-) (limited to 'fg21sim') diff --git a/fg21sim/extragalactic/clusters.py b/fg21sim/extragalactic/clusters.py index d23ddbf..3b3262f 100644 --- a/fg21sim/extragalactic/clusters.py +++ b/fg21sim/extragalactic/clusters.py @@ -585,6 +585,11 @@ class GalaxyClusters: def output(self, hpmap, frequency): """Write the simulated free-free map to disk with proper header keywords and history. + + Returns + ------- + filepath : str + The (absolute) path to the output HEALPix map file. """ if not os.path.exists(self.output_dir): os.mkdir(self.output_dir) @@ -604,6 +609,7 @@ class GalaxyClusters: write_fits_healpix(filepath, hpmap, header=header, clobber=self.clobber, checksum=self.checksum) logger.info("Write simulated map to file: {0}".format(filepath)) + return filepath def preprocess(self): """Perform the preparation procedures for the final simulations. @@ -647,7 +653,10 @@ class GalaxyClusters: Returns ------- hpmap_f : 1D `~numpy.ndarray` - HEALPix map data in RING ordering + The HEALPix map (RING ordering) at the input frequency. + filepath : str + The (absolute) path to the output HEALPix file if saved, + otherwise ``None``. See Also -------- @@ -665,8 +674,10 @@ class GalaxyClusters: hpmap_f[hpidx] += hpval # if self.save: - self.output(hpmap_f, frequency) - return hpmap_f + filepath = self.output(hpmap_f, frequency) + else: + filepath = None + return (hpmap_f, filepath) def simulate(self, frequencies): """Simulate the emission (HEALPix) maps of all Galactic SNRs for @@ -682,12 +693,16 @@ class GalaxyClusters: ------- hpmaps : list[1D `~numpy.ndarray`] List of HEALPix maps (in RING ordering) at each frequency. + paths : list[str] + List of (absolute) path to the output HEALPix maps. """ hpmaps = [] + paths = [] for f in np.array(frequencies, ndmin=1): - hpmap_f = self.simulate_frequency(f) + hpmap_f, filepath = self.simulate_frequency(f) hpmaps.append(hpmap_f) - return hpmaps + paths.append(filepath) + return (hpmaps, paths) def postprocess(self): """Perform the post-simulation operations before the end.""" diff --git a/fg21sim/foregrounds.py b/fg21sim/foregrounds.py index 2206edf..5df2584 100644 --- a/fg21sim/foregrounds.py +++ b/fg21sim/foregrounds.py @@ -149,6 +149,11 @@ class Foregrounds: def _output(self, hpmap, frequency): """Write the simulated free-free map to disk with proper header keywords and history. + + Returns + ------- + filepath : str + The (absolute) path to the output HEALPix map file. """ if not os.path.exists(self.output_dir): os.mkdir(self.output_dir) @@ -198,6 +203,7 @@ class Foregrounds: for comp_obj in self.components.values(): hpmap_f += comp_obj.simulate_frequency(f) # + hpmap, filepath = comp_obj.simulate_frequency(freq) if self.combine: self._output(hpmap_f, f) diff --git a/fg21sim/galactic/freefree.py b/fg21sim/galactic/freefree.py index f47f008..878a833 100644 --- a/fg21sim/galactic/freefree.py +++ b/fg21sim/galactic/freefree.py @@ -214,6 +214,11 @@ class FreeFree: def output(self, hpmap, frequency): """Write the simulated free-free map to disk with proper header keywords and history. + + Returns + ------- + filepath : str + The (absolute) path to the output HEALPix map file. """ if not os.path.exists(self.output_dir): os.mkdir(self.output_dir) @@ -233,6 +238,7 @@ class FreeFree: write_fits_healpix(filepath, hpmap, header=header, clobber=self.clobber, checksum=self.checksum) logger.info("Write simulated map to file: {0}".format(filepath)) + return filepath def preprocess(self): """Perform the preparation procedures for the final simulations. @@ -261,6 +267,14 @@ class FreeFree: References: [Dickinson2003], Eq.(11) NOTE: [Dickinson2003], Eq.(11) may wrongly have the "10^3" term. + + Returns + ------- + hpmap_f : 1D `~numpy.ndarray` + The HEALPix map (RING ordering) at the input frequency. + filepath : str + The (absolute) path to the output HEALPix file if saved, + otherwise ``None``. """ self.preprocess() # @@ -279,16 +293,28 @@ class FreeFree: hpmap_f = self.halphamap * ratio_K_R # if self.save: - self.output(hpmap_f, frequency) - return hpmap_f + filepath = self.output(hpmap_f, frequency) + else: + filepath = None + return (hpmap_f, filepath) def simulate(self, frequencies): - """Simulate the free-free map at every specified frequency.""" + """Simulate the synchrotron map at the specified frequencies. + + Returns + ------- + hpmaps : list[1D `~numpy.ndarray`] + List of HEALPix maps (in RING ordering) at each frequency. + paths : list[str] + List of (absolute) path to the output HEALPix maps. + """ hpmaps = [] + paths = [] for f in np.array(frequencies, ndmin=1): - hpmap_f = self.simulate_frequency(f) + hpmap_f, filepath = self.simulate_frequency(f) hpmaps.append(hpmap_f) - return hpmaps + paths.append(filepath) + return (hpmaps, paths) def postprocess(self): """Perform the post-simulation operations before the end.""" diff --git a/fg21sim/galactic/snr.py b/fg21sim/galactic/snr.py index b7bfadc..ed66649 100644 --- a/fg21sim/galactic/snr.py +++ b/fg21sim/galactic/snr.py @@ -345,6 +345,11 @@ class SuperNovaRemnants: def output(self, hpmap, frequency): """Write the simulated free-free map to disk with proper header keywords and history. + + Returns + ------- + filepath : str + The (absolute) path to the output HEALPix map file. """ if not os.path.exists(self.output_dir): os.mkdir(self.output_dir) @@ -364,6 +369,7 @@ class SuperNovaRemnants: write_fits_healpix(filepath, hpmap, header=header, clobber=self.clobber, checksum=self.checksum) logger.info("Write simulated map to file: {0}".format(filepath)) + return filepath def preprocess(self): """Perform the preparation procedures for the final simulations. @@ -399,7 +405,10 @@ class SuperNovaRemnants: Returns ------- hpmap_f : 1D `~numpy.ndarray` - HEALPix map data in RING ordering + The HEALPix map (RING ordering) at the input frequency. + filepath : str + The (absolute) path to the output HEALPix file if saved, + otherwise ``None``. See Also -------- @@ -415,8 +424,10 @@ class SuperNovaRemnants: hpmap_f[hpidx] += hpval # if self.save: - self.output(hpmap_f, frequency) - return hpmap_f + filepath = self.output(hpmap_f, frequency) + else: + filepath = None + return (hpmap_f, filepath) def simulate(self, frequencies): """Simulate the emission (HEALPix) maps of all Galactic SNRs for @@ -432,12 +443,16 @@ class SuperNovaRemnants: ------- hpmaps : list[1D `~numpy.ndarray`] List of HEALPix maps (in RING ordering) at each frequency. + paths : list[str] + List of (absolute) path to the output HEALPix maps. """ hpmaps = [] + paths = [] for f in np.array(frequencies, ndmin=1): - hpmap_f = self.simulate_frequency(f) + hpmap_f, filepath = self.simulate_frequency(f) hpmaps.append(hpmap_f) - return hpmaps + paths.append(filepath) + return (hpmaps, paths) def postprocess(self): """Perform the post-simulation operations before the end.""" diff --git a/fg21sim/galactic/synchrotron.py b/fg21sim/galactic/synchrotron.py index 9521155..22949b2 100644 --- a/fg21sim/galactic/synchrotron.py +++ b/fg21sim/galactic/synchrotron.py @@ -176,6 +176,11 @@ class Synchrotron: def output(self, hpmap, frequency): """Write the simulated synchrotron map to disk with proper header keywords and history. + + Returns + ------- + filepath : str + The (absolute) path to the output HEALPix map file. """ if not os.path.exists(self.output_dir): os.mkdir(self.output_dir) @@ -195,6 +200,7 @@ class Synchrotron: write_fits_healpix(filepath, hpmap, header=header, clobber=self.clobber, checksum=self.checksum) logger.info("Write simulated map to file: {0}".format(filepath)) + return filepath def preprocess(self): """Perform the preparation procedures for the final simulations. @@ -219,6 +225,14 @@ class Synchrotron: def simulate_frequency(self, frequency): """Transform the template map to the requested frequency, according to the spectral model and using an spectral index map. + + Returns + ------- + hpmap_f : 1D `~numpy.ndarray` + The HEALPix map (RING ordering) at the input frequency. + filepath : str + The (absolute) path to the output HEALPix file if saved, + otherwise ``None``. """ self.preprocess() # @@ -228,16 +242,28 @@ class Synchrotron: (frequency / self.template_freq) ** self.indexmap) # if self.save: - self.output(hpmap_f, frequency) - return hpmap_f + filepath = self.output(hpmap_f, frequency) + else: + filepath = None + return (hpmap_f, filepath) def simulate(self, frequencies): - """Simulate the synchrotron map at the specified frequencies.""" + """Simulate the synchrotron map at the specified frequencies. + + Returns + ------- + hpmaps : list[1D `~numpy.ndarray`] + List of HEALPix maps (in RING ordering) at each frequency. + paths : list[str] + List of (absolute) path to the output HEALPix maps. + """ hpmaps = [] + paths = [] for f in np.array(frequencies, ndmin=1): - hpmap_f = self.simulate_frequency(f) + hpmap_f, filepath = self.simulate_frequency(f) hpmaps.append(hpmap_f) - return hpmaps + paths.append(filepath) + return (hpmaps, paths) def postprocess(self): """Perform the post-simulation operations before the end.""" -- cgit v1.2.2