Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadParsedData of Profile class does not update Q_max #59

Open
rjkoch opened this issue Oct 8, 2019 · 1 comment
Open

loadParsedData of Profile class does not update Q_max #59

rjkoch opened this issue Oct 8, 2019 · 1 comment

Comments

@rjkoch
Copy link

rjkoch commented Oct 8, 2019

test_1.txt
test_2.txt

If I call this code with the appropriate PDF data file containing qmax metadata

from diffpy.srfit.fitbase import FitContribution, FitRecipe, Profile
from diffpy.srfit.pdf import PDFParser, PDFGenerator
import numpy as np

profile = Profile()
parser = PDFParser()
parser.parseFile("test_1.txt")
profile.loadParsedData(parser)

generator = PDFGenerator("G1")

contribution = FitContribution("crystal")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="r")

recipe = FitRecipe()

recipe.addContribution(contribution)

and then call recipe.crystal.G1.getQmax() I get the correct qmax from the file metadata.

If I then however replace the profile data with

parser = PDFParser()

parser.parseFile("test_2.txt")

metadata = parser.getMetaData()

file_q_max = metadata['qmax']

recipe.crystal.profile.loadParsedData(parser)

new_q_max = recipe.crystal.G1.getQmax()

new_q_max will still contain the old qmax value, from the first file.

This will successfully change it:

parser = PDFParser()

parser.parseFile("test_2.txt")


metadata = parser.getMetaData()

file_q_max = metadata['qmax']

recipe.crystal.profile.loadParsedData(parser)

new_q_max = recipe.crystal.G1.getQmax()
    
recipe.crystal.G1.setQmax(file_q_max)

Is this the expected behavior? Should I be doing this a different way? Perhaps instantiating a new Profile and passing that to the recipe through recipe.crystal.setProfile?

Below is the full code for a working example. Data is attached

from diffpy.srfit.fitbase import FitContribution, FitRecipe, Profile
from diffpy.srfit.pdf import PDFParser, PDFGenerator
import numpy as np

def check_qmax(desired,actual):
    print(f"\nMetadata in new file suggests Q_max should be {desired}, q_max is now {actual}")
    if not np.isclose(actual,desired):
        print("\nThese are not equal\n")
    elif np.isclose(actual,desired):
        print("\nThese are equal\n")
    

profile = Profile()
parser = PDFParser()
parser.parseFile("test_1.txt")
profile.loadParsedData(parser)

generator = PDFGenerator("G1")

contribution = FitContribution("crystal")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="r")

recipe = FitRecipe()

recipe.addContribution(contribution)

old_q_max = recipe.crystal.G1.getQmax()


parser = PDFParser()

parser.parseFile("test_2.txt")


metadata = parser.getMetaData()

file_q_max = metadata['qmax']

recipe.crystal.profile.loadParsedData(parser)

new_q_max = recipe.crystal.G1.getQmax()

check_qmax(file_q_max,new_q_max)
    
recipe.crystal.G1.setQmax(file_q_max)

new_q_max = recipe.crystal.G1.getQmax()
check_qmax(file_q_max,new_q_max)
@rjkoch
Copy link
Author

rjkoch commented Oct 8, 2019

I can confirm that

            profile = Profile()
            parser = PDFParser()
            parser.parseFile("test_2.txt")
            profile.loadParsedData(parser)

            recipe.crystal.setProfile(profile)

will correctly change the qmax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant