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

Minor notebook bugfixes, tiny changes to refinement manager logic #367

Merged
merged 4 commits into from
Dec 14, 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
4 changes: 2 additions & 2 deletions ImageD11/nbGui/S3DXRD/4_visualise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@
},
"outputs": [],
"source": [
"# look at unit cells\n",
"# look at unit cells - mean of a, b, c for cubic for now\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.hist(tmap.unitcell[0, :, :, :3].ravel(), bins=1000)\n",
"ax.hist(tmap.unitcell[0, :, :, :3].mean(axis=-1).ravel(), bins=1000)\n",
"ax.set_xlabel('unitcell of pixel')\n",
"plt.show()"
]
Expand Down
5 changes: 5 additions & 0 deletions ImageD11/nbGui/S3DXRD/tomo_3_refinement_minor_phase.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@
"\n",
" refine = PBPRefine(dset=ds, y0=y0, fpks=fpks, 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=forref)\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",
" refine.pbpmap_filename = os.path.splitext(refine.pbpmap_filename)[0] + f'_{phase_str}.h5'\n",
" refine.refinedmap_filename = os.path.splitext(refine.refinedmap_filename)[0] + f'_{phase_str}.h5'\n",
" \n",
" refine.setmap(pmap)\n",
" refine.setpeaks(cf_2d)\n",
" refine.mask = pmap.best_npks > 0\n",
Expand Down
21 changes: 3 additions & 18 deletions ImageD11/nbGui/calibration/silicon_calib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"import ImageD11.columnfile\n",
"import ImageD11.indexing\n",
"import ImageD11.grain\n",
"import ImageD11.nbGui.fit_geometry"
"import ImageD11.nbGui.fit_geometry\n",
"import silx.io"
]
},
{
Expand Down Expand Up @@ -154,7 +155,7 @@
"source": [
"# guess the detector distance in um\n",
"# you can also manually specify\n",
"distance_guess = auto_guess_distance(ds.masterfile, ds.scans[-1]) # detector distance in um\n",
"distance_guess = auto_guess_distance(dset.masterfile, dset.scans[-1]) # detector distance in um\n",
"# distance_guess = 140000 # 140 mm"
]
},
Expand Down Expand Up @@ -220,22 +221,6 @@
"ui.fitGui()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"ui.valuewidgets['fit_tolerance'].value = 0.5\n",
"ui.fit(2,9)\n",
"ui.valuewidgets['fit_tolerance'].value = 0.05\n",
"ui.fit(3,21)\n",
"ui.fit(0,180)\n",
"ui.updateGui()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
12 changes: 8 additions & 4 deletions ImageD11/sinograms/point_by_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ def __init__(self,
ifrac=None,
forref=None,
y0=0.0,
min_grain_npks=6
):
self.dset = dset
self.phase_name = phase_name
Expand All @@ -647,6 +648,7 @@ def __init__(self,
# refinement parameters
self.hkl_tol_refine = hkl_tol_refine
self.hkl_tol_refine_merged = hkl_tol_refine_merged
self.min_grain_npks = min_grain_npks
# geometry stuff
self.ystep = self.dset.ystep
self.y0 = y0
Expand Down Expand Up @@ -961,7 +963,7 @@ def to_h5(self, filename=None, h5group='PBPRefine'):

# other pars we need for refinement
pars = ['phase_name', 'hkl_tol_origins', 'hkl_tol_refine', 'hkl_tol_refine_merged', 'fpks', 'ds_tol',
'etacut', 'ifrac', 'forref', 'y0']
'etacut', 'ifrac', 'forref', 'y0', 'min_grain_npks']

for par in pars:
try:
Expand All @@ -974,6 +976,7 @@ def to_h5(self, filename=None, h5group='PBPRefine'):
def from_h5(cls, filename, h5group='PBPRefine'):
# load the stuff in
# then make an object
manager_filename = filename

with h5py.File(filename, "r") as hin:
parent_group = hin[h5group]
Expand All @@ -997,7 +1000,7 @@ def from_h5(cls, filename, h5group='PBPRefine'):
continue

pars = ['phase_name', 'hkl_tol_origins', 'hkl_tol_refine', 'hkl_tol_refine_merged', 'fpks', 'ds_tol',
'etacut', 'ifrac', 'forref', 'y0']
'etacut', 'ifrac', 'forref', 'y0', 'min_grain_npks']
pars_dict = {}
for par in pars:
try:
Expand All @@ -1007,6 +1010,7 @@ def from_h5(cls, filename, h5group='PBPRefine'):
# load the dataset
dset = ImageD11.sinograms.dataset.load(dsfile)
refine_obj = cls(dset=dset, **pars_dict)
refine_obj.own_filename = manager_filename
for filename_attr, filename in filenames.items():
setattr(refine_obj, filename_attr, filename)
for array_attr, array in arrays.items():
Expand All @@ -1030,7 +1034,6 @@ def from_h5(cls, filename, h5group='PBPRefine'):
refine_obj.loadmap(refine_obj.refinedmap_filename, refined=True)
except (AttributeError, OSError):
pass

return refine_obj

def get_origins(self, guess_speed=True, guess_npks=10000, save_peaks_after=True):
Expand Down Expand Up @@ -1168,7 +1171,8 @@ def run_refine(self, points_step_space=None, npoints=None, output_filename=None,
pars['chi'],
pars['wavelength'],
tol=self.hkl_tol_refine,
merge_tol=self.hkl_tol_refine_merged
merge_tol=self.hkl_tol_refine_merged,
min_grain_npks=int(self.min_grain_npks)
)
# now we match how the indexer returns dodgy values
# mask nan 3x3 entires to identity matrix
Expand Down