Skip to content

Commit

Permalink
Merge pull request #238 from jadball/scanbooks
Browse files Browse the repository at this point in the history
Local point-by-point indexing notebook
  • Loading branch information
jonwright authored Mar 4, 2024
2 parents 6662056 + 0f87c9d commit 811a659
Show file tree
Hide file tree
Showing 3 changed files with 587 additions and 192 deletions.
250 changes: 250 additions & 0 deletions ImageD11/nbGui/S3DXRD/1_2_3_S3DXRD_pbp_indexing_local.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# There is a bug with the current version of ImageD11 in the site-wide Jupyter env.\n",
"# This has been fixed here: https://github.com/FABLE-3DXRD/ImageD11/commit/4af88b886b1775585e868f2339a0eb975401468f\n",
"# Until a new release has been made and added to the env, we need to get the latest version of ImageD11 from GitHub\n",
"# Put it in your home directory\n",
"# USER: Change the path below to point to your local copy of ImageD11:\n",
"\n",
"import os\n",
"\n",
"username = os.environ.get(\"USER\")\n",
"\n",
"id11_code_path = f\"/home/esrf/{username}/Code/ImageD11\"\n",
"\n",
"import sys\n",
"\n",
"sys.path.insert(0, id11_code_path)\n",
"\n",
"os.environ['OMP_NUM_THREADS']='1'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"%matplotlib ipympl\n",
"\n",
"import ImageD11.sinograms.point_by_point\n",
"import ImageD11.sinograms.dataset\n",
"import ImageD11.sinograms.properties\n",
"import ImageD11.columnfile\n",
"\n",
"import ImageD11.nbGui.nb_utils as utils"
]
},
{
"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 = \"/home/esrf/james1997a/Data/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 = \"/home/esrf/james1997a/Data/ihma439/id11/20231211/PROCESSED_DATA/James/20240226\""
]
},
{
"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_nscope\"\n",
"dataset = \"top_250um\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"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\")\n",
"\n",
"# USER: specify the path to the parameter file\n",
"\n",
"par_path = os.path.join(processed_data_root_dir, 'Fe_refined.par')\n",
"\n",
"e2dx_path = os.path.join(processed_data_root_dir, '../../CeO2/e2dx_E-08-0173_20231127.edf')\n",
"e2dy_path = os.path.join(processed_data_root_dir, '../../CeO2/e2dy_E-08-0173_20231127.edf')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Load the dataset\n",
"dset = ImageD11.sinograms.dataset.load(dset_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Import the 2D columnfile, or make it if it doesn't exist\n",
"\n",
"if os.path.exists(dset.col2dfile):\n",
" cf_2d = ImageD11.columnfile.colfile_from_hdf(dset.col2dfile)\n",
"else:\n",
" # Import 2D peaks, make a spatially corrected columnfile, save it\n",
" peaks_table = ImageD11.sinograms.properties.pks_table.load(dset.pksfile)\n",
"\n",
" # Grab the 2d peak centroids\n",
" peaks_2d = peaks_table.pk2d(dset.omega, dset.dty)\n",
" cf_2d = utils.tocolf(peaks_2d, par_path, e2dx_path, e2dy_path)\n",
"\n",
" # save the 2D peaks to file so we don't have to spatially correct them again\n",
" ImageD11.columnfile.colfile_to_hdf(cf_2d, dset.col2dfile)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# filter the columnfile to discard weak peaks\n",
"\n",
"cf_2d.filter(cf_2d.Number_of_pixels > 5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"pbp_object = ImageD11.sinograms.point_by_point.PBP(par_path,\n",
" dset,\n",
" hkl_tol=0.01,\n",
" fpks=0.9,\n",
" ds_tol=0.01,\n",
" etacut=0.1,\n",
" ifrac=1./300,\n",
" cosine_tol=np.cos(np.radians(90 - 0.25)),\n",
" y0=-7.985,\n",
" symmetry=\"cubic\",\n",
" foridx=[0, 1, 2, 3, 4, 5],\n",
" forgen=[5, 1],\n",
" uniqcut=0.9)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"pbp_object.setpeaks(cf_2d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"fig, ax = pbp_object.iplot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"dset.pbpfile = os.path.join(dset.analysispath, dset.dsname + '_pbp_index.pbp')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"pbp_object.point_by_point(dset.pbpfile, loglevel=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (main)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 811a659

Please sign in to comment.