-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from jadball/master
Add scanning 3DXRD example notebooks
- Loading branch information
Showing
3 changed files
with
1,957 additions
and
0 deletions.
There are no files selected for viewing
232 changes: 232 additions & 0 deletions
232
ImageD11/nbGui/S3DXRD/0_S3DXRD_segment_and_label_single_dset.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8deabe5b", | ||
"metadata": {}, | ||
"source": [ | ||
"# Jupyter notebook based on ImageD11 to process scanning 3DXRD data\n", | ||
"# Written by Haixing Fang, Jon Wright and James Ball\n", | ||
"## Date: 16/01/2024" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "851fcab9-7631-439f-885c-438bcefeac84", | ||
"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 somewhere\n", | ||
"# USER: Change the path below to point to your local copy of ImageD11:\n", | ||
"\n", | ||
"id11_code_path = \"/home/esrf/james1997a/Code/ImageD11\"\n", | ||
"\n", | ||
"import sys\n", | ||
"\n", | ||
"sys.path.insert(0, id11_code_path)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9b5c1db6-5a32-4294-abef-cfc2150d24de", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# import functions we need\n", | ||
"\n", | ||
"import os, glob, pprint\n", | ||
"\n", | ||
"import ImageD11.sinograms.dataset\n", | ||
"import ImageD11.sinograms.lima_segmenter\n", | ||
"import ImageD11.sinograms.assemble_label\n", | ||
"import ImageD11.sinograms.properties" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f45e3647-2e1b-4a31-b5de-01adbd4d7573", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Check that we're importing ImageD11 from the home directory rather than from the Jupyter kernel\n", | ||
"\n", | ||
"?ImageD11.sinograms.dataset" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0a307437-2d15-4de5-985f-7c7daf68db0c", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# USER: specify your experimental directory\n", | ||
"\n", | ||
"base_dir = \"/home/esrf/james1997a/Data/ihma439/id11/20231211\"\n", | ||
"\n", | ||
"rawdata_path = os.path.join(base_dir, 'RAW_DATA')\n", | ||
"\n", | ||
"!ls -lrt {rawdata_path}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ad077c4b-39cc-4b90-9637-33c32f12e364", | ||
"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_700um\"\n", | ||
"\n", | ||
"# USER: specify path to detector mask\n", | ||
"\n", | ||
"mask_path = '/data/id11/nanoscope/Eiger/eiger_mask_E-08-0173_20231127.edf'\n", | ||
"\n", | ||
"processed_data_root_dir = os.path.join(base_dir, 'PROCESSED_DATA/James') # USER: modify this to change the destination folder if desired\n", | ||
"sparse_pixels_dir = os.path.join(processed_data_root_dir, \"SparsePixels_NewMask\") # USER: modify this to change the name of the SparsePixels folder inside processed_data_root_dir\n", | ||
"\n", | ||
"# makes folders if they don't already exist\n", | ||
"\n", | ||
"if not os.path.exists(processed_data_root_dir):\n", | ||
" os.makedir(processed_data_root_dir)\n", | ||
" \n", | ||
"if not os.path.exists(sparse_pixels_dir):\n", | ||
" os.makedirs(sparse_pixels_dir)\n", | ||
"\n", | ||
"# desination of H5 files\n", | ||
"\n", | ||
"dset_path = os.path.join(sparse_pixels_dir, f\"ds_{sample}_{dataset}.h5\" )\n", | ||
"sparse_path = os.path.join(sparse_pixels_dir, f'{sample}_{dataset}_sparse.h5')\n", | ||
"pks_path = os.path.join(sparse_pixels_dir, f'pks_{sample}_{dataset}.h5')\n", | ||
"\n", | ||
"# create ImageD11 dataset object\n", | ||
"\n", | ||
"ds = ImageD11.sinograms.dataset.DataSet(dataroot=rawdata_path,\n", | ||
" analysisroot=sparse_pixels_dir,\n", | ||
" sample=sample,\n", | ||
" dset=dataset)\n", | ||
"ds.import_all()\n", | ||
"ds.save(dset_path)\n", | ||
"\n", | ||
"# create batch file to send to SLURM cluster\n", | ||
"\n", | ||
"sbat = ImageD11.sinograms.lima_segmenter.setup(dset_path, maskfile=mask_path)\n", | ||
"sbat" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4b8bb44d", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# send batch file to SLURM cluster\n", | ||
"\n", | ||
"!sbatch {sbat}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a057fef3", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# check status of SLURM jobs\n", | ||
"\n", | ||
"!squeue -u $USER" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b56de064-adb9-4d9c-92e8-301d24598f16", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# you must wait until the SLURM jobs have completed before running the next cell!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "5de23264-4c22-43fe-8be6-8cc54039ea2d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# label sparse peaks\n", | ||
"\n", | ||
"ImageD11.sinograms.assemble_label.main(dset_path, sparse_path)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ddb029cd-7f66-4c91-abee-5f1723303360", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# generate peaks table\n", | ||
"\n", | ||
"ImageD11.sinograms.properties.main(dset_path, sparse_path, pks_path, options={'algorithm': 'lmlabel', 'wtmax': 70000, 'save_overlaps': False})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0b6e6575-bb8e-47ac-88e1-0ff5350ab1a5", | ||
"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": 5 | ||
} |
Oops, something went wrong.