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

Remove point selection from WPPF #719

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions hexrd/material/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,19 @@ def _set_sgnum(self, v):
self._newUnitcell()
self._hkls_changed()

@property
def sgsetting(self):
return self._sgsetting

@sgsetting.setter
def sgsetting(self, val):
if val in [0, 1]:
self._sgsetting = val
else:
msg = (f'space group setting must be either 0'
f' or 1.')
raise ValueError(msg)

sgnum = property(_get_sgnum, _set_sgnum, None, "Space group number")

@property
Expand Down
70 changes: 16 additions & 54 deletions hexrd/wppf/WPPF.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,14 @@ def initialize_bkg(self):

elif "spline" in self.bkgmethod.keys():
self._background = []
self.selectpoints()
for i, pts in enumerate(self.points):

points = self.bkgmethod["spline"]
if not points:
raise RuntimeError(
"Background points must be set to use spline"
)

for i, pts in enumerate(np.asarray(points)):
tth = self._spectrum_expt[i]._x
x = pts[:, 0]
y = pts[:, 1]
Expand Down Expand Up @@ -301,31 +307,6 @@ def chebyshevfit(self):
tth = self._tth_list[i]
self._background.append(Spectrum(x=tth, y=self.init_bkg(tth)))

def selectpoints(self):
"""
03/08/2021 SS spectrum_expt is a list now. accounting
for that change
"""
# Keep matplotlib as an optional dependency
# FIXME: move this function to where it is needed
from pylab import plot, ginput, close, title, xlabel, ylabel

self.points = []
for i, s in enumerate(self._spectrum_expt):
txt = (
f"Select points for background estimation\n"
f"click middle mouse button when done. segment # {i}"
)
title(txt)

plot(s.x, s.y, "-k")
xlabel(r"2$\theta$")
ylabel("intensity (a.u.)")

self.points.append(np.asarray(ginput(0, timeout=-1)))

close()

# cubic spline fit of background using custom points chosen from plot
def splinefit(self, x, y, tth):
"""
Expand Down Expand Up @@ -1751,8 +1732,14 @@ def initialize_bkg(self):

elif "spline" in self.bkgmethod.keys():
self._background = []
self.selectpoints()
for i, pts in enumerate(self.points):

points = self.bkgmethod["spline"]
if not points:
raise RuntimeError(
"Background points must be set to use spline"
)

for i, pts in enumerate(np.asarray(points)):
tth = self._spectrum_expt[i]._x
x = pts[:, 0]
y = pts[:, 1]
Expand Down Expand Up @@ -1842,31 +1829,6 @@ def chebyshevfit(self):
tth = self._tth_list[i]
self._background.append(Spectrum(x=tth, y=self.init_bkg(tth)))

def selectpoints(self):
"""
03/08/2021 SS spectrum_expt is a list now. accounting
for that change
"""

# Keep matplotlib as an optional dependency
from pylab import plot, ginput, close, title, xlabel, ylabel

self.points = []
for i, s in enumerate(self._spectrum_expt):
txt = (
f"Select points for background estimation\n"
f"click middle mouse button when done. segment # {i}"
)
title(txt)

plot(s.x, s.y, "-k")
xlabel(r"2$\theta$")
ylabel("intensity (a.u.)")

self.points.append(np.asarray(ginput(0, timeout=-1)))

close()

# cubic spline fit of background using custom points chosen from plot
def splinefit(self, x, y, tth):
"""
Expand Down
4 changes: 4 additions & 0 deletions hexrd/wppf/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def max(self):
def max(self, maxval):
self._max = maxval

# Make "lb" and "ub" references to the min/max properties
lb = min
ub = max

@property
def vary(self):
return self._vary
Expand Down
Loading