Commit 01c01090 authored by lapm's avatar lapm
Browse files

Summary plot of CXG006-01 and EpoxyData-01

parent 2dc6159d
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Summary plot of data-analysis\n",
"\n",
"Lars P. Mikkelsen (lapm@dtu.dk), Composite and Materials Mechanics, DTU Wind Energy, Fall 2020.\n",
"\n",
"The the following, a demonstration of how to make a data-analysis of multiple measurements can be performed."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import DataAnalysisFuncV1b as daf # Import functions for data analysis\n",
"import scipy.io\n",
"\n",
"# For Jupyter Notebook plotning\n",
"%matplotlib inline \n",
"#%matplotlib notebook \n",
"\n",
"SpecNames=('EpoxyData-01','EpoxyData-02')\n",
"LineTypes=('-r','-b','-g','--r','--b','--g',':r',':b',':g')\n",
"StrainRange = (0.05,0.25)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialize the arrays used for summery"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"Strains0=[]; Stresses0=[];\n",
"Strains=[]; Stresses=[]; Times=[]; Areas=[]; \n",
"MaxStresses=[]; MaxStrains=[]; \n",
"MaxStresses0=[]; MaxStrains0=[]; \n",
"MaxStresses0End=[]; MaxStrains0End=[]; \n",
"Emods=[]; EpsRates=[]; TableData=[]\n",
"pEmods0=[];pEmods1=[]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read the analysis results from the mat-file"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Specimen name: EpoxyData-01\n"
]
},
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: 'EpoxyData-01.mat'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\io\\matlab\\mio.py\u001b[0m in \u001b[0;36m_open_file\u001b[1;34m(file_like, appendmat, mode)\u001b[0m\n\u001b[0;32m 38\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 39\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_like\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 40\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mIOError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'EpoxyData-01.mat'",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-3-0be580d3f6ad>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;31m# Read mat-file\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Specimen name:'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mSpecName\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mmatvar\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mscipy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mio\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloadmat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mSpecName\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m'.mat'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;31m# Read array variable\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\io\\matlab\\mio.py\u001b[0m in \u001b[0;36mloadmat\u001b[1;34m(file_name, mdict, appendmat, **kwargs)\u001b[0m\n\u001b[0;32m 214\u001b[0m \"\"\"\n\u001b[0;32m 215\u001b[0m \u001b[0mvariable_names\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'variable_names'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 216\u001b[1;33m \u001b[1;32mwith\u001b[0m \u001b[0m_open_file_context\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_name\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mappendmat\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 217\u001b[0m \u001b[0mMR\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmat_reader_factory\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 218\u001b[0m \u001b[0mmatfile_dict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mMR\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_variables\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvariable_names\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\contextlib.py\u001b[0m in \u001b[0;36m__enter__\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 110\u001b[0m \u001b[1;32mdel\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 111\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 112\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgen\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 113\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 114\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"generator didn't yield\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\io\\matlab\\mio.py\u001b[0m in \u001b[0;36m_open_file_context\u001b[1;34m(file_like, appendmat, mode)\u001b[0m\n\u001b[0;32m 17\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mcontextmanager\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_open_file_context\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_like\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mappendmat\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'rb'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m \u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mopened\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_open_file\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_like\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mappendmat\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 20\u001b[0m \u001b[1;32myield\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mopened\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\io\\matlab\\mio.py\u001b[0m in \u001b[0;36m_open_file\u001b[1;34m(file_like, appendmat, mode)\u001b[0m\n\u001b[0;32m 43\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mappendmat\u001b[0m \u001b[1;32mand\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mfile_like\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mendswith\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'.mat'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 44\u001b[0m \u001b[0mfile_like\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;34m'.mat'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 45\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_like\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 46\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 47\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mIOError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Reader needs file name or open file-like object'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'EpoxyData-01.mat'"
]
}
],
"source": [
"i=0\n",
"for SpecName in SpecNames:\n",
" # Read mat-file\n",
" print('Specimen name:',SpecName)\n",
" matvar=scipy.io.loadmat(SpecName+'.mat')\n",
" \n",
" # Read array variable\n",
" Times.append(matvar.get('Time').flatten())\n",
" Stresses.append(matvar.get('Stress').flatten())\n",
" Strains.append(matvar.get('Strain').flatten())\n",
" Stresses0.append(matvar.get('Stress0').flatten())\n",
" Strains0.append(matvar.get('Strain0').flatten())\n",
" \n",
" # Read scalar values \n",
" Areas.append(matvar.get('area').flatten()[0])\n",
" MaxStresses.append(matvar.get('MaxStress').flatten()[0])\n",
" MaxStrains.append(matvar.get('MaxStrain').flatten()[0])\n",
" MaxStresses0.append(matvar.get('MaxStress0').flatten()[0])\n",
" MaxStrains0.append(matvar.get('MaxStrain0').flatten()[0])\n",
" MaxStresses0End.append(matvar.get('MaxStress0End').flatten()[0])\n",
" MaxStrains0End.append(matvar.get('MaxStrain0End').flatten()[0])\n",
" Emods.append(matvar.get('Emod').flatten()[0])\n",
" EpsRates.append(matvar.get('EpsRate').flatten()[0])\n",
" pEmods0.append(matvar.get('pEmod').flatten()[0])\n",
" pEmods1.append(matvar.get('pEmod').flatten()[1])\n",
" \n",
" \n",
" # Save table\n",
" TableHeading=(['Area [mm^2]','EpsRate [%/s]','Young Modulus [GPa]','Max Stress [MPa]','Max Strain [%]'])\n",
" TableData.append([Areas[-1],EpsRates[-1],Emods[-1],MaxStresses[-1],MaxStrains0End[-1]])\n",
" i=i+1 "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot summery of data\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"plt.figure(figsize=(10,5))\n",
"for SpecName,LineType,Time,Strain in zip(SpecNames,LineTypes,Times,Strains):\n",
" plt.plot(Time,Strain,LineType,label=SpecName)\n",
"\n",
"plt.ylabel(r'$\\varepsilon_{ln}$ [%]',fontsize=18)\n",
"plt.xlabel(r'Time [s]',fontsize=18)\n",
"plt.legend(loc=4)\n",
"plt.grid()\n",
"plt.show()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Calculate mean values"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pEmodmean=(np.mean(pEmods0),np.mean(pEmods1))\n",
"Emodmean=np.mean(Emods)\n",
"EmodSTDmean=np.std(Emods)/np.sqrt(len(Emods))\n",
"StrainFit=np.arange(0,np.max(Strain)/2.0)\n",
"(ia,ib) = daf.FuncRange(Strain,StrainRange)\n",
"MaxStressmean=np.mean(MaxStresses)\n",
"MaxStressSTDmean=np.std(MaxStresses)/np.sqrt(len(MaxStresses))\n",
"MaxStrainmean=np.mean(MaxStrains)\n",
"MaxStress0mean=np.mean(MaxStresses0)\n",
"MaxStress0STDmean=np.std(MaxStresses0)/np.sqrt(len(MaxStresses0))\n",
"MaxStrain0mean=np.mean(MaxStrains0)\n",
"MaxStress0Endmean=np.mean(MaxStresses0End)\n",
"MaxStress0EndSTDmean=np.std(MaxStresses0End)/np.sqrt(len(MaxStresses0End))\n",
"MaxStrain0Endmean=np.mean(MaxStrains0End)\n",
"MaxStrain0EndSTDmean=np.std(MaxStrains0End)/np.sqrt(len(MaxStrains0End))\n",
"EmodmeanStr = r'E=(%4.3f $\\pm$ %4.3f) GPa' % (Emodmean,EmodSTDmean)\n",
"MaxStressmeanStr = r'$\\sigma_t^{max}=(%4.1f \\pm$ %2.1f) MPa' % (MaxStressmean,MaxStressSTDmean)\n",
"MaxStress0meanStr = r'$\\sigma_n^{max}=(%4.1f \\pm$ %2.1f) MPa' % (MaxStress0mean,MaxStress0STDmean)\n",
"MaxStrain0EndmeanStr = r'$\\varepsilon_e^{max}=(%4.1f \\pm$ %2.1f) %%' % (MaxStrain0Endmean,MaxStrain0EndSTDmean)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Summary plot of nominal stress-strain curves"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"plt.figure()\n",
"for SpecName,LineType,Strain,Stress in zip(SpecNames,LineTypes, Strains0,Stresses0):\n",
" plt.plot(Strain,Stress,LineType,label=SpecName)\n",
"plt.plot(MaxStrain0mean,MaxStress0mean,'kx',label=MaxStress0meanStr)\n",
"plt.plot(MaxStrain0Endmean,MaxStress0Endmean,'ko',label=MaxStrain0EndmeanStr)\n",
"plt.xlabel(r'$\\varepsilon_{e}$ [%]',fontsize=18)\n",
"plt.ylabel(r'$\\sigma_n$ [MPa]',fontsize=18)\n",
"plt.legend(loc=4)\n",
"plt.grid() \n",
"plt.savefig('Summary0.png', bbox_inches='tight') \n",
"plt.show() "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Summary plot of true stress-strain curves"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"\n",
"plt.figure()\n",
"for SpecName,LineType,Strain,Stress in zip(SpecNames,LineTypes, Strains,Stresses):\n",
" plt.plot(Strain,Stress,LineType,label=SpecName)\n",
"plt.plot(StrainFit,np.polyval(pEmodmean,StrainFit),':k',linewidth=2,label='E fit line')\n",
"plt.plot(StrainRange,np.polyval(pEmodmean,StrainRange),'-k',linewidth=4,label=EmodmeanStr)\n",
"plt.plot(MaxStrainmean,MaxStressmean,'kx',label=MaxStressmeanStr)\n",
"plt.xlabel(r'$\\varepsilon_{ln}$ [%]',fontsize=18)\n",
"plt.ylabel(r'$\\sigma_t$ [MPa]',fontsize=18)\n",
"plt.legend(loc=4)\n",
"plt.grid() \n",
"plt.savefig('Summary.png', bbox_inches='tight') \n",
"plt.show() \n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot tabel of values"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"TableDataExt=TableData\n",
"SpecNamesExt=SpecNames+tuple(['Mean','STD','STDmean'])\n",
"TableDataExt.append([np.mean(Areas),np.mean(EpsRates),np.mean(Emods),np.mean(MaxStresses),np.mean(MaxStrains0End)])\n",
"TableDataExt.append([np.std(Areas),np.std(EpsRates),np.std(Emods),np.std(MaxStresses),np.std(MaxStrains0End)])\n",
"TableDataExt.append([np.std(Areas),np.std(EpsRates),np.std(Emods),np.std(MaxStresses),np.std(MaxStrains0End)]/np.sqrt(len(Areas)))\n",
"daf.PlotTable(TableHeading,SpecNamesExt,TableDataExt)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save table to csv-file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas\n",
"df = pandas.DataFrame(data={\"SpecNames\":SpecNames, \"Area\":Areas, \"EpsRate\":EpsRates,\"Emod\":Emods,\"MaxStress\":MaxStresses,\"MaxStrains\":MaxStrains0End})\n",
"df.to_csv('Summery.csv',sep=';',index=False)"
]
}
],
"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.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment