def testImplicit(self): print("==== BracketModel Test =======================") m1 = GaussModel() m1 += PolynomialModel(0) # Gauss on a constant background m2 = BracketModel(m1) m3 = SineModel() m3 *= m2 # sine * ( gauss + const ) print("Explicit Use") print(m3) g1 = GaussModel() g1 += PolynomialModel(0) # m1 is a chain of models g3 = SineModel() g3 *= g1 # sine * ( gauss + const ) print("Implicit Use") print(g3) # exactly the same p = [8.0, 1.0, 0.0, 1.0, 0.0, 0.2, 1.0] x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) assertAE(g3.result(x, p), m3.result(x, p)) assertAE(g3.partial(x, p), m3.partial(x, p)) assertAE(g3.derivative(x, p), m3.derivative(x, p)) stdModeltest(g3, p, plot=self.doplot)
def test2(self): print("\n CombiModel Test 2\n") gm = GaussModel() pars = numpy.linspace(0.0, 1.0, 3, dtype=float) gm.parameters = pars cm = CombiModel(gm, 3) Tools.printclass(cm) self.assertTrue(cm.deep == 1) print(str(cm._head)) self.assertTrue(str(cm._head) == "Combi of 3 times Gauss") self.assertTrue(cm._next is None) self.assertTrue(cm._npchain == 9 and cm.npchain == 9) assertAE(cm.addindex, []) assertAE(cm.addvalue, []) assertAE(cm.mulindex, []) assertAE(cm.mulvalue, []) assertAE(cm.expandindex, numpy.arange(9, dtype=int)) assertAE(cm.select, numpy.arange(9, dtype=int)) assertAE(cm.parameters, [0.0, 0.5, 1.0] * 3) p = numpy.ones(9, dtype=float) p[1:9:3] /= 2 p[2:9:3] /= 10 stdModeltest(cm, p, plot=self.doplot)
def testConstantModel(self): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******NULL***********************") m = ConstantModel() self.assertTrue(m.npchain == 0) p = [] stdModeltest(m, p) print("******CONSTANT VALUE*******************") sm = SineModel() m = ConstantModel(fixedModel=sm) m.values = [2.0, 0.0, 0.5] stdModeltest(m, p, silent=False) print("******CONSTANT MODEL*******************") tbl = numpy.linspace(0, 1, 11) m = ConstantModel(table=tbl) stdModeltest(m, p) print("******CONSTANT TABLE*******************") m = ConstantModel(values=5.5) stdModeltest(m, p) print("******COMPOUND*******************") m = ConstantModel(values=1.0) m.addModel(ExpModel()) self.assertTrue(m.npbase == 0) self.assertTrue(m.npchain == 2) p = [1.0, -3.0] stdModeltest(m, p, plot=self.doplot)
def testSplinesModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******SPLINES*************************") knots = numpy.arange(11, dtype=float) m0 = SplinesModel(knots=knots) self.assertTrue(m0.order == 3) self.assertTrue(m0.getNumberOfParameters() == 13) self.assertTrue(m0.npbase == 13) m1 = SplinesModel(nrknots=5, min=-1, max=1) self.assertTrue(m1.order == 3) self.assertTrue(m1.getNumberOfParameters() == 7) self.assertTrue(m1.npbase == 7) for k in range(len(m1.knots)): self.assertTrue(m1.knots[k] == -1 + k / 2) xin = numpy.linspace(0, 10, 101, dtype=float) m2 = SplinesModel(xrange=xin, order=2, nrknots=11) self.assertTrue(m2.order == 2) self.assertTrue(m2.getNumberOfParameters() == 12) self.assertTrue(m2.npbase == 12) for k in range(len(m2.knots)): self.assertTrue(m2.knots[k] == k) self.assertRaises(ValueError, SplinesModel) p = numpy.asarray([0, 1, 0, 1, 0, 1, 0], dtype=float) stdModeltest(m1, p, plot=plot)
def testVoigtModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******VOIGT***********************") m = VoigtModel() p = numpy.asarray([1.2, 0.2, 0.3, 0.4], dtype=float) print(p) stdModeltest(m, p, plot=plot, warn=["nopart"])
def test1b(self): model = SoftMaxModel(ndim=1, ndout=2, offset=True, normed=False) print(model.npars) p = numpy.asarray([1.0, 1.0, 2.0, 2.0]) x = numpy.linspace(0, 10, 101, dtype=float) stdModeltest(model, p, x=x, plot=self.doplot)
def testArctanModel(self): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******ARCTAN***********************") m = ArctanModel() p = numpy.asarray([1.2, -0.1, 30], dtype=float) stdModeltest(m, p, plot=self.doplot)
def testGaussModel(self): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******GAUSS*************************") m = GaussModel() p = numpy.asarray([1.2, -0.2, 0.3], dtype=float) stdModeltest(m, p, plot=self.doplot)
def test2(self): x = numpy.linspace(0, 10, 101, dtype=float) x += 0.01 ## avoid awkward non-continuities print("****** FREESHAPE test 2 ********************") m = FreeShapeModel(10, nconvolve=3, center=0.0) p = numpy.asarray([1.2, 0.2, 1.0, 0.5, 0.3, 1.2, 0.2, 1.0, 0.5, 0.3]) stdModeltest(m, p, x=x, plot=self.doplot)
def testEtalonModel(self): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******ETALON***********************") m = EtalonModel() p = numpy.asarray([1.2, 0.6, 2.0, 0.2], dtype=float) stdModeltest(m, p, plot=self.doplot)
def testGaussModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******GAUSS*************************") m = GaussModel(fixed={2: 0.3}) p = numpy.asarray([1.2, -0.2], dtype=float) stdModeltest(m, p, plot=plot)
def testExpModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******EXP**************************") m = ExpModel(fixed={1: 0.1}) p = numpy.asarray([1.2], dtype=float) stdModeltest(m, p, plot=plot)
def testLorentzModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******LORENTZ***********************") m = LorentzModel(fixed={0: 4}) p = numpy.asarray([-0.2, 0.3], dtype=float) stdModeltest(m, p, plot=plot)
def testLorentzModel(self): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******LORENTZ***********************") m = LorentzModel() p = numpy.asarray([1.2, -0.2, 0.3], dtype=float) stdModeltest(m, p, plot=self.doplot)
def testArctanModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******ARCTAN******************") m = ArctanModel(fixed={1: -1.2}) p = numpy.asarray([1.2, 30], dtype=float) stdModeltest(m, p, plot=plot)
def test2(self): print("******ASTROPY MODEL 2***********************") gm = modeling.models.Gaussian1D() m = AstropyModel(gm, fixed={0: 2.6}) p = numpy.asarray([-0.1, 30], dtype=float) stdModeltest(m, p, plot=self.doplot)
def testEtalonModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******ETALON***********************") m = EtalonModel(fixed={0: 1.5}) p = numpy.asarray([30.0, 2.0, 0.2], dtype=float) stdModeltest(m, p, plot=plot)
def testPowerLawModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******POWERLAW*******************") m = PowerLawModel(fixed={1: -2}) self.assertTrue(m.npchain == 2) self.assertTrue(m.npbase == 2) p = [2.3, 0.5] stdModeltest(m, p, plot=plot)
def testChebyshevPolynomialModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******CHEBYSHEV POLYNOMIAL*************") m = ChebyshevPolynomialModel(4, fixed={4: 0.1}) self.assertTrue(m.getNumberOfParameters() == 4) self.assertTrue(m.npbase == 4) p = numpy.asarray([1, -2, 3, -2], dtype=float) stdModeltest(m, p, plot=plot)
def testSineDriftModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******SINEDRIFT******************") m = SineDriftModel() self.assertTrue(m.npchain == 4) self.assertTrue(m.npbase == 4) p = [1.1, 0.5, 0.8, 0.4] stdModeltest(m, p, plot=plot)
def testSineModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******SINE***********************") m = SineModel(fixed={0: 1}) self.assertTrue(m.npchain == 2) self.assertTrue(m.npbase == 2) p = [-1.1, 0.5] stdModeltest(m, p, plot=plot)
def testFreeShapeModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******FREESHAPE********************") m = FreeShapeModel(5, pixperbin=1, xlo=-1, xhi=1.1) self.assertTrue(m.npbase == 5) p = numpy.asarray([1.2, 0.2, 1.0, 0.5, 0.3], dtype=float) stdModeltest(m, p, plot=plot)
def test1(self): x = numpy.linspace(0, 10, 101, dtype=float) x += 0.01 ## avoid awkward non-continuities print("****** FREESHAPE test 1 ********************") m = FreeShapeModel(10) self.assertTrue(m.npbase == 10) p = numpy.asarray([1.2, 0.2, 1.0, 0.5, 0.3, 1.2, 0.2, 1.0, 0.5, 0.3]) stdModeltest(m, p, x=x, plot=self.doplot)
def testPolynomialModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******POLYNOMIAL**********************") m = PolynomialModel(3) self.assertTrue(m.getNumberOfParameters() == 4) self.assertTrue(m.npbase == 4) p = numpy.asarray([1, -2, 3, -2], dtype=float) stdModeltest(m, p, plot=plot)
def testPadeModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******PADE**********************") m = PadeModel(3, 2) self.assertTrue(m.getNumberOfParameters() == 6) self.assertTrue(m.npbase == 6) p = numpy.asarray([1, -2, 3, -2, 0.3, 1], dtype=float) stdModeltest(m, p, plot=plot)
def testPowerModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******POWER**********************") m = PowerModel(3, fixed={0: 1.2}) self.assertTrue(m.getNumberOfParameters() == 0) self.assertTrue(m.npbase == 0) p = [] stdModeltest(m, p, plot=plot)
def testSincModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******SINC***********************") m = SincModel(fixed={2: 0.1, 1: 2}) self.assertTrue(m.npchain == 1) self.assertTrue(m.npbase == 1) p = [2.3] stdModeltest(m, p, plot=plot)
def testEtalonModel2(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******ETALON 2***********************") fm = PolynomialModel(1) m = EtalonModel(fixed={0: 1.5, 1: fm}) p = numpy.asarray([2.0, 0.2, 1.0, 0.9], dtype=float) stdModeltest(m, p, plot=plot)
def testSineAmpModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******SINEAMP********************") m = SineAmpModel(1.3, fixed={1: 1}) self.assertTrue(m.npchain == 1) self.assertTrue(m.npbase == 1) p = [-1.1] stdModeltest(m, p, plot=plot)
def testSincModel(self, plot=False): x = numpy.asarray( [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) print("******SINC***********************") m = SincModel() self.assertTrue(m.npchain == 3) self.assertTrue(m.npbase == 3) p = [2.3, -1.1, 0.5] stdModeltest(m, p, plot=plot)