예제 #1
0
    def testSetValue(self):
        host_role = "mango:stcextend.LonLatSkyPosition.coord"
        value_role = "mango:stcextend.LonLatPoint.longitude"

        appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                     output_mapping_path, None)
        appender.set_value(host_role, value_role, "ra_val")
        self.assertListEqual(
            get_vals(appender.mango_tree, host_role, value_role), ['ra_val'])
 def __init__(self, mango_path, component_path):
     '''
     Constructor
     '''
     self.mango_path = mango_path
     self.component_path = component_path
     self.position_path = os.path.join(component_path,
                                       "mango.GenericMeasure.mapping.xml")
     self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                       self.mango_path, self.position_path)
예제 #3
0
    def __init__(self, mango_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path

        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.mango_path, "")

        self.appender.add_globals()
        self.appender.insert_parameter_block()
예제 #4
0
    def __init__(self, mango_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path

        self.appender = ParameterAppender(PARAM_TEMPLATES.POSITION,
                                          self.mango_path, "")

        self.appender.add_globals()
        self.appender.add_param_parameter()
예제 #5
0
    def __init__(self, mango_path, param_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.status_path = param_path

        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.mango_path, self.status_path)

        self.appender.add_globals()
        self.appender.add_param_parameter()
예제 #6
0
    def __init__(self, mango_path, component_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.component_path = component_path
        self.position_path = os.path.join(
            component_path, "mango.LonLatSkyPosition.mapping.xml")
        self.appender = ParameterAppender(PARAM_TEMPLATES.POSITION,
                                          self.mango_path, self.position_path)

        #self.appender.add_globals()
        self.appender.add_param_parameter()
    def __init__(self, mango_path, component_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.component_path = component_path
        self.position_path = os.path.join(component_path,
                                          "mango.MJD.mapping.xml")
        logger.info("read  component %s", self.position_path)
        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.mango_path, self.position_path)

        #self.appender.add_globals()
        self.appender.add_param_parameter()
    def __init__(self, output_mapping_path, component_path):
        '''
        Constructor
        :param output_mapping_path: Output file with just the mapping block
        :type output_mapping_path: string
        :param component_path: Directory with all the mapping components
        :type component_path: string
        '''
        self.output_mapping_path = output_mapping_path
        self.component_path = component_path
        # get the mapping component attached to this appender
        self.position_path = os.path.join(
            component_path, "mango.LonLatSkyPosition.mapping.xml")
        logger.info("read  component %s", self.position_path)

        # Build the appender instance
        # The appender is in charge of all operations modifying the mapping component
        # to build an XML block ready to be inserted to the mapping
        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.output_mapping_path,
                                          self.position_path)
예제 #9
0
class IdentifierAppender:
    '''
    classdocs
    '''
    def __init__(self, mango_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path

        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.mango_path, "")

        self.appender.add_globals()
        self.appender.insert_parameter_block()

    def append_measure(self, source_descriptor):
        self.set_identifier(source_descriptor["identifier"])

        self.set_notset_value()

    def set_identifier(self, identifier_ref):
        self.appender.set_ref("root", "mango:MangoObject.identifier",
                              identifier_ref)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        self.appender.save(output_path)
예제 #10
0
class HardnessRatioAppender:
    '''
    classdocs
    '''
    def __init__(self, mango_path, component_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.component_path = component_path
        self.position_path = os.path.join(component_path,
                                          "mango.HardnessRatio.mapping.xml")
        self.appender = ParameterAppender(PARAM_TEMPLATES.POSITION,
                                          self.mango_path, self.position_path)

        #self.appender.add_globals()
        self.appender.add_param_parameter()

    def append_measure(self, measure_descriptor):
        self.set_param_semantic(measure_descriptor["ucd"],
                                measure_descriptor["semantic"],
                                measure_descriptor["description"])

        frames = measure_descriptor["frame"]["frame"]
        if type(frames) is list:
            for frame in frames:
                self.set_spaceframe(frame)
        else:
            self.set_spaceframe(frames)

        self.set_position(measure_descriptor["coordinate"]["value"])
        self.set_errors(measure_descriptor["errors"]["random"]["value"])
        self.set_notset_value()

    def set_spaceframe(self, frame):
        with open(
                os.path.join(self.component_path,
                             "mango.frame." + frame + ".xml")) as xml_file:
            data = xml_file.read()
            self.appender.add_globals_xx(data)
            self.appender.set_dmref("coords:Coordinate.coordSys",
                                    "PhotFrame_" + frame)
        return

    def set_position(self, luminosity):
        self.appender.set_ref_or_value(
            "mango:stcextend.Photometry.coord",
            "mango:stcextend.PhotometryCoord.luminosity", luminosity)

    def set_errors(self, err_ref):
        if err_ref is not None:
            self.appender.set_ref_or_value("meas:Error.statError",
                                           "ivoa:RealQuantity.value", err_ref)

    def set_param_semantic(self, ucd, semantic, descripton):
        self.appender.set_param_semantic(ucd, semantic, descripton)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        self.appender.save(output_path)
class DetectionFlagAppender:
    '''
    classdocs
    '''
    def __init__(self, mango_path, component_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.component_path = component_path
        self.position_path = os.path.join(component_path,
                                          "mango.DetectionFlag.mapping.xml")
        self.appender = ParameterAppender(PARAM_TEMPLATES.POSITION,
                                          self.mango_path, self.position_path)

        #self.appender.add_globals()
        self.appender.add_param_parameter()

    def append_measure(self, measure_descriptor):
        self.set_param_semantic(measure_descriptor["ucd"],
                                measure_descriptor["semantic"],
                                measure_descriptor["description"])

        self.set_position(measure_descriptor["coordinate"]["value"])
        self.set_spaceframe(measure_descriptor["frame"]["frame"])

        self.set_notset_value()

    def set_spaceframe(self, frame):
        with open(
                os.path.join(self.component_path,
                             "mango.frame." + frame + ".xml")) as xml_file:
            data = xml_file.read()
            self.appender.add_globals_xx(data)
            self.appender.set_dmref("coords:Coordinate.coordSys",
                                    "StatusFrame_" + frame)
        return

    def set_position(self, value):
        self.appender.set_ref_or_value("mango:stcextend.Flag.coord",
                                       "mango:stcextend.FlagCoord.coord",
                                       value)

    def set_param_semantic(self, ucd, semantic, description):
        self.appender.set_param_semantic(ucd, semantic, description)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        self.appender.save(output_path)
class GenericAppender:
    '''
    classdocs
    '''
    def __init__(self, mango_path, component_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.component_path = component_path
        self.position_path = os.path.join(component_path,
                                          "mango.GenericMeasure.mapping.xml")
        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.mango_path, self.position_path)

    def append_measure(self, measure_descriptor):
        self.set_param_semantic(measure_descriptor["ucd"],
                                measure_descriptor["semantic"],
                                measure_descriptor["description"],
                                measure_descriptor["reductionStatus"])

        self.set_position(measure_descriptor["coordinate"]["value"],
                          measure_descriptor["coordinate"]["unit"])

        if "randomerrors" in measure_descriptor.keys():
            self.set_errors(measure_descriptor["errors"])

        self.set_notset_value()
        self.appender.insert_parameter_block()

    def set_position(self, value, unit):
        self.appender.set_ref_or_value("coords:PhysicalCoordinate.cval",
                                       "ivoa:RealQuantity.value", value)
        self.appender.set_ref_or_value("coords:PhysicalCoordinate.cval",
                                       "ivoa:RealQuantity.unit", unit)

    def set_errors(self, error_object):

        if "random" in error_object.keys():
            rand = error_object["random"]
            if "value" in rand.keys() is not None:
                self.appender.set_ref_or_value("meas:Error.statError",
                                               "ivoa:RealQuantity.value",
                                               rand["value"])
            if "unit" in rand.keys() is not None:
                self.appender.set_ref_or_value("meas:Error.statError",
                                               "ivoa:RealQuantity.unit",
                                               rand["unit"])

    def set_param_semantic(self, ucd, semantic, description, reduction_status):
        self.appender.set_param_semantic(ucd, semantic, description,
                                         reduction_status)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        self.appender.save(output_path)
예제 #13
0
class GenericAppender:
    '''
    classdocs
    '''
    def __init__(self, mango_path, component_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.component_path = component_path
        self.position_path = os.path.join(component_path,
                                          "mango.GenericMeasure.mapping.xml")
        self.appender = ParameterAppender(PARAM_TEMPLATES.POSITION,
                                          self.mango_path, self.position_path)

        #self.appender.add_globals()
        self.appender.add_param_parameter()

    def append_measure(self, measure_descriptor):
        self.set_param_semantic(measure_descriptor["ucd"],
                                measure_descriptor["semantic"],
                                measure_descriptor["description"])

        self.set_position(measure_descriptor["coordinate"]["value"],
                          measure_descriptor["coordinate"]["unit"])

        self.set_notset_value()

    def set_position(self, value, unit):
        self.appender.set_ref_or_value("coords:PhysicalCoordinate.cval",
                                       "ivoa:RealQuantity.value", value)
        self.appender.set_ref_or_value("coords:PhysicalCoordinate.cval",
                                       "ivoa:RealQuantity.unit", unit)

    def set_param_semantic(self, ucd, semantic, description):
        self.appender.set_param_semantic(ucd, semantic, description)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        self.appender.save(output_path)
class PhotometryAppender:
    '''
    classdocs
    '''
    def __init__(self, mango_path, component_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.component_path = component_path
        self.position_path = os.path.join(component_path,
                                          "mango.Photometry.mapping.xml")
        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.mango_path, self.position_path)

    def append_measure(self, measure_descriptor):
        self.set_param_semantic(measure_descriptor["ucd"],
                                measure_descriptor["semantic"],
                                measure_descriptor["description"],
                                measure_descriptor["reductionStatus"])

        self.connect_spaceframe(measure_descriptor["frame"]["frame"])
        self.set_position(measure_descriptor["luminosity"]["luminosity"])

        self.set_errors(measure_descriptor["errors"])
        self.set_notset_value()
        self.appender.insert_parameter_block()
        self.set_spaceframe(measure_descriptor["frame"]["frame"])

    def connect_spaceframe(self, frame):
        self.appender.set_dmref("coords:Coordinate.coordSys",
                                "PhotFrame_" + frame)
        return

    def set_spaceframe(self, frame):
        with open(
                os.path.join(self.component_path,
                             "mango.frame." + frame + ".xml")) as xml_file:
            data = xml_file.read()
            self.appender.add_instance_to_globals(data)
        return

    def set_position(self, luminosity):
        self.appender.set_ref_or_value(
            "mango:stcextend.Photometry.coord",
            "mango:stcextend.PhotometryCoord.luminosity", luminosity)

    def set_errors(self, error_object):

        if "random" in error_object.keys():
            rand = error_object["random"]
            if "value" in rand.keys() is not None:
                self.appender.set_ref_or_value("meas:Error.statError",
                                               "ivoa:RealQuantity.value",
                                               rand["value"])
            if "unit" in rand.keys() is not None:
                self.appender.set_ref_or_value("meas:Error.statError",
                                               "ivoa:RealQuantity.unit",
                                               rand["unit"])

    def set_param_semantic(self, ucd, semantic, description, reduction_status):
        self.appender.set_param_semantic(ucd, semantic, description,
                                         reduction_status)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        self.appender.save(output_path)
예제 #15
0
class PositionAppender:
    '''
    classdocs
    '''
    def __init__(self, mango_path, component_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.component_path = component_path
        self.position_path = os.path.join(
            component_path, "mango.LonLatSkyPosition.mapping.xml")
        self.appender = ParameterAppender(PARAM_TEMPLATES.POSITION,
                                          self.mango_path, self.position_path)

        #self.appender.add_globals()
        self.appender.add_param_parameter()

    def append_measure(self, measure_descriptor):
        self.set_param_semantic(measure_descriptor["ucd"],
                                measure_descriptor["semantic"],
                                measure_descriptor["description"])

        self.set_spaceframe(measure_descriptor["frame"]["frame"],
                            measure_descriptor["frame"]["equinox"])
        self.set_position(measure_descriptor["position"]["longitude"],
                          measure_descriptor["position"]["latitude"])
        self.set_errors(measure_descriptor["errors"]["random"]["value"],
                        measure_descriptor["errors"]["random"]["unit"],
                        measure_descriptor["errors"]["systematic"]["value"],
                        measure_descriptor["errors"]["systematic"]["unit"])
        self.set_notset_value()

    def set_spaceframe(self, frame, equinox):
        with open(
                os.path.join(self.component_path,
                             "mango.frame." + frame + ".xml")) as xml_file:
            data = xml_file.read()
            self.appender.add_globals_xx(data)
            self.appender.set_dmref("coords:Coordinate.coordSys",
                                    "SpaceFrame_" + frame)
        return

    def set_position(self, ra_ref, dec_ref):
        self.appender.set_ref_or_value(
            "mango:stcextend.LonLatSkyPosition.coord",
            "mango:stcextend.LonLatPoint.longitude", ra_ref)
        self.appender.set_ref_or_value(
            "mango:stcextend.LonLatSkyPosition.coord",
            "mango:stcextend.LonLatPoint.latitude", dec_ref)

    def set_errors(self, err_ref, err_unit, sys_err_ref, sys_err_unit):
        if err_ref is not None:
            self.appender.set_ref_or_value("meas:Error.statError",
                                           "ivoa:RealQuantity.value", err_ref)

            self.appender.set_ref_or_value("meas:Error.statError",
                                           "ivoa:Quantity.unit", err_unit)
        if sys_err_ref is not None:
            self.appender.set_ref_or_value("meas:Error.sysError",
                                           "ivoa:RealQuantity.value",
                                           sys_err_ref)

            self.appender.set_ref_or_value("meas:Error.sysError",
                                           "ivoa:Quantity.unit", sys_err_unit)

    def set_param_semantic(self, ucd, semantic, description):
        self.appender.set_param_semantic(ucd, semantic, description)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        self.appender.save(output_path)
class MJDAppender:
    '''
    classdocs
    '''
    def __init__(self, mango_path, component_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.component_path = component_path
        self.position_path = os.path.join(component_path,
                                          "mango.MJD.mapping.xml")
        logger.info("read  component %s", self.position_path)
        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.mango_path, self.position_path)

        #self.appender.add_globals()
        self.appender.add_param_parameter()

    def append_measure(self, measure_descriptor):
        self.set_param_semantic(measure_descriptor["ucd"],
                                measure_descriptor["semantic"],
                                measure_descriptor["description"])

        self.set_spaceframe(measure_descriptor["frame"]["frame"])

        self.set_position(measure_descriptor["coordinate"]["value"],
                          measure_descriptor["coordinate"]["unit"])

        self.set_notset_value()

    def set_spaceframe(self, frame):
        #
        # set space frame instance
        #

        with open(
                os.path.join(self.component_path,
                             "mango.frame." + frame + ".xml")) as xml_file:
            data = xml_file.read()
            # Put the frame in the globals if it is not there
            self.appender.add_globals_xx(data)
            self.appender.set_dmref("coords:Coordinate.coordSys",
                                    "TimeFrame_" + frame)
        return

    def set_position(self, value, unit):
        self.appender.set_ref_or_value("meas:Time.coord", "coords:MJD.date",
                                       value)

    def set_param_semantic(self, ucd, semantic, description):
        self.appender.set_param_semantic(ucd, semantic, description)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        self.appender.save(output_path)
class LonLatPositionAppender:
    '''
    classdocs
    '''
    def __init__(self, output_mapping_path, component_path):
        '''
        Constructor
        :param output_mapping_path: Output file with just the mapping block
        :type output_mapping_path: string
        :param component_path: Directory with all the mapping components
        :type component_path: string
        '''
        self.output_mapping_path = output_mapping_path
        self.component_path = component_path
        # get the mapping component attached to this appender
        self.position_path = os.path.join(
            component_path, "mango.LonLatSkyPosition.mapping.xml")
        logger.info("read  component %s", self.position_path)

        # Build the appender instance
        # The appender is in charge of all operations modifying the mapping component
        # to build an XML block ready to be inserted to the mapping
        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.output_mapping_path,
                                          self.position_path)

    def append_measure(self, json_measure_descriptor):
        """
        push the values and refs read in the config into the new mapping block
        :param json_measure_descriptor: description of the position measure
        :type json_measure_descriptor: dict
        """
        self.set_param_semantic(json_measure_descriptor["ucd"],
                                json_measure_descriptor["semantic"],
                                json_measure_descriptor["description"],
                                json_measure_descriptor["reductionStatus"])
        self.connect_spaceframe(json_measure_descriptor["frame"]["frame"],
                                json_measure_descriptor["frame"]["equinox"])

        self.set_position(json_measure_descriptor["position"]["longitude"],
                          json_measure_descriptor["position"]["latitude"])
        self.set_errors(json_measure_descriptor["errors"])
        self.set_notset_value()
        self.appender.insert_parameter_block()
        self.set_spaceframe(json_measure_descriptor["frame"]["frame"],
                            json_measure_descriptor["frame"]["equinox"])

    def set_spaceframe(self, frame, equinox):
        #
        # set space frame instance
        #
        with open(
                os.path.join(self.component_path,
                             "mango.frame." + frame + ".xml")) as xml_file:
            data = xml_file.read()
            # Put the frame in the globals if it is not there
            self.appender.add_instance_to_globals(data)
        return

    def connect_spaceframe(self, frame, equinox):
        self.appender.set_dmref("coords:Coordinate.coordSys",
                                "SpaceFrame_" + frame)
        return

    def set_position(self, ra_ref, dec_ref):
        self.appender.set_ref_or_value(
            "mango:stcextend.LonLatSkyPosition.coord",
            "mango:stcextend.LonLatPoint.longitude", ra_ref)
        self.appender.set_ref_or_value(
            "mango:stcextend.LonLatSkyPosition.coord",
            "mango:stcextend.LonLatPoint.latitude", dec_ref)

    def set_errors(self, error_object):

        if "random" in error_object.keys():
            rand = error_object["random"]
            if "value" in rand.keys() is not None:
                self.appender.set_ref_or_value("meas:Error.statError",
                                               "ivoa:RealQuantity.value",
                                               rand["value"])
            if "unit" in rand.keys() is not None:
                self.appender.set_ref_or_value("meas:Error.statError",
                                               "ivoa:RealQuantity.unit",
                                               rand["unit"])

        if "systematic" in error_object.keys():
            rand = error_object["random"]
            if "value" in rand.keys() is not None:
                self.appender.set_ref_or_value("meas:Error.sysError",
                                               "ivoa:RealQuantity.value",
                                               rand["value"])
            if "unit" in rand.keys() is not None:
                self.appender.set_ref_or_value("meas:Error.sysError",
                                               "ivoa:RealQuantity.unit",
                                               rand["unit"])

    def set_param_semantic(self, ucd, semantic, description, reduction_status):
        self.appender.set_param_semantic(ucd, semantic, description,
                                         reduction_status)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        """
        Just for the developper to have a snapshot
        """
        self.appender.save(output_path)
예제 #18
0
class StatusAppender:
    '''
    classdocs
    '''
    def __init__(self, mango_path, param_path):
        '''
        Constructor
        '''
        self.mango_path = mango_path
        self.status_path = param_path

        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.mango_path, self.status_path)

        self.appender.add_globals()
        self.appender.add_param_parameter()

    def append_measure(self, measure_descriptor):
        self.set_param_semantic(measure_descriptor["ucd"],
                                measure_descriptor["semantic"],
                                measure_descriptor["description"])

        self.set_identifier(measure_descriptor["identifier"])

        self.set_status(measure_descriptor["status"]["value"])
        self.set_notset_value()

    def set_spaceframe(self, frame, equinox):

        self.appender.set_value("coords:PhysicalCoordSys.frame",
                                "coords:SpaceFrame.spaceRefFrame", frame)
        if equinox is not None:
            self.appender.set_value("coords:PhysicalCoordSys.frame",
                                    "coords:SpaceFrame.equinox", equinox)

    def set_status(self, status_ref):
        self.appender.set_ref("mango:STCStatus.coord",
                              "mango:STCStatusState.status", status_ref)

    def set_param_semantic(self, ucd, semantic, description):
        self.appender.set_param_semantic(ucd, semantic, description)

    def set_identifier(self, identifier_ref):
        self.appender.set_ref("root", "mango:MangoObject.identifier",
                              identifier_ref)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        self.appender.save(output_path)
class HardnessRatioAppender:
    '''
    classdocs
    '''
    
    def __init__(self, mango_path, component_path):           
        '''
        Constructor
        '''
        self.mango_path = mango_path    
        self.component_path = component_path  
        self.position_path = os.path.join(component_path, 
                                          "mango.HardnessRatio.mapping.xml")
        self.appender = ParameterAppender(
            PARAM_TABLE_MAPPING.POSITION,
            self.mango_path,
            self.position_path
            )
    
    def append_measure(self, measure_descriptor):  
        self.set_param_semantic(measure_descriptor["ucd"], 
                                measure_descriptor["semantic"],
                                measure_descriptor["description"],
                                measure_descriptor["reductionStatus"]
                                )
        self.connect_spaceframe(measure_descriptor["frame"]["frame"])

        self.set_position(measure_descriptor["coordinate"]["value"]
                          ) 
        self.set_errors(measure_descriptor["errors"]) 

        self.set_notset_value()
        self.appender.insert_parameter_block()
        
        frames = measure_descriptor["frame"]["frame"]
        self.set_spaceframe(frames)

    
    def connect_spaceframe(self, frame):   
        # frame array should starts with components and ends with the wanted frame
        if isinstance(frame, list) is True:
            sframe = frame[len(frame) - 1] 
        else :
            sframe = frame
        self.appender.set_dmref("coords:Coordinate.coordSys", "PhotFrame_" + sframe)
        return
    
    def set_spaceframe(self, frame):   
        # frame array should starts with components and ends with the wanted frame
        if isinstance(frame, list) is True:
            for sframe in frame:
                with open(os.path.join(self.component_path, "mango.frame." + sframe + ".xml")) as xml_file:
                    data = xml_file.read()
                    self.appender.add_instance_to_globals(data)            
        else :
            with open(os.path.join(self.component_path, "mango.frame." + frame + ".xml")) as xml_file:
                data = xml_file.read()
                self.appender.add_instance_to_globals(data)
        return
                 
    def set_position(self, luminosity):
        self.appender.set_ref_or_value("mango:stcextend.HardnessRatio.coord",
                              "mango:stcextend.HardnessRatioCoord.hardnessRatio",
                              luminosity)
                                     

    def set_errors(self, error_object):
        
        if "random" in error_object.keys():
            rand = error_object["random"]
            if "value" in rand.keys() is not None:
                self.appender.set_ref_or_value("meas:Error.statError", 
                    "ivoa:RealQuantity.value", 
                     rand["value"])
         
             
    def set_param_semantic(self, ucd, semantic, descripton, reduction_status):
        self.appender.set_param_semantic(ucd, semantic, descripton, reduction_status) 


    def set_notset_value(self):
        self.appender.set_notset_value()
        
    def tostring(self):
        return self.appender.tostring()
        
    def save(self, output_path):
        self.appender.save(output_path)
예제 #20
0
class ProperMotionAppender:
    '''
    classdocs
    '''
    def __init__(self, output_mapping_path, component_path):
        '''
        Constructor
        :param output_mapping_path: Output file with just the mapping block
        :type output_mapping_path: string
        :param component_path: Directory with all the mapping components
        :type component_path: string
        '''
        self.output_mapping_path = output_mapping_path
        self.component_path = component_path
        # get the mapping component attached to this appender
        self.position_path = os.path.join(component_path,
                                          "mango.ProperMotion.mapping.xml")
        logger.info("read  component %s", self.position_path)

        # Build the appender instance
        # The appender is in charge of all operations modifying the mapping component
        # to build an XML block ready to be inserted to the mapping
        self.appender = ParameterAppender(PARAM_TABLE_MAPPING.POSITION,
                                          self.output_mapping_path,
                                          self.position_path)

    def append_measure(self, json_measure_descriptor):
        """
        push the values and refs read in the config into the new mapping block
        :param json_measure_descriptor: description of the position measure
        :type json_measure_descriptor: dict
        """
        self.set_param_semantic(json_measure_descriptor["ucd"],
                                json_measure_descriptor["semantic"],
                                json_measure_descriptor["description"],
                                json_measure_descriptor["reductionStatus"])

        self.set_position(json_measure_descriptor["position"]["longitude"],
                          json_measure_descriptor["position"]["latitude"],
                          json_measure_descriptor["position"]["unit"])
        self.set_errors(
            json_measure_descriptor["errors"]["random"]["longitude"],
            json_measure_descriptor["errors"]["random"]["latitude"],
            json_measure_descriptor["errors"]["random"]["unit"])

        self.set_notset_value()
        self.appender.insert_parameter_block()

    def set_position(self, ra_ref, dec_ref, unit):
        self.appender.set_ref_or_value("meas:ProperMotion.lon",
                                       "ivoa:RealQuantity.value", ra_ref)
        self.appender.set_ref_or_value("meas:ProperMotion.lon",
                                       "ivoa:Quantity.unit", unit)
        self.appender.set_ref_or_value("meas:ProperMotion.lat",
                                       "ivoa:RealQuantity.value", dec_ref)
        self.appender.set_ref_or_value("meas:ProperMotion.lat",
                                       "ivoa:Quantity.unit", unit)

    def set_errors(self, err_ref_ra, err_ref_dec, err_unit):

        self.appender.set_ref_or_value("meas:Ellipse.posAngle",
                                       "ivoa:RealQuantity.value", "0.0")
        self.appender.set_ref_or_value("meas:Ellipse.posAngles",
                                       "ivoa:Quantity.unit", "deg")

        if err_ref_ra is not None:

            self.appender.set_ref_or_value("meas:Ellipse.semiAxis",
                                           "ivoa:RealQuantity.value",
                                           err_ref_ra,
                                           rank=0)

            self.appender.set_ref_or_value("meas:Ellipse.semiAxis",
                                           "ivoa:RealQuantity.value",
                                           err_ref_dec,
                                           rank=1)
            self.appender.set_ref_or_value("meas:Ellipse.semiAxis",
                                           "ivoa:Quantity.unit", err_unit)

    def set_param_semantic(self, ucd, semantic, description, reduction_status):
        self.appender.set_param_semantic(ucd, semantic, description,
                                         reduction_status)

    def set_notset_value(self):
        self.appender.set_notset_value()

    def tostring(self):
        return self.appender.tostring()

    def save(self, output_path):
        """
        Just for the developper to have a snapshot
        """
        self.appender.save(output_path)