diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-05-21 21:14:46 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-05-21 21:14:46 +0800 |
commit | b0c2d36a04d3b4ff89c0b8ed0540dd56df051cef (patch) | |
tree | 042389d9013cbb6db3de4754cdd553e3eb72efdd | |
parent | 3f830e6628366a12f37a431cbb7e0482e9d51839 (diff) | |
download | fg21sim-b0c2d36a04d3b4ff89c0b8ed0540dd56df051cef.tar.bz2 |
sky.py: Flatten 2D image of sky patch to 1D for easier processing
Flatten the image array to 1D makes it similar to the HEALPix map array,
therefore, it is easier to deal with both cases.
-rw-r--r-- | fg21sim/sky.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/fg21sim/sky.py b/fg21sim/sky.py index fb1e152..9b12092 100644 --- a/fg21sim/sky.py +++ b/fg21sim/sky.py @@ -44,10 +44,16 @@ class SkyPatch: Attributes ---------- + type : str, "patch" or "healpix" + The type of this sky map + data : 1D `numpy.ndarray` + The flattened 1D array of map data + NOTE: The 2D image is flattened to 1D, making it easier to be + manipulated in a similar way as the HEALPix map. size : int tuple, (width, height) The dimensions of the FITS image - shape : int tuple, (nrow, ncol) - The shape of the Numpy array + shape : int tuple, (nrow*ncol, ) + The shape of the flattened image array NOTE: nrow=height, ncol=width pixelsize : float The pixel size of the sky map [ arcmin ] @@ -58,7 +64,7 @@ class SkyPatch: # Input sky patch and its frequency [ MHz ] infile = None frequency = None - # Sky data; should be a ``numpy.ndarray`` + # Sky data; should be a 1D ``numpy.ndarray`` (i.e., flattened) data = None # Coordinates of each pixel coordinates = None @@ -80,7 +86,7 @@ class SkyPatch: if self.data is not None: return self.data.shape else: - return (self.ysize, self.xsize) + return (self.ysize * self.xsize, ) @property def center(self): @@ -107,12 +113,13 @@ class SkyPatch: logger.info("Read 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): - logger.warning("Scale input sky patch from size " + - "%dx%d to %dx%d" % (self.xsize_in, self.ysize_in, - self.xsize, self.ysize)) - self.data = ndimage.zoom(self.data, order=1, - zoom=(self.ysize/self.ysize_in, - self.xsize/self.xsize_in)) + logger.warning("Scale input sky patch to size %dx%d" % + (self.xsize, self.ysize)) + zoom = (self.ysize/self.ysize_in, self.xsize/self.xsize_in) + self.data = ndimage.zoom(self.data, zoom=zoom, order=1) + # Flatten the image + self.data = self.data.flatten() + logger.info("Flatten the image to a 1D array") def load(self, infile, frequency=None): """ @@ -141,7 +148,8 @@ class SkyPatch: if not os.path.exists(outdir): os.makedirs(outdir) logger.info("Created output directory: %s" % outdir) - hdu = fits.PrimaryHDU(data=self.data, header=self.header) + image = self.data.reshape(self.ysize, self.xsize) + hdu = fits.PrimaryHDU(data=image, header=self.header) hdu.writeto(outfile, clobber=clobber, checksum=checksum) logger.info("Write sky map to file: %s" % outfile) @@ -158,10 +166,9 @@ class SkyHealpix: Attributes ---------- shape : int tuple, (npix,) - The shape of the Numpy array - NOTE: nrow=height, ncol=width + The shape (i.e., length) of the HEALPix array pixelsize : float - The pixel size of the HEALPix sky [ arcmin ] + The pixel size of the HEALPix map [ arcmin ] """ type_ = "healpix" # Input sky patch and its frequency [ MHz ] |