Skip to content

Commit

Permalink
Merge pull request #367 from jadball/master
Browse files Browse the repository at this point in the history
Minor notebook bugfixes, tiny changes to refinement manager logic
  • Loading branch information
jonwright authored Dec 14, 2024
2 parents 7a72fc6 + a0908cb commit d03c18a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
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

0 comments on commit d03c18a

Please sign in to comment.