예제 #1
0
def test_tag_object():
    class SomeObject(object):
        pass

    tag = 'tag:nowhere.org:none/some/thing'
    instance = tagged.tag_object(tag, SomeObject())
    assert instance._tag == tag
예제 #2
0
    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
예제 #3
0
def test_tag_object():
    class SomeObject(object):
        pass

    tag = 'tag:nowhere.org:none/some/thing'
    instance = tagged.tag_object(tag, SomeObject())
    assert instance._tag == tag
예제 #4
0
파일: fits_support.py 프로젝트: sosey/jwst
 def callback(subschema, path, combiner, ctx, recurse):
     tag = subschema.get('tag')
     if tag is not None:
         cursor = tree
         for part in path[:-1]:
             if included(cursor, part):
                 cursor = cursor[part]
             else:
                 return
         part = path[-1]
         if included(cursor, part):
             cursor[part] = tagged.tag_object(tag, cursor[part])
예제 #5
0
파일: fits_support.py 프로젝트: rij/jwst
 def callback(subschema, path, combiner, ctx, recurse):
     tag = subschema.get('tag')
     if tag is not None:
         cursor = tree
         for part in path[:-1]:
             if included(cursor, part):
                 cursor = cursor[part]
             else:
                 return
         part = path[-1]
         if included(cursor, part):
             cursor[part] = tagged.tag_object(tag, cursor[part])
예제 #6
0
    def to_tree_tagged(cls, frame, ctx):
        if type(frame) not in frame_transform_graph.frame_set:
            raise ValueError("Can only save frames that are registered with the "
                             "transformation graph.")

        node = {}
        if frame.has_data:
            node['data'] = custom_tree_to_tagged_tree(frame.data, ctx)
        frame_attributes = {}
        for attr in frame.frame_attributes.keys():
            value = getattr(frame, attr, None)
            if value is not None:
                frame_attributes[attr] = value
        node['frame_attributes'] = custom_tree_to_tagged_tree(frame_attributes, ctx)

        return tagged.tag_object(cls._frame_name_to_tag(frame.name), node, ctx=ctx)
예제 #7
0
파일: frames.py 프로젝트: MaxNoe/astropy
    def to_tree_tagged(cls, frame, ctx):
        if type(frame) not in frame_transform_graph.frame_set:
            raise ValueError("Can only save frames that are registered with the "
                             "transformation graph.")

        node = {}
        if frame.has_data:
            node['data'] = custom_tree_to_tagged_tree(frame.data, ctx)
        frame_attributes = {}
        for attr in frame.frame_attributes.keys():
            value = getattr(frame, attr, None)
            if value is not None:
                frame_attributes[attr] = value
        node['frame_attributes'] = custom_tree_to_tagged_tree(frame_attributes, ctx)

        return tagged.tag_object(cls._frame_name_to_tag(frame.name), node, ctx=ctx)
예제 #8
0
파일: properties.py 프로젝트: rij/jwst
def _cast(val, schema):
    val = _unmake_node(val)
    if val is not None:
        if 'datatype' in schema:
            val = util.gentle_asarray(
                val, ndarray.asdf_datatype_to_numpy_dtype(schema['datatype']))
        if 'ndim' in schema and len(val.shape) != schema['ndim']:
            raise ValueError(
                "Array has wrong number of dimensions.  Expected {0}, got {1}".
                format(schema['ndim'], len(val.shape)))
        if 'max_ndim' in schema and len(val.shape) > schema['max_ndim']:
            raise ValueError(
                "Array has wrong number of dimensions.  Expected <= {0}, got {1}"
                .format(schema['max_ndim'], len(val.shape)))
        tag = schema.get('tag')
        if tag is not None:
            val = tagged.tag_object(tag, val)

    return val
예제 #9
0
def _fits_keyword_loader(hdulist, fits_keyword, schema, hdu_index, known_keywords):
    hdu_name = _get_hdu_name(schema)
    try:
        hdu = get_hdu(hdulist, hdu_name, hdu_index)
    except AttributeError:
        return None

    try:
        val = hdu.header[fits_keyword]
    except KeyError:
        return None

    tag = schema.get('tag')
    if tag is not None:
        val = tagged.tag_object(tag, val)

    known_keywords.setdefault(hdu, set()).add(fits_keyword)

    return val
예제 #10
0
def _cast(val, schema):
    val = _unmake_node(val)
    if val is not None:
        if 'datatype' in schema:
            val = util.gentle_asarray(
                val, ndarray.asdf_datatype_to_numpy_dtype(schema['datatype']))
        if 'ndim' in schema and len(val.shape) != schema['ndim']:
            raise ValueError(
                "Array has wrong number of dimensions.  Expected {0}, got {1}".format(
                    schema['ndim'], len(val.shape)))
        if 'max_ndim' in schema and len(val.shape) > schema['max_ndim']:
            raise ValueError(
                "Array has wrong number of dimensions.  Expected <= {0}, got {1}".format(
                    schema['max_ndim'], len(val.shape)))
        tag = schema.get('tag')
        if tag is not None:
            val = tagged.tag_object(tag, val)
            
    return val
