Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def from_tree(cls, node, ctx):
data = yamlutil.tagged_tree_to_custom_tree(
node['data'], ctx)
name = node['name']
description = node.get('description')
unit = node.get('unit')
meta = node.get('meta', None)
return table.Column(
data=data._make_array(), name=name, description=description,
unit=unit, meta=meta)
def remove_defaults(self):
"""
Remove any values in the tree that are the same as the default
values in the schema
"""
tree = yamlutil.custom_tree_to_tagged_tree(self._tree, self)
schema.remove_defaults(tree, self)
self._tree = yamlutil.tagged_tree_to_custom_tree(tree, self)
def from_tree(cls, node, ctx):
data = yamlutil.tagged_tree_to_custom_tree(
node['data'], ctx)
name = node['name']
description = node.get('description')
unit = node.get('unit')
meta = node.get('meta', None)
return table.Column(
data=data._make_array(), name=name, description=description,
unit=unit, meta=meta)
def _from_tree_base_transform_members(cls, model, node, ctx):
if 'inverse' in node:
model.inverse = yamlutil.tagged_tree_to_custom_tree(
node['inverse'], ctx)
if 'name' in node:
model = model.rename(node['name'])
# TODO: Remove domain in a later version.
if 'domain' in node:
model.bounding_box = cls._domain_to_bounding_box(node['domain'])
elif 'bounding_box' in node:
model.bounding_box = node['bounding_box']
return model
def from_tree_tagged(cls, node, ctx):
from astropy import modeling
tag = node._tag[node._tag.rfind('/')+1:]
tag = tag[:tag.rfind('-')]
oper = _tag_to_method_mapping[tag]
left = yamlutil.tagged_tree_to_custom_tree(
node['forward'][0], ctx)
if not isinstance(left, modeling.Model):
raise TypeError("Unknown model type '{0}'".format(
node['forward'][0]._tag))
right = yamlutil.tagged_tree_to_custom_tree(
node['forward'][1], ctx)
if not isinstance(right, modeling.Model):
raise TypeError("Unknown model type '{0}'".format(
node['forward'][1]._tag))
model = getattr(left, oper)(right)
model = cls._from_tree_base_transform_members(model, node, ctx)
return model
def fill_defaults(self):
"""
Fill in any values that are missing in the tree using default
values from the schema.
"""
tree = yamlutil.custom_tree_to_tagged_tree(self._tree, self)
schema.fill_defaults(tree, self)
self._tree = yamlutil.tagged_tree_to_custom_tree(tree, self)
d_x = QuantityType.from_tree(val[0], ctx)
d_y = QuantityType.from_tree(val[1], ctx)
d_z = QuantityType.from_tree(val[2], ctx)
val = CartesianDifferential(d_x, d_y, d_z)
else:
val = yamlutil.tagged_tree_to_custom_tree(val, ctx)
frame_kwargs[name] = val
kwargs['reference_frame'] = frame_cls(**frame_kwargs)
if 'axes_order' in node:
kwargs['axes_order'] = tuple(node['axes_order'])
if 'unit' in node:
kwargs['unit'] = tuple(
yamlutil.tagged_tree_to_custom_tree(node['unit'], ctx))
return kwargs
def from_tree(cls, node, ctx):
from astropy import table
data = yamlutil.tagged_tree_to_custom_tree(
node['data'], ctx)
name = node['name']
description = node.get('description')
unit = node.get('unit')
meta = node.get('meta', None)
return table.Column(
data=data._make_array(), name=name, description=description,
unit=unit, meta=meta)
def _from_tree(cls, node, ctx):
kwargs = {'name': node['name']}
if 'axes_type' in node and 'naxes' in node:
kwargs.update({
'axes_type': node['axes_type'],
'naxes': node['naxes']})
if 'axes_names' in node:
kwargs['axes_names'] = node['axes_names']
if 'reference_frame' in node:
kwargs['reference_frame'] = yamlutil.tagged_tree_to_custom_tree(
node['reference_frame'], ctx)
if 'axes_order' in node:
kwargs['axes_order'] = tuple(node['axes_order'])
if 'unit' in node:
kwargs['unit'] = tuple(
yamlutil.tagged_tree_to_custom_tree(node['unit'], ctx))
if 'axis_physical_types' in node:
kwargs['axis_physical_types'] = tuple(node['axis_physical_types'])
return kwargs