{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import packages\n",
    "import h5py                     # hdf5 reader\n",
    "import os                       # to determine current working directory\n",
    "import numpy as np              # numpy\n",
    "import matplotlib.pyplot as plt # plotting\n",
    "\n",
    "plt.rcParams.update({\n",
    "    \"pgf.texsystem\": \"pdflatex\",  # Use pdflatex for compatibility\n",
    "    \"text.usetex\": True,           # Use LaTeX for text rendering\n",
    "    \"font.family\": \"serif\",        # Use serif fonts\n",
    "    \"pgf.preamble\": r\"\\usepackage{amsmath}\",  # Add any necessary packages\n",
    "    \"pgf.rcfonts\": False,          # Disable rc fonts to avoid extra font definitions\n",
    "    \"font.size\": 22,\n",
    "    \"figure.figsize\": (6,6)\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#load data\n",
    "path_results = 'raw-data/KL.hdf'\n",
    "with h5py.File(path_results, 'r') as f:\n",
    "    print(f.keys())\n",
    "    dimension = f['Dimension'][()]\n",
    "    eigen_values = f['SingularValues'][:]**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# determine slope\n",
    "k = np.arange(0,dimension)+1\n",
    "slope_eigen_values = -4.5\n",
    "offset_eigen_values = 17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.subplots(constrained_layout=True)\n",
    "# plotting\n",
    "plt.loglog(k,eigen_values,'+')\n",
    "plt.loglog(k,np.e**offset_eigen_values*k**slope_eigen_values,'--',color='black')\n",
    "plt.xlabel('k')\n",
    "plt.ylim(1e-5,1e3)\n",
    "plt.legend(['eigenvalues','$k^{'+str(slope_eigen_values)+'}=k^{2p}$'], loc='lower left')\n",
    "plt.title('Eigenvalues of covariance operator')\n",
    "plt.savefig('plots/eigen_values.eps')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
