/usr/lib/python3/dist-packages/aplpy/slicer.py is in python3-aplpy 1.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | from __future__ import absolute_import, print_function, division
def slice_hypercube(data, header, dimensions=[0, 1], slices=[]):
'''
Extract a slice from an n-dimensional HDU data/header pair, and return the
new data (without changing the header).
'''
if type(slices) == int:
slices = (slices, )
else:
slices = slices[:]
shape = data.shape
if len(shape) < 2:
raise Exception("FITS file does not have enough dimensions")
elif len(shape) == 2:
if dimensions[1] < dimensions[0]:
data = data.transpose()
return data
else:
if slices:
if dimensions[0] < dimensions[1]:
slices.insert(dimensions[0], slice(None, None, None))
slices.insert(dimensions[1], slice(None, None, None))
else:
slices.insert(dimensions[1], slice(None, None, None))
slices.insert(dimensions[0], slice(None, None, None))
if type(slices) == list:
slices = tuple(slices)
data = data[slices[::-1]]
if dimensions[1] < dimensions[0]:
data = data.transpose()
else:
message = '''
Attempted to read in %i-dimensional FITS cube, but
dimensions and slices were not specified. Please specify these
using the dimensions= and slices= argument. The cube dimensions
are:\n\n''' % len(shape)
for i in range(1, len(shape) + 1):
message += " " * 10
message += " %i %s %i\n" % (i - 1,
header["CTYPE%i" % i],
header["NAXIS%i" % i])
raise Exception(message)
return data
|