Beispiel #1
0
    def _onSourceAddGALPROPDiffuseSource(self):
        if debug: print 'Source/Add GALPROP Diffuse Source'

        # Create a new GALPROP diffuse Source.
        name = 'GALPROP Diffuse Source %d' % self._getSourceID()

        # Create a constant value spectrum for the GALPROP source.
        spectrum = Spectrum(type='ConstantValue')

        # Adjust the Value parameter.
        parameter = spectrum.getParameterByName('Value')
        parameter.setValue(1.0)
        parameter.setScale(1.0)
        parameter.setMin(0.0)
        parameter.setMax(10.0)
        parameter.setFree(True)
        spectrum.setParameterByName('Value', parameter)

        # Create a map cube spatial model.
        spatialModel = SpatialModel(
            type='MapCubeFunction',
            file=ModelEditorApp._GalpropDiffuseSourcePath)

        # Adjust the Normalization parameter.
        parameter = spatialModel.getParameterByName('Normalization')
        parameter.setValue(1.0)
        parameter.setScale(1.0)
        parameter.setMin(0.001)
        parameter.setMax(1000.0)
        parameter.setFree(False)
        spatialModel.setParameterByName('Normalization', parameter)

        # Assemble the source.
        source = Source(name=name,
                        type='DiffuseSource',
                        spectrum=spectrum,
                        spatialModel=spatialModel)

        # Fetch the current SourceLibraryDocument.
        sourceLibraryDocument = self._sourceLibraryDocumentEditor.get()

        # Append the new Source to the list of Sources.
        sourceLibraryDocument.addSource(source)

        # Populate the editor with the changes.
        self._sourceLibraryDocumentEditor.set(sourceLibraryDocument)

        # Select the new source.
        self._sourceLibraryDocumentEditor.selectSource(name)
Beispiel #2
0
    def _onSourceAddExtragalacticDiffuseSource(self):
        if debug: print 'Source/Add Extragalactic Source'

        # Create a new extragalactic diffuse Source.
        name = 'Extragalactic Diffuse Source %d' % self._getSourceID()

        # Create a power law spectrum for the extragalactic
        # background.
        spectrum = Spectrum(type='PowerLaw')

        # Adjust the Prefactor parameter.
        parameter = spectrum.getParameterByName('Prefactor')
        parameter.setValue(1.6)
        parameter.setScale(1.0e-7)
        parameter.setMin(1.0e-5)
        parameter.setMax(100.0)
        parameter.setFree(True)
        spectrum.setParameterByName('Prefactor', parameter)

        # Adjust the Index parameter.
        parameter = spectrum.getParameterByName('Index')
        parameter.setValue(-2.1)
        parameter.setScale(1.0)
        parameter.setMin(-3.5)
        parameter.setMax(-1.0)
        parameter.setFree(False)
        spectrum.setParameterByName('Index', parameter)

        # Adjust the Scale parameter.
        parameter = spectrum.getParameterByName('Scale')
        parameter.setValue(100.0)
        parameter.setScale(1.0)
        parameter.setMin(50.0)
        parameter.setMax(200.0)
        parameter.setFree(False)
        spectrum.setParameterByName('Scale', parameter)

        # Create a constant value (all-sky) location model.
        spatialModel = SpatialModel(type='ConstantValue')

        # Assemble the source.
        source = Source(name=name,
                        type='DiffuseSource',
                        spectrum=spectrum,
                        spatialModel=spatialModel)

        # Fetch the current SourceLibraryDocument.
        sourceLibraryDocument = self._sourceLibraryDocumentEditor.get()

        # Append the new Source to the list of Sources.
        sourceLibraryDocument.addSource(source)

        # Populate the editor with the changes.
        self._sourceLibraryDocumentEditor.set(sourceLibraryDocument)

        # Select the new source.
        self._sourceLibraryDocumentEditor.selectSource(name)
Beispiel #3
0
    def _onSourceAddEGRETDiffuseSource(self):
        if debug: print ('Source/Add EGRET Diffuse Source')

        # Create a new EGRET diffuse Source.
        name = 'EGRET Diffuse Source %d' % self._getSourceID()

        # Create a power law spectrum for the EGRET diffuse source.
        spectrum = Spectrum(type = 'PowerLaw')

        # Adjust the Prefactor parameter.
        parameter = spectrum.getParameterByName('Prefactor')
        parameter.setValue(11.0)
        parameter.setScale(0.001)
        parameter.setMin(0.001)
        parameter.setMax(1000.0)
        parameter.setFree(True)
        spectrum.setParameterByName('Prefactor', parameter)

        # Adjust the Index parameter.
        parameter = spectrum.getParameterByName('Index')
        parameter.setValue(-2.1)
        parameter.setScale(1.0)
        parameter.setMin(-3.5)
        parameter.setMax(-1.0)
        parameter.setFree(False)
        spectrum.setParameterByName('Index', parameter)

        # Adjust the Scale parameter.
        parameter = spectrum.getParameterByName('Scale')
        parameter.setValue(100.0)
        parameter.setScale(1.0)
        parameter.setMin(50.0)
        parameter.setMax(200.0)
        parameter.setFree(False)
        spectrum.setParameterByName('Scale', parameter)

        # Create a spatial map spatial model.
        spatialModel = SpatialModel(type = 'SpatialMap',
                                    file = ModelEditorApp._EgretDiffuseSourcePath)
        source = Source(name = name, type = 'DiffuseSource',
                        spectrum = spectrum, spatialModel = spatialModel)

        # Assemble the source.
        source = Source(name = name, type = 'DiffuseSource',
                        spectrum = spectrum, spatialModel = spatialModel)

        # Fetch the current SourceLibraryDocument.
        sourceLibraryDocument = self._sourceLibraryDocumentEditor.get()

        # Append the new Source to the list of Sources.
        sourceLibraryDocument.addSource(source)

        # Populate the editor with the changes.
        self._sourceLibraryDocumentEditor.set(sourceLibraryDocument)

        # Select the new source.
        self._sourceLibraryDocumentEditor.selectSource(name)
