Skip to content

Commit

Permalink
Parameterise notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jadball committed Jan 22, 2025
1 parent 11efda1 commit 42bd07c
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 198 deletions.
11 changes: 11 additions & 0 deletions ImageD11/nbGui/S3DXRD/5_combine_phases.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@
"print(minor_phase_str, minor_phase_unitcell.lattice_parameters, minor_phase_unitcell.spacegroup)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e458287-439b-4dff-ac5b-2855a1f94f19",
"metadata": {},
"outputs": [],
"source": [
"# choose where to import your TensorMaps from\n",
"# if you refined them, you'll need to change the below paths to point to the separate refined tensormap h5 files."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 2 additions & 0 deletions ImageD11/nbGui/S3DXRD/6_stack_layers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
" ds = ImageD11.sinograms.dataset.load(dset_path)\n",
" \n",
" # read the tensormaps\n",
" # choose where to import your TensorMaps from\n",
" # if you refined them, you'll need to change the below paths to point to the separate refined tensormap h5 files.\n",
" ds.tensor_map = TensorMap.from_h5(ds.grainsfile, h5group=tmap_h5group)\n",
" ds_dict[dataset] = ds"
]
Expand Down
118 changes: 73 additions & 45 deletions ImageD11/nbGui/S3DXRD/pbp_1_indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,55 @@
"\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",
"# python environment stuff\n",
"PYTHONPATH = setup_ImageD11_from_git( ) # ( os.path.join( os.environ['HOME'],'Code'), 'ImageD11_git' )\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' )"
"# 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",
"# filter the columnfile to discard weak peaks\n",
"minpkint = 5\n",
"\n",
"# point-by-point parameters\n",
"hkl_tol = 0.025\n",
"fpks = 0.9\n",
"ds_tol = 0.004\n",
"etacut = 0.1\n",
"ifrac = 5e-3\n",
"y0 = 0.0\n",
"symmetry = \"cubic\"\n",
"foridx = [0, 1, 3, 5, 7]\n",
"forgen = [1, 5, 7]\n",
"uniqcut = 0.85\n",
"use_cluster = False"
]
},
{
Expand Down Expand Up @@ -72,8 +117,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 @@ -127,7 +170,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 @@ -163,8 +205,6 @@
"source": [
"# filter the columnfile to discard weak peaks\n",
"\n",
"minpkint = 5\n",
"\n",
"cf_2d.filter(cf_2d.Number_of_pixels > minpkint)"
]
},
Expand All @@ -176,19 +216,21 @@
},
"outputs": [],
"source": [
"cosine_tol=np.cos(np.radians(90 - ds.ostep))\n",
"\n",
"pbp_object = ImageD11.sinograms.point_by_point.PBP(ds.parfile,\n",
" ds,\n",
" hkl_tol=0.025,\n",
" fpks=0.9,\n",
" ds_tol=0.004,\n",
" etacut=0.1,\n",
" ifrac=5e-3,\n",
" cosine_tol=np.cos(np.radians(90 - ds.ostep)),\n",
" y0=0.0,\n",
" symmetry=\"cubic\",\n",
" foridx=[0, 1, 3, 5, 7],\n",
" forgen=[1, 5, 7],\n",
" uniqcut=0.85,\n",
" hkl_tol=hkl_tol,\n",
" fpks=fpks,\n",
" ds_tol=ds_tol,\n",
" etacut=etacut,\n",
" ifrac=ifrac,\n",
" cosine_tol=cosine_tol,\n",
" y0=y0,\n",
" symmetry=symmetry,\n",
" foridx=foridx,\n",
" forgen=forgen,\n",
" uniqcut=uniqcut,\n",
" phase_name=phase_str)\n",
"\n",
"pbp_object.setpeaks(cf_2d)"
Expand All @@ -213,8 +255,6 @@
},
"outputs": [],
"source": [
"use_cluster = True\n",
"\n",
"if use_cluster:\n",
" bash_script_path = utils.prepare_pbp_bash(pbp_object, PYTHONPATH, minpkint)\n",
" utils.slurm_submit_and_wait(bash_script_path, 15)\n",
Expand All @@ -233,16 +273,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 Expand Up @@ -270,8 +300,6 @@
" \n",
"# now we have our samples_dict, we can process our data:\n",
"\n",
"first_pbp_object = pbp_object\n",
"\n",
"sbats = []\n",
"for sample, datasets in samples_dict.items():\n",
" for dataset in datasets:\n",
Expand Down Expand Up @@ -304,18 +332,18 @@
" \n",
" pbp_object = ImageD11.sinograms.point_by_point.PBP(ds.parfile,\n",
" ds,\n",
" hkl_tol=first_pbp_object.hkl_tol,\n",
" fpks=first_pbp_object.fpks,\n",
" ds_tol=first_pbp_object.ds_tol,\n",
" etacut=first_pbp_object.etacut,\n",
" ifrac=first_pbp_object.ifrac,\n",
" cosine_tol=first_pbp_object.cosine_tol,\n",
" y0=first_pbp_object.y0,\n",
" symmetry=first_pbp_object.symmetry,\n",
" foridx=first_pbp_object.foridx,\n",
" forgen=first_pbp_object.forgen,\n",
" uniqcut=first_pbp_object.uniqcut,\n",
" phase_name=first_pbp_object.phase_name)\n",
" hkl_tol=hkl_tol,\n",
" fpks=fpks,\n",
" ds_tol=ds_tol,\n",
" etacut=etacut,\n",
" ifrac=ifrac,\n",
" cosine_tol=cosine_tol,\n",
" y0=y0,\n",
" symmetry=symmetry,\n",
" foridx=foridx,\n",
" forgen=forgen,\n",
" uniqcut=uniqcut,\n",
" phase_name=phase_str)\n",
" \n",
" pbp_object.setpeaks(cf_2d)\n",
"\n",
Expand Down
91 changes: 80 additions & 11 deletions ImageD11/nbGui/S3DXRD/pbp_2_visualise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,33 @@
},
"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",
"# the minimum number of peaks you want a pixel to have to be counted\n",
"min_unique = 20"
]
},
{
Expand Down Expand Up @@ -65,8 +90,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 @@ -101,7 +124,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 @@ -144,8 +166,6 @@
"source": [
"# choose the minimum number of peaks you want a pixel to have to be counted\n",
"\n",
"min_unique = 20\n",
"\n",
"pmap.choose_best(min_unique)"
]
},
Expand Down Expand Up @@ -270,8 +290,10 @@
"source": [
"# save the TensorMap to disk\n",
"\n",
"tmap.to_h5(os.path.join(ds.analysispath, 'pbp_tensormap.h5'))\n",
"tmap.to_paraview(os.path.join(ds.analysispath, 'pbp_tensormap.h5'))"
"tmap_path = os.path.join(ds.analysispath, f'{ds.sample}_{ds.dset}_tmap.h5')\n",
"\n",
"tmap.to_h5(tmap_path)\n",
"tmap.to_paraview(tmap_path)"
]
},
{
Expand All @@ -282,7 +304,7 @@
"source": [
"# you can also do an MTEX export if you like:\n",
"\n",
"ctf_path = os.path.join(ds.analysispath, 'pbp_tensormap.ctf')\n",
"ctf_path = os.path.join(ds.analysispath, f'{ds.sample}_{ds.dset}_tmap.ctf')\n",
"\n",
"tmap.to_ctf_mtex(ctf_path, z_index=0)"
]
Expand All @@ -292,7 +314,54 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"# We can run the below cell to do this in bulk for many samples/datasets\n",
"# by default this will do all samples in sample_list, all datasets with a prefix of dset_prefix\n",
"# you can add samples and datasets to skip in skips_dict\n",
"\n",
"skips_dict = {\n",
" \"FeAu_0p5_tR_nscope\": [\"top_-50um\", \"top_-100um\"]\n",
"}\n",
"\n",
"dset_prefix = \"top\"\n",
"\n",
"sample_list = [\"FeAu_0p5_tR_nscope\"]\n",
" \n",
"samples_dict = utils.find_datasets_to_process(ds.dataroot, skips_dict, dset_prefix, sample_list)\n",
" \n",
"# manual override:\n",
"# samples_dict = {\"FeAu_0p5_tR_nscope\": [\"top_100um\", \"top_150um\"]}\n",
" \n",
"# now we have our samples_dict, we can process our data:\n",
"\n",
"for sample, datasets in samples_dict.items():\n",
" for dataset in datasets:\n",
" print(f\"Processing dataset {dataset} in sample {sample}\")\n",
" dset_path = os.path.join(ds.analysisroot, sample, f\"{sample}_{dataset}\", f\"{sample}_{dataset}_dataset.h5\")\n",
" if not os.path.exists(dset_path):\n",
" print(f\"Missing DataSet file for {dataset} in sample {sample}, skipping\")\n",
" continue\n",
" \n",
" print(\"Importing DataSet object\")\n",
" \n",
" ds = ImageD11.sinograms.dataset.load(dset_path)\n",
" ds.phases = ds.get_phases_from_disk()\n",
" ref_ucell = ds.phases.unitcells[phase_str]\n",
" pmap = PBPMap(ds.pbpfile)\n",
" pmap.choose_best(min_unique)\n",
" phases = {0: ref_ucell}\n",
" phase_ids = TensorMap.recon_order_to_map_order(np.where(pmap.best_nuniq > min_unique, 0, -1))\n",
" tmap = TensorMap.from_pbpmap(pmap, steps=(1, ds.ystep, ds.ystep), phases=phases)\n",
" tmap['phase_ids'] = phase_ids\n",
" tmap.get_ipf_maps()\n",
" tmap_path = os.path.join(ds.analysispath, f'{ds.sample}_{ds.dset}_tmap.h5')\n",
" tmap.to_h5(tmap_path)\n",
" tmap.to_paraview(tmap_path)\n",
" ctf_path = os.path.join(ds.analysispath, f'{ds.sample}_{ds.dset}_tmap.ctf')\n",
" tmap.to_ctf_mtex(ctf_path, z_index=0)\n",
"\n",
"print(\"Done!\")"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 42bd07c

Please sign in to comment.