Coder Social home page Coder Social logo

threeml / astromodels Goto Github PK

View Code? Open in Web Editor NEW
42.0 5.0 45.0 105.46 MB

Spatial and spectral models for astrophysics

License: BSD 3-Clause "New" or "Revised" License

Python 88.17% C++ 10.26% Shell 1.47% Dockerfile 0.10%
astrophysics spectral-models modeling-tool astronomy multi-wavelength multi-messenger

astromodels's Introduction

astromodels

CI codecov Documentation Status License GitHub contributors DOI

GitHub pull requests GitHub issues

PyPi

PyPI version fury.io PyPI - Downloads

Conda

Conda Conda

alt text

Astromodels is a very flexible framework to define models for likelihood or Bayesian analysis of astrophysical data.

Even though it has been designed having in mind analysis in the spectral domain, it can be used also as a toolbox containing functions of any variable.

Astromodels is not a modeling package, it only gives you the tools to build a model as complex as you need. You then need a separate package (such as 3ML) to fit that model to the data.

Some of the features which distinguish astromodels from other similar packages are: * a model can contain an arbitrary number of sources at different positions in the sky * parameters can be linked through any function (not only identity) * parameters can vary with auxiliary variables such as time. For example, you can build a model where some parameters vary with time, and you can fit the parameters of the function which describe this variability. Similary you can build models where parameters vary with the phase of a pulsar, and so on. * models can be saved in and loaded from YAML file (a human-readable format) * physical units are fully supported in input, but they are handled so that they don’t slow down the actualy computation of the models.

Astromodels has been designed with performance as priority, and is considerably faster than other python-based solution for the same problem, such as astropy.modeling and the modeling part of sherpa. Documentation: http://astromodels.readthedocs.org/en/latest/

astromodels's People

Contributors

anastasia-tsvetkova avatar binitahona avatar bjoernbiltzinger avatar domeckert avatar giacomov avatar grburgess avatar hamogu avatar hayalaso avatar henrikef avatar israelmcmc avatar ndilalla avatar omodei avatar physics-andrea avatar rjlauer avatar rwiller avatar ssteinmassl avatar xboluna avatar zhoouhaoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

astromodels's Issues

are fits with Log_parabola broken?

Several of us have noticed that fits to point sources with LiFF+3ML appear to be having trouble with the Log_parabola model. The fits tend to be unstable and we find that in the case where there is no curvature the model does not reduce to a simple power law. The TS is also lower for Log_parabola than for powerlaw, which should not generally occur since the extra DoF should make Log_parabola a "better" fit most of the time.

Gaussian Prior minimum hardcoded Crash

I'm trying to test a Gaussian prior for the flux. Here is the traceback. The minimum seems to be hardcoded in priors.py as 1e-12

Looking at my model:
`source_name = "Crab"
crab_ra = 83.63
crab_dec = 22.01

from astromodels.functions.priors import Gaussian as GP
spectrum=threeML.Powerlaw()
source1=threeML.PointSource(name, ra=crab_ra, dec=crab_dec, spectral_shape=spectrum)

spectrum.index.value = -2.63
spectrum.index.bounds = (-4.0, -1.0)
spectrum.index.set_uninformative_prior(astromodels.Uniform_prior)
spectrum.index.fix = False

spectrum.piv.value = 7.0 * threeML.u.TeV
spectrum.piv.fix = True

spectrum.K.value = 3.5e-11 * fluxUnit
#spectrum.K.bounds = (1e-16 * fluxUnit, 1e-10*fluxUnit)
#spectrum.K.bounds = (None, None)
spectrum.K.prior = GP()

spectrum.K.prior.mu.units=fluxUnit

spectrum.K.prior.sigma.units=fluxUnit
spectrum.K.prior.sigma.min=1e-29*fluxUnit

spectrum.K.prior.mu = 0*fluxUnit
spectrum.K.prior.sigma= 1.16244891e-13 * fluxUnit
spectrum.K.fix = False
model=threeML.Model(source1)`

Setting the spectrum.K.prior.sigma.min does not seem to have any effect (regardless of whether or not units multiplied against it). I provided the traceback below:

Traceback (most recent call last): File "/Users/chad/software_base/aerie/src/liff/examples/3ml/untested/fitModel/fitModel.py", line 291, in <module> execfile(options.model) File "crab_bayes_gauss.model", line 38, in <module> model=threeML.Model(source1) File "/Users/chad/hawc/astromodels/astromodels/core/model.py", line 55, in __init__ super(Model, self).__init__("__root__") File "/Users/chad/hawc/astromodels/astromodels/core/tree.py", line 38, in __init__ assert is_valid_variable_name(name), "Illegal characters in name %s. You can only use letters and numbers, " \ File "/Users/chad/hawc/astromodels/astromodels/utils/valid_variable.py", line 14, in is_valid_variable_name parse('{} = None'.format(string_to_check)) File "/Users/chad/hawc/astromodels/astromodels/core/parameter.py", line 105, in handle_quantity return method(instance, new_value, *args, **kwargs) File "/Users/chad/hawc/astromodels/astromodels/core/parameter.py", line 425, in _set_value self.name, new_value, self.min_value)) astromodels.core.parameter.SettingOutOfBounds: Trying to set parameter sigma = 1.16244891e-22, which is less than the minimum allowed 1e-12

push access

I'm not able to push to a branch I created locally. It seems I do not have push access. Is this expected?

reloading of model with recursively linked parameters failed

Hi,
I have been working with a model, in which I linked two parameters with a StepFunction(). I then linked the StepFunction.lower_ bound to another parameter. Doing BayesianAnalysis.sample(...) it would then fail after the sampling when trying to clone the model. Saving the model and trying to reload it would obviously give a similar error message. Is there any good solution for that?

`---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
----> 1 test = load_model('my_modelRim.yml')

/home/simonste/.venv/3ml/local/lib/python2.7/site-packages/astromodels/core/model_parser.pyc in load_model(filename)
35 parser = ModelParser(filename)
36
---> 37 return parser.get_model()
38
39

/home/simonste/.venv/3ml/local/lib/python2.7/site-packages/astromodels/core/model_parser.pyc in get_model(self)
169 for link in self._links:
170
--> 171 path = link['parameter_path']
172 variable = link['variable']
173 law = link['law']

/home/simonste/.venv/3ml/local/lib/python2.7/site-packages/astromodels/core/model.pyc in getitem(self, path)
258 """
259
--> 260 return self._get_child_from_path(path)
261
262 def contains(self, path):

AttributeError: Node StepFunction does not exist`

Calling 2D functions with units?

Hi!

I'm trying to write tests for 2D functions/extended sources. While writing the tests, I noticed that there are several 2D functions (Asymm_Gaussian_on_sphere(), Ellipse_on_sphere(), Power_law_on_sphere()) that cannot be called with units because the evaluate functions implicitly assume that the coordinates are supplied without units. For example these lines in functions_2D.py:

dX=np.where( np.logical_or( np.logical_and( lon-lon0 >0, lon-lon0<180), np.logical_and( lon-lon0<-180, lon-lon0 > -360) ), dX, -dX)

norm = np.power(0.05 * np.pi / 180., 2.+index) * np.pi + 2. * np.pi * np.log(maxr / 0.05)

There's an example below, it should work for Gaussian_on_sphere() and Disk_on_sphere() and fail for the others.

Do we want/need to be able to call 2D functions with units? If we do, I can try to fix it and write some tests to be sure that future functions won't break either.

import astropy.units as u
import numpy as np

from astromodels.functions.functions import Powerlaw
from astromodels.functions.functions_2D import *
from astromodels.sources.extended_source import ExtendedSource
import traceback

ra, dec = (125.6, -75.3)

def test( shape ):

  source = ExtendedSource('test_source', spatial_shape = shape, spectral_shape = Powerlaw()  )
  shape.lon0=ra*u.degree
  shape.lat0=dec*u.degree

  try:
    spatial = source.spatial_shape( ra,dec )
    print "No units:", spatial
    spatial = source.spatial_shape( ra*u.deg,dec*u.deg )
    print "With units:",  spatial
  except Exception as e:
    print e
    traceback.print_exc()
    

shapes = [ Disk_on_sphere(), Gaussian_on_sphere(), Asymm_Gaussian_on_sphere(), Ellipse_on_sphere(), Power_law_on_sphere() ]
for shape in shapes:
  test(shape)

OrderedDict(('ra', self.ra), ('dec', self.dec)) in astromodels/core/sky_direction

I'm trying to get Fermi-LAT analysis working with 3ML. When I run the test script from the 3ML repository (3ML/threeML/test/test_FermipyLike.py), it fails at the fit() command. The error messages boil down to a problem with the "OrderedDict"s in astromodels/core/sky_direction, see the last lines of the error messages below.

Shouldn't it be

return collections.OrderedDict([('l', self.l), ('b', self.b)])

and

return collections.OrderedDict([('ra', self.ra), ('dec', self.dec)])

in lines 225 and 229 in astromodels/core/sky_direction.py? With the square brackets?


/home/henrikef/3ML_env/local/lib/python2.7/site-packages/astromodels/core/sky_direction.pyc in parameters(self)
    227         else:
    228 
--> 229             return collections.OrderedDict(('ra', self.ra), ('dec', self.dec))
    230 
    231     @property

