|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "mapfile = \"../../test/makemap/map.ubi\"\n", |
| 10 | + "energy = 37.0 # keV\n", |
| 11 | + "wavelength = 12.3984 / energy\n", |
| 12 | + "symmetry = 2 # space group number\n", |
| 13 | + "# ID11 Huber tower:\n", |
| 14 | + "diffrymax = 11 # degrees\n", |
| 15 | + "rxlim = 15\n", |
| 16 | + "rylim = 20" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": null, |
| 22 | + "metadata": {}, |
| 23 | + "outputs": [], |
| 24 | + "source": [ |
| 25 | + "from ImageD11 import grain, unitcell, parameters\n", |
| 26 | + "import numpy as np\n", |
| 27 | + "\n", |
| 28 | + "from scipy.spatial.transform import Rotation\n", |
| 29 | + "\n", |
| 30 | + "def tilt_grain( gvec ):\n", |
| 31 | + " \"\"\"Solves to put gvec along rotation axis\"\"\"\n", |
| 32 | + " phix = np.arctan2( gvec[1], gvec[2] )\n", |
| 33 | + " Rx = Rotation.from_euler( 'XYZ', (phix,0,0) )\n", |
| 34 | + " grot = Rx.apply( gvec )\n", |
| 35 | + " phiy = np.arctan2( -grot[0], grot[2] )\n", |
| 36 | + " return np.degrees( phix ), np.degrees( phiy )" |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "execution_count": null, |
| 42 | + "metadata": {}, |
| 43 | + "outputs": [], |
| 44 | + "source": [ |
| 45 | + "# read the grains and determine the max tilt of the base to give a dsmax\n", |
| 46 | + "grains = grain.read_grain_file(mapfile)\n", |
| 47 | + "sinthlmax = np.sin( np.radians(diffrymax) ) / wavelength\n", |
| 48 | + "dsmax = 2*sinthlmax\n", |
| 49 | + "print(dsmax)" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": null, |
| 55 | + "metadata": {}, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "# generate reflections, assuming all grains have the same symmetry\n", |
| 59 | + "g = grains[0]\n", |
| 60 | + "uc = unitcell.unitcell( g.unitcell, symmetry )\n", |
| 61 | + "pks = uc.gethkls( dsmax )\n", |
| 62 | + "hkls = np.array( [p[1] for p in pks ] , int)" |
| 63 | + ] |
| 64 | + }, |
| 65 | + { |
| 66 | + "cell_type": "code", |
| 67 | + "execution_count": null, |
| 68 | + "metadata": {}, |
| 69 | + "outputs": [], |
| 70 | + "source": [ |
| 71 | + "# sort by size if you want to\n", |
| 72 | + "# order = np.argsort([float(g.intensity_info.split()[2]) for g in grains])\n", |
| 73 | + "print(\"Warning: needs to be re-tested, last used in 2022 !!\\n\")\n", |
| 74 | + "for i in range(len(grains)):\n", |
| 75 | + " g = grains[i]\n", |
| 76 | + " print(\"\\n\".join( [\"Grain: \"+str(i),\"UBI: \"+str(g.ubi), 'Rod: '+str(g.Rod), \"Cell: \"+str(g.unitcell) ] ) )\n", |
| 77 | + " print(' h k l d* theta rx ry ')\n", |
| 78 | + " for hkl in hkls:\n", |
| 79 | + " gvec = np.dot( g.UB, hkl )\n", |
| 80 | + " ds = np.sqrt((gvec**2).sum())\n", |
| 81 | + " rx, ry = tilt_grain( gvec )\n", |
| 82 | + " if abs(rx)<rxlim and abs(ry)<rylim:\n", |
| 83 | + " print(('%4d '*3)%tuple(hkl), ('% 9.5f '*4)%(ds, np.degrees(np.arcsin( ds * wavelength / 2)), rx, ry))\n", |
| 84 | + " print()" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "execution_count": null, |
| 90 | + "metadata": {}, |
| 91 | + "outputs": [], |
| 92 | + "source": [] |
| 93 | + } |
| 94 | + ], |
| 95 | + "metadata": { |
| 96 | + "kernelspec": { |
| 97 | + "display_name": "Python 3 (main)", |
| 98 | + "language": "python", |
| 99 | + "name": "python3" |
| 100 | + }, |
| 101 | + "language_info": { |
| 102 | + "codemirror_mode": { |
| 103 | + "name": "ipython", |
| 104 | + "version": 3 |
| 105 | + }, |
| 106 | + "file_extension": ".py", |
| 107 | + "mimetype": "text/x-python", |
| 108 | + "name": "python", |
| 109 | + "nbconvert_exporter": "python", |
| 110 | + "pygments_lexer": "ipython3", |
| 111 | + "version": "3.12.9" |
| 112 | + }, |
| 113 | + "widgets": { |
| 114 | + "application/vnd.jupyter.widget-state+json": { |
| 115 | + "state": {}, |
| 116 | + "version_major": 2, |
| 117 | + "version_minor": 0 |
| 118 | + } |
| 119 | + } |
| 120 | + }, |
| 121 | + "nbformat": 4, |
| 122 | + "nbformat_minor": 4 |
| 123 | +} |
0 commit comments