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)
Metadata
Release files for MPyTools 0.0.28
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mpytools-0.0.28.tar.gz | 24.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mpytools-0.0.28-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.6 kB
Release files / mpytools-0.0.28.tar.gz
| Download URL | mpytools-0.0.28.tar.gz |
|---|---|
| Size | 24.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88669ee9847d6db57327a0cb9df9d1f7e05688a3239a2255ff122986c7658fcf
|
|
BLAKE2b-256 checksum How to use checksums |
7ad9dfdd9bcac8e28807a0b68c18dffb7e44bd37244d531c41adeffe78319ebf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Release files / mpytools-0.0.28-py3-none-any.whl
| Download URL | mpytools-0.0.28-py3-none-any.whl |
|---|---|
| Size | 33.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59bbda5678ebce73ddefa0dbdd86ecc9198fcbd50c1c005b854fb2d962197d6d
|
|
BLAKE2b-256 checksum How to use checksums |
bac007db92c4cd7d1453b5080435afc691c3338ab3aed2c6f3ae267de5737fb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|