aboutsummaryrefslogtreecommitdiffstats
path: root/astro
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-12-09 11:19:19 +0800
committerAaron LI <aly@aaronly.me>2017-12-09 11:19:19 +0800
commit3246ae683a1935b2d2c4ae98ce4c78d9f82397b3 (patch)
treed1911178e461ffdf0709b2657e9a6cd403e9953f /astro
parent36d4774d040a7ea7c77031dfcb4584d3e25a296a (diff)
downloadatoolbox-3246ae683a1935b2d2c4ae98ce4c78d9f82397b3.tar.bz2
astro/fitsimage.py: copy image data
Diffstat (limited to 'astro')
-rwxr-xr-xastro/fits/fitsimage.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/astro/fits/fitsimage.py b/astro/fits/fitsimage.py
index 5b416a2..566cb53 100755
--- a/astro/fits/fitsimage.py
+++ b/astro/fits/fitsimage.py
@@ -24,7 +24,7 @@ class FITSImage:
def __init__(self, infile, pixelsize=None):
self.infile = infile
with fits.open(infile) as f:
- self.header = f[0].header
+ self.header = f[0].header.copy(strip=True)
self.data = f[0].data
self.ndim = self.data.ndim
self.shape = self.data.shape
@@ -56,13 +56,13 @@ class FITSImage:
"""
if self.ndim == 2:
# NAXIS=2: [Y, X]
- image = self.data[:, :]
+ image = self.data[:, :].copy()
elif self.ndim == 3 and self.shape[0] == 1:
# NAXIS=3: [FREQ=1, Y, X]
- image = self.data[0, :, :]
+ image = self.data[0, :, :].copy()
elif self.ndim == 4 and self.shape[0] == 1 and self.shape[1] == 1:
# NAXIS=4: [STOKES=1, FREQ=1, Y, X]
- image = self.data[0, 0, :, :]
+ image = self.data[0, 0, :, :].copy()
else:
raise ValueError("invalid data shape: {1}".format(self.shape))
return image
@@ -71,13 +71,13 @@ class FITSImage:
def image(self, value):
if self.ndim == 2:
# NAXIS=2: [Y, X]
- self.data[:, :] = value
+ self.data = np.array(value)
elif self.ndim == 3:
# NAXIS=3: [FREQ=1, Y, X]
- self.data[0, :, :] = value
+ self.data = np.array(value)[np.newaxis, :, :]
else:
# NAXIS=4: [STOKES=1, FREQ=1, Y, X]
- self.data[0, 0, :, :] = value
+ self.data = np.array(value)[np.newaxis, np.newaxis, :, :]
@property
def pixelsize(self):
@@ -98,6 +98,7 @@ class FITSImage:
@pixelsize.setter
def pixelsize(self, value):
# Unit: [arcsec]
+ oldvalue = self.pixelsize
self._pixelsize = value
@property