Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_astropy_table(h_node):
py_type, data = get_type_and_data(h_node)
metadata = dict(h_node.attrs.items())
metadata.pop('type')
metadata.pop('colnames')
if six.PY3:
colnames = [cn.decode('ascii') for cn in h_node.attrs["colnames"]]
else:
colnames = h_node.attrs["colnames"]
t = Table(data, names=colnames, meta=metadata)
return t
def load_astropy_quantity_dataset(h_node):
py_type, data = get_type_and_data(h_node)
unit = h_node.attrs["unit"][0]
q = Quantity(data, unit)
return q
def load_astropy_time_dataset(h_node):
py_type, data = get_type_and_data(h_node)
if six.PY3:
fmt = h_node.attrs["format"][0].decode('ascii')
scale = h_node.attrs["scale"][0].decode('ascii')
else:
fmt = h_node.attrs["format"][0]
scale = h_node.attrs["scale"][0]
q = Time(data, format=fmt, scale=scale)
return q
def load_python_dtype_dataset(h_node):
py_type, data = get_type_and_data(h_node)
subtype = h_node.attrs["python_subdtype"]
type_dict = {
b"": int,
b"": float,
b"": bool,
b"": complex
}
tcast = type_dict.get(subtype)
return tcast(data)
def load_ndarray_dataset(h_node):
py_type, data = get_type_and_data(h_node)
return np.array(data, copy=False)
def load_list_dataset(h_node):
py_type, data = get_type_and_data(h_node)
py3_str_type = get_py3_string_type(h_node)
if py3_str_type == b"":
# Yuck. Convert numpy._bytes -> str -> bytes
return [bytes(str(item, 'utf8'), 'utf8') for item in data]
if py3_str_type == b"":
return [str(item, 'utf8') for item in data]
else:
return list(data)
def load_astropy_constant_dataset(h_node):
py_type, data = get_type_and_data(h_node)
unit = h_node.attrs["unit"][0]
abbrev = h_node.attrs["abbrev"][0]
name = h_node.attrs["name"][0]
ref = h_node.attrs["reference"][0]
unc = h_node.attrs["uncertainty"][0]
system = None
if "system" in h_node.attrs.keys():
system = h_node.attrs["system"][0]
c = Constant(abbrev, name, data, unit, unc, ref, system)
return c
def load_ndarray_masked_dataset(h_node):
py_type, data = get_type_and_data(h_node)
try:
mask_path = h_node.name + "_mask"
h_root = h_node.parent
mask = h_root.get(mask_path)[:]
except IndexError:
mask = h_root.get(mask_path)
except ValueError:
mask = h_root.get(mask_path)
data = np.ma.array(data, mask=mask)
return data
def load_string_dataset(h_node):
py_type, data = get_type_and_data(h_node)
return str(data[0])
def load_string_dataset(h_node):
py_type, data = get_type_and_data(h_node)
return str(data[0])