def create_spectrum_from_dict(spectrum_type, spectral_pars, fn=None):
    """Create a Function object from a parameter dictionary.

    Parameters
    ----------
    spectrum_type : str
       String identifying the spectrum type (e.g. PowerLaw).

    spectral_pars : dict
       Dictionary of spectral parameters.

    """

    if fn is None:
        fn = pyLike.SourceFactory_funcFactory().create(str(spectrum_type))

    if spectrum_type == 'PiecewisePowerLaw':        
        build_piecewise_powerlaw(fn, spectral_pars)

    for k, v in spectral_pars.items():

        v.setdefault('scale', 1.0)
        v.setdefault('min', v['value'] * 1E-3)
        v.setdefault('max', v['value'] * 1E3)

        par = fn.getParam(str(k))

        vmin = min(float(v['value']), float(v['min']))
        vmax = max(float(v['value']), float(v['max']))

        par.setValue(float(v['value']))
        par.setBounds(vmin, vmax)
        par.setScale(float(v['scale']))

        if 'free' in v and int(v['free']) != 0:
            par.setFree(True)
        else:
            par.setFree(False)
        fn.setParam(par)

    return fn
Create a Function object from a parameter dictionary.

    Parameters
    ----------
    spectrum_type : str
       String identifying the spectrum type (e.g. PowerLaw).

    spectral_pars : dict
       Dictionary of spectral parameters.