/usr/lib/python3/dist-packages/healpy/cookbook.py is in python3-healpy 1.8.1-1.1build1.
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | """Various generic useful functions
"""
def is_seq(o):
"""Check if the object is a sequence.
Parameters
----------
o : any object
The object to check
Returns
-------
is_seq : bool, scalar
True if *o* is a sequence, False otherwise
"""
return hasattr(o, '__len__')
def is_seq_of_seq(o):
"""Check if the object is a sequence of sequences. No check is done on
the sizes of the sequences.
Parameters
----------
o : any object
The object to check
Returns
-------
is_seq_of_seq : bool
True if *o* is a sequence of sequences, False otherwise.
"""
if not is_seq(o):
return False
for s in o:
if not is_seq(s):
return False
return True
def is_like2d(o):
"""Check if *o* is conformable to a 2d array.
Parameters
----------
o : any object
The object to check
Returns
-------
is_like2d : bool, scalar
True if *o* is conformable to a 2d array, False otherwise.
"""
if not is_seq(o):
return False
size = None
for s in o:
if not is_seq(s):
return False
if size is None:
size = len(s)
if len(s) != size:
return False
return True
def len_array_or_arrays(o):
"""Returns the length of a single array or list of arrays
Parameters
----------
o : either array or sequence of arrays
Returns
-------
length : length of array
"""
if is_seq_of_seq(o):
length = len(o[0])
else:
length = len(o)
return length
|