Example #1
0
    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'])

        if 'bounding_box' in node:
            model.bounding_box = yamlutil.tagged_tree_to_custom_tree(
                node['bounding_box'], ctx)

        if "inputs" in node:
            if model.n_inputs == 1:
                model.inputs = (node["inputs"], )
            else:
                model.inputs = tuple(node["inputs"])

        if "outputs" in node:
            if model.n_outputs == 1:
                model.outputs = (node["outputs"], )
            else:
                model.outputs = tuple(node["outputs"])

        return model
Example #2
0
File: wcs.py Project: olebole/gwcs
    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
Example #3
0
    def from_tree(cls, node, ctx):  # from ASDF to object representation

        sci = yamlutil.tagged_tree_to_custom_tree(node['sci'], ctx)
        wcs = yamlutil.tagged_tree_to_custom_tree(node['wcs'], ctx)
        spectrum = Spectrum(sci=sci, wcs=wcs)
        if 'obsinfo' in node:
            spectrum.obsinfo = yamlutil.tagged_tree_to_custom_tree(
                node['obsinfo'], ctx)
        if 'dq' in node:
            spectrum.dq = yamlutil.tagged_tree_to_custom_tree(node['dq'], ctx)
        if 'err' in node:
            spectrum.err = yamlutil.tagged_tree_to_custom_tree(
                node['err'], ctx)
        if 'aperture' in node:
            spectrum.aperture = yamlutil.tagged_tree_to_custom_tree(
                node['aperture'], ctx)
        if 'target_id' in node:
            spectrum.target_id = yamlutil.tagged_tree_to_custom_tree(
                node['target_id'], ctx)
        if 'background_corrected' in node:
            spectrum.background_corrected = yamlutil.tagged_tree_to_custom_tree(
                node['background_corrected'], ctx)
        if 'background_apertures' in node:
            spectrum.background_apertures = yamlutil.tagged_tree_to_custom_tree(
                node['background_apertures'], ctx)
        if 'meta' in node:
            spectrum.meta = yamlutil.tagged_tree_to_custom_tree(
                node['meta'], ctx)
        return spectrum
Example #4
0
    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'])

        if 'bounding_box' in node:
            model.bounding_box = yamlutil.tagged_tree_to_custom_tree(
                node['bounding_box'], ctx)

        if "inputs" in node:
            if model.n_inputs == 1:
                model.inputs = (node["inputs"], )
            else:
                model.inputs = tuple(node["inputs"])

        if "outputs" in node:
            if model.n_outputs == 1:
                model.outputs = (node["outputs"], )
            else:
                model.outputs = tuple(node["outputs"])

        param_and_model_constraints = {}
        for constraint in ['fixed', 'bounds']:
            if constraint in node:
                param_and_model_constraints[constraint] = node[constraint]
        model._initialize_constraints(param_and_model_constraints)

        return model
Example #5
0
 def from_tree(cls, node, ctx): # from ASDF to object representation
     fields = yamlutil.tagged_tree_to_custom_tree(node['fields'], ctx)
     field_separator = node['field_separator']
     datasets = yamlutil.tagged_tree_to_custom_tree(node['datasets'], ctx)
     mos = Mos(fields=fields, field_separator=field_separator, datasets=datasets)
     if 'meta' in node:
         mos.meta = yamlutil.tagged_tree_to_custom_tree(node['meta'], ctx)
     return mos
Example #6
0
 def from_tree(cls, node, ctx): # from ASDF to object representation
     id = node['proposal_id']
     prop = Proposal(id)
     if 'proposers' in node:
         prop.proposers = yamlutil.tagged_tree_to_custom_tree(node['proposers'], ctx)
     if 'proposal_title' in node:
         prop.title = node['proposal_title']
     if 'meta' in node:
         prop.meta = yamlutil.tagged_tree_to_custom_tree(node['meta'], ctx)
     return prop
Example #7
0
 def from_tree(cls, node, ctx): # from ASDF to object representation
     solar_system_body = node['solar_system_body']
     latitude = yamlutil.tagged_tree_to_custom_tree(node['latitude'], ctx)
     longitude = yamlutil.tagged_tree_to_custom_tree(node['longitude'], ctx)
     fixed_location = FixedLocation(latitude=latitude, longitude=longitude, 
                                    solar_system_body=solar_system_body)
     if 'altitude' in node:
         fixed_location.altitude = yamlutil.tagged_tree_to_custom_tree(node['altitude'], ctx)
     if 'meta' in node:
         fixed_location.meta = yamlutil.tagged_tree_to_custom_tree(node['meta'], ctx)
     return fixed_location
    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'])

        if 'bounding_box' in node:
            model.bounding_box = yamlutil.tagged_tree_to_custom_tree(node['bounding_box'], ctx)

        return model
    def from_tree(cls, node, ctx):  # from ASDF to object representation

        center = yamlutil.tagged_tree_to_custom_tree(node['center'], ctx)
        footprint = yamlutil.tagged_tree_to_custom_tree(node['footprint'], ctx)
        aperture_id = node['aperture_id']
        spectrum_aperture = SpectrumAperture(center=center,
                                             footprint=footprint,
                                             aperture_id=aperture_id)
        if 'meta' in node:
            spectrum_aperture.meta = yamlutil.tagged_tree_to_custom_tree(
                node['meta'], ctx)
        return spectrum_aperture
