Package: praktipy
praktipyPraktipy was originally designed as a small toolbox for theTU Dortmundphysics laboratory course.It contains tools forLaTeX table generationfromtext filesandmatplotlibfunctions 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 ContentspraktipyTable of ContentsPrerequirementsInstallation"But I don't want to install the whole thing"Handling tablesGenerating tables out of text filesGenerating tex tablesManipulating the tableUsing MatplotlibWildcard importsDocumentationOld versionsThanksPrerequirementspython>= 3.6with pip (other versions untested)some python 3 packages, which will be installed by the install scriptLaTeXInstallation# Via pip (preferred)$pipinstallpraktipy# or manually$gitclonehttps://github.com/The-Ludwig/praktipy.git
$python3setup.pyinstall"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: Usepraktiplot.pyin a similar way.Handling tablesIf you have installed the module useimportpraktipy.tablehandlerasthIf you just downloaded the fileimporttablehandlerasthGenerating tables out of text filesPraktipy 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. (Seebenchmarknotebook for details)Why gen_from_txt is useful:You can have "None" values in your table. (Holes)You can haveufloatsin your table. (Write them as "42.14+-6.5")You can havestringsin 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 parsedprint(table)More detailed information in the source code docstrings and the/examplesdirectory.Generating tex tablesOnce 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\inputthe generated file.You can split the table intosubtablesautomaticly.You can set laTeXlabelsandcaptions.You can set theprecisionper 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 theexamplesdirectory.Manipulating the tableYou can manipulate the table with all the known python list functions. Ontop of that some functions to make your life easier are provided.Tranposingtable: th.transposed(table)Getting thedata(numbers) from the table: th.raw_data(table)etc. (look in the module for further information, e.g. dir(th))Using MatplotlibPraktipy 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 thispplot.pretty()If you wan't to go back to the fast version again:pplot.fast()Important:Praktipy will set it'sstyle fileas default. If you have an existingmatplotlibrcfile, please make sure to merge them together. Apart from the LaTeX support,axes.formatter.use_locale : Truehas 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.Wildcard importsGenerally 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:frompraktipyimport*That will import everything you will probably need for the internship.DocumentationThe code currently is not very well documented (Allthough tablehandler.py itself provides nice Docstrings).
You will find some examples in theexamplesdirectory.Old versionsIf 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, likefrompraktipyimport*just substitutepraktipywithpraktipy.legacylike thatfrompraktipy.legacyimport*and your code will work without problems.ThanksThanks a lot toPEP et al.for theirToolbox-Workshopand materials they provide. I basicly stole their matplotlib-tex-header!