From d16eb3760522efc97eba7ca4578b5d6df636c932 Mon Sep 17 00:00:00 2001 From: Davide Tisi <47503434+DavideTisi@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:21:50 +0100 Subject: [PATCH] notebook works added test --- .../06_example_cepstrum_viscosity_h2o.ipynb | 72 ++++++++++++++++--- tests/test_notebooks.py | 7 ++ 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/examples/06_example_cepstrum_viscosity_h2o.ipynb b/examples/06_example_cepstrum_viscosity_h2o.ipynb index 960c8a0..59afda5 100644 --- a/examples/06_example_cepstrum_viscosity_h2o.ipynb +++ b/examples/06_example_cepstrum_viscosity_h2o.ipynb @@ -60,7 +60,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Temp\ts_xy\t_xz\ts_yz \n" + "Temp\ts_xy\ts_xz\ts_yz \n" ] } ], @@ -74,9 +74,63 @@ "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Temp\ts_xy\ts_xz\ts_yz \n", + " #####################################\n", + " all_ckeys = [('Temp', [0]), ('s_xy', [1]), ('s_xz', [2]), ('s_yz', [3])]\n", + " #####################################\n", + "Data length = 100000\n", + " ckey = [('Temp', [0]), ('s_xy', [1]), ('s_xz', [2]), ('s_yz', [3])]\n", + " step = 100000 - 100.00% completed\n", + " ( 100000 ) steps read.\n", + "DONE. Elapsed time: 1.4065170288085938 seconds\n" + ] + }, + { + "data": { + "text/plain": [ + "{'Temp': array([[408.14857],\n", + " [404.83967],\n", + " [400.74475],\n", + " ...,\n", + " [375.49635],\n", + " [374.86153],\n", + " [373.89371]]),\n", + " 's_xy': array([[788.37874],\n", + " [636.10743],\n", + " [478.48531],\n", + " ...,\n", + " [501.14159],\n", + " [552.52985],\n", + " [564.72988]]),\n", + " 's_xz': array([[ 14.137608],\n", + " [ -89.647884],\n", + " [-201.87593 ],\n", + " ...,\n", + " [-251.91173 ],\n", + " [-302.26323 ],\n", + " [-333.25187 ]]),\n", + " 's_yz': array([[-171.66794],\n", + " [-178.72951],\n", + " [-164.36904],\n", + " ...,\n", + " [ 633.03153],\n", + " [ 419.70789],\n", + " [ 191.02963]])}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "data = np.loadtxt('data/h2o/h2o.dat', skiprows = 1)" + "jfile = st.i_o.TableFile('./data/h2o/h2o.dat')\n", + "jfile.read_datalines()" ] }, { @@ -106,11 +160,12 @@ ], "source": [ "DT_FS = 1 # time step [fs]\n", - "TEMPERATURE = np.mean(data[:,0]) # temperature [K] (983.173 K)\n", + "TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K] (983.173 K)\n", "VOLUME = 1918.4149658 # volume [A^3]\n", "print(DT_FS, TEMPERATURE, VOLUME)\n", "\n", - "j = st.StressCurrent(data[:,1:], UNITS='real', DT_FS=DT_FS, TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)" + "j = st.StressCurrent(np.column_stack([jfile.data['s_xy'], jfile.data['s_xz'], jfile.data['s_yz']]),\n", + " UNITS='real', DT_FS=DT_FS, TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)" ] }, { @@ -629,15 +684,16 @@ "tgap = 10 # see Allen-Tildelsey's book for better understanding\n", "tcor = 10000 # maximum value of time (in timesteps) at which we want to compute the ACF \n", "acf_ = []\n", - "n = len(data[:,1:])//segments\n", + "data = np.column_stack([jfile.data['s_xy'], jfile.data['s_xz'], jfile.data['s_yz']])\n", + "n = len(data[:,1])//segments\n", "print(n)\n", "for i in range(segments):\n", + " tmp , norm = ACF(data[(i*n):(i*n+n),0],tcor,n-tcor,tgap=tgap)\n", + " acf_.append(tmp)\n", " tmp , norm = ACF(data[(i*n):(i*n+n),1],tcor,n-tcor,tgap=tgap)\n", " acf_.append(tmp)\n", " tmp , norm = ACF(data[(i*n):(i*n+n),2],tcor,n-tcor,tgap=tgap)\n", " acf_.append(tmp)\n", - " tmp , norm = ACF(data[(i*n):(i*n+n),3],tcor,n-tcor,tgap=tgap)\n", - " acf_.append(tmp)\n", " \n", "\n", "acf = np.column_stack(acf_)\n", diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py index 3c3cc7b..633b27b 100644 --- a/tests/test_notebooks.py +++ b/tests/test_notebooks.py @@ -33,6 +33,13 @@ def test_doublecomp_NaCl(tb, file_regression): def test_singlecomp_silica(tb, file_regression): res = tb.cell_output_text('results_cell') file_regression.check(res, basename='final_result2') + +@local_dir +@testbook(test_folder_path + '/../examples/06_example_cepstrum_viscosity_h2o.ipynb', execute=True) +def test_singlecomp_silica(tb, file_regression): + res = tb.cell_output_text('results_cell') + file_regression.check(res, basename='final_result6') + @local_dir