Skip to content

Commit 896f3a4

Browse files
committed
Fix issues with multiple texture models
This fixes a few issues with multiple texture models. Now, you can have some materials with texture modeling and some without texture modeling. You also no longer have to refine harmonic coefficients for all texture models (you can disable some). This also sanitizes the material name so that materials may contain a `-` in them without causing errors in lmfit. Signed-off-by: Patrick Avery <[email protected]>
1 parent adae415 commit 896f3a4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

hexrd/powder/wppf/WPPF.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ def computespectrum_2D(self):
20232023
simulated_2d = np.empty([nspec, x.shape[0]])
20242024
azimuth_texture_factor = {}
20252025
for iph, p in enumerate(self.phases):
2026-
if p in self.texture_model:
2026+
if self.texture_model.get(p) is not None:
20272027
self.texture_model[p].calc_pf_rings(
20282028
self.params,
20292029
eta_min=self.eta_min,
@@ -2112,15 +2112,20 @@ def Refine(self):
21122112
print("Nothing to refine...")
21132113

21142114
def RefineTexture(self):
2115+
final_result = None
21152116
for name, model in self.texture_model.items():
21162117
if model is None:
21172118
continue
21182119

21192120
print(f'Refining texture parameters for "{name}"')
21202121
results = model.calculate_harmonic_coefficients(self.params)
2122+
if results is None:
2123+
print(f'No "{name}" parameters marked as "vary". Skipping...')
2124+
2125+
final_result = results if results is not None else final_result
21212126

21222127
# Set the results to the final one
2123-
self.res = results
2128+
self.res = final_result
21242129

21252130
self.computespectrum()
21262131
self.niter += 1
@@ -2156,7 +2161,7 @@ def any_texture_params_varied(self):
21562161
@property
21572162
def texture_models_have_pfdata(self):
21582163
for model in self.texture_model.values():
2159-
if not model.pfdata:
2164+
if model is not None and not model.pfdata:
21602165
return False
21612166

21622167
return True
@@ -2419,6 +2424,9 @@ def compute_texture_data(
24192424
if model is None:
24202425
continue
24212426

2427+
# Sanitize the name
2428+
mat_key = mat_key.replace('-', '_')
2429+
24222430
pfdata = {}
24232431
for ii, nnz in enumerate(results[3]):
24242432
eta = self.eta_min + (nnz + 1) * np.radians(azimuthal_interval)

hexrd/powder/wppf/texture.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,10 @@ def calculate_harmonic_coefficients(self, params, hkls=None):
15541554
for name in self.parameter_names:
15551555
harmonic_params[name] = copy.deepcopy(params[name])
15561556

1557+
if not any(param.vary for param in harmonic_params.values()):
1558+
# No parameters are marked as vary. Return early.
1559+
return None
1560+
15571561
self.sph_c = {}
15581562
self.sph_s = {}
15591563

0 commit comments

Comments
 (0)