ground- water, geo- statistics, environmental- engineering, earth- science

iPython Shell to Execute both Python and traditional Shell commands

without comments

Wow, I just learned about this today: I am running gstat fairly frequently, for simulation purposes. Here is a nifty little way to run this from a shell that understands both python and traditional shell commands.

  1. open such an shell typing

    ipython -profile sh -pylab

  2. Let’s assume you want to simulate 30 fields, then type:

    import time
    for i in range(30):
     !gstat.exe "{name of gstat setup file}"
     !move "{gstat output file}" ${ "%03i" % (i,) }

Here are some explanations:

  • the gstat output is copied into folders that are named 001, 002,… up to 030
  • in order to invoke traditional shell commands they need to be preceded by an exclamation mark
  • the time.sleep command is placed, because I found that for a new random seed to happen in gstat it needs to pause for a little while. I am not sure if this is correct or if there are better ways to do this. If you are aware of any, please let me know.
  • a “$” is necessary in front of a python command if it is inside a shell command, so it is processed before it is passed to the shell.
  • important: “cd” is to be treated like a python command! so do NOT use “!cd ..”

Big thanks to Thomas, master of many things and especially of PyMF!

This is so wicked! I also discovered folder actions in OSX yesterday. How awesome are these two discoveries? ­čÖé

Well, it’s weekend now, and three machines are running full throttle. Cheers!

Written by Claus

April 16th, 2010 at 7:27 pm

Posted in

Leave a Reply