# Path: sherpa_contrib/utils.py
# def _is_boolean(val):
#     def __str__(self):
#         def fmt(key, val):
#     def __init__(self, id=None, fluxtype="photon"):
#     def _calc_bins(self, data):
#     def _apply_mask(self, data):
#     def save(self, filename, clobber=True):
#     def plot(self, overplot=False, clearwindow=True, **kwargs):
#     def _estimate_expmap(self, *args):
#     def estimate_expmap(self, *args):
#     def _calc_bins(self, data):
#     def _calc_bins(self, data):
#     def estimate_expmap(self, *args):
# def get_instmap_weights(id=None, fluxtype="photon"):
# def save_instmap_weights(*args, **kwargs):
# def plot_instmap_weights(id=None, fluxtype="photon",
#                          overplot=False, clearwindow=True, **kwargs):
# def estimate_weighted_expmap(id=None, arf=None, elo=None, ehi=None,
#                              specresp=None, fluxtype="photon",
#                              par=None, pvals=None):
# def renorm(id=None, cpt=None, bkg_id=None, names=None,
#            limscale=10000.0):
# class InstMapWeights:
# class InstMapWeights1DInt(InstMapWeights):
# class InstMapWeightsPHA(InstMapWeights):


import unittest
import numpy as np
import sys
from sherpa.astro import ui
from sherpa.utils.err import IdentifierErr
from sherpa_contrib import utils

    def test_no_source(self):
        self.assertRaises(IdentifierErr, utils.get_instmap_weights,
                          id='not-used')

    def test_invalid_fluxtype(self):
        self.assertRaises(ValueError, utils.get_instmap_weights,
                          fluxtype='nonsense')

    def check_spacing(self, wgt, nbins, lo, hi, step):
        xlo = wgt.xlo
        xhi = wgt.xhi
        xmid = wgt.xmid
        self.assertEqual(nbins, xlo.size)
        self.assertEqual(xlo.size, xhi.size)
        self.assertEqual(xlo.size, xmid.size)
        self.assertAlmostEqual(lo, xlo[0])
        self.assertAlmostEqual(hi, xhi[-1])
        self.assertAlmostEqual(step, (xmid[-1] - xmid[0]) /
                               (xlo.size - 1))

    def test_grid1(self):
        wgt = utils.get_instmap_weights()
        self.check_spacing(wgt, self.nbins[1], 0.01, 11.0, 0.01)

    def test_grid1_erg(self):
        wgt = utils.get_instmap_weights(fluxtype='erg')
        self.check_spacing(wgt, self.nbins[1], 0.01, 11.0, 0.01)

    def test_gridtst(self):

# Path: sherpa_contrib/utils.py
# def _is_boolean(val):
#     def __str__(self):
#         def fmt(key, val):
#     def __init__(self, id=None, fluxtype="photon"):
#     def _calc_bins(self, data):
#     def _apply_mask(self, data):
#     def save(self, filename, clobber=True):
#     def plot(self, overplot=False, clearwindow=True, **kwargs):
#     def _estimate_expmap(self, *args):
#     def estimate_expmap(self, *args):
#     def _calc_bins(self, data):
#     def _calc_bins(self, data):
#     def estimate_expmap(self, *args):
# def get_instmap_weights(id=None, fluxtype="photon"):
# def save_instmap_weights(*args, **kwargs):
# def plot_instmap_weights(id=None, fluxtype="photon",
#                          overplot=False, clearwindow=True, **kwargs):
# def estimate_weighted_expmap(id=None, arf=None, elo=None, ehi=None,
#                              specresp=None, fluxtype="photon",
#                              par=None, pvals=None):
# def renorm(id=None, cpt=None, bkg_id=None, names=None,
#            limscale=10000.0):
# class InstMapWeights:
# class InstMapWeights1DInt(InstMapWeights):
# class InstMapWeightsPHA(InstMapWeights):


# Path: sherpa_contrib/tests/test_weights.py
import unittest
import numpy as np
import sys
from sherpa.astro import ui
from sherpa.utils.err import IdentifierErr
from sherpa_contrib import utils


    def test_no_source(self):
        self.assertRaises(IdentifierErr, utils.get_instmap_weights,
                          id='not-used')

    def test_invalid_fluxtype(self):
        self.assertRaises(ValueError, utils.get_instmap_weights,
                          fluxtype='nonsense')

    def check_spacing(self, wgt, nbins, lo, hi, step):
        xlo = wgt.xlo
        xhi = wgt.xhi
        xmid = wgt.xmid
        self.assertEqual(nbins, xlo.size)
        self.assertEqual(xlo.size, xhi.size)
        self.assertEqual(xlo.size, xmid.size)
        self.assertAlmostEqual(lo, xlo[0])
        self.assertAlmostEqual(hi, xhi[-1])
        self.assertAlmostEqual(step, (xmid[-1] - xmid[0]) /
                               (xlo.size - 1))

    def test_grid1(self):
        wgt = utils.get_instmap_weights()
        self.check_spacing(wgt, self.nbins[1], 0.01, 11.0, 0.01)

    def test_grid1_erg(self):
        wgt = utils.get_instmap_weights(fluxtype='erg')
        self.check_spacing(wgt, self.nbins[1], 0.01, 11.0, 0.01)

    def test_gridtst(self):

        wgt = utils.get_instmap_weights('tst')