Convenient tools for CLI, GUI, and plotting
Project description
MPyTools
Set of custom python packages for various odds and ends.
- mcol defines a set of colours as ANSI escape strings.
- module provides the module() function that calls lmod to persistently load softare on EUREKA.
- mout provides a set of functions for formatted console output.
- mplot provides a variety of plotting functions using matplotlib.
mcol
Provides ANSI escape strings for colourised terminal output that fits into a colour scheme. I.e. green success messages, red errors, orange warnings, yellow filenames etc...
For example to output an error message:
import mcol
print(mcol.error + "Error: Something went wrong!" + mcol.clear)
Please note that for most cases the functions in mout will achieve the same functionality with less code:
import mout
mout.errorOut("Something went wrong!")
Colour strings in the scheme:
varNameVariable names, turqoisevarTypeVariable types/units, pinkfuncFunction/script name, underlined turqoisefileFilename/path, yellowerrorFor error messages, bold redsuccessFor success messages, bold greenwarningFor warning messages, bold greenresultFor results/variable values, blueargFor function arguments, lime
General colour strings:
-
clear -
bold -
inverse -
underline -
red -
green -
yellow
module
Access the unix modulecmd from within python. Load and unload packages, which will persist so that subsequest exec() or os.system() commands will see them. Comma delimited arguments instead of spaces:
import module
module.module('load','lammps/2018/mpi+intel-xe_2017_3')
mout
Write formatted output to the console.
General console message
mout.out(string,printScript=False,end="\n")
stringThe message to be displayedprintScriptPrepend the output with the name of the script?endEnd the output with this string.
Output a variable and its value
def varOut(name, value, unit="",valCol="",precision=8,printScript=False,end="\n")
nameThe name of the variablevalueValue of the variableunitUnit string for the variablevalColCustom colour string for the valueprecisionSignificant figures of the value outputprintScriptPrepend the output with the name of the script?endEnd the output with this string.
Warning message
def warningOut(string,printScript=False,code=None,end="\n")
stringThe message to be displayedprintScriptPrepend the output with the name of the script?codeThe warning codeendEnd the output with this string.
Error message
def errorOut(string,printScript=False,fatal=False,code=None,end="\n"):
stringThe message to be displayedprintScriptPrepend the output with the name of the script?fatalExit the script?codeThe warning codeendEnd the output with this string.
mplot
Functions for plotting data using matplotlib.
Requirements
mplot requires matplotlib
Usage
Plotting 2D data:
mplot.graph2D(xdata,ydata,ytitles=None,filename=None,show=True,xmin=None,xmax=None,ymin=None,ymax=None,xlab='x',ylab='y',title=None)
xdataList of x-axis valuesydataList of y-axis values or list of list of y-axis values.ytitlesList of titles for the different y-axis data-sets.filenameOutput filename.showOpen a GUI window with the plot?xminLower bound of x-axis.xmaxUpper bound of x-axis.yminLower bound of y-axis.ymaxUpper bound of y-axis.xlabx-axis label.xlaby-axis label.titleTitle of plot.verbosityVerbosity level. Every nested function call will passverbosity=verbosity-1.
Example:
import mplot
xdata = [1,2,3,4]
ydata1 = [1,2,3,4]
ydata2 = [3,4,5,6]
mplot.graph2D(xdata,ydata1,filename="test1.png",title="Test 1")
mplot.graph2D(xdata,[ydata1,ydata2],ytitles=["ydata1","ydata2"],filename="test2.png",title="Test 2")
Open figures in GUI windows
To show all the figures created in the interactive session:
mplot.show(verbosity=1)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mpytools-0.0.23.tar.gz.
File metadata
- Download URL: mpytools-0.0.23.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fda344fe475258b039cc105ad66e24cd30cc2aa3c5df6f20b411ef06fe729253
|
|
| MD5 |
3232c742002d6e078c148d1a6f059535
|
|
| BLAKE2b-256 |
b4b10972fd4a0b9291149089d0231aec6c086b8aff978f0ef5006844cc85e369
|
File details
Details for the file mpytools-0.0.23-py3-none-any.whl.
File metadata
- Download URL: mpytools-0.0.23-py3-none-any.whl
- Upload date:
- Size: 32.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
861dccba4fe596eaf14cfc391f73f59a598da4586667855ee99b1decf617933e
|
|
| MD5 |
886dca3d2e87d66ca97c108f1da2eb78
|
|
| BLAKE2b-256 |
93a4b98026975e43472006530fab31216fd0603eeb2058b010b630e30e6d5ccc
|