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

Add access to the linear polarisation rate #38

Open
vincefn opened this issue May 11, 2023 · 2 comments
Open

Add access to the linear polarisation rate #38

vincefn opened this issue May 11, 2023 · 2 comments
Assignees

Comments

@vincefn
Copy link
Collaborator

vincefn commented May 11, 2023

@kif
The linear polarisation rate is not interfaced in python ; it would also be useful to add a parameter for an azimuthal angle, in case the pattern is not recorded in the plane perpendicular to the polarisation plane.
Both parameters (linear polarisation and azimuthal angle) should also be listed as RefinablePar.

See https://gsas-ii.readthedocs.io/en/latest/GSASIIpwd.html#GSASIIpwd.Polarization and
J.Appl.Cryst.(2020).53, 1559–1561

@vincefn vincefn self-assigned this May 11, 2023
@kif
Copy link

kif commented May 11, 2023

Here is a quick & dirty monkey patch:

import io
import xml.etree.ElementTree as et
from pyobjcryst.powderpattern import PowderPattern

def get_polarization(powder_pattern):
    with io.StringIO() as file:
        powder_pattern.XMLOutput(file, 2)
        file.seek(0)
        xml_root = et.fromstring(file.read())
    xml_pol = xml_root.find("Radiation").find("LinearPolarRate")
    return float(xml_pol.text)
PowderPattern.LinearPolarRate=get_polarization

@vincefn
Copy link
Collaborator Author

vincefn commented May 12, 2023

A much less dirty approach would be to use the Radiation object (accessible through powder_pattern.GetRadiation()) XML string - using XMLInput on the entire PowderPattern has plenty of side effects (re-creating the powder pattern components), whereas re-importing just the radiation object is almost inconsequential.

In fact, you can input a modified value for just the linear polarisation rate with a stripped-down XML string:

s = "<Radiation>  <LinearPolarRate>0.9</LinearPolarRate> </Radiation>"
r.XMLInput(s)

Note however that after changing the linear polarisation rate, you'll need to change another parameter (such as the wavelength) to trigger an actual re-calculation of the powder pattern (because of the cached calculations and the fact that the linear polarisation rate is not a RefinablePar and thus its change does not invalidate stored computed values IIRC)....

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

No branches or pull requests

2 participants