nanoparticle_example.ipynb 4.05 KB
Newer Older
1 2
{
 "cells": [
Ida's avatar
Ida committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Atomap demo: Finding an atom lattice"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this demo the atom lattice of a nanoparticle will be found. The image is a STEM-simulation. The example will demonstrate how an atom lattice is found manually."
   ]
  },
17 18
  {
   "cell_type": "code",
Ida's avatar
Ida committed
19
   "execution_count": null,
Magnus Nord's avatar
Magnus Nord committed
20 21 22 23 24
   "metadata": {
    "tags": [
     "nbval-skip"
    ]
   },
25 26
   "outputs": [],
   "source": [
27
    "%matplotlib nbagg"
28 29 30 31
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
32
   "execution_count": null,
33
   "metadata": {},
Ida's avatar
Ida committed
34
   "outputs": [],
35
   "source": [
36 37
    "import hyperspy.api as hs\n",
    "import atomap.api as am"
38 39 40 41
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
42
   "execution_count": null,
43
   "metadata": {},
44 45
   "outputs": [],
   "source": [
46 47
    "s = hs.load(\"simulated_nanoparticle.tif\")\n",
    "s.change_dtype('float64')"
48 49 50
   ]
  },
  {
51 52
   "cell_type": "markdown",
   "metadata": {},
53
   "source": [
54
    "The important variable here is `threshold_rel`, means that very low intensity image values are ignored."
55 56 57 58
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
59
   "execution_count": null,
60
   "metadata": {},
Ida's avatar
Ida committed
61
   "outputs": [],
62 63 64 65 66 67
   "source": [
    "s_separation = am.get_feature_separation(s, separation_range=(2,7), threshold_rel=0.03)"
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
68
   "execution_count": null,
69 70 71
   "metadata": {
    "scrolled": false
   },
Ida's avatar
Ida committed
72
   "outputs": [],
73 74 75 76
   "source": [
    "s_separation.plot()"
   ]
  },
77 78 79 80 81 82 83
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A `separation` of 4 works well for this dataset"
   ]
  },
84 85
  {
   "cell_type": "code",
Ida's avatar
Ida committed
86
   "execution_count": null,
87
   "metadata": {},
88 89 90 91 92 93 94
   "outputs": [],
   "source": [
    "atom_positions = am.get_atom_positions(s, 4, threshold_rel=0.03)"
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
95
   "execution_count": null,
96
   "metadata": {},
97 98 99 100 101 102 103
   "outputs": [],
   "source": [
    "sublattice = am.Sublattice(atom_position_list=atom_positions, image=s.data)"
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
104
   "execution_count": null,
105 106 107
   "metadata": {
    "scrolled": false
   },
Ida's avatar
Ida committed
108
   "outputs": [],
109
   "source": [
110
    "sublattice.plot()"
111 112 113 114
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
115
   "execution_count": null,
116
   "metadata": {},
117 118 119 120 121 122 123
   "outputs": [],
   "source": [
    "sublattice.construct_zone_axes()"
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
124
   "execution_count": null,
125
   "metadata": {},
Ida's avatar
Ida committed
126
   "outputs": [],
127 128 129 130 131 132
   "source": [
    "sublattice.refine_atom_positions_using_center_of_mass(sublattice.image)"
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
133
   "execution_count": null,
134
   "metadata": {},
Ida's avatar
Ida committed
135
   "outputs": [],
136 137 138 139 140 141
   "source": [
    "sublattice.refine_atom_positions_using_2d_gaussian(sublattice.image)"
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
142
   "execution_count": null,
143
   "metadata": {
144
    "scrolled": false
145
   },
Ida's avatar
Ida committed
146
   "outputs": [],
147
   "source": [
Ida's avatar
Ida committed
148
    "sublattice.plot_planes()"
149 150 151 152
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
153
   "execution_count": null,
154 155 156 157 158 159 160 161 162 163
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "s_monolayer = sublattice.get_monolayer_distance_map()"
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
164
   "execution_count": null,
165
   "metadata": {
166
    "scrolled": false
167
   },
Ida's avatar
Ida committed
168
   "outputs": [],
169 170 171 172 173 174
   "source": [
    "s_monolayer.plot()"
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
175
   "execution_count": null,
176
   "metadata": {},
177 178 179 180 181 182 183
   "outputs": [],
   "source": [
    "atom_lattice = am.Atom_Lattice(sublattice_list=[sublattice], image=s.data, name=\"simulated nanoparticle\")"
   ]
  },
  {
   "cell_type": "code",
Ida's avatar
Ida committed
184
   "execution_count": null,
185
   "metadata": {},
186 187 188 189 190 191 192 193
   "outputs": [],
   "source": [
    "atom_lattice.save(\"nanoparticle_atom_lattice.hdf5\", overwrite=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
Magnus Nord's avatar
Magnus Nord committed
194
   "display_name": "Python 3",
195
   "language": "python",
Magnus Nord's avatar
Magnus Nord committed
196
   "name": "python3"
197 198 199 200 201 202 203 204 205 206 207
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
208
   "version": "3.6.7"
209 210 211 212 213
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}