Category "Python"

Travis Oliphant, creator of NumPy the array package for Python, wrote a analog to the Zen of Python for NumPy:

Strided is better than scattered
Contiguous is better than strided
Descriptive is better than imperative (use data-types)
Array-oriented is often better than object-oriented
Broadcasting is a great idea — use where possible
Vectorized is better than an explicit loop
Unless it’s complicated — then use numexpr, weave, or Cython
Think in higher dimensions

I tried something for IDL last year.

Awesome Python:

A curated list of awesome Python frameworks, libraries, software and resources.

Worth checking out when looking for an existing solution.

Great post examining some of the reasons why the FFT algorithm is so fast compared to a naive implementation:

The goal of this post is to dive into the Cooley-Tukey FFT algorithm, explaining the symmetries that lead to it, and to show some straightforward Python implementations putting the theory into practice. My hope is that this exploration will give data scientists like myself a more complete picture of what’s going on in the background of the algorithms we use.

A nice list of resources for doing remote sensing in Python, especially if you already know IDL.

I’ve found this translation guide for writing and understanding Python code quite useful. I think it should work if you are familiar with Python and wanting to read/write IDL code also.

Python Unlocked:

Python is a versatile programming language that can be used for a wide range of technical tasks — computation, statistics, data analysis, game development, and more. Though Python is easy to learn, its range of features means there are many aspects of it that even experienced Python developers don’t know about. Even if you’re confident with the basics, its logic and syntax, by digging deeper you can work much more effectively with Python – and get more from the language.

Python Unlocked walks you through the most effective techniques and best practices for high performance Python programming – showing you how to make the most of the Python language.

I find myself reading more about best practices, especially in Python.

If you are interested, promo code PYTUNL30 will get you 30% off the ebook until Feb 20.

One of the major features of IDL 8.5 is the two-way bridge between IDL and Python. This allows Python functionality to be accessed from IDL (Python has a lot of libraries for things that fall outside of the standard scientific routines found in IDL) as well as accessing IDL functionality from Python (call legacy IDL code).

The IDL-Python bridge works with either Python 2 or 3 (whew, I’m still on Python 2!).

Continue reading “IDL 8.5: IDL-Python bridge.”

The “Zen of Python” provides the basic philosophy of Python. From PEP 20:

There should be one — and preferably only one — obvious way to do it.

I doubt there is a single area in Python that violates this more than making a simple HTTP request. Python provides at least six builtin libraries to do this: httplib, httplib2, urllib, urllib2, urllib3, and pycurl. There are several reviews comparing the various libraries.

But there is a third party library, requests, that might be the “obvious way to do it” now:

import requests, json

url = ''
r = requests.get(url, auth=('mgalloy', 'my_password'))
print r.json()['updated_at']

requests is installed as part of Anaconda, which an easy way to get all the core scientific programming packages for Python.

Numba is a Python package that uses the LLVM compiler to compile Python code to native code. Numba 0.13, released a few weeks ago, offers support for automatically creating CUDA kernels from Python code.

I created a notebook1 (HTML) to show off the demo code.

  1. I’m not sure which is cooler, IPython notebooks or Numba. 

In Modern IDL, I give a short demo of using pyIDL to use IDL from within a Python session. I have had problems with installing pyIDL lately, but didn’t have an alternative until I found pIDLy recently. It easy_installs nicely and has an even nicer interface:

>>> import pidly
>>> idl = pidly.IDL()
>>> idl('x = total([1, 1], /int)')
>>> print idl.ev('x')
>>> print idl.ev('x ^ 2')
>>> idl.reform(range(4), 2, 2)
array([[0, 1],
       [2, 3]])
>>> idl.histogram(range(4), binsize=3, L64=True)
array([3, 1], dtype=int64)
>>>'plot', range(10), range(10), xstyle=True, ystyle=True)
>>> idl.interact()
IDL> print, x
IDL> exit
>>> idl.close()

I don’t see any versioned releases since 2008, but there are commits to the GitHub repo in the last few months so I believe the project is still alive. In any case, it does what I need right now and I can install it. Updating book to use pIDLy…

older posts »