예제 #11
0
파일: fits_support.py 프로젝트: sosey/jwst
def _fits_keyword_loader(hdulist, fits_keyword, schema, hdu_index, known_keywords):
    hdu_name = _get_hdu_name(schema)
    try:
        hdu = get_hdu(hdulist, hdu_name, hdu_index)
    except AttributeError:
        return None

    try:
        val = hdu.header[fits_keyword]
    except KeyError:
        return None

    tag = schema.get('tag')
    if tag is not None:
        val = tagged.tag_object(tag, val)

    known_keywords.setdefault(hdu, set()).add(fits_keyword)

    return val
예제 #12
0
def test_time_tag():
    schema = asdf_schema.load_schema(
        'http://stsci.edu/schemas/asdf/time/time-1.1.0',
        resolve_references=True)
    schema = _flatten_combiners(schema)

    date = time.Time(datetime.datetime.now())
    tree = {'date': date}
    asdf = AsdfFile(tree=tree)
    instance = yamlutil.custom_tree_to_tagged_tree(tree['date'], asdf)

    asdf_schema.validate(instance, schema=schema)

    tag = 'tag:stsci.edu:asdf/time/time-1.1.0'
    date = tagged.tag_object(tag, date)
    tree = {'date': date}
    asdf = AsdfFile(tree=tree)
    instance = yamlutil.custom_tree_to_tagged_tree(tree['date'], asdf)

    asdf_schema.validate(instance, schema=schema)
예제 #13
0
    def _to_tree_from_model_tree(cls, tree, ctx):
        if tree.left.isleaf:
            left = yamlutil.custom_tree_to_tagged_tree(tree.left.value, ctx)
        else:
            left = cls._to_tree_from_model_tree(tree.left, ctx)

        if tree.right.isleaf:
            right = yamlutil.custom_tree_to_tagged_tree(tree.right.value, 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.value]
        except KeyError:
            raise ValueError("Unknown operator '{0}'".format(tree.value))

        node = tagged.tag_object(cls.make_yaml_tag(tag_name), node, ctx=ctx)
        return node
예제 #14
0
def test_time_tag():
    schema = asdf_schema.load_schema(
        'http://stsci.edu/schemas/asdf/time/time-1.1.0',
        resolve_references=True)
    schema = _flatten_combiners(schema)

    date = time.Time(datetime.datetime.now())
    tree = {'date': date}
    asdf = AsdfFile(tree=tree)
    instance = yamlutil.custom_tree_to_tagged_tree(tree['date'], asdf)

    asdf_schema.validate(instance, schema=schema)

    tag = 'tag:stsci.edu:asdf/time/time-1.1.0'
    date = tagged.tag_object(tag, date)
    tree = {'date': date}
    asdf = AsdfFile(tree=tree)
    instance = yamlutil.custom_tree_to_tagged_tree(tree['date'], asdf)

    asdf_schema.validate(instance, schema=schema)
예제 #15
0
    def to_tree_tagged(cls, model, ctx):
        left = model.left

        if isinstance(model.right, dict):
            right = {
                'keys': list(model.right.keys()),
                'values': list(model.right.values())
            }
        else:
            right = model.right

        node = {'forward': [left, right]}

        try:
            tag_name = 'transform/' + _operator_to_tag_mapping[model.op]
        except KeyError:
            raise ValueError(f"Unknown operator '{model.op}'")

        node = tagged.tag_object(cls.make_yaml_tag(tag_name), node, ctx=ctx)
        cls._to_tree_base_transform_members(model, node, ctx)
        return node
예제 #16
0
    def to_tree_transform(self, model):
        left = model.left

        if isinstance(model.right, dict):
            right = {
                'keys': list(model.right.keys()),
                'values': list(model.right.values())
            }
        else:
            right = model.right

        node = {'forward': [left, right]}

        try:
            tag_name = ('http://asdf-format.org/schemas/transform/' +
                        _operator_to_tag_mapping[model.op] + '-2.0.0')
        except KeyError:
            raise ValueError(f"Unknown operator '{model.op}'")

        node = tagged.tag_object(tag_name, node)

        return node
예제 #17
0
파일: compound.py 프로젝트: Cadair/astropy
    def _to_tree_from_model_tree(cls, tree, ctx):
        if tree.left.isleaf:
            left = yamlutil.custom_tree_to_tagged_tree(
                tree.left.value, ctx)
        else:
            left = cls._to_tree_from_model_tree(tree.left, ctx)

        if tree.right.isleaf:
            right = yamlutil.custom_tree_to_tagged_tree(
                tree.right.value, 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.value]
        except KeyError:
            raise ValueError("Unknown operator '{0}'".format(tree.value))

        node = tagged.tag_object(cls.make_yaml_tag(tag_name), node, ctx=ctx)
        return node
예제 #18
0
 def to_tree_tagged(cls, node: IsoBaseGroove, ctx):
     """Serialize tree with custom tag definition."""
     tree = cls.to_tree(node, ctx)
     tag = (WELDX_TAG_BASE + "/" + _ISO_GROOVE_SCHEMA +
            type(node).__name__ + "-" + str(cls.version))
     return tag_object(tag, tree, ctx=ctx)
예제 #19
0
파일: process.py 프로젝트: vhirtham/weldx
 def to_tree_tagged(cls, node: GmawProcess, ctx):
     """Serialize tree with custom tag definition."""
     tree = cls.to_tree(node, ctx)
     tag = "tag:weldx.bam.de:weldx/process/" + tree["tag"] + "-" + str(
         cls.version)
     return tag_object(tag, tree, ctx=ctx)