/usr/lib/python2.7/collections.pyc in __init__(self, *args, **kwds)
     43         '''
     44         if len(args) > 1:
---> 45             raise TypeError('expected at most 1 arguments, got %d' % len(args))
     46         try:
     47             self.__root

TypeError: expected at most 1 arguments, got 2

units in log_normal prior

Hi!

I intentionally kept this separate from #67 since this is less of a problem, just something that could be more user-friendly.

Currently, the log_normal prior is defined as follows (some spaces removed for brevity):

    def evaluate(self, x, F, mu, sigma):
  
      if isinstance(F, astropy_units.Quantity):
            x_ = x.value
        else:
            x_ = x

        norm = self.__norm_const / (sigma * x_)
        return F * norm * np.exp(-np.power(np.log(x_) - mu, 2.) / (2 * np.power(sigma, 2.)))

Here, mu is forced to be unitless. If x carries units, e.g. a flux norm or a cutoff energy, the user has to keep track of what units will be used internally for that quantity, and then set mu accordingly.

A more straight-forward approach imho would be to define it like this:

    def evaluate(self, x, F, M, sigma):
  
        norm = self.__norm_const / (sigma * x_)
        return F * norm * np.exp(-np.power(np.log(x / M), 2.) / (2 * np.power(sigma, 2.)))

Where M (equivalent to exp(mu) ) carries the same units as x.

I don't know how many people are using log_normal priors though, so I'm hesitant to change it and potentially break things for everyone else.

memoization and SpatialTemplate_2D

Hi!

I've been tracking down a bug with SpatialTemplate_2D and I think I finally understand what's happening.

SpatialTemplate_2D is a 2D function that reads in a map from a fits file and reports its value at a given set of coordinates. The only free parameters is a normalizing constant K, which is usually fixed to 1 if we're fitting a spectrum in 3ML.

The problem occurs if I want to have 2 or more different SpatialTemplate_2D functions. As the snippet below shows, if the two SpatialTemplate_2D objects have the same value of the normalizing constant, their function calls will return the exact same values, even if they have different shapes according to the fits files read in. This means we cannot use 2 different SpatialTemplate_2D sources in astromodels/3ML at the same time.

I think this is due to memoization. If I get rid of the @memoize before Function2D._call_without_units, it works as it should.

Is there a way to turn off memoization just for this particular function? The only way that I've come up with is to introduce a 'dummy' parameter to SpatialTemplate_2D which is not actually used in the function evaluation, and rely on the user to set this parameter to a unique value for each template.

testmaps.tar.gz

from astromodels import *
from threeML import *

shape1=SpatialTemplate_2D()
shape2=SpatialTemplate_2D()

shape1.load_file("test1.fits")
shape2.load_file("test2.fits")

shape1.K = 1
shape2.K = 1

print "Using SpatialTemplate_2D.evaluate([312, 306], [41, 41], [1,1]):"
print "shape1:", shape1.evaluate( [312, 306], [41, 41], [1,1])
print "shape2:", shape2.evaluate( [312, 306], [41, 41], [1,1])

print "Using SpatialTemplate_2D function call (shape1.K = 1; shape2.K = 1):"
print "shape1:", shape1( [312, 306], [41, 41] )
print "shape2:", shape2( [312, 306], [41, 41] )

shape1.K = 1
shape2.K = 10
print "shape1.K = 1; shape2.K = 10"
print "Using SpatialTemplate_2D function call (shape1.K = 1; shape2.K = 10):"
print "shape1:", shape1( [312, 306], [41, 41] )
print "shape2:", shape2( [312, 306], [41, 41] )

shape1.K = 10
shape2.K = 10
print "Using SpatialTemplate_2D function call (shape1.K = 10; shape2.K = 10):"
print "shape1:", shape1( [312, 306], [41, 41] )
print "shape2:", shape2( [312, 306], [41, 41] )

output:

Using SpatialTemplate_2D.evaluate([312, 306], [41, 41], [1,1]):
shape1: [1. 0.]
shape2: [0. 1.]
Using SpatialTemplate_2D function call (shape1.K = 1; shape2.K = 1):
shape1: [1. 0.]
shape2: [1. 0.]
shape1.K = 1; shape2.K = 10
Using SpatialTemplate_2D function call (shape1.K = 1; shape2.K = 10):
shape1: [1. 0.]
shape2: [ 0. 10.]
Using SpatialTemplate_2D function call (shape1.K = 10; shape2.K = 10):
shape1: [ 0. 10.]
shape2: [ 0. 10.]

Latitude_galactic_diffuse

This is a function in functions_2D.py
When getting the boundaries, it seems like line 84 has an error.
max_b = self.sigma_b.max_value -> max_b = self.sigma_b.value.
At least that way I was able to test the code.

Linking two nuisance parameters crashes ModelParser via clone_model

It seems that linking two nuisance parameters is confusing the model parser:

<ipython-input-17-a2f05dc59f15> in <module>()
----> 1 clone_model(model)

/Users/jburgess/coding/astromodels/astromodels/core/model_parser.pyc in clone_model(model_instance)
     49     data = model_instance.to_dict_with_types()
     50 
---> 51     parser = ModelParser(model_dict=data)
     52 
     53     return parser.get_model()

/Users/jburgess/coding/astromodels/astromodels/core/model_parser.pyc in __init__(self, model_file, model_dict)
     88             self._model_dict = model_dict
     89 
---> 90         self._parse()
     91 
     92     def _parse(self):

/Users/jburgess/coding/astromodels/astromodels/core/model_parser.pyc in _parse(self)
    120                 var_name = source_or_var_name.split("(")[0].replace(" ", "")
    121 
--> 122                 this_parser = ParameterParser(var_name, source_or_var_definition)
    123 
    124                 res = this_parser.get_variable()

/Users/jburgess/coding/astromodels/astromodels/core/model_parser.pyc in __init__(self, name, definition)
    225 
    226 
--> 227         self._variable = parameter.Parameter(name, **definition)
    228 
    229     def get_variable(self):

TypeError: __init__() got an unexpected keyword argument 'law'

I am investigating and will try to provide a fix in a few hours.

Fixing values of XSPEC function parameters

When running the example Joint fitting XRT and GBM data with XSPEC models, I am no longer able to fix the values of XSPEC functions. It appears as if they are only floats and not model objects:

xspec_abund('angr')

spectral_model =  XS_phabs()* XS_zphabs() * XS_powerlaw()


spectral_model.nh_1_1=0.101
spectral_model.nh_1_1.fix = True

spectral_model.nh_2_2=0.1114424
spectral_model.nh_2_2.fix = True

spectral_model.redshift_2_2 = 0.618
spectral_model.redshift_2_2.fix =True

Result:

WARNING NonExistingAttribute: Attribute nh_1_1 does not exist. Check for typos.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-587577dd4140> in <module>()
      5 
      6 spectral_model.nh_1_1=0.101
----> 7 spectral_model.nh_1_1.fix = True
      8 
      9 spectral_model.nh_2_2=0.1114424

AttributeError: 'float' object has no attribute 'fix'

Note: This does not seem to affect normal astromodel models.

Error when using unit energy argument to Band function

When attempting pass a unit energy to a Model using the Band function, I get the following error:

triggerName = 'bn131014215'
ra = 121.8
dec = -61.3

b= Band() 

data_list = DataList(nai9, naia,naib,bgo1 )

GRB = PointSource( triggerName, ra, dec, spectral_shape=b )

model = Model( GRB )

#model.display()

GRB.spectrum.main(12.*u.keV)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-222-7b276d22e8a3> in <module>()
     13 #model.display()
     14 
---> 15 GRB.spectrum.main(12.*u.keV)

/usr/local/lib/python2.7/site-packages/astromodels-0.1-py2.7.egg/astromodels/spectral_component.pyc in __call__(self, energies)
     59     def __call__(self, energies):
     60 
---> 61         return self._spectral_shape(energies)

/usr/local/lib/python2.7/site-packages/astromodels-0.1-py2.7.egg/astromodels/functions/function.pyc in __call__(self, x, *args, **kwargs)
    847 
    848                 # Now convert to the expected y unit
--> 849                 return results.to(self.y_unit)
    850 
    851         else:

AttributeError: 'numpy.ndarray' object has no attribute 'to'

I think it id numpy.where that is causing this, however, I also have this issue:

b= Band()
print b(13)

b(13*u.keV)

0.000749488530468
---------------------------------------------------------------------------
UnitsError                                Traceback (most recent call last)
<ipython-input-228-df88bf4fb9ca> in <module>()
      2 print b(13)
      3 
----> 4 b(12*u.keV)

/usr/local/lib/python2.7/site-packages/astromodels-0.1-py2.7.egg/astromodels/functions/function.pyc in __call__(self, x, *args, **kwargs)
    844                 # This is an array with units, let's use the slow call which preserves units
    845 
--> 846                 results = self._call_with_units(x, *args, **kwargs)
    847 
    848                 # Now convert to the expected y unit

/usr/local/lib/python2.7/site-packages/astromodels-0.1-py2.7.egg/astromodels/functions/function.pyc in _call_with_units(self, x, *args, **kwargs)
    895 
    896             raise u.UnitsError("Looks like you didn't provide all the units, or you provided the wrong ones, when "
--> 897                                "calling function %s" % self.name)
    898 
    899         else:

UnitsError: Looks like you didn't provide all the units, or you provided the wrong ones, when calling function Band

XSPEC failing

It seems the newer version of XSPEC has removed some models which are hardcoded into our interface.

The first that fails is: xsgsmt

This was in an older XSPEC but is now gone. I do not see any exception catching that avoids compiling a model that is not there. I would not want to remove this as older XSPEC will not work. Can someone test that it is not just a problem with my setup?

order of operations

I found an issue with subtraction:

c=Constant(k=1)

func = 2-c

output:

description: (Constant{1} - 2)
formula: (no latex formula available)
parameters:
k_1:
value: 1.0
desc: Constant value
min_value: None
max_value: None
unit:
is_normalization: False
delta: 0.1
free: True

and:

func(0)


-1.0

It seems the order of operations is not respected

XSPEC models and astromodels import in threeML import

When loading 3ML with HEASOFT initialized, a crash occurs:

from threeML import *
Loading xspec models...
---------------------------------------------------------------------------
RuntimeWarning                            Traceback (most recent call last)
<ipython-input-1-949d564e9c35> in <module>()
      1 get_ipython().magic(u'matplotlib inline')
----> 2 from threeML import *
      3 import os

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/threeML-0.3.2-py2.7.egg/threeML/__init__.py in <module>()
     35 from .exceptions import custom_exceptions
     36 from .exceptions.custom_exceptions import custom_warnings
---> 37 from .plugin_prototype import PluginPrototype
     38 
     39 try:

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/threeML-0.3.2-py2.7.egg/threeML/plugin_prototype.py in <module>()
      4 
      5 import abc
----> 6 from astromodels.utils.valid_variable import is_valid_variable_name
      7 import warnings
      8 

build/bdist.macosx-10.11-x86_64/egg/astromodels/__init__.py in <module>()

build/bdist.macosx-10.11-x86_64/egg/astromodels/xspec/factory.py in <module>()

build/bdist.macosx-10.11-x86_64/egg/astromodels/xspec/factory.py in setup_xspec_models()

build/bdist.macosx-10.11-x86_64/egg/astromodels/xspec/factory.py in xspec_model_factory(model_name, xspec_function, model_type, definition)

<string> in <module>()

/Users/jburgess/.astromodels/data/XS_gadem.py in <module>()
      9 from astromodels.xspec import _xspec
     10 
---> 11 class XS_gadem(Function1D):
     12 
     13     """

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/functions/function.pyc in __init__(cls, name, bases, dct)
    254         for parameter_name, parameter_definition in function_definition['parameters'].iteritems():
    255 
--> 256             this_parameter = FunctionMeta.parse_parameter_definition(name, parameter_name, parameter_definition)
    257 
    258             cls.__parameters[this_parameter.name] = this_parameter

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/functions/function.pyc in parse_parameter_definition(func_name, par_name, definition)
    436 
    437         new_parameter = Parameter(par_name, value, min_value=min_value, max_value=max_value,
--> 438                                   delta=delta, desc=desc, free=free, unit=unit)
    439 
    440         return new_parameter

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/parameter.pyc in __init__(self, name, value, min_value, max_value, delta, desc, free, unit, prior)
    553         # well as a prior
    554 
--> 555         super(Parameter, self).__init__(name, value, min_value=min_value, max_value=max_value, desc=desc, unit=unit)
    556 
    557         self._free = bool(free)

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/parameter.pyc in __init__(self, name, value, min_value, max_value, desc, unit)
    173 
    174         self._max_value = None  # this will be overwritten immediately in the next line
--> 175         self.max_value = max_value
    176 
    177         # Store description

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/dual_access_class.pyc in __setattr__(self, key, value)
     51                 warnings.warn("Attribute %s does not exist. Check for typos." % key, NonExistingAttribute)
     52 
---> 53             super(DualAccessClass, self).__setattr__(key, value)
     54 
     55     def _add_attribute(self, name, value):

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/parameter.pyc in handle_quantity(instance, value, *args, **kwargs)
     91                 new_value = input_type(value)
     92 
---> 93                 return method(instance, new_value, *args, **kwargs)
     94 
     95             except TypeError:

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/parameter.pyc in _set_max_value(self, max_value)
    418             warnings.warn("The current value of the parameter %s (%s) "
    419                           "was above the new maximum %s." % (self.name, self.value, self._max_value),
--> 420                           exceptions.RuntimeWarning)
    421             self._value = self._max_value
    422 

RuntimeWarning: The current value of the parameter switch (2.0) was above the new maximum 1.0.

log parabola peak energy fix

in astromodels/functions/functions.py
the peak energy 10**(argument) is off by a factor of ln(10). On line 1511,

    return self.piv.value * pow(10, (2 + self.alpha.value) / (2 * self.beta.value))

should be

    return self.piv.value * pow(10, ( (2 + self.alpha.value) * np.log(10) ) / (2 * self.beta.value))

Multiplicative spectral components and Units

When wanting to make multiplicative composed spectral components (e.g. Band*Exponential_Cutoff), the overall unit also becomes the multiplication of those units. Attempting to change the normalization of the cutoff produces and error:

comp.K_2.unit = u.dimensionless_unscaled

UnitConversionError: '1 / (cm2 keV s)' (differential flux) and '' (dimensionless) are not convertible

I'm guessing the catch is to demand spectral models have the right unit, but in this case, it is needed. Is there a feature I ma missing that allows one to do this?

Proper access to units

What is the method for converting units? I notice that parameters have a private _set_unit(x,y) member, but I generally do not like to touch something private.

Also, it seems assumed that y_units as differential photon fluxes. I this always the case?

Python2 installation issue with numdifftools

Probably not a astromodels issue, but with numdifftools:

$ python2 setup.py install --user

 Xspec is detected. Will compile the Xspec extension.

Found library XSFunctions in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library XSModel in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library XSUtil in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library XS in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library cfitsio in None
Found library CCfits_2.5 in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library wcs in None
Found library gfortran in None
running install
running bdist_egg
running egg_info
writing requirements to astromodels.egg-info/requires.txt
writing astromodels.egg-info/PKG-INFO
writing top-level names to astromodels.egg-info/top_level.txt
writing dependency_links to astromodels.egg-info/dependency_links.txt
package init file 'astromodels/tests/__init__.py' not found (or not a regular file)
reading manifest template 'MANIFEST.in'
writing manifest file 'astromodels.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/astromodels
creating build/bdist.linux-x86_64/egg/astromodels/xspec
creating build/bdist.linux-x86_64/egg/astromodels/xspec/include
creating build/bdist.linux-x86_64/egg/astromodels/xspec/include/sherpa
copying build/lib.linux-x86_64-2.7/astromodels/xspec/include/sherpa/fcmp.hh -> build/bdist.linux-x86_64/egg/astromodels/xspec/include/sherpa
copying build/lib.linux-x86_64-2.7/astromodels/xspec/include/sherpa/extension.hh -> build/bdist.linux-x86_64/egg/astromodels/xspec/include/sherpa
copying build/lib.linux-x86_64-2.7/astromodels/xspec/include/sherpa/constants.hh -> build/bdist.linux-x86_64/egg/astromodels/xspec/include/sherpa
creating build/bdist.linux-x86_64/egg/astromodels/xspec/include/sherpa/astro
copying build/lib.linux-x86_64-2.7/astromodels/xspec/include/sherpa/astro/xspec_extension.hh -> build/bdist.linux-x86_64/egg/astromodels/xspec/include/sherpa/astro
copying build/lib.linux-x86_64-2.7/astromodels/xspec/include/sherpa/array.hh -> build/bdist.linux-x86_64/egg/astromodels/xspec/include/sherpa
copying build/lib.linux-x86_64-2.7/astromodels/xspec/__init__.py -> build/bdist.linux-x86_64/egg/astromodels/xspec
copying build/lib.linux-x86_64-2.7/astromodels/xspec/factory.py -> build/bdist.linux-x86_64/egg/astromodels/xspec
copying build/lib.linux-x86_64-2.7/astromodels/xspec/xspec_settings.py -> build/bdist.linux-x86_64/egg/astromodels/xspec
copying build/lib.linux-x86_64-2.7/astromodels/xspec/_xspec.so -> build/bdist.linux-x86_64/egg/astromodels/xspec
copying build/lib.linux-x86_64-2.7/astromodels/xspec/README -> build/bdist.linux-x86_64/egg/astromodels/xspec
creating build/bdist.linux-x86_64/egg/astromodels/xspec/src
copying build/lib.linux-x86_64-2.7/astromodels/xspec/src/_xspec.cc -> build/bdist.linux-x86_64/egg/astromodels/xspec/src
copying build/lib.linux-x86_64-2.7/astromodels/xspec/LICENSE -> build/bdist.linux-x86_64/egg/astromodels/xspec
creating build/bdist.linux-x86_64/egg/astromodels/sources
copying build/lib.linux-x86_64-2.7/astromodels/sources/point_source.py -> build/bdist.linux-x86_64/egg/astromodels/sources
copying build/lib.linux-x86_64-2.7/astromodels/sources/__init__.py -> build/bdist.linux-x86_64/egg/astromodels/sources
copying build/lib.linux-x86_64-2.7/astromodels/sources/source.py -> build/bdist.linux-x86_64/egg/astromodels/sources
copying build/lib.linux-x86_64-2.7/astromodels/sources/extended_source.py -> build/bdist.linux-x86_64/egg/astromodels/sources
copying build/lib.linux-x86_64-2.7/astromodels/sources/particle_source.py -> build/bdist.linux-x86_64/egg/astromodels/sources
creating build/bdist.linux-x86_64/egg/astromodels/functions
copying build/lib.linux-x86_64-2.7/astromodels/functions/functions_3D.py -> build/bdist.linux-x86_64/egg/astromodels/functions
copying build/lib.linux-x86_64-2.7/astromodels/functions/functions_2D.py -> build/bdist.linux-x86_64/egg/astromodels/functions
copying build/lib.linux-x86_64-2.7/astromodels/functions/function.py -> build/bdist.linux-x86_64/egg/astromodels/functions
creating build/bdist.linux-x86_64/egg/astromodels/functions/dark_matter
copying build/lib.linux-x86_64-2.7/astromodels/functions/dark_matter/__init__.py -> build/bdist.linux-x86_64/egg/astromodels/functions/dark_matter
copying build/lib.linux-x86_64-2.7/astromodels/functions/dark_matter/dm_models.py -> build/bdist.linux-x86_64/egg/astromodels/functions/dark_matter
copying build/lib.linux-x86_64-2.7/astromodels/functions/__init__.py -> build/bdist.linux-x86_64/egg/astromodels/functions
copying build/lib.linux-x86_64-2.7/astromodels/functions/priors.py -> build/bdist.linux-x86_64/egg/astromodels/functions
copying build/lib.linux-x86_64-2.7/astromodels/functions/template_model.py -> build/bdist.linux-x86_64/egg/astromodels/functions
copying build/lib.linux-x86_64-2.7/astromodels/functions/functions.py -> build/bdist.linux-x86_64/egg/astromodels/functions
copying build/lib.linux-x86_64-2.7/astromodels/__init__.py -> build/bdist.linux-x86_64/egg/astromodels
creating build/bdist.linux-x86_64/egg/astromodels/data
creating build/bdist.linux-x86_64/egg/astromodels/data/dark_matter
copying build/lib.linux-x86_64-2.7/astromodels/data/dark_matter/gammamc_dif.dat -> build/bdist.linux-x86_64/egg/astromodels/data/dark_matter
copying build/lib.linux-x86_64-2.7/astromodels/data/dark_matter/dmSpecTab.npy -> build/bdist.linux-x86_64/egg/astromodels/data/dark_matter
creating build/bdist.linux-x86_64/egg/astromodels/data/tests
copying build/lib.linux-x86_64-2.7/astromodels/data/tests/test.yaml -> build/bdist.linux-x86_64/egg/astromodels/data/tests
copying build/lib.linux-x86_64-2.7/astromodels/data/tests/black_hole.yaml -> build/bdist.linux-x86_64/egg/astromodels/data/tests
copying build/lib.linux-x86_64-2.7/astromodels/data/tests/simple_source.yaml -> build/bdist.linux-x86_64/egg/astromodels/data/tests
copying build/lib.linux-x86_64-2.7/astromodels/version.py -> build/bdist.linux-x86_64/egg/astromodels
creating build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/configuration.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/angular_distance.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/vincenty.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/valid_variable.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/data_files.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/io.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/__init__.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/table.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/long_path_formatter.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/disk_usage.py -> build/bdist.linux-x86_64/egg/astromodels/utils
copying build/lib.linux-x86_64-2.7/astromodels/utils/pretty_list.py -> build/bdist.linux-x86_64/egg/astromodels/utils
creating build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/parameter_transformation.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/memoization.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/spectral_component.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/sky_direction.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/my_yaml.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/model_parser.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/node_ctype.so -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/units.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/tree.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/__init__.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/thread_safe_unit_format.py -> build/bdist.linux-x86_64/egg/astromodels/core
creating build/bdist.linux-x86_64/egg/astromodels/core/node_ctype
copying build/lib.linux-x86_64-2.7/astromodels/core/node_ctype/node_ctype.cxx -> build/bdist.linux-x86_64/egg/astromodels/core/node_ctype
copying build/lib.linux-x86_64-2.7/astromodels/core/serialization.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/polarization.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/parameter.py -> build/bdist.linux-x86_64/egg/astromodels/core
copying build/lib.linux-x86_64-2.7/astromodels/core/model.py -> build/bdist.linux-x86_64/egg/astromodels/core
creating build/bdist.linux-x86_64/egg/astromodels/tests
copying build/lib.linux-x86_64-2.7/astromodels/tests/test_functions.py -> build/bdist.linux-x86_64/egg/astromodels/tests
copying build/lib.linux-x86_64-2.7/astromodels/tests/test_tree.py -> build/bdist.linux-x86_64/egg/astromodels/tests
copying build/lib.linux-x86_64-2.7/astromodels/tests/test_memoizer.py -> build/bdist.linux-x86_64/egg/astromodels/tests
copying build/lib.linux-x86_64-2.7/astromodels/tests/test_load_xspec_models.py -> build/bdist.linux-x86_64/egg/astromodels/tests
copying build/lib.linux-x86_64-2.7/astromodels/tests/test_point_source.py -> build/bdist.linux-x86_64/egg/astromodels/tests
copying build/lib.linux-x86_64-2.7/astromodels/tests/test_parameter.py -> build/bdist.linux-x86_64/egg/astromodels/tests
copying build/lib.linux-x86_64-2.7/astromodels/tests/test_model.py -> build/bdist.linux-x86_64/egg/astromodels/tests
copying build/lib.linux-x86_64-2.7/astromodels/tests/test_template_model.py -> build/bdist.linux-x86_64/egg/astromodels/tests
byte-compiling build/bdist.linux-x86_64/egg/astromodels/xspec/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/xspec/factory.py to factory.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/xspec/xspec_settings.py to xspec_settings.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/sources/point_source.py to point_source.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/sources/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/sources/source.py to source.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/sources/extended_source.py to extended_source.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/sources/particle_source.py to particle_source.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/functions/functions_3D.py to functions_3D.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/functions/functions_2D.py to functions_2D.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/functions/function.py to function.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/functions/dark_matter/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/functions/dark_matter/dm_models.py to dm_models.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/functions/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/functions/priors.py to priors.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/functions/template_model.py to template_model.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/functions/functions.py to functions.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/version.py to version.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/configuration.py to configuration.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/angular_distance.py to angular_distance.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/vincenty.py to vincenty.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/valid_variable.py to valid_variable.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/data_files.py to data_files.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/io.py to io.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/table.py to table.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/long_path_formatter.py to long_path_formatter.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/disk_usage.py to disk_usage.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/utils/pretty_list.py to pretty_list.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/parameter_transformation.py to parameter_transformation.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/memoization.py to memoization.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/spectral_component.py to spectral_component.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/sky_direction.py to sky_direction.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/my_yaml.py to my_yaml.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/model_parser.py to model_parser.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/units.py to units.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/tree.py to tree.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/thread_safe_unit_format.py to thread_safe_unit_format.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/serialization.py to serialization.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/polarization.py to polarization.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/parameter.py to parameter.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/model.py to model.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/tests/test_functions.py to test_functions.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/tests/test_tree.py to test_tree.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/tests/test_memoizer.py to test_memoizer.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/tests/test_load_xspec_models.py to test_load_xspec_models.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/tests/test_point_source.py to test_point_source.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/tests/test_parameter.py to test_parameter.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/tests/test_model.py to test_model.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/tests/test_template_model.py to test_template_model.pyc
creating stub loader for astromodels/xspec/_xspec.so
creating stub loader for astromodels/core/node_ctype.so
byte-compiling build/bdist.linux-x86_64/egg/astromodels/xspec/_xspec.py to _xspec.pyc
byte-compiling build/bdist.linux-x86_64/egg/astromodels/core/node_ctype.py to node_ctype.pyc
installing package data to build/bdist.linux-x86_64/egg
running install_data
creating build/bdist.linux-x86_64/egg/astromodels/data/functions
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying astromodels.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying astromodels.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying astromodels.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying astromodels.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying astromodels.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/astromodels-0.5.1-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing astromodels-0.5.1-py2.7-linux-x86_64.egg
Removing /mnt/data/daten/Master/home/.local/lib64/python2.7/site-packages/astromodels-0.5.1-py2.7-linux-x86_64.egg
Copying astromodels-0.5.1-py2.7-linux-x86_64.egg to /mnt/data/daten/Master/home/.local/lib64/python2.7/site-packages
astromodels 0.5.1 is already the active version in easy-install.pth

Installed /mnt/data/daten/Master/home/.local/lib64/python2.7/site-packages/astromodels-0.5.1-py2.7-linux-x86_64.egg
Processing dependencies for astromodels==0.5.1
Searching for numdifftools
Reading https://pypi.python.org/simple/numdifftools/
Downloading https://pypi.python.org/packages/70/25/1af07d513fc5fb60b80c4577971fdd3480f931291f783dde33de178b185f/numdifftools-0.9.20.tar.gz#md5=c0545b8d1d1b4cdd1d5dacd99ff42666
Best match: numdifftools 0.9.20
Processing numdifftools-0.9.20.tar.gz
Writing /tmp/easy_install-nJBrWo/numdifftools-0.9.20/setup.cfg
Running numdifftools-0.9.20/setup.py -q bdist_egg --dist-dir /tmp/easy_install-nJBrWo/numdifftools-0.9.20/egg-dist-tmp-X1wN3R
zip_safe flag not set; analyzing archive contents...

Installed /tmp/easy_install-nJBrWo/numdifftools-0.9.20/.eggs/pyscaffold-2.4.4-py2.7.egg
/usr/lib64/python2.7/site-packages/nose/plugins/manager.py:395: RuntimeWarning: Unable to load plugin answer-testing = yt.utilities.answer_testing.framework:AnswerTesting: super() argument 1 must be type, not None
  RuntimeWarning)
/usr/lib64/python2.7/site-packages/nose/plugins/manager.py:395: RuntimeWarning: Unable to load plugin tap = tap.plugin:TAP: (Pygments 2.2.0 (/usr/lib64/python2.7/site-packages), Requirement.parse('Pygments==2.0.1'))
  RuntimeWarning)
ERROR:root:Error parsing
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/pbr/core.py", line 111, in pbr
    attrs = util.cfg_to_args(path, dist.script_args)
  File "/usr/lib64/python2.7/site-packages/pbr/util.py", line 267, in cfg_to_args
    wrap_commands(kwargs)
  File "/usr/lib64/python2.7/site-packages/pbr/util.py", line 569, in wrap_commands
    cmdclass = ep.resolve()
  File "/usr/lib64/python2.7/site-packages/pkg_resources/__init__.py", line 2428, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib64/python2.7/site-packages/sphinx/setup_command.py", line 23, in <module>
    from sphinx.application import Sphinx
  File "/usr/lib64/python2.7/site-packages/sphinx/application.py", line 33, in <module>
    from sphinx.environment import BuildEnvironment
  File "/usr/lib64/python2.7/site-packages/sphinx/environment/__init__.py", line 45, in <module>
    from sphinx.util.websupport import is_commentable
  File "/usr/lib64/python2.7/site-packages/sphinx/util/websupport.py", line 11, in <module>
    from sphinxcontrib.websupport.utils import is_commentable  # NOQA
  File "/usr/lib64/python2.7/site-packages/sphinxcontrib/websupport/__init__.py", line 15, in <module>
    from sphinxcontrib.websupport.core import WebSupport  # NOQA
  File "/usr/lib64/python2.7/site-packages/sphinxcontrib/websupport/core.py", line 17, in <module>
    from jinja2 import Environment, FileSystemLoader
  File "/usr/lib64/python2.7/site-packages/jinja2/__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
  File "/usr/lib64/python2.7/site-packages/jinja2/environment.py", line 15, in <module>
    from jinja2 import nodes
  File "/usr/lib64/python2.7/site-packages/jinja2/nodes.py", line 19, in <module>
    from jinja2.utils import Markup
  File "/usr/lib64/python2.7/site-packages/jinja2/utils.py", line 486, in <module>
    MutableMapping.register(LRUCache)
  File "/usr/lib/python-exec/python2.7/../../../lib64/python2.7/abc.py", line 109, in register
    if issubclass(subclass, cls):
  File "/usr/lib/python-exec/python2.7/../../../lib64/python2.7/abc.py", line 180, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/usr/lib64/python2.7/site-packages/typing.py", line 1265, in __subclasscheck__
    return super(GenericMeta, self).__subclasscheck__(cls)
TypeError: super() argument 1 must be type, not None
error: Setup script exited with error in setup command: Error parsing /tmp/easy_install-nJBrWo/numdifftools-0.9.20/setup.cfg: TypeError: super() argument 1 must be type, not None

This was run on 33a71e1

pickle and table models

possibly related to #34, it seems that parallel operations do not work with table models because they cannot be pickled. Is this expected?

Python3

Discussing with @volodymyrss , we need to have the ability to run with python3 or some people are moving to xspec in their notebooks. I remember from ou=r meeting with @giacomov that there was something left to do in the astromodels c-implementation. What was that and what can we do to have this python3 ready when not using the fermi tools?

Functions list in the docs

Would it be possible to have an auto-updating functions list somewhere in the online documentation? This would provide a reference similar to XSPEC's online function docs.

Latitude_galactic_diffuse broken

Problem in Latitude_galactic_diffuse when using hawc_hal, astromodels functions should be plugin agnostic. Still working on a full description @zhoouhaoo suggested it may be related to get_boundaries().

For my analysis, the fit only converges when both K(shape) and K(flux norm) is fit for the galactic diffuse. After talking to people, only 1 of these should be fit.

load analysis results from table model

I'm attempting to load analysis results saved to disk from a fit with a template model.

I get the following error:

---------------------------------------------------------------------------
ModelSyntaxError                          Traceback (most recent call last)
<ipython-input-6-49c753aae90b> in <module>()
----> 1 load_analysis_results('test_fit.fit')

/Users/jburgess/coding/3ML/threeML/analysis_results.pyc in load_analysis_results(fits_file)
     61         if n_results == 1:
     62 
---> 63             return _load_one_results(f['ANALYSIS_RESULTS', 1])
     64 
     65         else:

/Users/jburgess/coding/3ML/threeML/analysis_results.pyc in _load_one_results(fits_extension)
     77     model_dict = my_yaml.load(serialized_model)
     78 
---> 79     optimized_model = ModelParser(model_dict=model_dict).get_model()
     80 
     81     # Gather statistics values

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.3.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in __init__(self, model_file, model_dict)
     83             self._model_dict = model_dict
     84 
---> 85         self._parse()
     86 
     87     def _parse(self):

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.3.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in _parse(self)
    125             else:
    126 
--> 127                 this_parser = SourceParser(source_or_var_name, source_or_var_definition)
    128 
    129                 res = this_parser.get_source()

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.3.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in __init__(self, source_name, source_definition)
    262         if source_type == POINT_SOURCE:
    263 
--> 264             self._parsed_source = self._parse_point_source(source_definition)
    265 
    266         elif source_type == EXTENDED_SOURCE:

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.3.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in _parse_point_source(self, pts_source_definition)
    337 
    338         for component_name, component_definition in pts_source_definition['spectrum'].iteritems():
--> 339             this_component = self._parse_spectral_component(component_name, component_definition)
    340 
    341             components.append(this_component)

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.3.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in _parse_spectral_component(self, component_name, component_definition)
    418         shape_parser = ShapeParser(self._source_name)
    419 
--> 420         shape = shape_parser.parse(component_name, function_name, parameters_definition)
    421 
    422         # Get the links and extra setups, if any

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.3.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in parse(self, component_name, function_name, parameters_definition)
    481     def parse(self, component_name, function_name, parameters_definition):
    482 
--> 483         return self._parse_shape_definition(component_name, function_name, parameters_definition)
    484 
    485     @staticmethod

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.3.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in _parse_shape_definition(self, component_name, function_name, parameters_definition)
    508 
    509                 raise ModelSyntaxError("Function %s, specified as shape for %s of source %s, is not a "
--> 510                                        "known function" % (function_name, component_name, self._source_name))
    511 
    512         # Loop over the parameters of the function instance, instead of the specification,

ModelSyntaxError: Function TemplateModel_synchrotron, specified as shape for main of source synch, is not a known function

I've attached the analysis results, but the template is too large, so I have stored it in dropbox: https://www.dropbox.com/s/l964mncqpm8vcm7/synchrotron.h5?dl=0

spectrum call is failing for model with linked parameter

I'm trying to evaluate a model where I have linked an independent parameter:

band = Band()

src = PointSource('s',0,0,spectral_shape=band)

model = Model(src)

time = IndependentVariable("time",1.0, unit='s')

law = Powerlaw(K=100)

model.link(model.s.spectrum.main.Band.xp,time,law)


model.s.spectrum.main(10)

TypeError                                 Traceback (most recent call last)

----> 2 model.s.spectrum.main(10)

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7.egg/astromodels/spectral_component.py in __call__(self, energies)
     67     def __call__(self, energies):
     68 
---> 69         return self._spectral_shape(energies)

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7.egg/astromodels/functions/function.py in __call__(self, x, *args, **kwargs)
   1002                 # Compute the function
   1003 
-> 1004                 result = self._call_without_units(new_input, *args, **kwargs)
   1005 
   1006                 # Now remove all dimensions of size 1. For example, an array of shape (1,) will become a single number.

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7.egg/astromodels/functions/function.py in memoizer(instance, x, *args, **kwargs)
    121         # Create a unique identifier for this combination of inputs
    122 
--> 123         key = hash(unique_id)
    124 
    125         # Let's do it this way so we only look into the dictionary once

TypeError: unhashable type: 'numpy.ndarray'


could it be a units issue?

Displaying LaTeX names in tables

The tables are very nice, but it would be a little easier on the eyes if the names of parameters and models were in LaTeX. I can add this functionality, but need to know where to look.

I think the idea would be to add a LaTeX name to the model and parameter objects and have the table call those for displaying.

Shall I do this? And if so, where to start?

Min and max values don't seem to get the unit conversion

I noticed that when trying to define the min_value and max_value when defining a powerlaw spectrum don't get the unit conversion. For example, if I write my spectrum like:

spectrum.index_1 = -2.75
spectrum.index_1.fix=True
spectrum.K_1 = 1e-11
spectrum.K_1.fix = False
spectrum.K_1.min_value = 1e-14
spectrum.K_1.max_value = 1e-09
spectrum.K_1.unit = (u.TeV * u.s * u.cm**2 )**(-1)

I get the following error: Trying to set parameter K_1 = 1e-20, which is less than the minimum allowed 1e-14. So the value got converted to units of keV s cm-2 but the minimum didn't.

For the max_value, I also get an error. For example:

spectrum.index_1 = -2.75
spectrum.index_1.fix=True
spectrum.K_1 = 1e-11
spectrum.K_1.fix = False
spectrum.K_1.min_value = 1e-23 
spectrum.K_1.max_value = 1e-19
spectrum.K_1.unit = (u.TeV * u.s * u.cm**2 )**(-1)

And I get The current value of the parameter K_1 (1e-11) was above the new maximum 1e-19. Seems that the code is not converting the value units in this case to compare it to the maximum value, but it does changes the unit of the value before comparing to the minimum.

Negative flux in pixel not allowed in extended sources

L182 in sources/extended_sources.py, "return np.maximum(result, 1e-60)", sets the flux in a pixel to almost 0 when it is negative. It caused the problem Andrea saw, i.e. all same logL when flux <=0, which may skew the uncertainty calculation.

I know this is to avoid some problems with extremely small values. Can we change the requirement on absolute values? For example, "return np.maximum(result, 1e-60) if result>=0 else np.minimum(result, -1e-60)". It may not work as result is an array but something like that.

Broken function names in Model_tutorial.ipynb

In Model_tutorial.ipynb, the Powerlaw() class is called as powerlaw(), thus failing. I was about to replace each of these calls and commit, but then saw that also functions are called that I couldn't find at all anymore in astromodels, like bias() and line(). This should be fixed to make the tutorial useful. I can help, if someone points me to the new equivalents of those functions.

Xspec models are regenerated every time

At this stage Xspec models are regenerated every time astromodels is imported, which makes the import stage unnecessarily slow.

Let's change it so that the code will be generated only once, saved in the astromodels data directory (~/.astromodels/data) and then loaded from there.

Custom models

What is the procedure to add a custom model? If I write my own, how does astromodels import?

linking more than two parameters

Hi,
is it possible to link more than two parameters in the Model.link() function at the same time other than linking them recursively? I would actually like to link 7 parameters to be linked such that they have the same value.

Cheers
Simon

polarization node

I'm working to add the polarization nodes into the model. However, it is currently added through a SpectralComponent and thus, if you want to access the polarization of a source, you need to know the name of the spectral component directly.

Should we add a method to access the polarizations at a higher level in the tree?

clone_model and template model

When using the clone_model function on a template model, the following error occurs:

---------------------------------------------------------------------------
ModelSyntaxError                          Traceback (most recent call last)
<ipython-input-29-35143b5543c2> in <module>()
----> 1 clone_model(model_lund)

/usr/local/lib/python2.7/site-packages/astromodels-0.3.0-py2.7.egg/astromodels/core/model_parser.pyc in clone_model(model_instance)
     49     data = model_instance.to_dict_with_types()
     50 
---> 51     parser = ModelParser(model_dict=data)
     52 
     53     return parser.get_model()

/usr/local/lib/python2.7/site-packages/astromodels-0.3.0-py2.7.egg/astromodels/core/model_parser.pyc in __init__(self, model_file, model_dict)
     83             self._model_dict = model_dict
     84 
---> 85         self._parse()
     86 
     87     def _parse(self):

/usr/local/lib/python2.7/site-packages/astromodels-0.3.0-py2.7.egg/astromodels/core/model_parser.pyc in _parse(self)
    125             else:
    126 
--> 127                 this_parser = SourceParser(source_or_var_name, source_or_var_definition)
    128 
    129                 res = this_parser.get_source()

/usr/local/lib/python2.7/site-packages/astromodels-0.3.0-py2.7.egg/astromodels/core/model_parser.pyc in __init__(self, source_name, source_definition)
    262         if source_type == POINT_SOURCE:
    263 
--> 264             self._parsed_source = self._parse_point_source(source_definition)
    265 
    266         elif source_type == EXTENDED_SOURCE:

/usr/local/lib/python2.7/site-packages/astromodels-0.3.0-py2.7.egg/astromodels/core/model_parser.pyc in _parse_point_source(self, pts_source_definition)
    337 
    338         for component_name, component_definition in pts_source_definition['spectrum'].iteritems():
--> 339             this_component = self._parse_spectral_component(component_name, component_definition)
    340 
    341             components.append(this_component)

/usr/local/lib/python2.7/site-packages/astromodels-0.3.0-py2.7.egg/astromodels/core/model_parser.pyc in _parse_spectral_component(self, component_name, component_definition)
    418         shape_parser = ShapeParser(self._source_name)
    419 
--> 420         shape = shape_parser.parse(component_name, function_name, parameters_definition)
    421 
    422         # Get the links and extra setups, if any

/usr/local/lib/python2.7/site-packages/astromodels-0.3.0-py2.7.egg/astromodels/core/model_parser.pyc in parse(self, component_name, function_name, parameters_definition)
    481     def parse(self, component_name, function_name, parameters_definition):
    482 
--> 483         return self._parse_shape_definition(component_name, function_name, parameters_definition)
    484 
    485     @staticmethod

/usr/local/lib/python2.7/site-packages/astromodels-0.3.0-py2.7.egg/astromodels/core/model_parser.pyc in _parse_shape_definition(self, component_name, function_name, parameters_definition)
    508 
    509                 raise ModelSyntaxError("Function %s, specified as shape for %s of source %s, is not a "
--> 510                                        "known function" % (function_name, component_name, self._source_name))
    511 
    512         # Loop over the parameters of the function instance, instead of the specification,

ModelSyntaxError: Function lundman, specified as shape for main of source bn100507577, is not a known function

Bug in prior assignment

When attempting to assign a prior the following is occurring:

comp.K_1.prior = Log_uniform_prior(lower_bound=1E-5,upper_bound=1E-1)

NotCallableOrErrorInCall                  Traceback (most recent call last)
<ipython-input-16-0a86e595c312> in <module>()
----> 1 comp.K_1.prior = Log_uniform_prior(lower_bound=1E-5,upper_bound=1E-1)
      2 comp.K_2.prior = Log_uniform_prior(lower_bound=1E0,upper_bound=1E4)
      3 comp.xp_1 = Log_uniform_prior(lower_bound=1E2,upper_bound=1E4)
      4 comp.xc_2 = Log_uniform_prior(lower_bound=1E2,upper_bound=1E4)
      5 comp.alpha_1=Uniform_prior(lower_bound=-2,upper_bound=1)

/usr/local/lib/python2.7/site-packages/astromodels-0.2.1-py2.7.egg/astromodels/dual_access_class.pyc in __setattr__(self, key, value)
     51                 warnings.warn("Attribute %s does not exist. Check for typos." % key, NonExistingAttribute)
     52 
---> 53             super(DualAccessClass, self).__setattr__(key, value)
     54 
     55     def _add_attribute(self, name, value):

/usr/local/lib/python2.7/site-packages/astromodels-0.2.1-py2.7.egg/astromodels/parameter.pyc in _set_prior(self, prior)
    589 
    590             raise NotCallableOrErrorInCall("Could not call the provided prior. " +
--> 591                                            "Is it a function accepting the current value of the parameter?")
    592 
    593         prior.set_units(self.unit, u.dimensionless_unscaled)

NotCallableOrErrorInCall: Could not call the provided prior. Is it a function accepting the current value of the parameter?

I'm looking into the issue, but do not know the guts of astromodels so well.

ModelParser fails on sky position prior

I have defined a uniform prior for the sky position in a plugin:

super(BALROGLike, self).set_model(likelihoodModel)
        if self._free_position:

            for key in self._like_model.point_sources.keys():

                self._like_model.point_sources[key].position.ra.free = True
                self._like_model.point_sources[key].position.dec.free = True

                self._like_model.point_sources[key].position.ra.prior = Uniform_prior(lower_bound=0.,upper_bound=360)
                self._like_model.point_sources[key].position.dec.prior = Cosine_Prior(lower_bound=-90.,upper_bound=90)

After performing a JL fit, when the model is cloned I get the following error:

---------------------------------------------------------------------------
NotCallableOrErrorInCall                  Traceback (most recent call last)
<ipython-input-12-eb2dae7a50af> in <module>()
      1 
      2 
----> 3 _ = jl.fit()

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/threeML-0.3.2-py2.7.egg/threeML/classicMLE/joint_likelihood.pyc in fit(self, quiet, compute_covariance)
    249         # Now instance an analysis results class
    250         self._analysis_results = MLEResults(self.likelihood_model, self._minimizer.covariance_matrix,
--> 251                                             minus_log_likelihood_values)
    252 
    253         # Show the results

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/threeML-0.3.2-py2.7.egg/threeML/analysis_results.pyc in __init__(self, optimized_model, covariance_matrix, likelihood_values, n_samples)
    763         # Finally build the class
    764 
--> 765         super(MLEResults, self).__init__(optimized_model, samples, likelihood_values, "MLE")
    766 
    767         # Store the covariance matrix

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/threeML-0.3.2-py2.7.egg/threeML/analysis_results.pyc in __init__(self, optimized_model, samples, statistic_values, analysis_type)
    328         # changed
    329 
--> 330         self._optimized_model = astromodels.clone_model(optimized_model)
    331 
    332         # Save a transposed version of the samples for easier access

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.4.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in clone_model(model_instance)
     49     data = model_instance.to_dict_with_types()
     50 
---> 51     parser = ModelParser(model_dict=data)
     52 
     53     return parser.get_model()

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.4.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in __init__(self, model_file, model_dict)
     83             self._model_dict = model_dict
     84 
---> 85         self._parse()
     86 
     87     def _parse(self):

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.4.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in _parse(self)
    125             else:
    126 
--> 127                 this_parser = SourceParser(source_or_var_name, source_or_var_definition)
    128 
    129                 res = this_parser.get_source()

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.4.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in __init__(self, source_name, source_definition)
    262         if source_type == POINT_SOURCE:
    263 
--> 264             self._parsed_source = self._parse_point_source(source_definition)
    265 
    266         elif source_type == EXTENDED_SOURCE:

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.4.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in _parse_point_source(self, pts_source_definition)
    322             raise ModelSyntaxError("Point source %s is missing the 'position' attribute" % self._source_name)
    323 
--> 324         this_sky_direction = self._parse_sky_direction(position_definition)
    325 
    326         # Parse the spectral information

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.4.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/model_parser.pyc in _parse_sky_direction(self, sky_direction_definition)
    357             definition.update(sky_direction_definition['ra'])
    358 
--> 359             ra = parameter.Parameter(**definition)
    360             ra.bounds = (0, 360)
    361 

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.4.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/parameter.pyc in __init__(self, name, value, min_value, max_value, delta, desc, free, unit, prior)
    587             # Use the property on purpose, so all checks and setups are applied
    588 
--> 589             self.prior = prior
    590 
    591         # Now perform a very lazy check that we can perform math operations on the delta

/Users/jburgess/.environs/3ml/lib/python2.7/site-packages/astromodels-0.4.0-py2.7-macosx-10.12-x86_64.egg/astromodels/core/parameter.pyc in _set_prior(self, prior)
    647 
    648             raise NotCallableOrErrorInCall("Could not call the provided prior. " +
--> 649                                            "Is it a function accepting the current value of the parameter?")
    650 
    651         try:

NotCallableOrErrorInCall: Could not call the provided prior. Is it a function accepting the current value of the parameter?

Linked spatial parameters and cloning a model

See #86 (comment)

Here's an example that shows what's going on with the current master... A model with 2 extended sources, 4 free parameters and 2 linked parameters. After cloning or reading from yml, S2.Gaussian_on_sphere.sigma is fixed to 0.5 (default value) instead of being linked to S1.Gaussian_on_sphere.sigma. The index is fine (still shows as linked parameter after cloning the model).

from astromodels import *
from threeML import *

spectrum = Powerlaw()
shape = Gaussian_on_sphere()
spectrum2 = Powerlaw()
shape2 = Gaussian_on_sphere()

source = ExtendedSource("S1", spatial_shape=shape, spectral_shape=spectrum)
source2 = ExtendedSource("S2", spatial_shape=shape2, spectral_shape=spectrum2)

fluxUnit = 1. / (u.TeV * u.cm ** 2 * u.s)

for sp in [spectrum, spectrum2]:

    # Set spectral parameters
    sp.K = 1e-14 * fluxUnit
    sp.K.bounds = (1e-16 * fluxUnit, 1e-12 * fluxUnit)

    sp.piv = 20 * u.TeV
    sp.piv.fix = True

    sp.index = -2.4
    sp.index.bounds = (-4., -1.)

for sh in [shape, shape2 ]:

    # Set spatial parameters
    sh.lon0 = 80. * u.degree
    sh.lon0.fix = True

    sh.lat0 = 20.0 * u.degree
    sh.lat0.fix = True

    sh.sigma = 6.0 * u.degree
    sh.sigma.fix = False
    sh.sigma.max_value = 12.

lm = Model(source, source2)

lm.link( shape2.sigma, shape.sigma)
lm.link( spectrum2.index, spectrum.index)

lm.save("test1.yml", overwrite=True )
lm.display(complete=True)

lm2 = clone_model( lm )
lm2.display(complete=True)
lm2.save("test2.yml", overwrite=True )

lm3  = load_model( "test1.yml")
lm3.display(complete=True)
lm2.save("test3.yml", overwrite=True )

Output with master branch:

Model summary:
==============

                  N
Point sources     0
Extended sources  2
Particle sources  0

Free parameters (4):
--------------------

                                 value min_value max_value            unit
S1.Gaussian_on_sphere.sigma          6         0        12             deg
S1.spectrum.main.Powerlaw.K      1e-23     1e-25     1e-21  keV-1 s-1 cm-2
S1.spectrum.main.Powerlaw.index   -2.4        -4        -1                
S2.spectrum.main.Powerlaw.K      1e-23     1e-25     1e-21  keV-1 s-1 cm-2

Fixed parameters (10):
---------------------

                                        value min_value max_value unit
S1.Gaussian_on_sphere.lon0                 80         0       360  deg
S1.Gaussian_on_sphere.lat0                 20       -90        90  deg
S1.spectrum.main.Powerlaw.piv           2e+10      None      None  keV
S2.Gaussian_on_sphere.lon0                 80         0       360  deg
S2.Gaussian_on_sphere.lat0                 20       -90        90  deg
S2.Gaussian_on_sphere.sigma.Line.a          1      None      None     
S2.Gaussian_on_sphere.sigma.Line.b          0      None      None  deg
S2.spectrum.main.Powerlaw.piv           2e+10      None      None  keV
S2.spectrum.main.Powerlaw.index.Line.a      1      None      None     
S2.spectrum.main.Powerlaw.index.Line.b      0      None      None     

Linked parameters (2):
----------------------

               S2.Gaussian_on_sphere.sigma
current value                          6.0
function                              Line
linked to      S1.Gaussian_on_sphere.sigma
unit                                   deg

               S2.spectrum.main.Powerlaw.index
current value                             -2.4
function                                  Line
linked to      S1.spectrum.main.Powerlaw.index
unit                                          


Independent variables:
----------------------

(none)

Model summary:
==============

                  N
Point sources     0
Extended sources  2
Particle sources  0

Free parameters (4):
--------------------

                                 value min_value max_value            unit
S1.Gaussian_on_sphere.sigma          6         0        12             deg
S1.spectrum.main.Powerlaw.K      1e-23     1e-25     1e-21  keV-1 s-1 cm-2
S1.spectrum.main.Powerlaw.index   -2.4        -4        -1                
S2.spectrum.main.Powerlaw.K      1e-23     1e-25     1e-21  keV-1 s-1 cm-2

Fixed parameters (9):
---------------------

                                        value min_value max_value unit
S1.Gaussian_on_sphere.lon0                 80         0       360  deg
S1.Gaussian_on_sphere.lat0                 20       -90        90  deg
S1.spectrum.main.Powerlaw.piv           2e+10      None      None  keV
S2.Gaussian_on_sphere.lon0                 80         0       360  deg
S2.Gaussian_on_sphere.lat0                 20       -90        90  deg
S2.Gaussian_on_sphere.sigma               0.5         0        12  deg
S2.spectrum.main.Powerlaw.piv           2e+10      None      None  keV
S2.spectrum.main.Powerlaw.index.Line.a      1      None      None     
S2.spectrum.main.Powerlaw.index.Line.b      0      None      None     

Linked parameters (1):
----------------------

               S2.spectrum.main.Powerlaw.index
current value                             -2.4
function                                  Line
linked to      S1.spectrum.main.Powerlaw.index
unit                                          


Independent variables:
----------------------

(none)

Model summary:
==============

                  N
Point sources     0
Extended sources  2
Particle sources  0

Free parameters (4):
--------------------

                                 value min_value max_value            unit
S1.Gaussian_on_sphere.sigma          6         0        12             deg
S1.spectrum.main.Powerlaw.K      1e-23     1e-25     1e-21  keV-1 s-1 cm-2
S1.spectrum.main.Powerlaw.index   -2.4        -4        -1                
S2.spectrum.main.Powerlaw.K      1e-23     1e-25     1e-21  keV-1 s-1 cm-2

Fixed parameters (9):
---------------------

                                        value min_value max_value unit
S1.Gaussian_on_sphere.lon0                 80         0       360  deg
S1.Gaussian_on_sphere.lat0                 20       -90        90  deg
S1.spectrum.main.Powerlaw.piv           2e+10      None      None  keV
S2.Gaussian_on_sphere.lon0                 80         0       360  deg
S2.Gaussian_on_sphere.lat0                 20       -90        90  deg
S2.Gaussian_on_sphere.sigma               0.5         0        12  deg
S2.spectrum.main.Powerlaw.piv           2e+10      None      None  keV
S2.spectrum.main.Powerlaw.index.Line.a      1      None      None     
S2.spectrum.main.Powerlaw.index.Line.b      0      None      None     

Linked parameters (1):
----------------------

               S2.spectrum.main.Powerlaw.index
current value                             -2.4
function                                  Line
linked to      S1.spectrum.main.Powerlaw.index
unit                                          


Independent variables:
----------------------

(none)

pyyaml 5.1

Some people have reported issues using the new version of pyyaml (5.1).

There are warnings like

/Users/Chang/miniconda3/envs/st_test/lib/python2.7/site-packages/astromodels/functions/function.py:120: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  function_definition = my_yaml.load(dct['__doc__'])

The code runs, but there are issues with parsing functions/loading models from file, leading to errors like

E                                  UnitsError: Looks like you didn't provide all the units, or you provided the wrong ones, when calling function Powerlaw

or

E               ModelSyntaxError: Function polarization, specified as shape for main of source one, is not a known function

during the tests.

Again, the underlying issues is changes in pyyaml, which break parsing of yml files in astromodels. See also yaml/pyyaml#265 . I suggest anyone experiencing issues downgrade to pyyaml==3.13 and yaml==0.1.7.

There are some more issues with the new version of pyyaml, see e.g. yaml/pyyaml#275 .

XSPEC Units in composite models

After doing a clean install of astromodels, I'm having an issue with passing multiplicative models to 3ML's Model class. From the 3ML joint XRT demo:

xspec_abund('angr')

spectral_model =  XS_phabs()* XS_zphabs() * XS_powerlaw()


spectral_model.nh_1=0.101
spectral_model.nh_1.fix = True

spectral_model.nh_2=0.1114424
spectral_model.nh_2.fix = True

spectral_model.redshift_2 = 0.618
spectral_model.redshift_2.fix =True

screenshot 2016-09-21 08 51 30

ptsrc = PointSource(trigger,ra,dec,spectral_shape=spectral_model)
model = Model(ptsrc)

data = DataList(xrt,nai3)

jl = JointLikelihood(model, data, verbose=False)
model.display()

Output:

RuntimeError                              Traceback (most recent call last)
<ipython-input-14-600bcb96e340> in <module>()
----> 1 ptsrc = PointSource(trigger,ra,dec,spectral_shape=spectral_model)
      2 model = Model(ptsrc)
      3 
      4 data = DataList(xrt,nai3)
      5 

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/sources/point_source.pyc in __init__(self, source_name, ra, dec, spectral_shape, l, b, components, sky_position)
    139         for component in self._components.values():
    140 
--> 141             component.shape.set_units(x_unit, y_unit)
    142 
    143     def __call__(self, x):

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/functions/function.pyc in set_units(self, x_unit, y_unit)
   1563             else:
   1564 
-> 1565                 function.set_units(x_unit, y_unit)
   1566 
   1567         #If there are multiple free normalizations, freeze them to 1 and fix the unit of the corresponding

/usr/local/Cellar/python/HEAD/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astromodels-0.2.3-py2.7-macosx-10.11-x86_64.egg/astromodels/functions/function.pyc in set_units(self, in_x_unit, in_y_unit)
    907 
    908         # Now call the underlying method to set units, which is defined by each function
--> 909         new_units = self._set_units(in_x_unit, in_y_unit)
    910 
    911         # Store the units.

/Users/jburgess/.astromodels/data/XS_zphabs.py in _set_units(self, x_unit, y_unit)
    132         except:
    133 
--> 134             raise RuntimeError("Xspec model %s cannot have units of %s" % (self.name, y_unit))
    135 
    136     def _integral(self, low_bounds, hi_bounds, nh, redshift):

RuntimeError: Xspec model XS_zphabs cannot have units of 1 / (cm2 keV s)

with xspec + python3 installation fails

I suspect this is a python 3 issue. module init functions are called differently now. Might be solvable with an #ifdef
see here: https://docs.python.org/3/howto/cporting.html

$ . ~/bin/xspec/xspec.sh
$ python setup.py install --user

 Xspec is detected. Will compile the Xspec extension.

Found library XSFunctions in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library XSModel in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library XSUtil in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library XS in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library cfitsio in None
Found library CCfits_2.5 in /home/user/bin/xspec/x86_64-unknown-linux-gnu-libc2.25/lib
Found library wcs in None
Found library gfortran in None
running install
running bdist_egg
running egg_info
creating astromodels.egg-info
writing requirements to astromodels.egg-info/requires.txt
writing top-level names to astromodels.egg-info/top_level.txt
writing astromodels.egg-info/PKG-INFO
writing dependency_links to astromodels.egg-info/dependency_links.txt
writing manifest file 'astromodels.egg-info/SOURCES.txt'
package init file 'astromodels/tests/__init__.py' not found (or not a regular file)
reading manifest template 'MANIFEST.in'
writing manifest file 'astromodels.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.linux-x86_64-3.5
creating build/lib.linux-x86_64-3.5/astromodels
copying astromodels/__init__.py -> build/lib.linux-x86_64-3.5/astromodels
copying astromodels/version.py -> build/lib.linux-x86_64-3.5/astromodels
creating build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/parameter_transformation.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/memoization.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/spectral_component.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/sky_direction.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/my_yaml.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/model_parser.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/units.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/tree.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/__init__.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/thread_safe_unit_format.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/serialization.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/polarization.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/parameter.py -> build/lib.linux-x86_64-3.5/astromodels/core
copying astromodels/core/model.py -> build/lib.linux-x86_64-3.5/astromodels/core
creating build/lib.linux-x86_64-3.5/astromodels/functions
copying astromodels/functions/functions_3D.py -> build/lib.linux-x86_64-3.5/astromodels/functions
copying astromodels/functions/functions_2D.py -> build/lib.linux-x86_64-3.5/astromodels/functions
copying astromodels/functions/function.py -> build/lib.linux-x86_64-3.5/astromodels/functions
copying astromodels/functions/__init__.py -> build/lib.linux-x86_64-3.5/astromodels/functions
copying astromodels/functions/priors.py -> build/lib.linux-x86_64-3.5/astromodels/functions
copying astromodels/functions/template_model.py -> build/lib.linux-x86_64-3.5/astromodels/functions
copying astromodels/functions/functions.py -> build/lib.linux-x86_64-3.5/astromodels/functions
creating build/lib.linux-x86_64-3.5/astromodels/functions/dark_matter
copying astromodels/functions/dark_matter/__init__.py -> build/lib.linux-x86_64-3.5/astromodels/functions/dark_matter
copying astromodels/functions/dark_matter/dm_models.py -> build/lib.linux-x86_64-3.5/astromodels/functions/dark_matter
creating build/lib.linux-x86_64-3.5/astromodels/sources
copying astromodels/sources/point_source.py -> build/lib.linux-x86_64-3.5/astromodels/sources
copying astromodels/sources/__init__.py -> build/lib.linux-x86_64-3.5/astromodels/sources
copying astromodels/sources/source.py -> build/lib.linux-x86_64-3.5/astromodels/sources
copying astromodels/sources/extended_source.py -> build/lib.linux-x86_64-3.5/astromodels/sources
copying astromodels/sources/particle_source.py -> build/lib.linux-x86_64-3.5/astromodels/sources
creating build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/configuration.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/angular_distance.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/vincenty.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/valid_variable.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/data_files.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/io.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/__init__.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/table.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/long_path_formatter.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/disk_usage.py -> build/lib.linux-x86_64-3.5/astromodels/utils
copying astromodels/utils/pretty_list.py -> build/lib.linux-x86_64-3.5/astromodels/utils
creating build/lib.linux-x86_64-3.5/astromodels/xspec
copying astromodels/xspec/__init__.py -> build/lib.linux-x86_64-3.5/astromodels/xspec
copying astromodels/xspec/factory.py -> build/lib.linux-x86_64-3.5/astromodels/xspec
copying astromodels/xspec/xspec_settings.py -> build/lib.linux-x86_64-3.5/astromodels/xspec
creating build/lib.linux-x86_64-3.5/astromodels/tests
copying astromodels/tests/test_functions.py -> build/lib.linux-x86_64-3.5/astromodels/tests
copying astromodels/tests/test_tree.py -> build/lib.linux-x86_64-3.5/astromodels/tests
copying astromodels/tests/test_memoizer.py -> build/lib.linux-x86_64-3.5/astromodels/tests
copying astromodels/tests/test_load_xspec_models.py -> build/lib.linux-x86_64-3.5/astromodels/tests
copying astromodels/tests/test_point_source.py -> build/lib.linux-x86_64-3.5/astromodels/tests
copying astromodels/tests/test_parameter.py -> build/lib.linux-x86_64-3.5/astromodels/tests
copying astromodels/tests/test_model.py -> build/lib.linux-x86_64-3.5/astromodels/tests
copying astromodels/tests/test_template_model.py -> build/lib.linux-x86_64-3.5/astromodels/tests
creating build/lib.linux-x86_64-3.5/astromodels/data
creating build/lib.linux-x86_64-3.5/astromodels/data/dark_matter
copying astromodels/data/dark_matter/dmSpecTab.npy -> build/lib.linux-x86_64-3.5/astromodels/data/dark_matter
copying astromodels/data/dark_matter/gammamc_dif.dat -> build/lib.linux-x86_64-3.5/astromodels/data/dark_matter
creating build/lib.linux-x86_64-3.5/astromodels/data/tests
copying astromodels/data/tests/black_hole.yaml -> build/lib.linux-x86_64-3.5/astromodels/data/tests
copying astromodels/data/tests/simple_source.yaml -> build/lib.linux-x86_64-3.5/astromodels/data/tests
copying astromodels/data/tests/test.yaml -> build/lib.linux-x86_64-3.5/astromodels/data/tests
creating build/lib.linux-x86_64-3.5/astromodels/core/node_ctype
copying astromodels/core/node_ctype/node_ctype.cxx -> build/lib.linux-x86_64-3.5/astromodels/core/node_ctype
copying astromodels/xspec/LICENSE -> build/lib.linux-x86_64-3.5/astromodels/xspec
copying astromodels/xspec/README -> build/lib.linux-x86_64-3.5/astromodels/xspec
creating build/lib.linux-x86_64-3.5/astromodels/xspec/include
creating build/lib.linux-x86_64-3.5/astromodels/xspec/include/sherpa
copying astromodels/xspec/include/sherpa/array.hh -> build/lib.linux-x86_64-3.5/astromodels/xspec/include/sherpa
copying astromodels/xspec/include/sherpa/constants.hh -> build/lib.linux-x86_64-3.5/astromodels/xspec/include/sherpa
copying astromodels/xspec/include/sherpa/extension.hh -> build/lib.linux-x86_64-3.5/astromodels/xspec/include/sherpa
copying astromodels/xspec/include/sherpa/fcmp.hh -> build/lib.linux-x86_64-3.5/astromodels/xspec/include/sherpa
creating build/lib.linux-x86_64-3.5/astromodels/xspec/include/sherpa/astro
copying astromodels/xspec/include/sherpa/astro/xspec_extension.hh -> build/lib.linux-x86_64-3.5/astromodels/xspec/include/sherpa/astro
creating build/lib.linux-x86_64-3.5/astromodels/xspec/src
copying astromodels/xspec/src/_xspec.cc -> build/lib.linux-x86_64-3.5/astromodels/xspec/src
running build_ext
building 'astromodels.xspec._xspec' extension
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/astromodels
creating build/temp.linux-x86_64-3.5/astromodels/xspec
creating build/temp.linux-x86_64-3.5/astromodels/xspec/src
x86_64-pc-linux-gnu-g++ -pthread -fPIC -I/usr/include/python3.5m -I/usr/lib64/python3.5/site-packages/numpy/core/include -Iastromodels/xspec/include -c astromodels/xspec/src/_xspec.cc -o build/temp.linux-x86_64-3.5/astromodels/xspec/src/_xspec.o
astromodels/xspec/src/_xspec.cc: In function ‘PyObject* init_xspec()’:
astromodels/xspec/src/_xspec.cc:1300:1: error: conflicting declaration of C function ‘PyObject* init_xspec()’
 init_xspec(void)
 ^~~~~~~~~~
astromodels/xspec/src/_xspec.cc:34:6: note: previous declaration ‘void init_xspec()’
 void init_xspec();
      ^~~~~~~~~~
astromodels/xspec/src/_xspec.cc:1304:3: error: ‘Py_InitModule’ was not declared in this scope
   Py_InitModule( (char*)"_xspec", XSpecMethods );
   ^~~~~~~~~~~~~
astromodels/xspec/src/_xspec.cc:1304:3: note: suggested alternative: ‘Py_Initialize’
   Py_InitModule( (char*)"_xspec", XSpecMethods );
   ^~~~~~~~~~~~~
   Py_Initialize
error: command 'x86_64-pc-linux-gnu-g++' failed with exit status 1
 $ 

Parameter class docstring formatting

There's a Sphinx formatting error in the Parameter class docstring:
https://astromodels.readthedocs.io/en/latest/api/astromodels.core.html#astromodels.core.parameter.Parameter

The issue seems to be that the newline in the description of the transformation parameter isn't handled correctly:
https://github.com/giacomov/astromodels/blob/f8741ff9386409dbf30868665a9e3186185cbcbc/astromodels/core/parameter.py#L769-L770

I'm not familiar with this docstring format, all projects I work on use the Numpy docstring standard, so I'll leave it to you.

Use CamelCase for functions

We were using Camel_case for functions to distinguish them from other classes, but it looks like it is more confusing then helpful.

Log Normal prior Negative values

The log_normal distribution in priors.py lets negative values get evaluated in the np.log() function.
Despite adding bounds to a parameter in the model specification, emcee kinda does its own thing and tries negative flux values when the prior is non-zero. The prior for a log normal then returns -np.inf. Naively to me, the behavior should be that for negative x the log_normal distribution would return 0.

Adding these lines
if x_ <=0: return 0
seems to fix the issue.

I did not submit a pull request because there is an additional units question to consider that should be decided upon for the best way to address the problem.

Several Templates at once

Hi,
I am running into issues while loading several template models at once. when trying to plot them with a looping function for a given parameter set some of them seem to adapt values from other template models before them in the loop. Unfortunately there does not seem to be a regularity when this happens or not. So sometimes even rerunning the same script yields different results. Further if I just print out the values for a given parameter set the values are sometimes coming from different template models as well. Hence I guess that some of the values might be cached somewhere and then reused instead calling the actual template model. I used TemplateModel('name', log_interp = False) and the plotted them as a function of phase between 0 and 1.

Cheers
Simon

XSPEC model not working

It seems the XS_zdust is only outputting '1':



from astromodels.xspec import *


zdust = XS_zdust() 


zdust.method = 3
zdust.rv = 2.93
zdust.redshift=1


wl = (np.linspace(400,10000,500) * astropy_units.nm).to('keV', equivalencies=u.spectral()).value


zdust.e_bmv = 10.
zdust(wl)

zdust.e_bmv = 0.
zdust(wl)

the output is always 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.