fermiPy / fermipy

Fermi-LAT Python Analysis Framework
http://fermipy.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
50 stars 51 forks source link

Support for Eric Charles' merge_sources.py #567

Open jballet opened 5 months ago

jballet commented 5 months ago

Feature Request

Is your feature request related to a problem? Please describe. Eric Charles has a very useful utility called merge_sources.py that takes a (potentially long) XML source file and generates a source map that can be appended to an existing source map file and later used as a diffuse source. This is very convenient because it saves the trouble of generating over and over the background of fixed point sources in the outer parts of a ROI, while avoiding the enormous size of creating one source map per source. It is easy to add that source map to an existing fermipy source map. However, a later call fails because the type of DiffuseSource entry in the XML file is not foreseen. File ".../site-packages/fermipy/roi_model.py", line 1179, in create_from_xml {'Spectrum_Filename': spec['file'], KeyError: 'file' The source model is simply entered as everything constant

<spectrum type="ConstantValue">
  <parameter free="0" max="100" min="0" name="Value" scale="1" value="1"/>
</spectrum>
<spatialModel type="ConstantValue">
  <parameter free="0" max="10" min="0" name="Value" scale="1" value="0"/>
</spatialModel>

Describe the solution you'd like Just support this and enter it as part of the diffuse model.

Describe alternatives you've considered A workaround is to cheat and make the model appear as spectrum type="FileFunction" pointing to a constant file.

omodei commented 3 months ago

Hi Jan, I do nốt have the file "merge_sources.py" can you send it to me, I can have a look to check the compatibility with the create_from_xml method.

jballet commented 3 months ago

Hi Nicola, You don't really need the merge_sources.py file to solve this. All that is required is support the ConstantValue spectral type. The attached file contains the merge_sources.py script and the FixedSources_template.xml file with the ConstantValue spectral type.

omodei commented 3 months ago

Thanks! In think I know what I need to do, but it will require small changes in several files. I'll work on this (not top priority though...)