A small toolbox for physics laboratory courses at the TU Dortmund.
Praktipy was originally designed as a small toolbox for the TU Dortmund physics laboratory course.
It contains tools for LaTeX table generation from text files and matplotlib functions to generate fitting curve plots. These python files will make your life easier when handling with human readable tables in the physik-praktikum at TU-Dortmund (, hopefully).
Table of Contents
- Table of Contents
- Handling tables
- Generating tex tables
- Manipulating the table
- Using Matplotlib
- Wildcard imports
- Old versions
>= 3.6with pip (other versions untested)
- some python 3 packages, which will be installed by the install script
# Via pip (preferred) $ pip install praktipy # or manually $ git clone https://github.com/The-Ludwig/praktipy.git $ python3 setup.py install
"But I don't want to install the whole thing"
If you don't want to install the whole package on your computer, you can just download the relevant files directly:
- Table handling: praktipy/tablehandler.py. Just put the file into your currently used directory and import it with "import tablehandler as th"
- Plots: Use praktiplot.py in a similar way.
If you have installed the module use
import praktipy.tablehandler as th
If you just downloaded the file
import tablehandler as th
Generating tables out of text files
Praktipy uses 2-dimensional standard python-lists, to represent its lists. It can generate them out of a human readable text file (th.gen_from_txt). That seems very similar to numpy.genfromtxt, but although it is way more inefficient, it much more powerful. I can't recommend it to parse very large files (use numpy.genfromtxt for that), but every human readable table should be fine. (See benchmark notebook for details)
Why gen_from_txt is useful:
- You can have "None" values in your table. (Holes)
- You can have ufloats in your table. (Write them as "42.14+-6.5")
- You can have strings in your table.
- You can write your table visually. (gen_from_txt(filename, explicit_none=False))
- You can write your table explicitly. (gen_from_txt(filename, explicit_none=True))
table = th.gen_from_txt("./path/to/table") # Look what the parser has parsed print(table)
More detailed information in the source code docstrings and the /examples directory.
Generating tex tables
Once you have an 2 dimensional python list (actually it could be any 2 dimensional iterable), you can very easily make a beautiful .tex table out of it.
Why gen_tex_table is useful:
- You can direcly \input the generated file.
- You can split the table into subtables automaticly.
- You can set laTeX labels and captions.
- You can set the precision per column or globaly.
# It is that quick. th.gen_tex_table( table, "/path/to/output/tex/file", tex_caption="Put your laTeX caption here", tex_label="Put your laTex label here", subtables=2, precision=["2.3", 3, "1.9"], midrule=2 )
More detailed information in the source code docstrings and the examples directory.
Manipulating the table
You can manipulate the table with all the known python list functions. Ontop of that some functions to make your life easier are provided.
- Tranposing table: th.transposed(table)
- Getting the data (numbers) from the table: th.raw_data(table)
- etc. (look in the module for further information, e.g. dir(th))
Praktipy will try to set up the matplotlib backend to enable printing of pretty (german number format and nice math-font) plots. If you want to set up matplotlib yourself, just do that before you import anything from praktipy.
On default, praktipy will try to use a faster LaTeX setup, so your python scripts won't take too long to finish. If you indent to make nice plots and you have a little bit of time, you can use this
If you wan't to go back to the fast version again:
Important: Praktipy will set it's style file as default. If you have an existing
matplotlibrc file, please make sure to merge them together. Apart from the LaTeX support,
axes.formatter.use_locale : True has to be set, in order to use system locale based decimal separators (e.g.
, instead of
. for german)
Praktipy also provides some convenience function, for example to generate nice datapoints ontop of a fitted function.
Generally you should only import things you need in python. But nontheless it is quite handy to just import everything you need and see some code completion of things you usally need for the internship. Praktipy provides that with the wildcard import:
from praktipy import *
That will import everything you will probably need for the internship.
The code currently is not very well documented (Allthough tablehandler.py itself provides nice Docstrings). You will find some examples in the examples directory.
If you have already written some code with an old version of praktipy (before 2.0), it is very likely that that won't work with the new versions.
I redid the whole code style of praktipy to be a bit more pythonic.
But fear not! There is an easy trick to access old version of praktipy fro within the new version. Whenever you have written something with praktipy, like
from praktipy import *
just substitute praktipy with praktipy.legacy like that
from praktipy.legacy import *
and your code will work without problems.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|praktipy-2.1.6-py3-none-any.whl (19.8 kB) Copy SHA256 hash SHA256||Wheel||py3|
|praktipy-2.1.6.tar.gz (18.3 kB) Copy SHA256 hash SHA256||Source||None|