Example #10
0
 def from_tree(cls, node, ctx):  # from ASDF to object representation
     name = node['name']
     size = node['size']
     detector = Detector2dCCD(name, size)
     if 'binning' in node:
         detector.binning = yamlutil.tagged_tree_to_custom_tree(
             node['binning'], ctx)
     if 'subarray' in node:
         detector.subarray = yamlutil.tagged_tree_to_custom_tree(
             node['subarray'], ctx)
     if 'meta' in node:
         detector.meta = yamlutil.tagged_tree_to_custom_tree(
             node['meta'], ctx)
     return detector
 def from_tree(cls, node, ctx):  # from ASDF to object representation
     id = node['id']
     coordinates = yamlutil.tagged_tree_to_custom_tree(
         node['coordinates'], ctx)
     target = Target(id, coordinates=coordinates)
     if 'name' in node:
         target.name = node['name']
     if 'aliases' in node:
         target.aliases = yamlutil.tagged_tree_to_custom_tree(
             node['aliases'], ctx)
     if 'meta' in node:
         target.meta = yamlutil.tagged_tree_to_custom_tree(
             node['meta'], ctx)
     return target
Example #12
0
    def from_tree(cls, tree, ctx):
        """
        Converts tree representation back into Spectrum1D object
        """
        flux = tagged_tree_to_custom_tree(tree['flux'], ctx)
        spectral_axis = tagged_tree_to_custom_tree(tree['spectral_axis'], ctx)
        uncertainty = tree.get('uncertainty', None)
        if uncertainty is not None:
            klass = UNCERTAINTY_TYPE_MAPPING[uncertainty['uncertainty_type']]
            data = tagged_tree_to_custom_tree(uncertainty['data'], ctx)
            uncertainty = klass(data)

        return Spectrum1D(flux=flux, spectral_axis=spectral_axis,
                          uncertainty=uncertainty)
Example #13
0
    def _reference_frame_from_tree(cls, node, ctx):
        from astropy.units import Quantity
        from astropy.io.misc.asdf.tags.unit.quantity import QuantityType
        from astropy.coordinates import ICRS, CartesianRepresentation

        version = cls.version
        reference_frame = node['reference_frame']
        reference_frame_name = reference_frame['type']

        frame_cls = cls._get_reference_frame_mapping()[reference_frame_name]

        frame_kwargs = {}
        for name in frame_cls.get_frame_attr_names().keys():
            val = reference_frame.get(name)
            if val is not None:
                if name in ['obsgeoloc', 'obsgeovel']:
                    x = QuantityType.from_tree(val[0], ctx)
                    y = QuantityType.from_tree(val[1], ctx)
                    z = QuantityType.from_tree(val[2], ctx)
                    val = CartesianRepresentation(x, y, z)
                elif name == 'galcen_v_sun':
                    from astropy.coordinates import CartesianDifferential
                    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
        has_ra_and_dec = reference_frame.get('galcen_dec') and \
            reference_frame.get('galcen_ra')

        return frame_cls(**frame_kwargs)
Example #14
0
    def _reference_frame_from_tree(cls, node, ctx):
        from astropy.units import Quantity
        from astropy.io.misc.asdf.tags.unit.quantity import QuantityType
        from astropy.coordinates import ICRS, CartesianRepresentation

        version = cls.version
        reference_frame = node['reference_frame']
        reference_frame_name = reference_frame['type']

        frame_cls = cls._get_reference_frame_mapping()[reference_frame_name]

        frame_kwargs = {}
        for name in frame_cls.get_frame_attr_names().keys():
            val = reference_frame.get(name)
            if val is not None:
                if name in ['obsgeoloc', 'obsgeovel']:
                    x = QuantityType.from_tree(val[0], ctx)
                    y = QuantityType.from_tree(val[1], ctx)
                    z = QuantityType.from_tree(val[2], ctx)
                    val = CartesianRepresentation(x, y, z)
                elif name == 'galcen_v_sun':
                    from astropy.coordinates import CartesianDifferential
                    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
        has_ra_and_dec = reference_frame.get('galcen_dec') and \
            reference_frame.get('galcen_ra')

        return frame_cls(**frame_kwargs)
 def from_tree(cls, node, ctx): # from ASDF to object representation
     name = node['name']
     instrument_type = node['instrument_type']
     filters = yamlutil.tagged_tree_to_custom_tree(node['filters'], ctx)
     mode = yamlutil.tagged_tree_to_custom_tree(node['mode'], ctx)
     detectors = yamlutil.tagged_tree_to_custom_tree(node['detectors'], ctx)
     instrument = Instrument(name, instrument_type=instrument_type, filters=filters,
                             mode=mode, detectors=detectors)
     if 'disperser' in node:
         instrument.detector = node['disperser']
     if 'spectral_range' in node:
         instrument.spectral_range = node['spectral_range']
     if 'engineering' in node:
         instrument.engineering = node['engineering']
     if 'meta' in node:
         instrument.meta = node['meta']
     return instrument
