def testUpdate(self): """Update and change the profile to make sure generator is flushed.""" gen = self.gen prof = self.profile # Make sure attributes get updated with a change in the calculation # points. x = arange(0, 9, 0.1) prof.setCalculationPoints(x) self.assertTrue(gen._value is None) val = gen.value self.assertTrue(array_equal(x, prof.ycalc)) self.assertTrue(array_equal(prof.x, prof.ycalc)) self.assertTrue(array_equal(val, prof.ycalc)) self.assertTrue(array_equal(gen._value, prof.ycalc)) # Make sure attributes get updated with a new profile. x = arange(0, 8, 0.1) prof = Profile() prof.setCalculationPoints(x) gen.setProfile(prof) self.assertTrue(gen._value is None) val = gen.value self.assertTrue(array_equal(x, prof.ycalc)) self.assertTrue(array_equal(prof.x, prof.ycalc)) self.assertTrue(array_equal(val, prof.ycalc)) self.assertTrue(array_equal(gen._value, prof.ycalc)) return
def setUp(self): self.gen = ProfileGenerator("test") self.profile = Profile() x = arange(0, 10, 0.1) self.profile.setCalculationPoints(x) self.gen.setProfile(self.profile) return
def testUpdate(self): """Update and change the profile to make sure generator is flushed.""" gen = self.gen prof = self.profile # Make sure attributes get updated with a change in the calculation # points. x = arange(0, 9, 0.1) prof.setCalculationPoints(x) self.assertTrue(gen._value is None) val = gen.value self.assertTrue(array_equal(x, val)) # Verify generated value listens to changes in profile.x. x3 = x + 3 prof.x = x3 self.assertTrue(array_equal(x3, gen.value)) # Make sure attributes get updated with a new profile. x = arange(0, 8, 0.1) prof = Profile() prof.setCalculationPoints(x) gen.setProfile(prof) self.assertTrue(gen._value is None) self.assertTrue(array_equal(x, gen.value)) return
def testReplacements(self): """Test attribute integrity when objects get replaced.""" fc = self.fitcontribution xobs = arange(0, 10, 0.5) yobs = xobs profile = self.profile profile.setObservedProfile(xobs, yobs) xobs2 = arange(0, 10, 0.8) yobs2 = 0.5*xobs2 profile2 = Profile() profile2.setObservedProfile(xobs2, yobs2) gen = self.gen # Validate equations fc.setProfile(profile) fc.addProfileGenerator(gen, "I") self.assertTrue(array_equal(gen.value, xobs)) self.assertTrue(array_equal(fc._eq(), xobs)) self.assertAlmostEquals(0, sum(fc._reseq())) eq = fc._eq reseq = fc._reseq # Now set a different profile fc.setProfile(profile2) self.assertTrue(fc.profile is profile2) self.assertTrue(gen.profile is profile2) self.assertTrue(fc._eq is eq) self.assertTrue(fc._reseq is reseq) self.assertTrue(fc._eq._value is None) self.assertTrue(fc._reseq._value is None) # Validate equations self.assertTrue(array_equal(xobs2, gen.value)) self.assertTrue(array_equal(fc._eq(), gen.value)) return
def _create_recipe(self) -> md.MyRecipe: pgs = [] for name, structure in self._structures.items(): pg = md.PDFGenerator(name) pg.setStructure(structure, periodic=True) pgs.append(pg) fc = md.MyContribution(self.__class__.__name__) fc.setProfile(Profile()) for pg in pgs: fc.addProfileGenerator(pg) for name, sf in self._characteristics.items(): argnames = rename_args(sf, "{}_".format(name), fc.xname) fc.registerFunction(sf, name, argnames) fc.setEquation(self._equation) fr = md.MyRecipe() fr.clearFitHooks() fr.addContribution(fc) md.initialize(fr, **self._init_mode) return fr
def __init__(self, name="fit", conclass=FitContribution): """Initialization.""" FitRecipe.__init__(self, name) self.fithooks[0].verbose = 3 contribution = conclass("contribution") self.profile = Profile() contribution.setProfile(self.profile) self.addContribution(contribution) self.results = FitResults(self, update=False) # Adopt all the FitContribution methods public = [ aname for aname in dir(contribution) if aname not in dir(self) and not aname.startswith("_") ] for mname in public: method = getattr(contribution, mname) setattr(self, mname, method) return
def setUp(self): self.recipe = FitRecipe("recipe") self.recipe.fithooks[0].verbose = 0 # Set up the Profile self.profile = Profile() x = linspace(0, pi, 10) y = sin(x) self.profile.setObservedProfile(x, y) # Set up the FitContribution self.fitcontribution = FitContribution("cont") self.fitcontribution.setProfile(self.profile) self.fitcontribution.setEquation("A*sin(k*x + c)") self.fitcontribution.A.setValue(1) self.fitcontribution.k.setValue(1) self.fitcontribution.c.setValue(0) self.recipe.addContribution(self.fitcontribution) return
def setUp(self): self.gen = ProfileGenerator("test") self.profile = Profile() self.fitcontribution = FitContribution("test") return
def setUp(self): self.profile = Profile() return