/pycse

Python computations in science and engineering

Primary LanguagePythonGNU General Public License v2.0GPL-2.0

Coverage Status

If you want to cite this project, use this doi:10.5281/zenodo.19111.

10.5281/zenodo.19111
@misc{john_kitchin_2015_19111,
  author       = {John R. Kitchin},
  title        = {pycse: First release},
  month        = jun,
  year         = 2015,
  doi          = {10.5281/zenodo.19111},
  url          = {http://dx.doi.org/10.5281/zenodo.19111}
}

This git repository hosts my notes on using python in scientific and engineering calculations. The aim is to collect examples that span the types of computation/calculations scientists and engineers typically do to demonstrate the utility of python as a computational platform in engineering education.

Most of the sections in the pycse.org file are posted at http://jkitchin.github.com. Feel free to leave comments there.

You may also like to visit the html version of the document at: http://jkitchin.github.com/pycse/pycse.html

You may want to install the python library with pycse:

pip install pycse

Feeling brave? Try:

pip install git+git://github.com/jkitchin/pycse

John Kitchin jkitchin@andrew.cmu.edu

What can you do with it?

org-mode integration

If you use org-mode and regular python blocks consider this:

import pycse.orgmode as org
import matplotlib.pyplot as plt

data = [['x', 'y'], None, [1, 2], [2, 4]]
org.table(data, name='table-data', caption='Data from a python table')

print()

plt.plot([4, 5, 6])
org.figure(plt.savefig('images/a-figure.png'), name='fig:1', caption='A figure in org-mode')
xy
12
24

images/a-figure.png

The orgmode module provides functions that generate org syntax for many org-elements. See for more details: pydoc:pycse.orgmode

These don’t work as well with ipython blocks. Ipython has a different org-integration setup in ob-ipython (an emacs library).

Python/lisp interaction

You can use Python to generate lisp. You might do that to generate code to be run in lisp, e.g.

from pycse.lisp import *

print([Symbol("setf"), Symbol("x"), Cons("a", 5)].lisp)

Or you might want to use the results from a Python command in lisp like this:

(run-python)
(mapcar (lambda (x) (* 2 x))
	(read (python-shell-send-string-no-output
	       "from pycse.lisp import *
import numpy as np
a = np.array([0, 1, 2, 3]) * 2
print(a.lisp)")))

Float comparisons

Float comparisons are tricky because they are not exact. Pycse provides these comparison functions which use a tolerance in the comparison:

feq==
flt<
fgt>
fle<=
fge>=