Example #16
0
    def from_tree_tagged(cls, node, ctx):
        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, 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, 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)
        model.map_parameters()
        return model
Example #17
0
    def from_tree(cls, node, ctx):

        columns = [
            yamlutil.tagged_tree_to_custom_tree(c, ctx)
            for c in node['columns']
        ]

        return table.Table(columns, meta=node.get('meta', {}))
Example #18
0
    def from_tree(cls, node, ctx):

        columns = [
            yamlutil.tagged_tree_to_custom_tree(c, ctx)
            for c in node['columns']
        ]

        return table.Table(columns, meta=node.get('meta', {}))
Example #19
0
    def from_tree(cls, node, ctx):  # from ASDF to object representation

        obscontext = ObsContext()
        if 'telescope' in node:
            obscontext.telescope = yamlutil.tagged_tree_to_custom_tree(
                node['telescope'], ctx)
        if 'instrument' in node:
            obscontext.instrument = yamlutil.tagged_tree_to_custom_tree(
                node['instrument'], ctx)
        if 'proposal' in node:
            obscontext.proposal = yamlutil.tagged_tree_to_custom_tree(
                node['proposal'], ctx)
        if 'observers' in node:
            obscontext.observers = yamlutil.tagged_tree_to_custom_tree(
                node['observers'], ctx)
        if 'target' in node:
            obscontext.target = yamlutil.tagged_tree_to_custom_tree(
                node['target'], ctx)
        if 'associated_data' in node:
            obscontext.associated_data = yamlutil.tagged_tree_to_custom_tree(
                node['associated_data'], ctx)
        if 'meta' in node:
            obscontext.meta = yamlutil.tagged_tree_to_custom_tree(
                node['meta'], ctx)
        return obscontext
Example #20
0
    def from_tree_tagged(cls, node, ctx):
        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 from_tree(cls, node, ctx):  # from ASDF to object representation
     name = node['name']
     location = yamlutil.tagged_tree_to_custom_tree(node['location'], ctx)
     telescope = Telescope(name=name, location=location)
     if 'organization' in node:
         telescope.organization = node['organization']
     if 'org_url' in node:
         telescope.org_url = node['org_url']
     if 'telescope_url' in node:
         telescope.telescope_url = node['telescope_url']
     if 'telescope_type' in node:
         telescope.telescope_type = yamlutil.tagged_tree_to_custom_tree(
             node['telescope_type'], ctx)
     if 'location_name' in node:
         telescope.location_name = node['location_name']
     if 'meta' in node:
         telescope.meta = yamlutil.tagged_tree_to_custom_tree(
             node['meta'], ctx)
     return telescope
Example #22
0
    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)
Example #23
0
    def from_tree_tagged(cls, node, ctx):
        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, 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, Model) and \
            not (oper == 'fix_inputs' and isinstance(right, dict)):
            raise TypeError("Unknown model type '{0}'".format(
                node['forward'][1]._tag))
        if oper == 'fix_inputs':
            right = dict(zip(right['keys'], right['values']))
            model = CompoundModel('fix_inputs', left, right)
        else:
            model = getattr(left, oper)(right)

        model = cls._from_tree_base_transform_members(model, node, ctx)
        return model
Example #24
0
    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)
Example #25
0
    def from_tree(cls, node, ctx):

        # This is getting meta, guys
        meta = node.get('meta', {})

        # This enables us to support files that use the table definition from
        # the ASDF Standard, rather than the custom one that Astropy defines.
        if cls._compat:
            columns = [
                yamlutil.tagged_tree_to_custom_tree(col, ctx)
                for col in node['columns']
            ]
            return table.Table(columns, meta=meta)

        if node.get('qtable', False):
            t = table.QTable(meta=node.get('meta', {}))
        else:
            t = table.Table(meta=node.get('meta', {}))

        for name, col in zip(node['colnames'], node['columns']):
            t[name] = yamlutil.tagged_tree_to_custom_tree(col, ctx)

        return t
