Skip to content

Commit de11139

Browse files
Updated colormap
1 parent 47655ac commit de11139

16 files changed

Lines changed: 4413 additions & 13 deletions
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
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+
" colornames = ['#646464', '#666666', '#6a6a6a', '#6f6f6f', '#737373', '#787878', '#7d7d7d', '#828282', '#878787', '#8d8d8d', '#929292', '#989898', '#9e9e9e', '#a4a4a4', '#aaaaaa', '#b0b0b0', '#b6b6b6', '#bcbcbc', '#c2c2c2', '#c9c9c9', '#cfcfcf', '#d6d6d6', '#dcdcdc', '#e3e3e3', '#eaeaea', '#efefee', '#efeee5', '#efeddc', '#efecd3', '#eeebca', '#eeeac0', '#eee9b7', '#eee8ad', '#ede7a4', '#ede69a', '#ede590', '#ede487', '#ece37d', '#ece273', '#ece069', '#ecdf5f', '#ebde55', '#ebdd4b', '#ebdc41', '#ebdb37', '#ebd333', '#ebc933', '#ecbe32', '#ecb432', '#eda931', '#ee9e31', '#ee9330', '#ef8830', '#ef7d2f', '#f0722f', '#f0672e', '#f15c2e', '#f2512d', '#f2462d', '#f33b2c', '#f3302c', '#f4252b', '#f4192b', '#ef182f', '#e81834', '#e21939', '#db1a3e', '#d51a43', '#ce1b48', '#c71b4d', '#c11c52', '#ba1c58', '#b31d5d', '#ac1d62', '#a61e67', '#9f1e6c', '#981f72', '#911f77', '#8a207c', '#842182']\n",
113+
" custom_cmap = mpl.colors.LinearSegmentedColormap.from_list('custom', colornames, N=256)\n",
114+
" plt.imshow(pathDiagram[:450, :], cmap=custom_cmap, aspect=10.9, extent=[0, nSegPoints, elo, ehi], vmin=0, vmax=vmax)\n",
115+
" ax.set_xticks(pathInds)\n",
116+
" ax.set_xticklabels(['$\\overline{\\Gamma}$', '$\\overline{\\mathrm{M}}$',\n",
117+
" '$\\overline{\\mathrm{K}}$', '$\\overline{\\Gamma}$'], fontsize=15)\n",
118+
" for p in pathInds[:-1]:\n",
119+
" ax.axvline(x=p, c='r', ls='--', lw=2, dashes=[4, 2])\n",
120+
" # ax.axhline(y=0, ls='--', color='r', lw=2)\n",
121+
" ax.yaxis.set_major_locator(MultipleLocator(2))\n",
122+
" ax.yaxis.set_minor_locator(MultipleLocator(1))\n",
123+
" ax.yaxis.set_label_position(\"right\")\n",
124+
" ax.yaxis.tick_right()\n",
125+
" ax.set_ylabel('Energy (eV)', fontsize=15, rotation=-90, labelpad=20)\n",
126+
" ax.tick_params(axis='x', length=0, pad=6)\n",
127+
" ax.tick_params(which='both', axis='y', length=8, width=2, labelsize=15)\n",
128+
" \n",
129+
" plt.savefig(save_path, dpi=200)\n",
130+
" plt.show()"
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": null,
136+
"metadata": {},
137+
"outputs": [],
138+
"source": [
139+
"# Load data\n",
140+
"data = fp.readBinnedhdf5('../data/pes/0_binned.h5')\n",
141+
"I = data['V']\n",
142+
"E = data['E']\n",
143+
"kx = data['kx']\n",
144+
"ky = data['ky']\n",
145+
"\n",
146+
"# Create reconstruction object from data file\n",
147+
"mrf = MrfRec(E=E, kx=kx, ky=ky, I=I)\n",
148+
"\n",
149+
"# Create plot folder if needed\n",
150+
"if not os.path.exists('../results/figures'):\n",
151+
" os.mkdir('../results/figures')"
152+
]
153+
},
154+
{
155+
"cell_type": "markdown",
156+
"metadata": {},
157+
"source": [
158+
"### Main Figure 1c: photoemission band mapping data"
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": null,
164+
"metadata": {
165+
"scrolled": false
166+
},
167+
"outputs": [],
168+
"source": [
169+
"plot_path(mrf, 0.5, '../results/figures/fig_1c.png')"
170+
]
171+
},
172+
{
173+
"cell_type": "markdown",
174+
"metadata": {},
175+
"source": [
176+
"### Main Figure 1d: Pattern symmetrization in $(k_x, k_y)$ plane (rotation and reflection)"
177+
]
178+
},
179+
{
180+
"cell_type": "code",
181+
"execution_count": null,
182+
"metadata": {
183+
"scrolled": true
184+
},
185+
"outputs": [],
186+
"source": [
187+
"mrf.symmetrizeI()\n",
188+
"plot_path(mrf, 0.5, '../results/figures/fig_1d.png')"
189+
]
190+
},
191+
{
192+
"cell_type": "markdown",
193+
"metadata": {},
194+
"source": [
195+
"### Main Figure 1e: Normalization and contrast enhancement (MCLAHE)\n",
196+
"MCLAHE stands for multidimensional contrast limited adaptive histogram equalization (see publication [here](https://ieeexplore.ieee.org/document/8895993))"
197+
]
198+
},
199+
{
200+
"cell_type": "code",
201+
"execution_count": null,
202+
"metadata": {
203+
"scrolled": false
204+
},
205+
"outputs": [],
206+
"source": [
207+
"mrf.normalizeI(kernel_size=(20, 20, 25), n_bins=256, clip_limit=0.15, use_gpu=True)\n",
208+
"plot_path(mrf, 1, '../results/figures/fig_1e.png')"
209+
]
210+
},
211+
{
212+
"cell_type": "markdown",
213+
"metadata": {},
214+
"source": [
215+
"### Main Figure 1f: Multidimensional smoothing using Gaussian filter"
216+
]
217+
},
218+
{
219+
"cell_type": "code",
220+
"execution_count": null,
221+
"metadata": {},
222+
"outputs": [],
223+
"source": [
224+
"mrf.smoothenI(sigma=(.8, .8, 1.))\n",
225+
"plot_path(mrf, 1, '../results/figures/fig_1f.png')"
226+
]
227+
},
228+
{
229+
"cell_type": "code",
230+
"execution_count": null,
231+
"metadata": {
232+
"pycharm": {
233+
"name": "#%%\n"
234+
}
235+
},
236+
"outputs": [],
237+
"source": [
238+
"# # Save data to disc if needed\n",
239+
"# data_save = [['axes', {'E': mrf.E, 'kx': mrf.kx, 'ky': mrf.ky}], ['binned', {'V': mrf.I}]]\n",
240+
"# saveHDF(*data_save, save_addr='../data/preprocessed.h5')"
241+
]
242+
}
243+
],
244+
"metadata": {
245+
"kernelspec": {
246+
"display_name": "Python 3 (ipykernel)",
247+
"language": "python",
248+
"name": "python3"
249+
},
250+
"language_info": {
251+
"codemirror_mode": {
252+
"name": "ipython",
253+
"version": 3
254+
},
255+
"file_extension": ".py",
256+
"mimetype": "text/x-python",
257+
"name": "python",
258+
"nbconvert_exporter": "python",
259+
"pygments_lexer": "ipython3",
260+
"version": "3.7.13"
261+
},
262+
"pycharm": {
263+
"stem_cell": {
264+
"cell_type": "raw",
265+
"metadata": {
266+
"collapsed": false
267+
},
268+
"source": ""
269+
}
270+
}
271+
},
272+
"nbformat": 4,
273+
"nbformat_minor": 2
274+
}

0 commit comments

Comments
 (0)