From 4e393b5430d36750d644c50342d6481cf1567b36 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 13 Aug 2017 12:26:03 +0800 Subject: sky.py: Add parameter "clobber" to "write()" method Signed-off-by: Aaron LI --- fg21sim/sky.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fg21sim/sky.py b/fg21sim/sky.py index d10186f..53586c0 100644 --- a/fg21sim/sky.py +++ b/fg21sim/sky.py @@ -157,7 +157,7 @@ class SkyBase: """ raise NotImplementedError - def write(self, outfile): + def write(self, outfile, clobber=None): """ Write the sky image (with current data) into a FITS file. @@ -165,6 +165,10 @@ class SkyBase: ---------- outfile : str The path/filename to the output FITS file. + clobber : bool, optional + If not ``None``, then overwrite the default ``self.clobber_`` + from the configuration file, to determine whether to overwrite + the existing output file. """ raise NotImplementedError @@ -350,13 +354,15 @@ class SkyPatch(SkyBase): zoom = (self.ysize/self.ysize_in, self.xsize/self.xsize_in) self.data = ndimage.zoom(self.data, zoom=zoom, order=1) - def write(self, outfile): + def write(self, outfile, clobber=None): """ Write current data to file. """ + if clobber is None: + clobber = self.clobber_ write_fits_image(outfile, image=self.data, header=self.header, float32=self.float32_, - clobber=self.clobber_, + clobber=clobber, checksum=self.checksum_) @property @@ -553,10 +559,12 @@ class SkyHealpix(SkyBase): logger.warning("Upgrade/downgrade sky map from Nside " + "{0} to {1}".format(self.nside_in, self.nside)) - def write(self, outfile): + def write(self, outfile, clobber=None): """ Write current data to file. """ + if clobber is None: + clobber = self.clobber_ write_fits_healpix(outfile, hpmap=self.data, header=self.header, float32=self.float32_, clobber=self.clobber_, -- cgit v1.2.2