Example #26
0
    def from_tree(cls, node, ctx):

        # This is getting meta, guys
        meta = node.get('meta', {})

        # This enables us to support files that use the table definition from
        # the ASDF Standard, rather than the custom one that Astropy defines.
        if cls._compat:
            columns = [
                yamlutil.tagged_tree_to_custom_tree(col, ctx)
                for col in node['columns']
            ]
            return table.Table(columns, meta=meta)

        if node.get('qtable', False):
            t = table.QTable(meta=node.get('meta', {}))
        else:
            t = table.Table(meta=node.get('meta', {}))

        for name, col in zip(node['colnames'], node['columns']):
            t[name] = yamlutil.tagged_tree_to_custom_tree(col, ctx)

        return t
 def from_tree(cls, node, ctx):  # from ASDF to object representation
     name = node['name']
     obs = Observer(name)
     if 'email' in node:
         obs.email = node['email']
     if 'address' in node:
         obs.address = node['address']
     if 'institution' in node:
         obs.institution = node['institution']
     if 'PI' in node:
         obs.isPI = node['PI']
     if 'meta' in node:
         obs.meta = yamlutil.tagged_tree_to_custom_tree(node['meta'], ctx)
     return obs
Example #28
0
    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
Example #29
0
    def _from_tree(cls, node, ctx):
        kwargs = {'name': node['name']}

        if 'axes_names' in node:
            kwargs['axes_names'] = node['axes_names']

        if 'reference_frame' in node:
            kwargs['reference_frame'] = \
                cls._reference_frame_from_tree(node, 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))

        return kwargs
Example #30
0
    def _from_tree(cls, node, ctx):
        kwargs = {'name': node['name']}

        if 'axes_names' in node:
            kwargs['axes_names'] = node['axes_names']

        if 'reference_frame' in node:
            kwargs['reference_frame'] = \
                cls._reference_frame_from_tree(node, 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))

        return kwargs
Example #31
0
    def from_tree(cls, tree, ctx):
        mapping = tuple((i.get("unit"), o.get("unit"))
                        for i, o in zip(tree["inputs"], tree["outputs"]))

        equivalencies = None
        for i in tree["inputs"]:
            if "equivalencies" in i:
                if equivalencies is None:
                    equivalencies = {}
                equivalencies[i["name"]] = yamlutil.tagged_tree_to_custom_tree(
                    i["equivalencies"], ctx)

        kwargs = {
            "input_units_equivalencies": equivalencies,
            "input_units_allow_dimensionless": {
                i["name"]: i.get("allow_dimensionless", False)
                for i in tree["inputs"]
            },
        }

        if "name" in tree:
            kwargs["name"] = tree["name"]

        return mappings.UnitsMapping(mapping, **kwargs)
Example #32
0
 def from_tree(cls, tree, ctx):
     node = {}
     node['name'] = tree['name']
     node['things'] = yamlutil.tagged_tree_to_custom_tree(
         tree['things'], ctx)
     return node
Example #33
0
 def from_tree(cls, tree, ctx):
     """
     Converts tree representation back into SpectrumList object
     """
     spectra = [tagged_tree_to_custom_tree(node, ctx) for node in tree]
     return SpectrumList(spectra)
Example #34
0
 def from_tree(cls, tree, ctx):
     node = {}
     node['a'] = yamlutil.tagged_tree_to_custom_tree(tree['a'], ctx)
     node['b'] = yamlutil.tagged_tree_to_custom_tree(tree['b'], ctx)
     return node
    def from_tree(cls, node, ctx): # from ASDF to object representation

        wcs_set = WcsSet(yamlutil.tagged_tree_to_custom_tree(node['default'], ctx))
        # need to fill this out!
        return wcs_set
Example #36
0
    def from_tree(cls, node, ctx): # from ASDF to object representation

        xxxtype = Xxxtype()
        if 'meta' in node:
            prop.meta = yamlutil.tagged_tree_to_custom_tree(node['meta'], ctx)
        return xxxtype
Example #37
0
 def from_tree(cls, tree, ctx):
     node = {}
     node['name'] = tree['name']
     node['things'] = yamlutil.tagged_tree_to_custom_tree(tree['things'], ctx)
     return node
Example #38
0
 def from_tree(cls, tree, ctx):
     node = {}
     node['a'] = yamlutil.tagged_tree_to_custom_tree(tree['a'], ctx)
     node['b'] = yamlutil.tagged_tree_to_custom_tree(tree['b'], ctx)
     return node
Example #39
0
 def from_tree(cls, tree, ctx):
     x = yamlutil.tagged_tree_to_custom_tree(tree['x'], ctx)
     y = yamlutil.tagged_tree_to_custom_tree(tree['y'], ctx)
     return Fractional2dCoord(x, y)