Beispiel #4
0
    def _addNewSource(self, ra, dec):
        """Add new source to the model

        Parameters:
        - self - This DS9Connector object
        - ra - The RA of the center of the ds9 region to be added as a source
        - dec - The Dec of the cetner of the ds9 region to be added as a source

        Return value:
        - none

        Description:
            This method adds a default Source object (PowerLaw spectrum) at
        the RA and Dec passed to it.  The source name is constructed from the
        RA and Dec and proceeded with the 'ME_' designation to show it was
        added via ds9 and the model editor.
            Access to the SourceLibraryDocumentEditor object is controlled
        via a thread lock to prevent race conditions.  As this method causes
        modifications in the GUI, it must be run on the main thread.
        """
        #        print "Entering _addNewSource"
        # create a name
        name = "ME_" + str(ra) + "_" + str(dec)
        # make a default PL source
        source = Source(name=name)
        # set the RA/dec
        raParam = Parameter(name="RA",
                            value=ra,
                            scale=1.0,
                            min=0.0,
                            max=360.0,
                            free=False)
        decParam = Parameter(name="DEC",
                             value=dec,
                             scale=1.0,
                             min=-90.0,
                             max=90.0,
                             free=False)
        spatialModel = SpatialModel(type="SkyDirFunction",
                                    parameters=[raParam, decParam])
        source.setSpatialModel(spatialModel)

        #        print "Locking editor"
        # add source to model list
        with self.docLock:
            sourceLibraryDocument = self.sourceLibraryDocumentEditor.get()
            sourceLibraryDocument.addSource(source)
            self.sourceLibraryDocumentEditor.set(sourceLibraryDocument)
            self.sourceLibraryDocumentEditor.commit()
#        print "Unlocked editor"
#get Source index of new source and set as selected source
        self.sourceLibraryDocumentEditor.selectSource(name)
Beispiel #5
0
    def fromDom(self, dom):
        """Initialize this Source from a xml.dom.minidom.Element.

        Parameters:

        self: This object.

        dom (xml.dom.minidom.Element): DOM element to use as the
        source of this Source.

        Return value:

        None.

        Description:

        Use the specified DOM element as the source of the content of
        this Source. Set all data attributes using the corresponding
        attribute and element nodes of the DOM element.
        """

        # Call the inherited method.
        Element.fromDom(self, dom)

        # name
        self.setName(dom.getAttribute('name'))

        # type
        self.setType(dom.getAttribute('type'))

        # <spectrum> element
        domSpectrum = dom.getElementsByTagName('spectrum').item(0)
        spectrum = Spectrum(dom=domSpectrum)
        self.setSpectrum(spectrum)

        # <spatialModel> element
        domSpatialModel = dom.getElementsByTagName('spatialModel').item(0)
        spatialModel = SpatialModel(dom=domSpatialModel)
        self.setSpatialModel(spatialModel)
Beispiel #6
0
# Self-test code.

# If this code generates any output, an error has been found.

if __name__ == '__main__':

    # Default constructor.
    source = Source()
    assert str(
        source
    ) == 'Source(_name=source,_spatialModel=SpatialModel(_file=None,_parameters=[Parameter(_free=False,_max=360.0,_min=0.0,_name=RA,_scale=1.0,_tagName=parameter,_value=0.0),Parameter(_free=False,_max=90.0,_min=-90.0,_name=DEC,_scale=1.0,_tagName=parameter,_value=0.0)],_tagName=spatialModel,_type=SkyDirFunction),_spectrum=Spectrum(_file=None,_parameters=[Parameter(_free=True,_max=1000.0,_min=0.001,_name=Prefactor,_scale=1e-09,_tagName=parameter,_value=1.0),Parameter(_free=True,_max=-1.0,_min=-5.0,_name=Index,_scale=1.0,_tagName=parameter,_value=-2.1),Parameter(_free=False,_max=2000.0,_min=30.0,_name=Scale,_scale=1.0,_tagName=parameter,_value=100.0)],_tagName=spectrum,_type=PowerLaw),_tagName=source,_type=PointSource)'

    # Constructor with attribute values.
    spectrum = Spectrum()
    spatialModel = SpatialModel()
    source = Source(name='source 1',
                    type='PointSource',
                    spectrum=spectrum,
                    spatialModel=spatialModel)
    assert str(
        source
    ) == 'Source(_name=source 1,_spatialModel=SpatialModel(_file=None,_parameters=[Parameter(_free=False,_max=360.0,_min=0.0,_name=RA,_scale=1.0,_tagName=parameter,_value=0.0),Parameter(_free=False,_max=90.0,_min=-90.0,_name=DEC,_scale=1.0,_tagName=parameter,_value=0.0)],_tagName=spatialModel,_type=SkyDirFunction),_spectrum=Spectrum(_file=None,_parameters=[Parameter(_free=False,_max=10.0,_min=0.0,_name=Value,_scale=1.0,_tagName=parameter,_value=1.0)],_tagName=spectrum,_type=ConstantValue),_tagName=source,_type=PointSource)'

    # Convert to/from DOM object.
    import xml.dom.minidom
    domDocument = xml.dom.minidom.Document()
    domSource = source.toDom(domDocument)
    sourceCopy = Source(dom=domSource)
    assert sourceCopy == source
    assert not (sourceCopy != source)