Skip to content

Commit

Permalink
Grain scatterplot function in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jadball committed Nov 12, 2024
1 parent 532fbca commit 744b354
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 220 deletions.
127 changes: 55 additions & 72 deletions ImageD11/nbGui/TDXRD/2_3DXRD_index.ipynb
Original file line number Diff line number Diff line change
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
48 changes: 6 additions & 42 deletions ImageD11/nbGui/TDXRD/2_3DXRD_index_friedel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -567,27 +567,9 @@
},
"outputs": [],
"source": [
"centre_plot = False\n",
"\n",
"fig = plt.figure(figsize=(12, 12))\n",
"ax = fig.add_subplot(projection='3d', proj_type=\"ortho\")\n",
"xx = [grain.translation[0] for grain in fittedgrains]\n",
"yy = [grain.translation[1] for grain in fittedgrains]\n",
"zz = [grain.translation[2] for grain in fittedgrains]\n",
"# col = [utils.grain_to_rgb(grain) for grain in grains_filtered] # IPF-Z colour instead\n",
"col = [float(grain.npks) for grain in fittedgrains]\n",
"sizes = [0.01*(float(grain.intensity_info.split(\"mean = \")[1].split(\" , \")[0].replace(\"'\", \"\"))) for grain in fittedgrains]\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_aspect(\"equal\")\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(fittedgrains, colour='npks', centre_plot=False, size_scaling=0.5)"
]
},
{
Expand Down Expand Up @@ -636,27 +618,9 @@
},
"outputs": [],
"source": [
"centre_plot = False\n",
"\n",
"fig = plt.figure(figsize=(12, 12))\n",
"ax = fig.add_subplot(projection='3d', proj_type=\"ortho\")\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_aspect(\"equal\")\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
Loading

0 comments on commit 744b354

Please sign in to comment.