Giter Site home page Giter Site logo

dstauffman

The "dstauffman" module is a generic Python code library of functions that I (David C. Stauffer) have found useful.

Written by David C. Stauffer in March 2015.

Library dependencies

This code relies on newer features within the Python language. These include enums from v3.4, the '@' operator for matrix multiplication from v3.5, ordered dictionaries and f-strings from v3.6, and assignment expressions ":=" from v3.8, and eventually newer typing methods from v3.9. As such, it currently requires at least v3.8 of Python and will not run on v2.7.

I do lots of plotting with matplotlib, and additionally use the PyQt5 library for GUIs and adding buttons (like next plot, previous plot and close all) to the standard MPL toolbar. This code is backend specific, and Qt is much more powerful than Tk/Tcl, so I use PyQt5 instead of the core tkinter.

Built-in libraries

The following built-in Python libraries are used within the dstauffman library.

  • argparse
  • collections
  • contextlib
  • copy
  • datetime
  • doctest
  • enum
  • functools
  • gc
  • glob
  • inspect
  • io
  • logging
  • os
  • pathlib
  • platform
  • pickle
  • re
  • shlex
  • subprocess
  • sys
  • time
  • types
  • unittest
  • warnings

Additional libraries

The following non-standard, but for the most part very well known libraries, are also used by the dstauffman library. Of all of these, PyQt5 is by far the one most likely to cause you issues. (It uses python configure.py instead of python setup.py, so it fails under pip or easy_install. It also depends on SIP, which has the same limitations, and once installed matplotlib has to be told to use the same matching backend.

  • h5py
  • matplotlib
  • numpy
  • pandas (minimal usage)
  • PyQt5
  • pytest
  • scipy (minimal usage)
  • tblib (minimal usage)

Installation

Installing on Windows with WinPython or Anaconda

WinPython or Anaconda come with all the libraries you will need. I highly recommend using one of them. Just download and run their respective installers.

Configuration

Configuring matplotlib to use PyQt5

When matplotlib is imported, it has to use a graphics backend, and once set, it usually is not possible to change on the fly without restarting the application. So you have to either do import matplotlib; matplotlib.use('Qt5Agg') as the very first import every single time, or the much better solution is to configure the matplotlibrc file to use Qt. Newer versions of Anaconda often default to this, and if you are using the built-in Spyder IDE, then there is a menu based preference to choose it.

First, find the matplotlibrc file location, or if it doesn't exist, then create one from a template found online.

import matplotlib as mpl
mpl.matplotlib_fname()

Change the line with the backend option to:

backend : Qt5Agg

Preparing Python

The code is designed to be imported as a library. In order for that to happen, the "dstauffman" folder must be on either your system path or python path.

The recommended method is to modify your user "PYTHONPATH" variable. On Windows 10, you can do this by hitting start, and then starting to type "environment" and choosing the "Edit environment variables for your account" within the control panel. Then if the user variable for "PYTHONPATH" (one word, all caps) doesn't exist, create a new one. If it does, append to it. On Windows use a semi-colon (;) to separate folders, and on Unix, use a colon (:) and don't put any spaces between folders. Add the folder location that contains the "dstauffman subfolder" folder. In my case, that's the GitHub folder where I keep my local copy of the repository.

Running the Code

At least one example script should be available in the ./dstauffman/scripts folder. This script can be run via a command prompt:

python script_name.py

If you are on Windows and installed Anaconda as described earlier, then python may not be on your system path, and you'll likely need to launch the Anaconda Prompt instead.

If you want to be able to interact with the results or the plots, then the better way to run the script is by opening it within Spyder and running it in that application using the IPython console.

Command Line Interface

In addition to import the code as a library, some functionality is available through the command line, via a script called "dcs". (In reality, it still just imports the library under the hood and passes the argument on).

For any of the given commands, you can get more information with a '-h' or '--help' option.

The following commands are available:

  • coverage
  • enforce
  • help
  • make_init
  • tests
  • version

David Stauffer's Projects

dstauffman2 icon dstauffman2

The "dstauffman2" module is a collection of games, applications, extended utilities and miscellaneous documentation that I (David C. Stauffer) have found useful.

forsat icon forsat

Collect of Modern Fortran utilities written to the latest (F2018+) standards

matlab2 icon matlab2

This library is a collection of MATLAB applications, archery tools, games and tricks by DStauffman (David C. Stauffer). Mostly this is just a playground. Use as you wish per the license.

nubs icon nubs

Wrapper to Python numba library for times when it may or may not exist.

numba icon numba

NumPy aware dynamic Python compiler using LLVM

numpy icon numpy

The fundamental package for scientific computing with Python.

slog icon slog

Customizable extensions to built-in Python logging.

spyder icon spyder

Official repository for Spyder - The Scientific PYthon Development EnviRonment

t2dmriskeqns icon t2dmriskeqns

Updated risk equations for type 2 diabetes complications

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.