Skip to content

Commit

Permalink
Tomo route notebooks parameterized
Browse files Browse the repository at this point in the history
  • Loading branch information
jadball committed Jan 22, 2025
1 parent 5735b9c commit 6b65fc2
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 198 deletions.
62 changes: 40 additions & 22 deletions ImageD11/nbGui/S3DXRD/4_visualise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,41 @@
"\n",
"os.environ['OMP_NUM_THREADS'] = '1'\n",
"os.environ['OPENBLAS_NUM_THREADS'] = '1'\n",
"os.environ['MKL_NUM_THREADS'] = '1'\n",
"os.environ['MKL_NUM_THREADS'] = '1'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"exec(open('/data/id11/nanoscope/install_ImageD11_from_git.py').read())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"# this cell is tagged with 'parameters'\n",
"# to view the tag, select the cell, then find the settings gear icon (right or left sidebar) and look for Cell Tags\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' )"
"PYTHONPATH = setup_ImageD11_from_git( ) # ( os.path.join( os.environ['HOME'],'Code'), 'ImageD11_git' )\n",
"\n",
"# dataset file to import\n",
"dset_file = 'si_cube_test/processed/Si_cube/Si_cube_S3DXRD_nt_moves_dty/Si_cube_S3DXRD_nt_moves_dty_dataset.h5'\n",
"\n",
"# which phase to index\n",
"phase_str = 'Si'\n",
"\n",
"# the minimum number of peaks you want a pixel to have to be counted\n",
"min_unique = 400"
]
},
{
Expand Down Expand Up @@ -69,8 +100,6 @@
"source": [
"# USER: Pass path to dataset file\n",
"\n",
"dset_file = 'si_cube_test/processed/Si_cube/Si_cube_S3DXRD_nt_moves_dty/Si_cube_S3DXRD_nt_moves_dty_dataset.h5'\n",
"\n",
"ds = ImageD11.sinograms.dataset.load(dset_file)\n",
" \n",
"sample = ds.sample\n",
Expand Down Expand Up @@ -105,7 +134,6 @@
"outputs": [],
"source": [
"# now let's select a phase to index from our parameters json\n",
"phase_str = 'Fe'\n",
"\n",
"ref_ucell = ds.phases.unitcells[phase_str]\n",
"\n",
Expand Down Expand Up @@ -148,8 +176,6 @@
"source": [
"# choose the minimum number of peaks you want a pixel to have to be counted\n",
"\n",
"min_unique = 400\n",
"\n",
"refine.refinedmap.choose_best(min_unique)\n",
"\n",
"# refine.refinedmap.choose_best(min_unique)"
Expand Down Expand Up @@ -332,8 +358,10 @@
"source": [
"# save the refined TensorMap to disk\n",
"\n",
"tmap.to_h5(os.path.join(ds.analysispath, 'pbp_tensormap_refined.h5'))\n",
"tmap.to_paraview(os.path.join(ds.analysispath, 'pbp_tensormap_refined.h5'))"
"refined_tmap_path = os.path.join(ds.analysispath, f'{ds.sample}_{ds.dset}_refined_tmap.h5')\n",
"\n",
"tmap.to_h5(refined_tmap_path)\n",
"tmap.to_paraview(refined_tmap_path)"
]
},
{
Expand All @@ -346,9 +374,9 @@
"source": [
"# you can also do an MTEX export if you like:\n",
"\n",
"ctf_path = os.path.join(ds.analysispath, 'pbp_tensormap_refined.ctf')\n",
"refined_ctf_path = os.path.join(ds.analysispath, f'{ds.sample}_{ds.dset}_refined_tmap.ctf')\n",
"\n",
"tmap.to_ctf_mtex(ctf_path, z_index=0)"
"tmap.to_ctf_mtex(refined_ctf_path, z_index=0)"
]
},
{
Expand All @@ -362,16 +390,6 @@
"ds.save()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if 1:\n",
" raise ValueError(\"Change the 1 above to 0 to allow 'Run all cells' in the notebook\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
25 changes: 19 additions & 6 deletions ImageD11/nbGui/S3DXRD/import_test_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,27 @@
{
"cell_type": "code",
"execution_count": null,
"id": "6c9f1867-2a3c-4b01-83d4-431a7177ebcc",
"id": "6f943f39-15ab-4bda-b0d9-38ed46f06b5a",
"metadata": {},
"outputs": [],
"source": [
"exec(open('/data/id11/nanoscope/install_ImageD11_from_git.py').read())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7630a0b8-d900-47ca-bb87-6f54df591887",
"metadata": {
"tags": []
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"exec(open('/data/id11/nanoscope/install_ImageD11_from_git.py').read())\n",
"# this cell is tagged with 'parameters'\n",
"# to view the tag, select the cell, then find the settings gear icon (right or left sidebar) and look for Cell Tags\n",
"download_dir = 'si_cube_test'\n",
"PYTHONPATH = setup_ImageD11_from_git( ) # ( os.path.join( os.environ['HOME'],'Code'), 'ImageD11_git' )"
]
},
Expand Down Expand Up @@ -82,8 +96,6 @@
"source": [
"# USER: change this as you like!\n",
"\n",
"download_dir = 'si_cube_test'\n",
"\n",
"if not os.path.exists(download_dir):\n",
" os.mkdir(download_dir)"
]
Expand Down Expand Up @@ -158,7 +170,8 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"toc-showcode": false
},
"nbformat": 4,
"nbformat_minor": 5
Expand Down
88 changes: 49 additions & 39 deletions ImageD11/nbGui/S3DXRD/tomo_1_index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,53 @@
},
"outputs": [],
"source": [
"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' )"
"exec(open('/data/id11/nanoscope/install_ImageD11_from_git.py').read())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"# this cell is tagged with 'parameters'\n",
"# to view the tag, select the cell, then find the settings gear icon (right or left sidebar) and look for Cell Tags\n",
"\n",
"# python environment stuff\n",
"PYTHONPATH = setup_ImageD11_from_git( ) # ( os.path.join( os.environ['HOME'],'Code'), 'ImageD11_git' )\n",
"\n",
"# dataset file to import\n",
"dset_file = 'si_cube_test/processed/Si_cube/Si_cube_S3DXRD_nt_moves_dty/Si_cube_S3DXRD_nt_moves_dty_dataset.h5'\n",
"\n",
"# which phase to index\n",
"phase_str = 'Si'\n",
"\n",
"# peak filtration parameters\n",
"cf_strong_frac = 0.9939\n",
"cf_strong_dsmax = 1.594\n",
"cf_strong_dstol = 0.005\n",
"\n",
"# indexing parameters\n",
"indexer_ds_tol = 0.01\n",
"# we have to choose which rings we want to generate orientations on\n",
"# generally we want two or three low-multiplicity rings that are isolated from other phases\n",
"# take a look at the ring assignment output from a few cells above, and choose two or three\n",
"rings_for_gen = [0, 1, 3]\n",
"# now we want to decide which rings to score our found orientations against\n",
"# generally we can just exclude dodgy rings (close to other phases, only a few peaks in etc)\n",
"rings_for_scoring = [0, 1, 2, 3, 4]\n",
"# the sequence of hkl tolerances the indexer will iterate through\n",
"hkl_tols_seq = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.075]\n",
"# the sequence of minpks fractions the indexer will iterate through\n",
"fracs = [0.9, 0.7]\n",
"# the max number of UBIs we can find per pair of rings\n",
"max_grains = 1000\n",
"\n",
"peak_assign_tol = 0.05"
]
},
{
Expand Down Expand Up @@ -67,8 +112,6 @@
"source": [
"# USER: Pass path to dataset file\n",
"\n",
"dset_file = 'si_cube_test/processed/Si_cube/Si_cube_S3DXRD_nt_moves_dty/Si_cube_S3DXRD_nt_moves_dty_dataset.h5'\n",
"\n",
"ds = ImageD11.sinograms.dataset.load(dset_file)\n",
" \n",
"sample = ds.sample\n",
Expand Down Expand Up @@ -123,7 +166,6 @@
"outputs": [],
"source": [
"# now let's select a phase to index from our parameters json\n",
"phase_str = 'Si'\n",
"\n",
"ucell = ds.phases.unitcells[phase_str]\n",
"\n",
Expand Down Expand Up @@ -221,14 +263,10 @@
"# here we are filtering our peaks (cf_4d) to select only the strongest ones for indexing purposes only!\n",
"# dsmax is being set to limit rings given to the indexer - 6-8 rings is normally good\n",
"\n",
"# USER: modify the \"frac\" parameter below and re-run the cell until the orange dot sits nicely on the \"elbow\" of the blue line\n",
"# USER: modify the \"frac\" parameter and re-run the cell until the orange dot sits nicely on the \"elbow\" of the blue line\n",
"# 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_frac = 0.9939\n",
"cf_strong_dsmax = 1.594\n",
"cf_strong_dstol = 0.005\n",
"\n",
"cf_strong = select_ring_peaks_by_intensity(cf_4d, frac=cf_strong_frac, dsmax=cf_strong_dsmax, dstol=cf_strong_dstol, doplot=0.95)\n",
"print(cf_4d.nrows)\n",
"print(cf_strong.nrows)"
Expand Down Expand Up @@ -298,7 +336,6 @@
"source": [
"# USER: set a tolerance in d-space (for assigning peaks to powder rings)\n",
"\n",
"indexer_ds_tol = 0.01\n",
"indexer.ds_tol = indexer_ds_tol\n",
"\n",
"# change the log level so we can see what the ring assigments look like\n",
Expand Down Expand Up @@ -346,23 +383,8 @@
"outputs": [],
"source": [
"# now we are indexing!\n",
"# we have to choose which rings we want to generate orientations on\n",
"# generally we want two or three low-multiplicity rings that are isolated from other phases\n",
"# take a look at the ring assignment output from a few cells above, and choose two or three\n",
"rings_for_gen = [0, 1, 3]\n",
"\n",
"# now we want to decide which rings to score our found orientations against\n",
"# generally we can just exclude dodgy rings (close to other phases, only a few peaks in etc)\n",
"rings_for_scoring = [0, 1, 2, 3, 4]\n",
"\n",
"# the sequence of hkl tolerances the indexer will iterate through\n",
"hkl_tols_seq = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.075]\n",
"# the sequence of minpks fractions the indexer will iterate through\n",
"fracs = [0.9, 0.7]\n",
"# the tolerance in g-vector angle\n",
"# the tolerance in g-vector angle - automatically computed from dataset\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",
"grains, indexer = utils.do_index(cf=cf_strong,\n",
" unitcell=ds.phases.unitcells[phase_str],\n",
Expand Down Expand Up @@ -423,8 +445,6 @@
"source": [
"# assign peaks to grains\n",
"\n",
"peak_assign_tol = 0.05\n",
"\n",
"utils.assign_peaks_to_grains(grains, cf_strong, tol=peak_assign_tol)"
]
},
Expand Down Expand Up @@ -476,16 +496,6 @@
"ds.save()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if 1:\n",
" raise ValueError(\"Change the 1 above to 0 to allow 'Run all cells' in the notebook\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Loading

0 comments on commit 6b65fc2

Please sign in to comment.