{"cells": [{"cell_type": "markdown", "id": "9f197eab-b00a-415b-857f-78b679c52690", "metadata": {"tags": []}, "source": ["# 3DXRD indexing notebook - Grid indexing method \n", "__Written by Haixing Fang, Jon Wright and James Ball__ \n", "__Date: 21/02/2025__"]}, {"cell_type": "markdown", "metadata": {}, "source": "Source: [ImageD11/nbGui/TDXRD/1_index_grid.ipynb](https://github.com/FABLE-3DXRD/ImageD11/blob/master/ImageD11/nbGui/TDXRD/1_index_grid.ipynb). Shown as saved in git; the documentation build does not run it."}, {"cell_type": "code", "execution_count": null, "id": "bdf2e7f7-773b-464e-a0b1-5cb56a76676e", "metadata": {"tags": []}, "outputs": [], "source": ["import os\n", "\n", "os.environ['OMP_NUM_THREADS'] = '1'\n", "os.environ['OPENBLAS_NUM_THREADS'] = '1'\n", "os.environ['MKL_NUM_THREADS'] = '1'\n", "\n", "exec(open('/data/id11/nanoscope/install_ImageD11_from_git.py').read())"]}, {"cell_type": "code", "execution_count": null, "id": "9686b3bc-6618-4a1c-b440-2a8ebc3ab9de", "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", "IMAGED11_PATH = None # means do not use git, otherwise \"ImageD11\" or \"ImageD11_version_xx\", etc\n", "CHECKOUT_PATH = None # None means guess, or you can specify a folder for the checkout\n", "\n", "# desination of H5 files\n", "# replace below with e.g.:\n", "# dset_path = '/data/visitor/expt1234/20240101/PROCESSED_DATA/sample/dataset/sample_dataset.h5'\n", "\n", "dset_path = ''\n", "\n", "phase_str = 'Fe'\n", "\n", "# path to parameters .json/.par\n", "parfile = ''\n", "\n", "# peak filtration options\n", "cf_strong_frac = 0.999\n", "cf_strong_dsmax = 1.017\n", "cf_strong_dstol = 0.025\n", "\n", "# indexing options\n", "rings_to_use = [0, 1, 3]\n", "\n", "# makemap options\n", "symmetry = \"cubic\"\n", "makemap_tol_seq = [0.02, 0.015, 0.01]\n", "\n", "gridpars = {\n", " 'DSTOL' : 0.004,\n", " 'RING1' : [1,0,],\n", " 'RING2' : [0,],\n", " 'NUL' : True,\n", " 'FITPOS' : True,\n", " 'tolangle' : 0.50,\n", " 'toldist' : 100.,\n", " 'NTHREAD' : 1 ,\n", "}\n", "\n", "grid_xlim = 600 # SAME UNITS AS DISTANCE IN PAR FILE - extent away from rotation axis to search for grains\n", "grid_ylim = 600\n", "grid_zlim = 200\n", "grid_step = 100 # step size of search grid, SAME UNITS AS DISTANCE IN PAR FILE\n", "\n", "# fraction of expected number of peaks to accept in Makemap output\n", "frac = 0.85\n", "\n", "# find the spike\n", "absolute_minpks = 56"]}, {"cell_type": "code", "execution_count": null, "id": "696bdb1e-9526-4c3b-b54f-490c1be2fd52", "metadata": {}, "outputs": [], "source": ["if IMAGED11_PATH is not None:\n", " exec(open('/data/id11/nanoscope/install_ImageD11_from_git.py').read())\n", " PYTHONPATH=setup_ImageD11_from_git(CHECKOUT_PATH, IMAGED11_PATH)\n", "else:\n", " import site\n", " PYTHONPATH = site.getsitepackages()[0]\n", " print(PYTHONPATH)"]}, {"cell_type": "code", "execution_count": null, "id": "16f32f19-7eaa-4e4b-a347-3b9a44f8ada1", "metadata": {"tags": []}, "outputs": [], "source": ["import os\n", "import numpy as np\n", "from matplotlib import pyplot as plt\n", "\n", "import random\n", "import ImageD11.cImageD11\n", "import ImageD11.grain\n", "import ImageD11.indexing\n", "import ImageD11.columnfile\n", "from ImageD11.sinograms import dataset\n", "from ImageD11.peakselect import select_ring_peaks_by_intensity\n", "from ImageD11.nbGui import nb_utils as utils\n", "from ImageD11.grid_index_parallel import grid_index_parallel\n", "\n", "%matplotlib widget"]}, {"cell_type": "markdown", "id": "27d1ccc3-4c03-4380-a8a1-1862db88f01c", "metadata": {}, "source": ["# Load data\n", "## Dataset"]}, {"cell_type": "code", "execution_count": null, "id": "8f366d52-a560-4f08-bb1e-6d585cc41f4d", "metadata": {"tags": []}, "outputs": [], "source": ["ds = ImageD11.sinograms.dataset.load(dset_path)\n", "print(ds)"]}, {"cell_type": "markdown", "id": "1b433752-5a85-4f92-bc38-e52deabd79b7", "metadata": {}, "source": ["## Parameters\n", "Specify the path to your parameter file.\n", "\n", "You can optionally set up some default parameters for either an Eiger or Frelon detector like so:\n", "```python\n", "from ImageD11.parameters import AnalysisSchema\n", "asc = AnalysisSchema.from_default(detector='eiger') # or detector='frelon'\n", "asc.save('./pars.json')\n", "```\n", "Please note in this case that you will still have to update the `geometry.par` values accordingly for your experiment. \n", "If you haven't already, you should run one of the calibration notebooks to determine these."]}, {"cell_type": "code", "execution_count": null, "id": "a6bbd76b-aae4-42c6-b850-5165efc651b0", "metadata": {}, "outputs": [], "source": ["ds.parfile = parfile\n", "ds.save()"]}, {"cell_type": "markdown", "id": "f66a96ff-2f28-409a-b916-f8a18994a051", "metadata": {}, "source": ["## Phases\n", "If the parameter file was a json, we can access the unit cells via `ds.phases.unitcells`"]}, {"cell_type": "code", "execution_count": null, "id": "5622b831-3fec-4b49-a1eb-d40fe25584a1", "metadata": {}, "outputs": [], "source": ["ds.phases = ds.get_phases_from_disk()\n", "ds.phases.unitcells"]}, {"cell_type": "code", "execution_count": null, "id": "16ae5fb2-de97-468c-b83c-82fc72d3aa56", "metadata": {"tags": []}, "outputs": [], "source": ["ucell = ds.phases.unitcells[phase_str]\n", "print(ucell)"]}, {"cell_type": "markdown", "id": "128e5a46-9895-4b6b-b6c9-6baa455d3f1d", "metadata": {}, "source": ["## Peaks"]}, {"cell_type": "code", "execution_count": null, "id": "f8b62f6a-0290-474c-b704-742293397518", "metadata": {"tags": []}, "outputs": [], "source": ["cf_3d = ds.get_cf_3d_from_disk()\n", "ds.update_colfile_pars(cf_3d, phase_name=phase_str) \n", "cf_3d_path = 'cf_3d.flt'\n", "cf_3d.writefile(cf_3d_path)"]}, {"cell_type": "markdown", "id": "eaf6ddbf-1b4e-48a6-8be6-0b2420cf44e8", "metadata": {}, "source": ["# Visualise data\n", "### $d^{*}$ vs $\\eta$"]}, {"cell_type": "code", "execution_count": null, "id": "2058371d-b908-4698-b567-67126bbb144a", "metadata": {"tags": []}, "outputs": [], "source": ["skip = 1 # we can skip peaks to speed up plotting if needed\n", "ucell.makerings(cf_3d.ds.max())\n", "fig, ax = plt.subplots(figsize=(10,5), layout='constrained')\n", "ax.plot(cf_3d.ds[::skip], cf_3d.eta[::skip], ',')\n", "ax.vlines(ucell.ringds, -50, 50, color='red')\n", "ax.set(xlabel=r'$d^{*}~(\\AA^{-1})$', ylabel=r'$\\eta~(\\degree)$', title='2D azimuthal transform')\n", "plt.show()"]}, {"cell_type": "markdown", "id": "ad6fab3b-2297-4d05-ae0a-1f266782e7b5", "metadata": {}, "source": ["# Filtration\n", "Here we are filtering our peaks (`cf_3d`) to select only the strongest ones for indexing purposes only! \n", "We first filter the peaks in $d^{*}$ to keep only those close to the predicted peaks from the unit cell. \n", "We then sort our peaks by intensity, and take a certain intensity-weighted fraction of them. \n", "`dstol`: The tolerance in $d^{*}$ between a peak and a predicted reflection. \n", "`dsmax`: The maximum allowed peak $d^{*}$ value. Used to limit the number of rings given to the indexer - 6-8 rings max are normally sufficient. \n", "`frac`: The intensity fraction: `frac=0.9` keeps 90% of the peak intensity. We recommend that you choose a value close to the 'elbow' of the plot."]}, {"cell_type": "code", "execution_count": null, "id": "3f8d51c9-b2f9-418c-a4b9-746d84dfbbb8", "metadata": {"tags": []}, "outputs": [], "source": ["cf_strong = select_ring_peaks_by_intensity(cf_3d, frac=cf_strong_frac, dsmax=cf_strong_dsmax, dstol=cf_strong_dstol, ucell=ucell, doplot=0.5)"]}, {"cell_type": "code", "execution_count": null, "id": "b37656ec-1d8b-4ada-bf39-de97842950f1", "metadata": {}, "outputs": [], "source": ["# we will also export some additional strong peaks across all rings\n", "# this will be useful for grain refinement later (using makemap)\n", "cf_strong_allrings = select_ring_peaks_by_intensity(cf_3d, frac=cf_strong_frac, dsmax=cf_3d.ds.max(), dstol=cf_strong_dstol, ucell=ucell, doplot=0.5)\n", "cf_strong_allrings_path = 'cf_strong_allrings.flt'\n", "cf_strong_allrings.writefile(cf_strong_allrings_path)"]}, {"cell_type": "code", "execution_count": null, "id": "e3d423d9-15b3-4d0e-9824-168c0e8bceea", "metadata": {"tags": []}, "outputs": [], "source": ["skip = 1 # we can skip peaks to speed up plotting if needed\n", "fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True)\n", "ax.plot(cf_3d.ds[::skip], cf_3d.sum_intensity[::skip],',', label='cf_3d')\n", "ax.plot(cf_strong.ds[::skip], cf_strong.sum_intensity[::skip],',', label='cf_strong')\n", "ax.vlines(ucell.ringds, 1e3, 1e4, color='red')\n", "ax.set(xlabel=r'$d^{*}~(\\AA^{-1})$', ylabel='Intensity', yscale='log', title='Peak filtration')\n", "ax.legend()\n", "plt.show()"]}, {"cell_type": "markdown", "id": "ef9e323d-bd9a-496d-ac28-d331de54cec8", "metadata": {}, "source": ["# Indexing\n", "## Ring assignment"]}, {"cell_type": "code", "execution_count": null, "id": "6a2e4aaa-3caf-4af5-8d2e-312a0aa31956", "metadata": {"tags": []}, "outputs": [], "source": ["indexer = ImageD11.indexing.indexer_from_colfile_and_ucell(cf_strong, ucell)\n", "indexer.ds_tol = cf_strong_dstol\n", "ImageD11.indexing.loglevel = 1\n", "indexer.assigntorings()\n", "ImageD11.indexing.loglevel = 3\n", "print(f\"Indexing {cf_strong.nrows} peaks\")"]}, {"cell_type": "code", "execution_count": null, "id": "db701ea9-de81-43b9-b68d-3b78a77f9520", "metadata": {"tags": []}, "outputs": [], "source": ["skip = 1 # we can skip peaks to speed up plotting if needed\n", "fig, ax = plt.subplots(layout='constrained', figsize=(10,5))\n", "ax.scatter(indexer.colfile.ds[::skip], indexer.colfile.eta[::skip], c=indexer.ra[::skip]%20, cmap='tab20', s=1)\n", "ax.vlines(ucell.ringds, -50, 50, color='red')\n", "ax.set(xlabel=r'$d^{*}~(\\AA^{-1})$', ylabel=r'$\\eta~(\\degree)$', xlim=(min(ucell.ringds[0], cf_strong.ds.min()) - 0.02, cf_strong.ds.max() + 0.02), title='Ring assignments')\n", "plt.show()"]}, {"cell_type": "markdown", "id": "7c51b7f1-2f80-4309-a6f2-64f4c30807a1", "metadata": {}, "source": ["Now we need to compute the number of expected peaks. \n", "To do this, you add up the multiplicites of the rings you chose. \n", "If you recorded a 360 degree scan, multiply the result by 2. \n", "e.g given this output:\n", "```\n", "# info: Ring ( h, k, l) Mult total indexed to_index ubis peaks_per_ubi tth\n", "# info: Ring 3 ( -2, -2, 0) 12 2251 0 2251 93 24 16.11\n", "# info: Ring 2 ( -1, -1, -2) 24 4899 0 4899 101 48 13.94\n", "# info: Ring 1 ( -2, 0, 0) 6 1233 0 1233 102 12 11.37\n", "# info: Ring 0 ( -1, -1, 0) 12 2861 0 2861 118 24 8.03\n", "```\n", "Selecting rings `[0,1,3]` we would get `(12+6+12)*2 = 84` peaks"]}, {"cell_type": "code", "execution_count": null, "id": "97a39004-8af2-44a7-a6c2-65a28075b5e9", "metadata": {}, "outputs": [], "source": ["peaks_expected = (12+6+12)*2\n", "\n", "# choose the fraction of the number of peaks expected - this should be around 0.9 if you had a good clean segementation\n", "# if you suspect you are missing peaks in your data, decrease to around 0.6\n", "\n", "minpeaks = int(np.round(peaks_expected * frac, 2))\n", "minpeaks"]}, {"cell_type": "markdown", "id": "54e0a7ce-6489-475d-ba44-c5fbdd8e76ba", "metadata": {}, "source": ["## Choose rings to export for grid index"]}, {"cell_type": "code", "execution_count": null, "id": "8b904e07-7481-4396-b502-29f19fdbf924", "metadata": {"tags": []}, "outputs": [], "source": ["mask = np.zeros(cf_strong.nrows, dtype=bool)\n", "for ring in rings_to_use:\n", " mask |= indexer.ra == ring\n", "peaks_to_export = cf_strong.copy()\n", "peaks_to_export.filter(mask)"]}, {"cell_type": "code", "execution_count": null, "id": "ca11f2e9-a16b-4474-80de-58cc9f8c4ba7", "metadata": {"tags": []}, "outputs": [], "source": ["skip = 1 # we can skip peaks to speed up plotting if needed\n", "fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True)\n", "ax.plot(cf_3d.ds[::skip], cf_3d.sum_intensity[::skip],',', label='cf_3d')\n", "ax.plot(peaks_to_export.ds[::skip], peaks_to_export.sum_intensity[::skip],',', label='peaks_to_export')\n", "ax.vlines(ucell.ringds, 1e3, 1e4, color='red')\n", "ax.set(xlabel=r'$d^{*}~(\\AA^{-1})$', ylabel='Intensity', yscale='log', title='Peak filtration')\n", "ax.legend()\n", "plt.show()"]}, {"cell_type": "markdown", "id": "09938785-65b4-441f-829b-64312d1a71b4", "metadata": {}, "source": ["## Grid index"]}, {"cell_type": "code", "execution_count": null, "id": "ba4e4d1c-0ec7-4dea-a75b-97765cb28d80", "metadata": {"tags": []}, "outputs": [], "source": ["grid_peaks_path = 'grid_peaks.flt'\n", "new_grid_peaks_path = 'grid_peaks.flt.new'\n", "peaks_to_export.writefile(grid_peaks_path) # export peaks\n", "oldparfile = phase_str + '.par'\n", "ds.phases.to_old_pars_file(oldparfile, phase_str) # export parameter file\n", "nproc = max( ImageD11.cImageD11.cores_available() - 1 , 1)\n", "\n", "\n", "omega_slop = ds.ostep/2\n", "gridpars['COSTOL'] = np.cos(np.radians(90 - ds.ostep))\n", "gridpars['NPROC'] = nproc\n", "gridpars['NTHREAD'] = 1\n", "gridpars['NPKS'] = minpeaks\n", "gridpars['OMEGAFLOAT'] = omega_slop\n", "gridpars['TOLSEQ'] = makemap_tol_seq\n", "gridpars['SYMMETRY'] = symmetry\n", "\n", "translations = [(t_x, t_y, t_z) # grid to search\n", " for t_x in range(-grid_xlim, grid_xlim+1, grid_step)\n", " for t_y in range(-grid_ylim, grid_ylim+1, grid_step) \n", " for t_z in range(-grid_zlim, grid_zlim+1, grid_step) ]\n", "\n", "random.seed(42) # reproducible\n", "random.shuffle(translations)\n", "tmp_output_path = 'tmp'\n", "map_path = 'alltmp.map'\n", "new_map_path = f'alltmp.map.new'\n", "grid_index_parallel(grid_peaks_path, oldparfile, tmp_output_path, gridpars, translations)"]}, {"cell_type": "markdown", "id": "352f7da7-aaac-4354-b579-b702086c60d6", "metadata": {}, "source": ["# View outputs"]}, {"cell_type": "code", "execution_count": null, "id": "3d981eae-dd1a-40dd-a05e-147ab92a37f7", "metadata": {"tags": []}, "outputs": [], "source": ["grains2 = ImageD11.grain.read_grain_file(map_path)\n", "for g in grains2:\n", " g.ref_unitcell = ucell\n", "utils.get_rgbs_for_grains(grains2)"]}, {"cell_type": "code", "execution_count": null, "id": "80b7c444-1183-4a04-8c69-1f442da9db7f", "metadata": {}, "outputs": [], "source": ["utils.plot_all_ipfs(grains2)"]}, {"cell_type": "code", "execution_count": null, "id": "9bf840f9-f6e1-47ba-a0b8-ccf00f13d3f1", "metadata": {"tags": []}, "outputs": [], "source": ["utils.plot_grain_positions(grains2, colour='npks', centre_plot=False, size_scaling=0.5)"]}, {"cell_type": "code", "execution_count": null, "id": "a11efaf8-7246-49c5-bfc6-78c6654cf01a", "metadata": {}, "outputs": [], "source": ["utils.plot_grain_positions(grains2, colour='z', centre_plot=False, size_scaling=0.5)"]}, {"cell_type": "markdown", "id": "a31cde46-9fba-44ee-89f1-29832cf7435c", "metadata": {}, "source": ["# Grain refinement"]}, {"cell_type": "code", "execution_count": null, "id": "3f40d348-98bc-4d95-a372-e2da82fecc11", "metadata": {"tags": []}, "outputs": [], "source": ["makemap_output = !makemap.py -p {oldparfile} -u {map_path} -U {new_map_path} -f {grid_peaks_path} -s {symmetry} -t {makemap_tol_seq[-1]} --omega_slop={omega_slop} --no_sort"]}, {"cell_type": "code", "execution_count": null, "id": "6ace88c5-a7ae-4a90-94b1-1f27965fd1cb", "metadata": {}, "outputs": [], "source": ["utils.plot_grain_histograms(new_grid_peaks_path, new_map_path, oldparfile, omega_slop, tol=makemap_tol_seq[-1])"]}, {"cell_type": "code", "execution_count": null, "id": "707bbfbb-cdc0-460d-a941-02067798e777", "metadata": {"tags": []}, "outputs": [], "source": ["grains3 = ImageD11.grain.read_grain_file(new_map_path)\n", "grains3 = [grain for grain in grains3 if \"no peaks\" not in grain.intensity_info]\n", "for g in grains3:\n", " g.intensity = float(g.intensity_info.split(\"mean = \")[1].split(\" , \")[0].replace(\"'\", \"\"))"]}, {"cell_type": "code", "execution_count": null, "id": "87c3d3f9-f9ad-4cc1-a8d1-4d897f48a064", "metadata": {"tags": []}, "outputs": [], "source": ["utils.plot_grain_positions(grains3, colour='npks', centre_plot=False, size_scaling=0.5)"]}, {"cell_type": "code", "execution_count": null, "id": "39784af8-8960-4a3b-8097-9923bb5517c7", "metadata": {"tags": []}, "outputs": [], "source": ["fig, ax = plt.subplots(figsize=(10, 7), layout='constrained')\n", "ax.hist([float(grain.npks) for grain in grains3], bins=30)\n", "ax.set(xlabel='Number of peaks per grain', ylabel='Count', title='Histogram of peaks per grain')\n", "plt.show()"]}, {"cell_type": "code", "execution_count": null, "id": "aa22b5c7-ac6b-4284-aa49-5b04ee93e289", "metadata": {}, "outputs": [], "source": ["# filter out grains with fewer than absolute_minpks peaks\n", "# most grains should have a high number of peaks\n", "# choose absolute_minpks such that the low-peak grains are removed\n", "grains_filtered = [grain for grain in grains3 if float(grain.npks) > absolute_minpks]"]}, {"cell_type": "code", "execution_count": null, "id": "9bd8f651-5279-4071-9681-4bdf7905c826", "metadata": {"tags": []}, "outputs": [], "source": ["utils.plot_grain_positions(grains_filtered, colour='npks', centre_plot=False, size_scaling=0.5)"]}, {"cell_type": "code", "execution_count": null, "id": "949697dd-6919-4226-a91c-505069df3598", "metadata": {"tags": []}, "outputs": [], "source": ["filtered_map_path = 'nice_grains.map'\n", "new_filtered_map_path = 'nice_grains.map.new'\n", "new_cf_3d_path = cf_3d_path + '.new'\n", "\n", "# run makemap again against all peaks\n", "ImageD11.grain.write_grain_file(filtered_map_path, grains_filtered)\n", "\n", "# run makemap on filtered grains with all 3D peaks\n", "makemap_output = !makemap.py -p {oldparfile} -u {filtered_map_path} -U {new_filtered_map_path} -f {cf_3d_path} -s {symmetry} -t {makemap_tol_seq[-1]} --omega_slop={omega_slop} --no_sort\n", "\n", "# import makemap output columnfile with peak assignments\n", "cf_3d = ImageD11.columnfile.columnfile(new_cf_3d_path)\n", "\n", "# write 3D columnfile to disk\n", "ImageD11.columnfile.colfile_to_hdf(cf_3d, ds.col3dfile, name='peaks')\n", "\n", "# re-import filtered grains with new peak statistics\n", "grains_final = ImageD11.grain.read_grain_file(new_filtered_map_path)\n", "for g in grains_final:\n", " g.ref_unitcell = ucell\n", "\n", "utils.get_rgbs_for_grains(grains_final)\n", "print(f\"{len(grains_final)} final grains imported\")"]}, {"cell_type": "code", "execution_count": null, "id": "f493a9ea-2744-4e2b-96d1-e8561c6ab395", "metadata": {"tags": []}, "outputs": [], "source": ["utils.plot_grain_positions(grains_final, colour='npks', centre_plot=False, size_scaling=0.5)"]}, {"cell_type": "code", "execution_count": null, "id": "b9178835-a3ce-4829-846f-b99a71a1300f", "metadata": {}, "outputs": [], "source": ["utils.plot_grain_positions(grains_final, colour='z', centre_plot=False, size_scaling=0.5)"]}, {"cell_type": "code", "execution_count": null, "id": "9ca1a55e-14b1-4672-b78f-d32ca1aa0c3a", "metadata": {"tags": []}, "outputs": [], "source": ["fig, ax = plt.subplots(figsize=(10, 7), layout='constrained')\n", "ax.hist([float(grain.npks) for grain in grains_final], bins=30)\n", "ax.set(xlabel='Number of peaks per grain', ylabel='Count', title='Histogram of peaks per grain')\n", "plt.show()"]}, {"cell_type": "code", "execution_count": null, "id": "2c1cc664-b29d-4b8e-9159-1d31e31fcd47", "metadata": {}, "outputs": [], "source": ["utils.plot_grain_histograms(new_cf_3d_path, new_filtered_map_path, oldparfile, omega_slop, tol=makemap_tol_seq[-1])"]}, {"cell_type": "code", "execution_count": null, "id": "86667129-8e2d-4ae2-bb3a-e6b8e4ea90b5", "metadata": {}, "outputs": [], "source": ["unit_cell_lengths = np.array([np.sort(g.unitcell.copy()) for g in grains_final])\n", "median_unit_cell = np.median(unit_cell_lengths, axis=0)\n", "print(\"Median unit cell:\", median_unit_cell)\n", "fig, ax = plt.subplots(constrained_layout=True)\n", "ax.plot(unit_cell_lengths[:,:3])\n", "ax.hlines(median_unit_cell[:3], 0, len(unit_cell_lengths))\n", "ax.set(xlabel=\"Grain ID\", ylabel=\"Unit cell length\")\n", "plt.show()"]}, {"cell_type": "markdown", "id": "cda822ef-fa93-4eec-af58-ef7fec9685a5", "metadata": {"tags": []}, "source": ["# Export data"]}, {"cell_type": "code", "execution_count": null, "id": "0c99f8e7-3353-4677-927a-99ef749e2bbc", "metadata": {}, "outputs": [], "source": ["ds.save_grains_to_disk(grains_final, phase_name=phase_str)"]}, {"cell_type": "code", "execution_count": null, "id": "997b7d27-c48c-41b0-8b9a-cc5b55cf073d", "metadata": {"tags": []}, "outputs": [], "source": ["ds.save()"]}, {"cell_type": "markdown", "id": "6f554e63-2cee-4603-98b0-33b0398a4762", "metadata": {}, "source": ["# Deleting temporary files"]}, {"cell_type": "code", "execution_count": null, "id": "c1306c40-ace6-4680-8ae9-d9ccdf5db8de", "metadata": {}, "outputs": [], "source": ["for path in [\n", " cf_3d_path,\n", " cf_strong_allrings_path,\n", " grid_peaks_path,\n", " tmp_output_path + '.flt',\n", " map_path,\n", " new_map_path,\n", " new_grid_peaks_path,\n", " filtered_map_path,\n", " new_filtered_map_path,\n", " new_cf_3d_path,\n", "]:\n", " if os.path.exists(path):\n", " os.remove(path)"]}], "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.12.9"}, "widgets": {"application/vnd.jupyter.widget-state+json": {"state": {}, "version_major": 2, "version_minor": 0}}}, "nbformat": 4, "nbformat_minor": 5}