Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jadball committed Jan 25, 2025
1 parent 2725757 commit 69d5e52
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ImageD11/nbGui/S3DXRD/tomo_3_refinement.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
" pmap = tensor_map.to_pbpmap(z_layer=0, default_npks=default_npks, default_nuniq=default_nuniq)\n",
" pmap.choose_best(1)\n",
"\n",
" refine = PBPRefine(dset=ds, y0=y0, hkl_tol_origins=hkl_tol_origins, hkl_tol_refine=hkl_tol_refine, hkl_tol_refine_merged=hkl_tol_refine_merged, ds_tol=ds_tol, ifrac=ifrac, phase_name=minor_phase_str, forref=rings_to_refine)\n",
" refine = PBPRefine(dset=ds, y0=y0, hkl_tol_origins=hkl_tol_origins, hkl_tol_refine=hkl_tol_refine, hkl_tol_refine_merged=hkl_tol_refine_merged, ds_tol=ds_tol, ifrac=ifrac, phase_name=phase_str, forref=rings_to_refine)\n",
" \n",
" refine.own_filename = os.path.splitext(refine.own_filename)[0] + f'_{phase_str}.h5'\n",
" refine.icolf_filename = os.path.splitext(refine.icolf_filename)[0] + f'_{phase_str}.h5'\n",
Expand Down
13 changes: 9 additions & 4 deletions ImageD11/sinograms/point_by_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,10 +1592,18 @@ def refine_map(refine_points, all_pbpmap_ubis, ri_col, rj_col, sx_grid, sy_grid,

if grain_npks > min_grain_npks:
w, ubifit, residuals, rank, sing_vals = weighted_lstsq_ubi_fit(grain_ydist, gve_grain, hkl)

problem_fitting = False
try:
# get U from UBI without using ImageD11 grain class
ucell = ubi_to_unitcell(ubifit)
U = ubi_and_ucell_to_u(ubifit, ucell)
except:
problem_fitting = True

# check the quality of the fit
worth_fitting = (ubifit is not None) and (rank == 3) and (np.linalg.cond(ubifit) < 1e14) and (
np.linalg.det(ubifit) > 0) and (np.linalg.matrix_rank(ubifit) == 3)
np.linalg.det(ubifit) > 0) and (np.linalg.matrix_rank(ubifit) == 3) and (not np.any(np.isnan(U))) and (not problem_fitting)

# do we like the quality?
if worth_fitting:
Expand Down Expand Up @@ -1631,9 +1639,6 @@ def refine_map(refine_points, all_pbpmap_ubis, ri_col, rj_col, sx_grid, sy_grid,
hkl = hkli[:, grain_peak_mask]
ydist = ydist_grain[grain_peak_mask]

# get U from UBI without using ImageD11 grain class
ucell = ubi_to_unitcell(ubifit)
U = ubi_and_ucell_to_u(ubi_out, ucell)
gve0 = U.dot(B0).dot(hkl.astype(np.float64))
gTg0 = np.sum(gve_grain_strainfit * gve0, axis=0)
gTg = np.sum(gve_grain_strainfit * gve_grain_strainfit, axis=0)
Expand Down
6 changes: 3 additions & 3 deletions test/papermill_test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def noteboook_exec_pmill(nb_input_path, nb_output_path, params_dict):
print('Executing notebook', nb_input_path)
# change output path if it already exists, in case we run the same notebook twice
if os.path.exists(nb_output_path):
nb_output_path.replace('.ipynb', '_2.ipynb')
nb_output_path = nb_output_path.replace('.ipynb', '_2.ipynb')
papermill.execute_notebook(
nb_input_path,
nb_output_path,
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_FeAu_JADB_pbp():
{'PYTHONPATH': sys.path[0], # pbp_2_visualise.ipynb - minor phase
'dset_file': dset_file,
'phase_str': 'Au',
'min_unique': 5,
'min_unique': 10,
'dset_prefix': "top_",
},
{'PYTHONPATH': sys.path[0], # pbp_3_refinement.ipynb - major phase
Expand All @@ -452,7 +452,7 @@ def test_FeAu_JADB_pbp():
{'PYTHONPATH': sys.path[0], # pbp_3_refinement.ipynb - minor phase
'dset_file': dset_file,
'phase_str': 'Au',
'min_unique': 5,
'min_unique': 10,
'manual_threshold': None,
'y0': -16.0,
'hkl_tol_origins': 0.05,
Expand Down

0 comments on commit 69d5e52

Please sign in to comment.