diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a277040 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,51 @@ +# Install pre-commit hooks via +# pre-commit install + +- repo: local + hooks: + # yapf = yet another python formatter + - id: yapf + name: yapf + entry: yapf + language: system + types: [python] + args: ["-i"] + exclude: &exclude_files > + (?x)^( + thermocepstrum_gui/utils/tk_html_widgets/*.py| + docs/.*| + examples/.*| + setup.py| + )$ + +- repo: git://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: check-merge-conflict + - id: check-symlinks + - id: check-json + - id: check-executables-have-shebangs + - id: double-quote-string-fixer + - id: end-of-file-fixer + - id: trailing-whitespace + exclude: > + (?x)^( + thermocepstrum_gui/utils/tk_html_widgets/*.py| + docs/.*| + examples/.*| + )$ + +# # prospector: collection of linters +# - id: prospector +# language: system +# types: [file, python] +# name: prospector +# description: "This hook runs Prospector: https://github.com/landscapeio/prospector" +# entry: prospector +# +# - id: version-number +# name: Check version numbers +# entry: python ./.travis-data/check_version.py +# language: system +# files: '^(setup.json)|(aiida_diff/__init__.py)' diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 0000000..c21132a --- /dev/null +++ b/.style.yapf @@ -0,0 +1,6 @@ +[style] +based_on_style=google +column_limit=120 +spaces_before_comment=3 +disable_ending_comma_heuristic=True +SPLIT_BEFORE_NAMED_ASSIGNS=False diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..13cc1c3 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,11 @@ +recursive-include examples * +include LICENSE.txt +include setup.json +include thermocepstrum/README.md +include thermocepstrum/metadata.json +include thermocepstrum/utils/plot_style.mplstyle +exclude thermocepstrum/utils/blocks.py +exclude thermocepstrum/utils/blockanalysis.py +include thermocepstrum_gui/README_GUI.md +include thermocepstrum_gui/assets/icon.gif +include thermocepstrum_gui/assets/languages.json diff --git a/README.md b/README.md index 293eb18..8dbe0d2 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,51 @@ # thermocepstrum Code to compute thermal conductivity through cepstral analysis of heat flux time series, as described in papers: - - Ercole, Marcolongo, Baroni, Sci. Rep. 7, 15835 (2017), https://doi.org/10.1038/s41598-017-15843-2 - - for the multi-component analysis: Baroni, Bertossa, Ercole, Grasselli, Marcolongo, https://arxiv.org/abs/1802.08006 -**Acknowledgement** The development of this software is part of the scientific program of the EU MaX Centre of Excellence for Supercomputing Applications (Grant No. 676598) and has been partly funded through it. + - (cepstral analysis) [Ercole, Marcolongo, Baroni, *Sci. Rep.* **7**, 15835 (2017)](https://doi.org/10.1038/s41598-017-15843-2) + - (multicomponent systems) [Bertossa, Grasselli, Ercole, Baroni, *Phys. Rev. Lett.* **122**, 255901 (2019)](https://doi.org/10.1103/PhysRevLett.122.255901) ([arXiv](https://arxiv.org/abs/1808.03341)) + - (review) [Baroni, Bertossa, Ercole, Grasselli, Marcolongo, *Handbook of Materials Modeling* (2018)](https://doi.org/10.1007/978-3-319-50257-1_12-1) ([arXiv](https://arxiv.org/abs/1802.08006)) + +**Acknowledgment** The development of this software is part of the scientific program of the EU MaX Centre of Excellence for Supercomputing Applications (Grant No. 676598, 824143) and has been partly funded through it. ### Usage -The code can be used as a **library**, for example in a Jupyter notebook. -In the `examples` folder you can find some examples. +There is a [**GUI**](README_GUI.md) that you can try after installing everything (only Python 3). + +The code can be used as a **library**, for example in a Jupyter notebook. +In the [`examples`](examples/) folder you can find some examples. -Alternatively, you can run the code `analysis.py` from the **command line**. +Alternatively, you can run the code `analysis.py` from the **command line** without any installation procedure. It can execute most of the cepstral analysis routines, returning the results in a series of data files and PDF plots. -See the `examples` folder and the help (`python analysis.py --help`) for more information. +See the [`examples/example_commandline_NaCl`](examples/example_commandline_NaCl/) folder and the help (`python analysis.py --help`) for more information. ### Requirements - - Python 2.7 - - Numpy - - Scipy - - Matplotlib +#### only cepstral analysis (command line interface) + - Python 2.7 or 3.x + - numpy + - scipy + - matplotlib +#### graphical user interface + - all the requirements of cepstral analysis + - Python 3 only + - tkinter + - future-fstrings + - pillow (you may need upgrade it) + - tk-html-widgets + - markdown2 ### Installation - You can simply pip-install thermocepstrum with `pip install thermocepstrum`. + You can simply pip-install thermocepstrum downloading it from PyPI with `pip install thermocepstrum`. Alternatively: + 1. Clone this repository: `git clone https://github.com/lorisercole/thermocepstrum.git` 2. Install the package with pip (dependencies will be automatically downloaded). For example: ``` cd thermocepstrum pip install . ``` - You are done! You can check that the installation is working by trying to run the command `thermocepstrum-analysis`. + + If you use Python 3, the Graphical User Interface will be installed and can be started with the command `thermocepstrum-gui`. + +### Issues + You are strongly encouraged to report any issue on the [official](https://github.com/lorisercole/thermocepstrum/issues) GitHub issues page. diff --git a/README_GUI.md b/README_GUI.md new file mode 100644 index 0000000..643ae9b --- /dev/null +++ b/README_GUI.md @@ -0,0 +1,19 @@ +# Thermocepstrum GUI + +### Installation + See [README.md](README.md) + +### Usage + - run `thermocepstrum-gui` from the command line + - select the input file with the "..." button. After you select the file a preview will be shown if possible. If a binary file was selected the preview will not update, and a message will pop up. + - select the input format. "table" is the standard column formatted data file with in the first line an header with the names of the columns. Vector data (like the 3 components of the currents) must be grouped with "name_[1] name_[2] name_[3]" ("[]" must be present). Vectors will be automatically recognized. "dict" is a numpy dictionary (saved with np.save() ) with binary data. This type of file can be generated by this program when you press "export data" in the "File" menu. They are a lot faster to save and to load. + - "Next". If the selected file type is wrong, an error message will pop up and the program will return to the previous step. + - read the instructions and select the type of data of the various columns + - select the units + - "Next" + - Input the required values (if not already filled with the information encoded in the input file). "filter width" can be left as is, it is only for visualization purposes and can be changed later. + - select the resampling frequency with the cursor. You can press "Resample" to see the effect. This is necessary to not run the analysis on useless portions of the spectrum. You can select the first important feature of the plot near zero. + - "Next" + - the result is shown. It is possible to modify the number of cepstral coefficients and see the effect + +At any time it is possible to save everything by pressing "export data" in the menu. Later all the parameters will be automatically loaded if you select the generated file as the input. diff --git a/examples/README.md b/examples/README.md index 5ba87f6..dd29285 100644 --- a/examples/README.md +++ b/examples/README.md @@ -11,4 +11,4 @@ These examples show how to use the thermocepstrum package in a Python script, st #### Command line examples These examples show how to use the command line program `analysis.py` to perform cepstral analysis in a straightforward. This is an expedient tool to analyse a time series using predefined parameters. Results are produced in the form of numerous text/binary files and pdf plots. -* `example_commandline_NaCl`: analysis of molten NaCl, a two-component system. \ No newline at end of file +* `example_commandline_NaCl`: analysis of molten NaCl, a two-component system. diff --git a/examples/data/Silica.npy b/examples/data/Silica.npy new file mode 100644 index 0000000..7cbb344 Binary files /dev/null and b/examples/data/Silica.npy differ diff --git a/examples/example_cepstrum_doublecomp_NaCl.ipynb b/examples/example_cepstrum_doublecomp_NaCl.ipynb index 5eca714..51d684b 100644 --- a/examples/example_cepstrum_doublecomp_NaCl.ipynb +++ b/examples/example_cepstrum_doublecomp_NaCl.ipynb @@ -49,7 +49,9 @@ { "cell_type": "code", "execution_count": 3, - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [ { "name": "stdout", @@ -57,7 +59,7 @@ "text": [ "Temp c_flux[1] c_flux[2] c_flux[3] c_vcm[1][1] c_vcm[1][2] c_vcm[1][3]\n", " #####################################\n", - " all_ckeys = {'flux': array([1, 2, 3]), 'vcm[1]': array([4, 5, 6]), 'Temp': [0]}\n", + " all_ckeys = {'Temp': [0], 'flux': array([1, 2, 3]), 'vcm[1]': array([4, 5, 6])}\n", " #####################################\n", "Data length = 20000\n" ] @@ -83,32 +85,32 @@ "name": "stdout", "output_type": "stream", "text": [ - " ckey = {'flux': array([1, 2, 3]), 'vcm[1]': array([4, 5, 6]), 'Temp': [0]}\n", + " ckey = {'Temp': [0], 'flux': array([1, 2, 3]), 'vcm[1]': array([4, 5, 6])}\n", " ( 20000 ) steps read.\n", - "DONE. Elapsed time: 0.241985082626 seconds\n" + "DONE. Elapsed time: 0.26084303855895996 seconds\n" ] }, { "data": { "text/plain": [ - "{'Temp': array([[1442.7319],\n", - " [1440.806 ],\n", - " [1440.6008],\n", - " ...,\n", - " [1402.7391],\n", - " [1392.6822],\n", - " [1385.4031]]),\n", + "{'Temp': array([[ 1442.7319],\n", + " [ 1440.806 ],\n", + " [ 1440.6008],\n", + " ..., \n", + " [ 1402.7391],\n", + " [ 1392.6822],\n", + " [ 1385.4031]]),\n", " 'flux': array([[ 250.86549 , 20.619423 , 200.115 ],\n", " [ 196.22265 , 82.667342 , 284.3325 ],\n", " [ 126.39441 , 160.75472 , 340.36769 ],\n", - " ...,\n", + " ..., \n", " [ 179.91856 , 18.612706 , -132.65623 ],\n", " [ 204.71193 , -0.46643315, -204.0165 ],\n", " [ 241.23318 , -18.295461 , -252.46475 ]]),\n", " 'vcm[1]': array([[-0.15991832, -0.07137043, 0.02068792],\n", " [-0.13755206, -0.07100293, -0.01127988],\n", " [-0.10615044, -0.06238124, -0.04156812],\n", - " ...,\n", + " ..., \n", " [-0.0919399 , -0.08477829, 0.06001139],\n", " [-0.13384949, -0.1147453 , 0.08932355],\n", " [-0.18385053, -0.1369343 , 0.1143406 ]])}" @@ -150,8 +152,8 @@ "DT_FS = 5.0 # time step [fs]\n", "TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K]\n", "VOLUME = 40.21**3 # volume [A^3]\n", - "print 'T = {:f} K'.format(TEMPERATURE)\n", - "print 'V = {:f} A^3'.format(VOLUME)\n", + "print('T = {:f} K'.format(TEMPERATURE))\n", + "print('V = {:f} A^3'.format(VOLUME))\n", "\n", "j = tc.HeatCurrent([jfile.data['flux'], jfile.data['vcm[1]']], 'metal', DT_FS, TEMPERATURE, VOLUME)" ] @@ -174,7 +176,7 @@ " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", - " alert('Your browser does not have WebSocket support.' +\n", + " alert('Your browser does not have WebSocket support. ' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", @@ -391,7 +393,7 @@ "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", - " var nav_element = $('
')\n", + " var nav_element = $('
');\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", @@ -448,7 +450,7 @@ " var fmt = mpl.extensions[ind];\n", " var option = $(\n", " '