Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _validate(self, tree, custom=True, reading=False):
tagged_tree = yamlutil.custom_tree_to_tagged_tree(
tree, self)
schema.validate(tagged_tree, self, reading=reading)
# Perform secondary validation pass if requested
if custom and self._custom_schema:
schema.validate(tagged_tree, self, self._custom_schema,
reading=reading)
result['source'] = ctx.blocks.get_source(block)
result['datatype'] = dtype
result['byteorder'] = byteorder
if offset > 0:
result['offset'] = offset
if strides is not None:
result['strides'] = list(strides)
if isinstance(data, ma.MaskedArray):
if np.any(data.mask):
if block.array_storage == 'inline':
ctx.blocks.set_array_storage(ctx.blocks[data.mask], 'inline')
result['mask'] = yamlutil.custom_tree_to_tagged_tree(
data.mask, ctx)
return result
def to_tree(cls, data, ctx):
node = {
'data': yamlutil.custom_tree_to_tagged_tree(
data.data, ctx),
'name': data.name
}
if data.description:
node['description'] = data.description
if data.unit:
node['unit'] = yamlutil.custom_tree_to_tagged_tree(
data.unit, ctx)
if data.meta:
node['meta'] = data.meta
return node
"""
if isinstance(instance, Tagged):
instance._tag = tag
elif isinstance(instance, dict):
instance = TaggedDict(instance, tag)
elif isinstance(instance, list):
instance = TaggedList(instance, tag)
elif isinstance(instance, str):
instance = TaggedString(instance)
instance._tag = tag
else:
from . import AsdfFile, yamlutil
if ctx is None:
ctx = AsdfFile()
try:
instance = yamlutil.custom_tree_to_tagged_tree(instance, ctx)
except TypeError:
raise TypeError("Don't know how to tag a {0}".format(type(instance)))
instance._tag = tag
return instance
node = time.Time(node, format='isot')
format = node.format
format = _astropy_format_to_asdf_format.get(format, format)
guessable_format = format in _guessable_formats
if node.scale == 'utc' and guessable_format:
if node.isscalar:
return node.value
else:
return yamlutil.custom_tree_to_tagged_tree(
node.value, ctx)
d = {'value': yamlutil.custom_tree_to_tagged_tree(node.value, ctx)}
if not guessable_format:
d['format'] = format
if node.scale != 'utc':
d['scale'] = node.scale
if node.location is not None:
d['location'] = {
'x': node.location.x,
'y': node.location.y,
'z': node.location.z
}
return d
def _to_tree_from_model_tree(cls, tree, ctx):
if not isinstance(tree.left, CompoundModel):
left = yamlutil.custom_tree_to_tagged_tree(
tree.left, ctx)
else:
left = cls._to_tree_from_model_tree(tree.left, ctx)
if not isinstance(tree.right, CompoundModel):
if isinstance(tree.right, dict):
right = {'keys': list(tree.right.keys()),
'values': list(tree.right.values())
}
else:
right = yamlutil.custom_tree_to_tagged_tree(
tree.right, ctx)
else:
right = cls._to_tree_from_model_tree(tree.right, ctx)
node = {
'forward': [left, right]
}
try:
tag_name = 'transform/' + _operator_to_tag_mapping[tree.op]
except KeyError:
raise ValueError(f"Unknown operator '{tree.op}'")
node = tagged.tag_object(cls.make_yaml_tag(tag_name), node, ctx=ctx)
return node
node = time.Time(node, format='jyear_str')
elif format in ('fits', 'datetime', 'plot_date'):
node = time.Time(node, format='isot')
format = node.format
format = _astropy_format_to_asdf_format.get(format, format)
guessable_format = format in _guessable_formats
if node.scale == 'utc' and guessable_format:
if node.isscalar:
return node.value
else:
return yamlutil.custom_tree_to_tagged_tree(
node.value, ctx)
d = {'value': yamlutil.custom_tree_to_tagged_tree(node.value, ctx)}
if not guessable_format:
d['format'] = format
if node.scale != 'utc':
d['scale'] = node.scale
if node.location is not None:
x, y, z = node.location.x, node.location.y, node.location.z
# Preserve backwards compatibility for writing the old schema
# This allows WCS to test backwards compatibility with old frames
# This code does get tested in CI, but we don't run a coverage test
if cls.version == '1.0.0': # pragma: no cover
node = time.Time(node, format='isot')
format = node.format
format = _astropy_format_to_asdf_format.get(format, format)
guessable_format = format in _guessable_formats
if node.scale == 'utc' and guessable_format:
if node.isscalar:
return node.value
else:
return yamlutil.custom_tree_to_tagged_tree(
node.value, ctx)
d = {'value': yamlutil.custom_tree_to_tagged_tree(node.value, ctx)}
if not guessable_format:
d['format'] = format
if node.scale != 'utc':
d['scale'] = node.scale
if node.location is not None:
x, y, z = node.location.x, node.location.y, node.location.z
# Preserve backwards compatibility for writing the old schema
# This allows WCS to test backwards compatibility with old frames
# This code does get tested in CI, but we don't run a coverage test
if cls.version == '1.0.0': # pragma: no cover
unit = node.location.unit
d['location'] = { 'x': x, 'y': y, 'z': z, 'unit': unit }
else:
if node.location is not None:
x, y, z = node.location.x, node.location.y, node.location.z
# Preserve backwards compatibility for writing the old schema
# This allows WCS to test backwards compatibility with old frames
# This code does get tested in CI, but we don't run a coverage test
if cls.version == '1.0.0': # pragma: no cover
unit = node.location.unit
d['location'] = { 'x': x, 'y': y, 'z': z, 'unit': unit }
else:
d['location'] = {
# It seems like EarthLocations can be represented either in
# terms of Cartesian coordinates or latitude and longitude, so
# we rather arbitrarily choose the former for our representation
'x': yamlutil.custom_tree_to_tagged_tree(x, ctx),
'y': yamlutil.custom_tree_to_tagged_tree(y, ctx),
'z': yamlutil.custom_tree_to_tagged_tree(z, ctx)
}
return d