Skip to content

Commit

Permalink
Updated colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentStimper committed Nov 11, 2022
1 parent 47655ac commit de11139
Show file tree
Hide file tree
Showing 16 changed files with 4,413 additions and 13 deletions.
274 changes: 274 additions & 0 deletions figures/.ipynb_checkpoints/Fig1_Data_preprocessing-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
{
"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",
" 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",
" custom_cmap = mpl.colors.LinearSegmentedColormap.from_list('custom', colornames, N=256)\n",
" plt.imshow(pathDiagram[:450, :], cmap=custom_cmap, 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 de11139

Please sign in to comment.