INTRODUCTION

  1. Installing X11

  2. Accessing the class server

    1. Make sure you are connected to the network before starting your X11 application.

    2. Start your X11 application and get a terminal window (xterm).

    3. In the terminal window, use ssh to connect to geoflop:

      ssh -Y geo232?@geoflop.uchicago.edu
      (Replace the '?' with the letter for your username on geoflop.)

    4. Launch the Python programming environment:

      idle -n

  3. Using IDLE

    1. The initial window is a Python interpreter. It accepts commands you type and runs them immediately without saving the code.

    2. You can open a Notepad-style text editor window by opening IDLE's "File" menu and choosing "New Window." You can type and edit your code in this window before running it. You can save this code to a file on the class server with the text editor window's File menu's "Save" or "Save As" items. You will have to save your code before you can run it from this window. Once you have saved your code, you can run it by choosing "Run Module" from the "Run" menu or by pressing F5. The output of your Python program will appear in the interpreter window.

    3. When you are finished, you can choose "Quit" from the File menu. Then, at the command-prompt window (the xterm), you can use the 'logout' command to log out.

  4. Class-specific Python

    1. Graphing

    2. The ClimateUtilities module has a Curve object for drawing graphs. The system draws the graphs using the X11 windowing system, so you will need to have X11 running on your local machine. The easiest way to get started is to import everything from ClimateUtilities:

      from ClimateUtilities import *
      Then, create a curve object:
      c = Curve()
      Curve objects accept Python lists as data to graph. The first list you give it becomes the X axis. All subsequent lists will be plotted on the Y axis against that first list. The last thing to do is plot the graph: w = plot(c).

      Here is an example that puts everything together:

      
      from ClimateUtilities import *
      xList = range(10)
      yListOne = [x**2 for x in xList]
      yListTwo = [x**3 for x in xList]
      c=Curve()
      c.addCurve(xList)
      c.addCurve(yListOne)
      c.addCurve(yListTwo)
      w = plot(c)

      The result should look like this:

      To save that graph, take a screenshot, or save it to your home directory on geoflop: w.save("filename") will save the graph to a PostScript file called "filename.eps" in your home directory. To get rid of the graph window, do w.delete().

    3. Additional graphing tricks

    4. Numerical integration of an ODE
    5. In lab, we modified the professor's ODE script so that we could graph the analytical and numerical solutions and their difference. We only used the Euler method. Here is the code:

      
      #Tutorial on numerical integration of first order ODE.
      #
      #We integrate the first order ODE
      #                  dy/dx = -x*y
      #numerically using the Euler method, the midpoint method,
      #and the Runge-Kutta method, and compare with the exact
      #solution.
      #
      #This is the basic version, using no plotting and using only
      #Python language constructs that are more or less common to
      #all programming languages.  
      
      import math
      from ClimateUtilities import *
      
      xx=[]
      numerical=[]
      analytical = []
      error=[]
      
      #Define the function you are integrating. To
      #keep things simple, this function has no parameters.
      #The analytic solution to this
      #problem is y(x) = y(0)*exp(-x**2/2)
      
      def yAnalytical(y0,x):
          #return y0*math.exp(x)
          return y0*math.exp(-x**2/2.)
      
      def F(x,y):
          #return y
          #return math.exp(x)
          return -x*y
      
      #Initial conditions
      xstart = 0
      ystart = 1.
      #
      #Increment. Try re-running the script with different
      #values
      dx = .5
      #
      #How many steps?
      nsteps = 10 #Try 15 steps, to show instability of midpoint method
      
      #Do an Euler integration and save results for plotting
      #Do the loop to find the solution starting from the
      #initial condition
      x = xstart
      y = ystart
      xx=[x]
      analytical = [yAnalytical(ystart, x)]
      numerical=[ystart]
      error=[numerical[0]-analytical[0]]
      
      for i in range(nsteps):
          slope = F(x,y)
          x = x + dx
          y = y + slope*dx
          #yExact = ystart*math.exp(-x**2/2.)
          yExact = yAnalytical(ystart, x)
          #print x,y,yExact,y-yExact
          xx.append(x)
          analytical.append(yExact)
          numerical.append(y)
          error.append(y-yExact)
      
      def graph():
          c=Curve()
          c.addCurve(xx)
          c.addCurve(analytical, label='Analytical solution')
          c.addCurve(numerical, label='Numerical solution')
          c.addCurve(error, label='Error')
          w=plot(c)
          # raw_input("Press Enter to delete the graph and return...")
          # w.delete()
          return w
              

      When the slope (dy/dx) is -x*y, it turns out that the analytical solution is the function that gives the Gaussian distribution (centered at zero with variance=1). When we ran the code and graphed the result, we got the following:

      Notice that the numerical solution converges on the true (analytical) solution, and the error goes to zero, but, initially, there is a spurious oscillation.

      We also did this exercise with dy/dx=y, which has the obvious solution of y=ex (because dy/dx = ex = y). We got the following graph.

      Notice that the error is growing exponentially.

  5. Misc

    1. Taking a screenshot

    2. Using EPS files saved on geoflop

    3. If you save a graph to your home directory on geoflop (w.save('filename')), it will be a Postscript file ('filename.eps'). You can download the file to your local machine using SCP, the secure copy program: scp geoflop.uchicago.edu:filename.eps . The dot ('.') at the end is part of the command that you run on the local machine, and it just means that the file is copied to whatever directory you are already in when you issue the command on the local machine.

      If your local machine can't deal with postscript files, you can convert the file to a PDF on geoflop before you download it: ps2pdf filename.eps will produce filename.pdf. Then, you can download the pdf with the scp command: scp geoflop.uchicago.edu:filename.pdf .

      If you just want to display the EPS files on geoflop so that you can take a screenshot, you can use the 'gs' command on geoflop: gs filename.eps will display the file. When you're finished with it, go back to the terminal window where you ran the 'gs' command. Press 'Enter' to get a command prompt in GS, then type 'quit' and press 'Enter' again to get out of GS.