Skip to content

Commit

Permalink
Merge pull request #317 from jadball/master
Browse files Browse the repository at this point in the history
Box-beam and PBP scanning notebook overhauls
  • Loading branch information
jonwright authored Aug 1, 2024
2 parents 4f0b214 + 6f3d38f commit 30bd958
Show file tree
Hide file tree
Showing 15 changed files with 2,729 additions and 880 deletions.
286 changes: 74 additions & 212 deletions ImageD11/nbGui/3DXRD/0_3DXRD_segment_frelon.ipynb

Large diffs are not rendered by default.

151 changes: 53 additions & 98 deletions ImageD11/nbGui/3DXRD/1_3DXRD_refine_parameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
"source": [
"This notebook will help you to refine the experimental parameters (such as sample to detector distance etc).\n",
"\n",
"We do this by indexing a Z slice of a sample, refining the positions of the grains we find, then refining the parameters using the grain diffraction data\n",
"\n",
"This notebook has already been run to generate Fe_refined.par\n",
"\n",
"There's no need to run it again :)"
"We do this by indexing a Z slice of a sample, refining the positions of the grains we find, then refining the parameters using the grain diffraction data"
]
},
{
Expand All @@ -32,20 +28,8 @@
},
"outputs": [],
"source": [
"# USER: Change the path below to point to your local copy of ImageD11:\n",
"\n",
"import os\n",
"\n",
"home_dir = !echo $HOME\n",
"home_dir = str(home_dir[0])\n",
"\n",
"# USER: You can change this location if you want\n",
"\n",
"id11_code_path = os.path.join(home_dir, \"Code/ImageD11\")\n",
"\n",
"import sys\n",
"\n",
"sys.path.insert(0, id11_code_path)"
"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 @@ -79,41 +63,6 @@
"from ImageD11.peakselect import select_ring_peaks_by_intensity"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# NOTE: For old datasets before the new directory layout structure, we don't distinguish between RAW_DATA and PROCESSED_DATA\n",
"\n",
"### USER: specify your experimental directory\n",
"\n",
"rawdata_path = \"/data/visitor/ihma439/id11/20231211/RAW_DATA\"\n",
"\n",
"!ls -lrt {rawdata_path}\n",
"\n",
"### USER: specify where you want your processed data to go\n",
"\n",
"processed_data_root_dir = \"/data/visitor/ihma439/id11/20231211/PROCESSED_DATA/James/nb_testing\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# USER: pick a sample and a dataset you want to segment\n",
"\n",
"sample = \"FeAu_0p5_tR\"\n",
"dataset = \"ff1\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -124,7 +73,7 @@
"source": [
"# desination of H5 files\n",
"\n",
"dset_path = os.path.join(processed_data_root_dir, sample, f\"{sample}_{dataset}\", f\"{sample}_{dataset}_dataset.h5\")"
"dset_path = '/data/visitor/ihma439/id11/20231211/PROCESSED_DATA/James/20240724/FeAu_0p5_tR/FeAu_0p5_tR_ff1/FeAu_0p5_tR_ff1_dataset.h5'"
]
},
{
Expand Down Expand Up @@ -163,6 +112,20 @@
" cf_3d.addcolumn(np.arange(cf_3d.nrows), \"index\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# now we can define a unit cell from our parameters\n",
"\n",
"ucell = ImageD11.unitcell.unitcell_from_parameters(cf_3d.parameters)\n",
"ucell.makerings(cf_3d.ds.max())"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -199,9 +162,9 @@
"# this indicates the fractional intensity cutoff we will select\n",
"# if the blue line does not look elbow-shaped in the logscale plot, try changing the \"doplot\" parameter (the y scale of the logscale plot) until it does\n",
"\n",
"cf_strong = select_ring_peaks_by_intensity(cf_3d, frac=0.985, dsmax=1.04, doplot=0.8, dstol=0.01)\n",
"cf_strong = select_ring_peaks_by_intensity(cf_3d, frac=0.9850, dsmax=1.01, doplot=0.8, dstol=0.01)\n",
"print(f\"Got {cf_strong.nrows} strong peaks for indexing\")\n",
"cf_strong.writefile(f'{sample}_{dataset}_3d_peaks_strong.flt')"
"cf_strong.writefile(f'{ds.sample}_{ds.dsname}_3d_peaks_strong.flt')"
]
},
{
Expand All @@ -215,9 +178,9 @@
"# we will also export some additional strong peaks across all rings\n",
"# this will be useful for grain refinement later (using makemap)\n",
"\n",
"cf_strong_allrings = select_ring_peaks_by_intensity(cf_3d, frac=0.95, dsmax=cf_3d.ds.max(), doplot=0.05, dstol=0.01)\n",
"cf_strong_allrings = select_ring_peaks_by_intensity(cf_3d, frac=0.9855, dsmax=cf_3d.ds.max(), doplot=0.05, dstol=0.01)\n",
"print(f\"Got {cf_strong_allrings.nrows} strong peaks for makemap\")\n",
"cf_strong_allrings_path = f'{sample}_{dataset}_3d_peaks_strong_all_rings.flt'\n",
"cf_strong_allrings_path = f'{ds.sample}_{ds.dsname}_3d_peaks_strong_all_rings.flt'\n",
"cf_strong_allrings.writefile(cf_strong_allrings_path)"
]
},
Expand All @@ -231,48 +194,17 @@
"source": [
"# now we can take a look at the intensities of the remaining peaks\n",
"\n",
"fig, ax = plt.subplots()\n",
"fig, ax = plt.subplots(figsize=(16, 9), constrained_layout=True)\n",
"\n",
"ax.plot(cf_strong.ds, cf_strong.sum_intensity,',')\n",
"ax.plot( ucell.ringds, [1e4,]*len(ucell.ringds), '|', ms=90, c=\"red\")\n",
"\n",
"ax.plot(cf_3d.ds, cf_3d.sum_intensity,',', label='cf_3d')\n",
"ax.plot(cf_strong.ds, cf_strong.sum_intensity,',', label='cf_strong')\n",
"ax.semilogy()\n",
"\n",
"ax.set_xlabel(\"D-star\")\n",
"ax.set_xlabel(\"Dstar\")\n",
"ax.set_ylabel(\"Intensity\")\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# now we can define a unit cell from our parameters\n",
"\n",
"Fe = ImageD11.unitcell.unitcell_from_parameters(cf_strong.parameters)\n",
"Fe.makerings(cf_strong.ds.max())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# now let's plot our peaks again, with the rings from the unitcell included, to check our lattice parameters are good\n",
"\n",
"fig, ax = plt.subplots()\n",
"\n",
"skip=1\n",
"ax.scatter( cf_strong.ds[::skip], cf_strong.eta[::skip], s=0.5)\n",
"ax.plot( Fe.ringds, [0,]*len(Fe.ringds), '|', ms=90, c='orange')\n",
"ax.set_xlabel('1 / d ($\\AA$)')\n",
"ax.set_ylabel('$\\\\eta$ (deg)')\n",
"ax.legend()\n",
"\n",
"plt.show()"
]
Expand Down Expand Up @@ -321,8 +253,10 @@
"# indexer.ra is the ring assignments\n",
"\n",
"ax.scatter(cf_strong.ds, cf_strong.eta, c=indexer.ra, cmap='tab20', s=1)\n",
"ax.plot( ucell.ringds, [0,]*len(ucell.ringds), '|', ms=90, c=\"red\")\n",
"ax.set_xlabel(\"d-star\")\n",
"ax.set_ylabel(\"eta\")\n",
"ax.set_xlim(cf_strong.ds.min()-0.05, cf_strong.ds.max()+0.05)\n",
"\n",
"plt.show()"
]
Expand Down Expand Up @@ -389,6 +323,9 @@
},
"outputs": [],
"source": [
"sample = ds.sample\n",
"dataset = ds.dsname\n",
"\n",
"tmp_ubi_path = f'{sample}_{dataset}_grains.ubi'\n",
"tmp_map_path = f'{sample}_{dataset}_grains.map'\n",
"\n",
Expand Down Expand Up @@ -464,6 +401,17 @@
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"np.array([np.mean(g.unitcell[0:3]) for g in grains_refined_positions]).mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -504,7 +452,7 @@
},
"outputs": [],
"source": [
"refined_parfile = 'Fe_refined.par'"
"refined_parfile = ds.parfile"
]
},
{
Expand Down Expand Up @@ -544,6 +492,13 @@
"source": [
"# refined parameter file has now been created!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 30bd958

Please sign in to comment.