Skip to content

Commit 47655ac

Browse files
Vs dev (#1)
* Added nbs to generate figures for paper * Updated readme
1 parent 98dbed8 commit 47655ac

20 files changed

Lines changed: 5222 additions & 0 deletions
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Stages of data preprocessing"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import warnings as wn\n",
17+
"wn.filterwarnings(\"ignore\")\n",
18+
"\n",
19+
"import numpy as np\n",
20+
"from fuller.mrfRec import MrfRec\n",
21+
"from fuller.generator import rotosymmetrize\n",
22+
"from fuller.utils import saveHDF\n",
23+
"from mpes import analysis as aly, fprocessing as fp\n",
24+
"\n",
25+
"import os\n",
26+
"import matplotlib.pyplot as plt\n",
27+
"import matplotlib as mpl\n",
28+
"from matplotlib.ticker import MultipleLocator, FormatStrFormatter\n",
29+
"%matplotlib inline\n",
30+
"\n",
31+
"# mpl.rcParams['font.family'] = 'sans-serif'\n",
32+
"# mpl.rcParams['font.sans-serif'] = 'Arial'\n",
33+
"mpl.rcParams['axes.linewidth'] = 2\n",
34+
"mpl.rcParams['pdf.fonttype'] = 42\n",
35+
"mpl.rcParams['ps.fonttype'] = 42"
36+
]
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"metadata": {},
41+
"source": [
42+
"Before we start with the preprocessing, we determine the location of the high symmetry points which we need for plotting the data. For simplicity and linearity of the code, we do this using the symmetrized data from file but of course we could also do the preprocessing first before plotting the resulting data."
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"fdata = fp.readBinnedhdf5('../data/pes/1_sym.h5')\n",
52+
"mc = aly.MomentumCorrector(fdata['V'])\n",
53+
"\n",
54+
"mc.selectSlice2D(selector=slice(30, 32), axis=2)\n",
55+
"mc.featureExtract(mc.slice, method='daofind', sigma=6, fwhm=20, symscores=False)\n",
56+
"\n",
57+
"# False detection filter, if needed\n",
58+
"try:\n",
59+
" mc.pouter_ord = mc.pouter_ord[[0,1,3,5,6,9],:]\n",
60+
"except:\n",
61+
" pass"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"mc.view(image=mc.slice, annotated=True, points=mc.features)"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": null,
76+
"metadata": {},
77+
"outputs": [],
78+
"source": [
79+
"# Define high-symmetry points\n",
80+
"G = mc.pcent # Gamma point\n",
81+
"K = mc.pouter_ord[0,:] # K point\n",
82+
"K1 = mc.pouter_ord[1,:] # K' point\n",
83+
"M = (K + K1) / 2 # M point\n",
84+
"\n",
85+
"# Define cutting path\n",
86+
"pathPoints = np.asarray([G, M, K, G])\n",
87+
"nGM, nMK, nKG = 70, 39, 79\n",
88+
"segPoints = [nGM, nMK, nKG]\n",
89+
"rowInds, colInds, pathInds = aly.points2path(pathPoints[:,0], pathPoints[:,1], npoints=segPoints)\n",
90+
"nSegPoints = len(rowInds)"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": null,
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"# Define plotting function\n",
100+
"\n",
101+
"def plot_path(mrf, vmax, save_path):\n",
102+
" # Normalize data\n",
103+
" imNorm = mrf.I / mrf.I.max()\n",
104+
"\n",
105+
" # Sample the data along high-symmetry lines (k-path) connecting the corresponding high-symmetry points\n",
106+
" pathDiagram = aly.bandpath_map(imNorm, pathr=rowInds, pathc=colInds, eaxis=2)\n",
107+
"\n",
108+
" Evals = mrf.E\n",
109+
" ehi, elo = Evals[0], Evals[449]\n",
110+
"\n",
111+
" f, ax = plt.subplots(figsize=(10, 6))\n",
112+
" plt.imshow(pathDiagram[:450, :], cmap='Blues', aspect=10.9, extent=[0, nSegPoints, elo, ehi], vmin=0, vmax=vmax)\n",
113+
" ax.set_xticks(pathInds)\n",
114+
" ax.set_xticklabels(['$\\overline{\\Gamma}$', '$\\overline{\\mathrm{M}}$',\n",
115+
" '$\\overline{\\mathrm{K}}$', '$\\overline{\\Gamma}$'], fontsize=15)\n",
116+
" for p in pathInds[:-1]:\n",
117+
" ax.axvline(x=p, c='r', ls='--', lw=2, dashes=[4, 2])\n",
118+
" # ax.axhline(y=0, ls='--', color='r', lw=2)\n",
119+
" ax.yaxis.set_major_locator(MultipleLocator(2))\n",
120+
" ax.yaxis.set_minor_locator(MultipleLocator(1))\n",
121+
" ax.yaxis.set_label_position(\"right\")\n",
122+
" ax.yaxis.tick_right()\n",
123+
" ax.set_ylabel('Energy (eV)', fontsize=15, rotation=-90, labelpad=20)\n",
124+
" ax.tick_params(axis='x', length=0, pad=6)\n",
125+
" ax.tick_params(which='both', axis='y', length=8, width=2, labelsize=15)\n",
126+
" \n",
127+
" plt.savefig(save_path, dpi=200)\n",
128+
" plt.show()"
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": null,
134+
"metadata": {},
135+
"outputs": [],
136+
"source": [
137+
"# Load data\n",
138+
"data = fp.readBinnedhdf5('../data/pes/0_binned.h5')\n",
139+
"I = data['V']\n",
140+
"E = data['E']\n",
141+
"kx = data['kx']\n",
142+
"ky = data['ky']\n",
143+
"\n",
144+
"# Create reconstruction object from data file\n",
145+
"mrf = MrfRec(E=E, kx=kx, ky=ky, I=I)\n",
146+
"\n",
147+
"# Create plot folder if needed\n",
148+
"if not os.path.exists('../results/figures'):\n",
149+
" os.mkdir('../results/figures')"
150+
]
151+
},
152+
{
153+
"cell_type": "markdown",
154+
"metadata": {},
155+
"source": [
156+
"### Main Figure 1c: photoemission band mapping data"
157+
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": null,
162+
"metadata": {
163+
"scrolled": false
164+
},
165+
"outputs": [],
166+
"source": [
167+
"plot_path(mrf, 0.5, '../results/figures/fig_1c.png')"
168+
]
169+
},
170+
{
171+
"cell_type": "markdown",
172+
"metadata": {},
173+
"source": [
174+
"### Main Figure 1d: Pattern symmetrization in $(k_x, k_y)$ plane (rotation and reflection)"
175+
]
176+
},
177+
{
178+
"cell_type": "code",
179+
"execution_count": null,
180+
"metadata": {
181+
"scrolled": true
182+
},
183+
"outputs": [],
184+
"source": [
185+
"mrf.symmetrizeI()\n",
186+
"plot_path(mrf, 0.5, '../results/figures/fig_1d.png')"
187+
]
188+
},
189+
{
190+
"cell_type": "markdown",
191+
"metadata": {},
192+
"source": [
193+
"### Main Figure 1e: Normalization and contrast enhancement (MCLAHE)\n",
194+
"MCLAHE stands for multidimensional contrast limited adaptive histogram equalization (see publication [here](https://ieeexplore.ieee.org/document/8895993))"
195+
]
196+
},
197+
{
198+
"cell_type": "code",
199+
"execution_count": null,
200+
"metadata": {
201+
"scrolled": false
202+
},
203+
"outputs": [],
204+
"source": [
205+
"mrf.normalizeI(kernel_size=(20, 20, 25), n_bins=256, clip_limit=0.15, use_gpu=True)\n",
206+
"plot_path(mrf, 1, '../results/figures/fig_1e.png')"
207+
]
208+
},
209+
{
210+
"cell_type": "markdown",
211+
"metadata": {},
212+
"source": [
213+
"### Main Figure 1f: Multidimensional smoothing using Gaussian filter"
214+
]
215+
},
216+
{
217+
"cell_type": "code",
218+
"execution_count": null,
219+
"metadata": {},
220+
"outputs": [],
221+
"source": [
222+
"mrf.smoothenI(sigma=(.8, .8, 1.))\n",
223+
"plot_path(mrf, 1, '../results/figures/fig_1f.png')"
224+
]
225+
},
226+
{
227+
"cell_type": "code",
228+
"execution_count": null,
229+
"metadata": {
230+
"pycharm": {
231+
"name": "#%%\n"
232+
}
233+
},
234+
"outputs": [],
235+
"source": [
236+
"# # Save data to disc if needed\n",
237+
"# data_save = [['axes', {'E': mrf.E, 'kx': mrf.kx, 'ky': mrf.ky}], ['binned', {'V': mrf.I}]]\n",
238+
"# saveHDF(*data_save, save_addr='../data/preprocessed.h5')"
239+
]
240+
}
241+
],
242+
"metadata": {
243+
"kernelspec": {
244+
"display_name": "Python 3 (ipykernel)",
245+
"language": "python",
246+
"name": "python3"
247+
},
248+
"language_info": {
249+
"codemirror_mode": {
250+
"name": "ipython",
251+
"version": 3
252+
},
253+
"file_extension": ".py",
254+
"mimetype": "text/x-python",
255+
"name": "python",
256+
"nbconvert_exporter": "python",
257+
"pygments_lexer": "ipython3",
258+
"version": "3.7.13"
259+
},
260+
"pycharm": {
261+
"stem_cell": {
262+
"cell_type": "raw",
263+
"metadata": {
264+
"collapsed": false
265+
},
266+
"source": ""
267+
}
268+
}
269+
},
270+
"nbformat": 4,
271+
"nbformat_minor": 2
272+
}

0 commit comments

Comments
 (0)