Skip to content

loadParsedData of Profile class does not update Q_max #59

Open
@rjkoch

Description

@rjkoch

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions