From 4b5967f7c51a340ecbfb418fabf62e292b65020d Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 26 Aug 2017 09:51:16 +0800 Subject: sky.py: Rename load() -> open(), read() -> load() --- fg21sim/galactic/freefree.py | 6 +++--- fg21sim/galactic/synchrotron.py | 6 +++--- fg21sim/sky.py | 42 +++++++++++++++++++++++------------------ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/fg21sim/galactic/freefree.py b/fg21sim/galactic/freefree.py index a1fcf6d..2db6f84 100644 --- a/fg21sim/galactic/freefree.py +++ b/fg21sim/galactic/freefree.py @@ -97,13 +97,13 @@ class FreeFree: """ sky = get_sky(self.configs) logger.info("Loading H[alpha] map ...") - self.halphamap = sky.load(self.halphamap_path) + self.halphamap = sky.open(self.halphamap_path) # Validate input map unit if self.halphamap_unit != au.Unit("Rayleigh"): raise ValueError("unsupported Halpha map unit: {0}".format( self.halphamap_unit)) logger.info("Loading dust map ...") - self.dustmap = sky.load(self.dustmap_path) + self.dustmap = sky.open(self.dustmap_path) # Validate input map unit if self.dustmap_unit != au.Unit("MJy / sr"): raise ValueError("unsupported dust map unit: {0}".format( @@ -256,7 +256,7 @@ class FreeFree: _preprocessed : bool This attribute presents and is ``True`` after the preparation procedures are performed, which indicates that it is ready to - do the final simulations. + do the subsequent simulations. """ if hasattr(self, "_preprocessed") and self._preprocessed: return diff --git a/fg21sim/galactic/synchrotron.py b/fg21sim/galactic/synchrotron.py index 5881c4c..9f89217 100644 --- a/fg21sim/galactic/synchrotron.py +++ b/fg21sim/galactic/synchrotron.py @@ -75,9 +75,9 @@ class Synchrotron: """Load the template map and spectral index map.""" sky = get_sky(self.configs) logger.info("Loading template map ...") - self.template = sky.load(self.template_path) + self.template = sky.open(self.template_path) logger.info("Loading spectral index map ...") - self.indexmap = sky.load(self.indexmap_path) + self.indexmap = sky.open(self.indexmap_path) def _add_smallscales(self): """ @@ -194,7 +194,7 @@ class Synchrotron: _preprocessed : bool This attribute presents and is ``True`` after the preparation procedures are performed, which indicates that it is ready to - do the final simulations. + do the subsequent simulations. """ if hasattr(self, "_preprocessed") and self._preprocessed: return diff --git a/fg21sim/sky.py b/fg21sim/sky.py index ede9c1d..ee5fe82 100644 --- a/fg21sim/sky.py +++ b/fg21sim/sky.py @@ -222,16 +222,7 @@ class SkyBase: def load(self, infile, frequency=None): """ - Make a new *copy* of this instance, then read the given sky - image in and return the loaded new instance. - """ - sky = self.copy() - sky.read(infile=infile, frequency=frequency) - return sky - - def read(self, infile, frequency=None): - """ - Read the given sky image into this instance. + Load the given sky image into this instance. Parameters ---------- @@ -243,6 +234,21 @@ class SkyBase: """ raise NotImplementedError + def open(self, infile, frequency=None): + """ + Open the given input file as a *new* instance. + + The current instance is *copied*, load the given sky image, + and then returned. + + Returns + ------- + sky : a *new* instance with given sky image loaded. + """ + sky = self.copy() + sky.load(infile=infile, frequency=frequency) + return sky + def write(self, outfile, clobber=None): """ Write the sky image (with current data) into a FITS file. @@ -340,7 +346,7 @@ class SkyPatch(SkyBase): self.xcenter, self.ycenter = center if infile is not None: - self.read(infile, frequency) + self.load(infile, frequency) @property def area(self): @@ -478,9 +484,9 @@ class SkyPatch(SkyBase): ci = np.round((x - self.xcenter) / pixelsize + ci0).astype(np.int) return (ri, ci) - def read(self, infile, frequency=None): + def load(self, infile, frequency=None): """ - Read input sky data from file. + Load input sky image from file into this instance. Parameters ---------- @@ -498,7 +504,7 @@ class SkyPatch(SkyBase): header = f[0].header.copy(strip=True) self.header_.extend(header, update=True) self.ysize_in, self.xsize_in = self.data.shape - logger.info("Read sky patch from: %s (%dx%d)" % + logger.info("Loaded sky patch from: %s (%dx%d)" % (infile, self.xsize_in, self.ysize_in)) if (self.xsize_in != self.xsize) or (self.ysize_in != self.ysize): @@ -674,7 +680,7 @@ class SkyHealpix(SkyBase): self.data = np.zeros(shape=hp.nside2npix(self.nside)) if infile is not None: - self.read(infile, frequency) + self.load(infile, frequency) @property def area(self): @@ -684,9 +690,9 @@ class SkyHealpix(SkyBase): """ return 4*np.pi * AUC.rad2deg**2 - def read(self, infile, frequency=None): + def load(self, infile, frequency=None): """ - Read input HEALPix all-sky map. + Load input HEALPix all-sky map into this instance. Parameters ---------- @@ -702,7 +708,7 @@ class SkyHealpix(SkyBase): self.data, header = read_fits_healpix(infile) self.header_.extend(header, update=True) self.nside_in = header["NSIDE"] - logger.info("Read HEALPix sky map from: {0} (Nside={1})".format( + logger.info("Loaded HEALPix sky map from: {0} (Nside={1})".format( infile, self.nside_in)) if self.nside_in != self.nside: self.data = hp.ud_grade(self.data, nside_out=self.nside) -- cgit v1.2.2