diff --git a/docs/examples/coreshellnp.py b/docs/examples/coreshellnp.py index 5b8c6eb2..deef927f 100644 --- a/docs/examples/coreshellnp.py +++ b/docs/examples/coreshellnp.py @@ -66,8 +66,8 @@ def makeRecipe(stru1, stru2, datname): # The FitContribution # Add both generators and the profile to the FitContribution. contribution = FitContribution("cdszns") - contribution.addProfileGenerator(generator_cds) - contribution.addProfileGenerator(generator_zns) + contribution.add_profile_generator(generator_cds) + contribution.add_profile_generator(generator_zns) contribution.set_profile(profile, xname="r") # Set up the characteristic functions. We use a spherical CF for the core diff --git a/docs/examples/crystalpdf.py b/docs/examples/crystalpdf.py index 835eb977..c3f1122c 100644 --- a/docs/examples/crystalpdf.py +++ b/docs/examples/crystalpdf.py @@ -74,7 +74,7 @@ def makeRecipe(ciffile, datname): # Here we associate the Profile and ProfileGenerator, as has been done # before. contribution = FitContribution("nickel") - contribution.addProfileGenerator(generator) + contribution.add_profile_generator(generator) contribution.set_profile(profile, xname="r") # Make the FitRecipe and add the FitContribution. diff --git a/docs/examples/crystalpdfall.py b/docs/examples/crystalpdfall.py index 8926952a..365e6f34 100644 --- a/docs/examples/crystalpdfall.py +++ b/docs/examples/crystalpdfall.py @@ -47,7 +47,7 @@ def makeProfile(datafile): def makeContribution(name, generator, profile): """Make a FitContribution and add a generator and profile.""" contribution = FitContribution(name) - contribution.addProfileGenerator(generator) + contribution.add_profile_generator(generator) contribution.set_profile(profile, xname="r") return contribution @@ -93,7 +93,7 @@ def makeRecipe( xcontribution_sini = makeContribution( "xsini", xgenerator_sini_ni, xprofile_sini ) - xcontribution_sini.addProfileGenerator(xgenerator_sini_si) + xcontribution_sini.add_profile_generator(xgenerator_sini_si) xcontribution_sini.setEquation("scale * (xG_sini_ni + xG_sini_si)") # As explained in another example, we want to minimize using Rw^2. diff --git a/docs/examples/crystalpdfobjcryst.py b/docs/examples/crystalpdfobjcryst.py index d28af6a3..f7236bcc 100644 --- a/docs/examples/crystalpdfobjcryst.py +++ b/docs/examples/crystalpdfobjcryst.py @@ -62,7 +62,7 @@ def makeRecipe(ciffile, datname): # The FitContribution contribution = FitContribution("nickel") - contribution.addProfileGenerator(generator) + contribution.add_profile_generator(generator) contribution.set_profile(profile, xname="r") # Make the FitRecipe and add the FitContribution. diff --git a/docs/examples/crystalpdftwodata.py b/docs/examples/crystalpdftwodata.py index b13da27f..fda20258 100644 --- a/docs/examples/crystalpdftwodata.py +++ b/docs/examples/crystalpdftwodata.py @@ -84,11 +84,11 @@ def makeRecipe(ciffile, xdatname, ndatname): # The FitContributions # We associate the x-ray PDFGenerator and Profile in one FitContribution... xcontribution = FitContribution("xnickel") - xcontribution.addProfileGenerator(xgenerator) + xcontribution.add_profile_generator(xgenerator) xcontribution.set_profile(xprofile, xname="r") # and the neutron objects in another. ncontribution = FitContribution("nnickel") - ncontribution.addProfileGenerator(ngenerator) + ncontribution.add_profile_generator(ngenerator) ncontribution.set_profile(nprofile, xname="r") # This example is different than the previous ones in that we are composing diff --git a/docs/examples/crystalpdftwophase.py b/docs/examples/crystalpdftwophase.py index 95e659b7..a47ff46e 100644 --- a/docs/examples/crystalpdftwophase.py +++ b/docs/examples/crystalpdftwophase.py @@ -72,8 +72,8 @@ def makeRecipe(niciffile, siciffile, datname): # Add both generators to the FitContribution. Add the Profile. This will # send the metadata to the generators. contribution = FitContribution("nisi") - contribution.addProfileGenerator(generator_ni) - contribution.addProfileGenerator(generator_si) + contribution.add_profile_generator(generator_ni) + contribution.add_profile_generator(generator_si) contribution.set_profile(profile, xname="r") # Write the fitting equation. We want to sum the PDFs from each phase and diff --git a/docs/examples/ellipsoidsas.py b/docs/examples/ellipsoidsas.py index 5c0826ec..35d8abd7 100644 --- a/docs/examples/ellipsoidsas.py +++ b/docs/examples/ellipsoidsas.py @@ -57,7 +57,7 @@ def makeRecipe(datname): # Here we associate the Profile and ProfileGenerator, as has been done # before. contribution = FitContribution("ellipsoid") - contribution.addProfileGenerator(generator) + contribution.add_profile_generator(generator) contribution.set_profile(profile, xname="q") # We want to fit the log of the signal to the log of the data so that the diff --git a/docs/examples/gaussiangenerator.py b/docs/examples/gaussiangenerator.py index f806e4a2..4f24b73c 100644 --- a/docs/examples/gaussiangenerator.py +++ b/docs/examples/gaussiangenerator.py @@ -144,7 +144,7 @@ def makeRecipe(): # attribute of the FitContribution by its name ("g"). Note that this will # set the fitting equation to "g", which calls the GaussianGenerator. contribution = FitContribution("g1") - contribution.addProfileGenerator(generator) + contribution.add_profile_generator(generator) contribution.set_profile(profile) # The FitRecipe diff --git a/docs/examples/npintensity.py b/docs/examples/npintensity.py index c193922e..5793d318 100644 --- a/docs/examples/npintensity.py +++ b/docs/examples/npintensity.py @@ -203,7 +203,7 @@ def makeRecipe(strufile, datname): # the FitContribution to name the x-variable of the profile "q", so we can # use it in equations with this name. contribution = FitContribution("bucky") - contribution.addProfileGenerator(generator) + contribution.add_profile_generator(generator) contribution.set_profile(profile, xname="q") # Now we're ready to define the fitting equation for the FitContribution. diff --git a/docs/examples/npintensityII.py b/docs/examples/npintensityII.py index 552eba96..44716cab 100644 --- a/docs/examples/npintensityII.py +++ b/docs/examples/npintensityII.py @@ -88,10 +88,10 @@ def makeRecipe(strufile, datname1, datname2): # The FitContributions # Create the FitContributions. contribution1 = FitContribution("bucky1") - contribution1.addProfileGenerator(generator1) + contribution1.add_profile_generator(generator1) contribution1.set_profile(profile1, xname="q") contribution2 = FitContribution("bucky2") - contribution2.addProfileGenerator(generator2) + contribution2.add_profile_generator(generator2) contribution2.set_profile(profile2, xname="q") # Now we're ready to define the fitting equation for each FitContribution. diff --git a/docs/examples/nppdfcrystal.py b/docs/examples/nppdfcrystal.py index 49ed32e6..fdaa3a8f 100644 --- a/docs/examples/nppdfcrystal.py +++ b/docs/examples/nppdfcrystal.py @@ -54,7 +54,7 @@ def makeRecipe(ciffile, grdata): pdfgenerator.setQmax(30.0) stru = loadCrystal(ciffile) pdfgenerator.setStructure(stru) - pdfcontribution.addProfileGenerator(pdfgenerator) + pdfcontribution.add_profile_generator(pdfgenerator) # Register the nanoparticle shape factor. from diffpy.srfit.pdf.characteristicfunctions import sphericalCF diff --git a/docs/examples/nppdfobjcryst.py b/docs/examples/nppdfobjcryst.py index 70c0bf83..25a9444d 100644 --- a/docs/examples/nppdfobjcryst.py +++ b/docs/examples/nppdfobjcryst.py @@ -52,7 +52,7 @@ def makeRecipe(molecule, datname): # The FitContribution contribution = FitContribution("bucky") - contribution.addProfileGenerator(generator) + contribution.add_profile_generator(generator) contribution.set_profile(profile, xname="r") # Make a FitRecipe. diff --git a/docs/examples/nppdfsas.py b/docs/examples/nppdfsas.py index 665e2377..08619722 100644 --- a/docs/examples/nppdfsas.py +++ b/docs/examples/nppdfsas.py @@ -58,7 +58,7 @@ def makeRecipe(ciffile, grdata, iqdata): pdfgenerator.setQmax(30.0) stru = loadCrystal(ciffile) pdfgenerator.setStructure(stru) - pdfcontribution.addProfileGenerator(pdfgenerator) + pdfcontribution.add_profile_generator(pdfgenerator) pdfcontribution.setResidualEquation("resv") # Create a SAS contribution as well. We assume the nanoparticle is roughly @@ -77,7 +77,7 @@ def makeRecipe(ciffile, grdata, iqdata): model = EllipsoidModel() sasgenerator = SASGenerator("generator", model) - sascontribution.addProfileGenerator(sasgenerator) + sascontribution.add_profile_generator(sasgenerator) sascontribution.setResidualEquation("resv") # Now we set up a characteristic function calculator that depends on the diff --git a/news/addprofilegenerator-dep.rst b/news/addprofilegenerator-dep.rst new file mode 100644 index 00000000..3a281ff7 --- /dev/null +++ b/news/addprofilegenerator-dep.rst @@ -0,0 +1,23 @@ +**Added:** + +* Added ``add_profile_generator`` to replace deprecated function. + +**Changed:** + +* + +**Deprecated:** + +* Deprecated ``addProfileGenerator`` for removal in 4.0.0. + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/srfit/fitbase/fitcontribution.py b/src/diffpy/srfit/fitbase/fitcontribution.py index 71048092..bbb23fb3 100644 --- a/src/diffpy/srfit/fitbase/fitcontribution.py +++ b/src/diffpy/srfit/fitbase/fitcontribution.py @@ -41,6 +41,13 @@ removal_version, ) +addprofilegenerator_dep_msg = build_deprecation_message( + base, + "addProfileGenerator", + "add_profile_generator", + removal_version, +) + class FitContribution(ParameterSet): """FitContribution class. @@ -179,7 +186,7 @@ def setProfile(self, profile, xname=None, yname=None, dyname=None): profile, xname=xname, yname=yname, dyname=dyname ) - def addProfileGenerator(self, gen, name=None): + def add_profile_generator(self, gen, name=None): """Add a ProfileGenerator to be used by this FitContribution. The ProfileGenerator is given a name so that it can be used as part of @@ -223,6 +230,18 @@ def addProfileGenerator(self, gen, name=None): return + @deprecated(addprofilegenerator_dep_msg) + def addProfileGenerator(self, gen, name=None): + """This function has been deprecated and will be removed in version + 4.0.0. + + Please use + diffpy.srfit.fitbase.FitContribution.add_profile_generator + instead. + """ + self.add_profile_generator(gen, name=name) + return + def setEquation(self, eqstr, ns={}): """Set the profile equation for the FitContribution. diff --git a/src/diffpy/srfit/pdf/pdfcontribution.py b/src/diffpy/srfit/pdf/pdfcontribution.py index bcd694ff..4809676c 100644 --- a/src/diffpy/srfit/pdf/pdfcontribution.py +++ b/src/diffpy/srfit/pdf/pdfcontribution.py @@ -273,7 +273,7 @@ def _setup_generator(self, gen): with setStructure or setPhase. """ # Add the generator to this FitContribution - self.addProfileGenerator(gen) + self.add_profile_generator(gen) # Set the proper equation for the fit, depending on the number of # phases we have. diff --git a/tests/test_contribution.py b/tests/test_contribution.py index 1332de33..37eae01b 100644 --- a/tests/test_contribution.py +++ b/tests/test_contribution.py @@ -67,6 +67,18 @@ def testAddProfileGenerator(self): self.assertTrue(fc._eq is not None) return + def test_add_profile_generator(self): + fc = self.fitcontribution + gen = self.gen + fc.add_profile_generator(gen, "gen") + + xobs = arange(0, 10, 0.5) + self.assertTrue(array_equal(xobs, gen(xobs))) + + self.assertTrue(gen.profile is None) + self.assertTrue(fc._eq is not None) + return + def testInteraction(self): """Test the interaction between the profile and profile generator.""" fc = self.fitcontribution @@ -75,7 +87,7 @@ def testInteraction(self): # Add the calculator and profile fc.set_profile(profile) - fc.addProfileGenerator(gen, "I") + fc.add_profile_generator(gen, "I") # Check attributes are created self.assertTrue(fc.profile is profile) @@ -120,7 +132,7 @@ def testReplacements(self): # Validate equations fc.set_profile(profile) - fc.addProfileGenerator(gen, "I") + fc.add_profile_generator(gen, "I") self.assertTrue(array_equal(gen.value, xobs)) self.assertTrue(array_equal(fc._eq(), xobs)) self.assertAlmostEqual(0, sum(fc._reseq())) @@ -196,7 +208,7 @@ def testResidual(noObserversInGlobalBuilders): # Add the calculator and profile fc.set_profile(profile) assert fc.profile is profile - fc.addProfileGenerator(gen, "I") + fc.add_profile_generator(gen, "I") assert fc._eq._value is None assert fc._reseq._value is None assert 1 == len(fc._generators)