Skip to content

Commit

Permalink
Vs dev (#1)
Browse files Browse the repository at this point in the history
* Added nbs to generate figures for paper

* Updated readme
  • Loading branch information
VincentStimper authored Nov 11, 2022
1 parent 98dbed8 commit 47655ac
Show file tree
Hide file tree
Showing 20 changed files with 5,222 additions and 0 deletions.
272 changes: 272 additions & 0 deletions figures/Fig1_Data_preprocessing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Stages of data preprocessing"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import warnings as wn\n",
"wn.filterwarnings(\"ignore\")\n",
"\n",
"import numpy as np\n",
"from fuller.mrfRec import MrfRec\n",
"from fuller.generator import rotosymmetrize\n",
"from fuller.utils import saveHDF\n",
"from mpes import analysis as aly, fprocessing as fp\n",
"\n",
"import os\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib as mpl\n",
"from matplotlib.ticker import MultipleLocator, FormatStrFormatter\n",
"%matplotlib inline\n",
"\n",
"# mpl.rcParams['font.family'] = 'sans-serif'\n",
"# mpl.rcParams['font.sans-serif'] = 'Arial'\n",
"mpl.rcParams['axes.linewidth'] = 2\n",
"mpl.rcParams['pdf.fonttype'] = 42\n",
"mpl.rcParams['ps.fonttype'] = 42"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fdata = fp.readBinnedhdf5('../data/pes/1_sym.h5')\n",
"mc = aly.MomentumCorrector(fdata['V'])\n",
"\n",
"mc.selectSlice2D(selector=slice(30, 32), axis=2)\n",
"mc.featureExtract(mc.slice, method='daofind', sigma=6, fwhm=20, symscores=False)\n",
"\n",
"# False detection filter, if needed\n",
"try:\n",
" mc.pouter_ord = mc.pouter_ord[[0,1,3,5,6,9],:]\n",
"except:\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mc.view(image=mc.slice, annotated=True, points=mc.features)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Define high-symmetry points\n",
"G = mc.pcent # Gamma point\n",
"K = mc.pouter_ord[0,:] # K point\n",
"K1 = mc.pouter_ord[1,:] # K' point\n",
"M = (K + K1) / 2 # M point\n",
"\n",
"# Define cutting path\n",
"pathPoints = np.asarray([G, M, K, G])\n",
"nGM, nMK, nKG = 70, 39, 79\n",
"segPoints = [nGM, nMK, nKG]\n",
"rowInds, colInds, pathInds = aly.points2path(pathPoints[:,0], pathPoints[:,1], npoints=segPoints)\n",
"nSegPoints = len(rowInds)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Define plotting function\n",
"\n",
"def plot_path(mrf, vmax, save_path):\n",
" # Normalize data\n",
" imNorm = mrf.I / mrf.I.max()\n",
"\n",
" # Sample the data along high-symmetry lines (k-path) connecting the corresponding high-symmetry points\n",
" pathDiagram = aly.bandpath_map(imNorm, pathr=rowInds, pathc=colInds, eaxis=2)\n",
"\n",
" Evals = mrf.E\n",
" ehi, elo = Evals[0], Evals[449]\n",
"\n",
" f, ax = plt.subplots(figsize=(10, 6))\n",
" plt.imshow(pathDiagram[:450, :], cmap='Blues', aspect=10.9, extent=[0, nSegPoints, elo, ehi], vmin=0, vmax=vmax)\n",
" ax.set_xticks(pathInds)\n",
" ax.set_xticklabels(['$\\overline{\\Gamma}$', '$\\overline{\\mathrm{M}}$',\n",
" '$\\overline{\\mathrm{K}}$', '$\\overline{\\Gamma}$'], fontsize=15)\n",
" for p in pathInds[:-1]:\n",
" ax.axvline(x=p, c='r', ls='--', lw=2, dashes=[4, 2])\n",
" # ax.axhline(y=0, ls='--', color='r', lw=2)\n",
" ax.yaxis.set_major_locator(MultipleLocator(2))\n",
" ax.yaxis.set_minor_locator(MultipleLocator(1))\n",
" ax.yaxis.set_label_position(\"right\")\n",
" ax.yaxis.tick_right()\n",
" ax.set_ylabel('Energy (eV)', fontsize=15, rotation=-90, labelpad=20)\n",
" ax.tick_params(axis='x', length=0, pad=6)\n",
" ax.tick_params(which='both', axis='y', length=8, width=2, labelsize=15)\n",
" \n",
" plt.savefig(save_path, dpi=200)\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load data\n",
"data = fp.readBinnedhdf5('../data/pes/0_binned.h5')\n",
"I = data['V']\n",
"E = data['E']\n",
"kx = data['kx']\n",
"ky = data['ky']\n",
"\n",
"# Create reconstruction object from data file\n",
"mrf = MrfRec(E=E, kx=kx, ky=ky, I=I)\n",
"\n",
"# Create plot folder if needed\n",
"if not os.path.exists('../results/figures'):\n",
" os.mkdir('../results/figures')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Main Figure 1c: photoemission band mapping data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"plot_path(mrf, 0.5, '../results/figures/fig_1c.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Main Figure 1d: Pattern symmetrization in $(k_x, k_y)$ plane (rotation and reflection)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"mrf.symmetrizeI()\n",
"plot_path(mrf, 0.5, '../results/figures/fig_1d.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Main Figure 1e: Normalization and contrast enhancement (MCLAHE)\n",
"MCLAHE stands for multidimensional contrast limited adaptive histogram equalization (see publication [here](https://ieeexplore.ieee.org/document/8895993))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"mrf.normalizeI(kernel_size=(20, 20, 25), n_bins=256, clip_limit=0.15, use_gpu=True)\n",
"plot_path(mrf, 1, '../results/figures/fig_1e.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Main Figure 1f: Multidimensional smoothing using Gaussian filter"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mrf.smoothenI(sigma=(.8, .8, 1.))\n",
"plot_path(mrf, 1, '../results/figures/fig_1f.png')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"# # Save data to disc if needed\n",
"# data_save = [['axes', {'E': mrf.E, 'kx': mrf.kx, 'ky': mrf.ky}], ['binned', {'V': mrf.I}]]\n",
"# saveHDF(*data_save, save_addr='../data/preprocessed.h5')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.7.13"
},
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"metadata": {
"collapsed": false
},
"source": ""
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 47655ac

Please sign in to comment.