Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
row number, or sequences thereof. Numpy arrays and slices are also
fine.
Examples:
'field'
35
[35,55,86]
['f1',f2',...]
Can also be tuples or arrays.
"""
flags = set()
#
if isinstance(arg, (tuple, list, numpy.ndarray)):
# a sequence was entered
if isstring(arg[0]):
result = arg
else:
result = arg
flags.add('isrows')
elif isstring(arg):
# a single string was entered
result = arg
elif isinstance(arg, slice):
if unpack:
flags.add('isrows')
result = self._slice2rows(arg.start, arg.stop, arg.step)
else:
flags.add('isrows')
flags.add('isslice')
result = self._process_slice(arg)
else:
def set_record(self, record):
"""
check the record is valid and set keys in the dict
parameters
----------
record: string
Dict representing a record or a string representing a FITS header
card
"""
if isstring(record):
card = FITSCard(record)
self.update(card)
self.verify()
else:
if isinstance(record, FITSRecord):
self.update(record)
elif isinstance(record, dict):
if 'name' in record and 'value' in record:
self.update(record)
elif 'card_string' in record:
self.set_record(record['card_string'])
# use the example image to build the type in C
img2send = numpy.zeros(1, dtype=dtype)
# sending an array simplifies access
dims2send = numpy.array(dims, dtype='i8', ndmin=1)
if img2send is not None:
if img2send.dtype.fields is not None:
raise ValueError(
"got record data type, expected regular ndarray")
if extname is None:
# will be ignored
extname = ""
else:
if not isstring(extname):
raise ValueError("extension name must be a string")
extname = mks(extname)
if extname is not None and extver is not None:
extver = check_extver(extver)
if extver is None:
# will be ignored
extver = 0
comptype = get_compress_type(compress)
tile_dims = get_tile_dims(tile_dims, dims)
if img2send is not None:
check_comptype_img(comptype, dtstr)
def _check_type(self):
card_string = self['card_string']
if not isstring(card_string):
raise TypeError(
"card must be a string, got type %s" % type(card_string))
if not isinstance(dims, list):
raise ValueError("dims should be a list")
if len(dims) != len(names):
raise ValueError("names and dims must be same length")
if units is not None:
if not isinstance(units, list):
raise ValueError("units should be a list")
if len(units) != len(names):
raise ValueError("names and units must be same length")
if extname is None:
# will be ignored
extname = ""
else:
if not isstring(extname):
raise ValueError("extension name must be a string")
extname = mks(extname)
if extname is not None and extver is not None:
extver = check_extver(extver)
if extver is None:
# will be ignored
extver = 0
if extname is None:
# will be ignored
extname = ""
if header is not None:
nkeys = len(header)
else:
nkeys = 0
KEYLC = 323423432 / a comment for long
basically,
- 8 chars, left aligned, for the keyword name
- a space
- 20 chars for value, left aligned for strings, right aligned for
numbers
- if there is a comment, one space followed by / then another space
then the comment out to 80 chars
"""
name = record['name']
value = record['value']
comment = record.get('comment', '')
v_isstring = isstring(value)
if name is None:
card = ' %s' % comment
elif name == 'COMMENT':
card = 'COMMENT %s' % comment
elif name == 'CONTINUE':
card = 'CONTINUE %s' % value
elif name == 'HISTORY':
card = 'HISTORY %s' % value
else:
if len(name) > 8:
card = 'HIERARCH %s= ' % name
else:
card = '%-8s= ' % name[0:8]
# these may be string representations of data, or actual strings