Skip to content

Commit

Permalink
Merge pull request #349 from jadball/master
Browse files Browse the repository at this point in the history
Various notebook quality-of-life changes, some TensorMap stuff
  • Loading branch information
jadball authored Nov 12, 2024
2 parents 83ad4d7 + 36ebde2 commit 8db3d8d
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 243 deletions.
2 changes: 2 additions & 0 deletions ImageD11/frelon_peaksearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ def process(ds, worker_args, ncpu=None):
"""
if ncpu is None:
nthreads = max(1, ImageD11.cImageD11.cores_available() - 1)
else:
nthreads = int(ncpu)
hname = ds.masterfile
scan_name = ds.scans[0]
frames_dset = scan_name + "/measurement/" + ds.detector
Expand Down
6 changes: 6 additions & 0 deletions ImageD11/nbGui/S3DXRD/pbp_1_indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ['OMP_NUM_THREADS'] = '1'\n",
"os.environ['OPENBLAS_NUM_THREADS'] = '1'\n",
"os.environ['MKL_NUM_THREADS'] = '1'\n",
"\n",
"exec(open('/data/id11/nanoscope/install_ImageD11_from_git.py').read())\n",
"PYTHONPATH = setup_ImageD11_from_git( ) # ( os.path.join( os.environ['HOME'],'Code'), 'ImageD11_git' )"
]
Expand Down
15 changes: 11 additions & 4 deletions ImageD11/nbGui/S3DXRD/run_astra_recon.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
def main(h5name, dsfile, group_name):
print('Loading dataset')
# load the dataset
ds = ImageD11.sinograms.dataset.load(dsfile)


print('Loading grain sinograms from disk')
grainsinos = read_h5(h5name, ds, group_name=group_name)

for gs in grainsinos:

print('Reconstructing grain sinograms')
for inc, gs in enumerate(grainsinos):
gs.recon(method="astra", astra_method="EM_CUDA")
print('Reconstructed ' + inc+1 + '/' + len(grainsinos))

# mask recon after running
print('Masking reconstructions')
for gs in grainsinos:
gs.recons['astra'] = np.where(gs.recon_mask, gs.recons['astra'], 0)


print('Reconstructions finished')
print('Writing grains to disk')
write_h5(h5name, grainsinos, overwrite_grains=True, group_name=group_name)


Expand Down
10 changes: 5 additions & 5 deletions ImageD11/nbGui/S3DXRD/tomo_1_index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"\n",
"ucell.makerings(cf_4d.ds.max())\n",
"\n",
"fig, ax = plt.subplots(figsize=(16,9), layout='constrained')\n",
"fig, ax = plt.subplots(figsize=(10,5), layout='constrained')\n",
"\n",
"ax.scatter(cf_4d.ds, cf_4d.eta, s=1)\n",
"ax.plot( ucell.ringds, [0,]*len(ucell.ringds), '|', ms=90, c=\"red\")\n",
Expand Down Expand Up @@ -258,7 +258,7 @@
"source": [
"# now we can take a look at the intensities of the remaining peaks\n",
"\n",
"fig, ax = plt.subplots(figsize=(16, 9), constrained_layout=True)\n",
"fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True)\n",
"\n",
"ax.plot(cf_4d.ds, cf_4d.sum_intensity,',', label='cf_4d')\n",
"ax.plot(cf_strong.ds, cf_strong.sum_intensity,',', label='cf_strong')\n",
Expand Down Expand Up @@ -324,7 +324,7 @@
"source": [
"# let's plot the assigned peaks\n",
"\n",
"fig, ax = plt.subplots(layout='constrained', figsize=(16,9))\n",
"fig, ax = plt.subplots(layout='constrained', figsize=(10,5))\n",
"\n",
"# indexer.ra is the ring assignments\n",
"\n",
Expand Down Expand Up @@ -360,7 +360,7 @@
"# the sequence of minpks fractions the indexer will iterate through\n",
"fracs = [0.9, 0.7]\n",
"# the tolerance in g-vector angle\n",
"cosine_tol = np.cos(np.radians(90 - 0.25))\n",
"cosine_tol = np.cos(np.radians(90 - ds.ostep))\n",
"# the max number of UBIs we can find per pair of rings\n",
"max_grains = 1000\n",
"\n",
Expand Down Expand Up @@ -447,7 +447,7 @@
},
"outputs": [],
"source": [
"utils.plot_grain_sinograms(grains, cf_strong)"
"utils.plot_grain_sinograms(grains, cf_strong, min(len(grains), 25))"
]
},
{
Expand Down
33 changes: 32 additions & 1 deletion ImageD11/nbGui/S3DXRD/tomo_2_map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ['OMP_NUM_THREADS'] = '1'\n",
"os.environ['OPENBLAS_NUM_THREADS'] = '1'\n",
"os.environ['MKL_NUM_THREADS'] = '1'\n",
"\n",
"exec(open('/data/id11/nanoscope/install_ImageD11_from_git.py').read())\n",
"PYTHONPATH = setup_ImageD11_from_git( ) # ( os.path.join( os.environ['HOME'],'Code'), 'ImageD11_git' )"
]
Expand Down Expand Up @@ -110,7 +116,9 @@
"outputs": [],
"source": [
"# pick a phase\n",
"phase_str = 'Fe'"
"phase_str = 'Fe'\n",
"\n",
"ucell = ds.phases.unitcells[phase_str]"
]
},
{
Expand Down Expand Up @@ -178,6 +186,29 @@
"cf_strong.nrows"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# now we can take a look at the intensities of the remaining peaks\n",
"\n",
"fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True)\n",
"\n",
"ax.plot(cf_4d.ds, cf_4d.sum_intensity,',', label='cf_4d')\n",
"ax.plot(cf_strong.ds, cf_strong.sum_intensity,',', label='cf_strong')\n",
"ax.plot(ucell.ringds, [1e4,]*len(ucell.ringds), '|', ms=90, c=\"red\")\n",
"\n",
"ax.semilogy()\n",
"\n",
"ax.set_xlabel(\"Dstar\")\n",
"ax.set_ylabel(\"Intensity\")\n",
"ax.legend()\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
6 changes: 6 additions & 0 deletions ImageD11/nbGui/S3DXRD/tomo_2_map_minor_phase.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ['OMP_NUM_THREADS'] = '1'\n",
"os.environ['OPENBLAS_NUM_THREADS'] = '1'\n",
"os.environ['MKL_NUM_THREADS'] = '1'\n",
"\n",
"exec(open('/data/id11/nanoscope/install_ImageD11_from_git.py').read())\n",
"PYTHONPATH = setup_ImageD11_from_git( ) # ( os.path.join( os.environ['HOME'],'Code'), 'ImageD11_git' )"
]
Expand Down
129 changes: 56 additions & 73 deletions ImageD11/nbGui/TDXRD/2_3DXRD_index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
"# the sequence of minpks fractions the indexer will iterate through\n",
"fracs = [0.9, 0.75]\n",
"# the tolerance in g-vector angle\n",
"cosine_tol = np.cos(np.radians(90 - 0.25))\n",
"cosine_tol = np.cos(np.radians(90 - ds.ostep))\n",
"# the max number of UBIs we can find per pair of rings\n",
"max_grains = 1000\n",
"\n",
Expand Down Expand Up @@ -342,6 +342,8 @@
"metadata": {},
"outputs": [],
"source": [
"# inverse pole figure of grain orientations\n",
"\n",
"utils.plot_all_ipfs(grains)"
]
},
Expand Down Expand Up @@ -434,7 +436,12 @@
"source": [
"# re-import our refined grains from the makemap procedure\n",
"\n",
"grains2 = ImageD11.grain.read_grain_file(tmp_map_path)"
"grains2 = ImageD11.grain.read_grain_file(tmp_map_path)\n",
"\n",
"for g in grains2:\n",
" g.ref_unitcell = ucell\n",
"\n",
"utils.get_rgbs_for_grains(grains2)"
]
},
{
Expand All @@ -458,29 +465,9 @@
},
"outputs": [],
"source": [
"centre_plot = False\n",
"\n",
"fig = plt.figure(figsize=(12, 12))\n",
"ax = fig.add_subplot(projection='3d')\n",
"xx = [grain.translation[0] for grain in grains2]\n",
"yy = [grain.translation[1] for grain in grains2]\n",
"zz = [grain.translation[2] for grain in grains2]\n",
"# col = [utils.grain_to_rgb(grain) for grain in grains2] # IPF-Z colour instead\n",
"col = [float(grain.npks) for grain in grains2]\n",
"sizes = [0.01*(float(grain.intensity_info.split(\"mean = \")[1].split(\" , \")[0].replace(\"'\", \"\"))) for grain in grains2]\n",
"if centre_plot:\n",
" scatterplot = ax.scatter(xx-np.mean(xx), yy-np.mean(yy), zz, c=col, s=sizes)\n",
"else:\n",
" scatterplot = ax.scatter(xx, yy, zz, c=col, s=sizes)\n",
"ax.set_xlim(-200,200)\n",
"ax.set_ylim(-200,200)\n",
"ax.set_zlim(-200,200)\n",
"plt.colorbar(scatterplot)\n",
"ax.set_title(\"Grains coloured by n peaks\")\n",
"ax.set_xlabel(\"x\")\n",
"ax.set_ylabel(\"y\")\n",
"ax.set_zlabel(\"z\")\n",
"plt.show()"
"# 3D scatter plot of grain positions coloured by grain volume\n",
"\n",
"utils.plot_grain_positions(grains2, colour='npks', centre_plot=False, size_scaling=0.5)"
]
},
{
Expand Down Expand Up @@ -528,29 +515,9 @@
},
"outputs": [],
"source": [
"centre_plot = False\n",
"\n",
"fig = plt.figure(figsize=(12, 12))\n",
"ax = fig.add_subplot(projection='3d')\n",
"xx = [grain.translation[0] for grain in grains_filtered]\n",
"yy = [grain.translation[1] for grain in grains_filtered]\n",
"zz = [grain.translation[2] for grain in grains_filtered]\n",
"# col = [utils.grain_to_rgb(grain) for grain in grains_filtered] # IPF-Z colour instead\n",
"col = [float(grain.npks) for grain in grains_filtered]\n",
"sizes = [0.01*(float(grain.intensity_info.split(\"mean = \")[1].split(\" , \")[0].replace(\"'\", \"\"))) for grain in grains_filtered]\n",
"if centre_plot:\n",
" scatterplot = ax.scatter(xx-np.mean(xx), yy-np.mean(yy), zz, c=col, s=sizes)\n",
"else:\n",
" scatterplot = ax.scatter(xx, yy, zz, c=col, s=sizes)\n",
"ax.set_xlim(-200,200)\n",
"ax.set_ylim(-200,200)\n",
"ax.set_zlim(-200,200)\n",
"plt.colorbar(scatterplot)\n",
"ax.set_title(\"Grains coloured by n peaks\")\n",
"ax.set_xlabel(\"x\")\n",
"ax.set_ylabel(\"y\")\n",
"ax.set_zlabel(\"z\")\n",
"plt.show()"
"# 3D scatter plot of grain positions coloured by grain volume\n",
"\n",
"utils.plot_grain_positions(grains_filtered, colour='npks', centre_plot=False, size_scaling=0.5)"
]
},
{
Expand Down Expand Up @@ -584,6 +551,31 @@
"grains_filtered = ImageD11.grain.read_grain_file(map_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# compute IPF colours for grains\n",
"\n",
"for g in grains_filtered:\n",
" g.ref_unitcell = ucell\n",
"\n",
"utils.get_rgbs_for_grains(grains_filtered)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# inverse pole figure of grain orientations\n",
"\n",
"utils.plot_all_ipfs(grains_filtered)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -592,9 +584,20 @@
},
"outputs": [],
"source": [
"# save grain data\n",
"# 3D scatter plot of grain positions coloured by grain volume\n",
"\n",
"ds.save_grains_to_disk(grains_filtered, phase_name=phase_str)"
"utils.plot_grain_positions(grains_filtered, colour='npks', centre_plot=False, size_scaling=0.5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 3D scatter plot of grain positions coloured by inverse pole figure orientation\n",
"\n",
"utils.plot_grain_positions(grains_filtered, colour='z', centre_plot=False, size_scaling=0.5)"
]
},
{
Expand All @@ -605,29 +608,9 @@
},
"outputs": [],
"source": [
"centre_plot = False\n",
"\n",
"fig = plt.figure(figsize=(12, 12))\n",
"ax = fig.add_subplot(projection='3d')\n",
"xx = [grain.translation[0] for grain in grains_filtered]\n",
"yy = [grain.translation[1] for grain in grains_filtered]\n",
"zz = [grain.translation[2] for grain in grains_filtered]\n",
"# col = [utils.grain_to_rgb(grain) for grain in grains_filtered] # IPF-Z colour instead\n",
"col = [float(grain.npks) for grain in grains_filtered]\n",
"sizes = [0.01*(float(grain.intensity_info.split(\"mean = \")[1].split(\" , \")[0].replace(\"'\", \"\"))) for grain in grains_filtered]\n",
"if centre_plot:\n",
" scatterplot = ax.scatter(xx-np.mean(xx), yy-np.mean(yy), zz, c=col, s=sizes)\n",
"else:\n",
" scatterplot = ax.scatter(xx, yy, zz, c=col, s=sizes)\n",
"ax.set_xlim(-200,200)\n",
"ax.set_ylim(-200,200)\n",
"ax.set_zlim(-200,200)\n",
"plt.colorbar(scatterplot)\n",
"ax.set_title(\"Grains coloured by n peaks\")\n",
"ax.set_xlabel(\"x\")\n",
"ax.set_ylabel(\"y\")\n",
"ax.set_zlabel(\"z\")\n",
"plt.show()"
"# save grain data\n",
"\n",
"ds.save_grains_to_disk(grains_filtered, phase_name=phase_str)"
]
},
{
Expand Down
Loading

0 comments on commit 8db3d8d

Please sign in to comment.