Example: marketing

Mathematical Methods in Python A companion to Principles ...

Mathematical Methods in PythonA companion toPrinciples of planetary ClimateR. T. Pierrehumbertc Draft date September 29, 2010 PrefaceThis document goes over some basic computer skills that will be useful in doing the problems inthe Workbook sections ofPrinciples of planetary climate , and in reproducing the calculations dis-cussed in the text. It also serves as a quick-start introduction to the Python language, emphasizingthose aspects of most interest to applications in the physical Some basic computer Basic Skills .. Using xterms and logging in to the server .. About the Python Shell and idle .. Running Python Locally .. 62 Introduction to Fun with Python .. Basic operations.

Mathematical Methods in Python A companion to Principles of Planetary Climate ... In the examples, we will suppose that the server is ... SOME BASIC COMPUTER SKILLS how various Python functions are used. As an exercise at this point, you should try creating and

Tags:

  Python, Basics, Principles, Climate, Example, Companion, Planetary, Companion to principles of planetary climate

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Mathematical Methods in Python A companion to Principles ...

1 Mathematical Methods in PythonA companion toPrinciples of planetary ClimateR. T. Pierrehumbertc Draft date September 29, 2010 PrefaceThis document goes over some basic computer skills that will be useful in doing the problems inthe Workbook sections ofPrinciples of planetary climate , and in reproducing the calculations dis-cussed in the text. It also serves as a quick-start introduction to the Python language, emphasizingthose aspects of most interest to applications in the physical Some basic computer Basic Skills .. Using xterms and logging in to the server .. About the Python Shell and idle .. Running Python Locally .. 62 Introduction to Fun with Python .. Basic operations.

2 Lists, tuples and strings .. Modules .. Getting help .. Program control: Looping, conditionals and functions .. More advanced Python .. Writing your own modules and executable scripts .. List comprehension .. Using objects in Python .. Thenumpyarray module .. Courseware modules .. TheClimateUtilitiesmodule .. Thephysmodule .. Theplanetsmodule .. Advanced Python Topics .. Defining your own objects .. Getting input interactively .. Dictionaries .. Writing text data to files .. Reading text data from a file .. 343 Appendix A: Hints for the user of Unix and its Simple Unix for the masses .. A few useful Unix utilities.

3 Nasty Unix stuff I hope you won t have to deal with .. Public domain software to install on the server .. 412 Chapter 1 Some basic computer skills34 CHAPTER 1. SOME BASIC COMPUTER Basic SkillsTo do the labs and the problem sets,you will need some basic computer skills. I will outline thesebriefly here. The instructions below assume that the exercises will be done using what I ll callthedefault setup. In the default setup, the course software and the necessary datasets reside ona centralized server; the student logs on to the server from a workstation that supports the sshprotocol and the X windowing system. The X window system is needed to allow a remote serverto write graphics ( a plot, or a graphical user interface) to the screen of the local specific instructions below apply most closely to Unix workstations.

4 The necessary skills forusing the default setup are: Logging in to a Linux server from a workstation on the network. Setting things up for the Linux machine to display its graphics on the workstation you aresitting at, using the X windowing system. Working with Linux directories and files (commandscd,ls,mv,rm,mkdir). Starting up the Python interpreter and using the Python Integrated Development Environ-ment, Using xterms and logging in to the serverThe software that you will be using, as well as the data you will be looking at, resides on aserver running the Unix operating system. In the examples, we will suppose that the server ; your own server will have a different name, which will be providedby your instructor.

5 To use the software, you will need to log intoclimate, which you can do fromany machine anywhere in the world, as long as the machine has ansshprogram. The first step isto get an X terminal window ( xterm for short) on the screen of the workstation at which youare sitting. If your workstation is a Unix computer the standard window you get when you requesta shell or a terminal window is already an xterm, assuming the system has been started upinto a graphical user environment, as is generally the case these days. To get a new xterm, youjust need to click on the appropriate icon on the desktop. The specific icon varies somewhat fromsystem to system, but will generally look like a scallop shell or a computer running OSX are actually running a form of Unix, but the default graphical interfacedoes not use the X windowing system.

6 This will be less confusing if you recall that the X in OSX is actually pronounced 10 . The standard terminal, or shell, window you get with theOSX terminal tool isnotan xterm. While you can issue Unix commands and log onto remotesystems for text-based applications by issuing the ssh command in this window, the OSX terminalwindow does not handle graphics. Further, OSX does not come with the X windowing systeminstalled by default. Fortunately, Appole provides an excellent implementation for X on OSX,which can be installed from the system install disk. If you have your own OSX Mac, or haveadministrative privileges for some OSX Mac you can use, you can installX11yourself very Macs set up for this course should, in principle, already haveX11installed.

7 To get an xterm,you just click on theX11icon in the toolbar and wait for X to start up. The default windows Xputs up on the screen are all xterms. You can make a window go away by typingctrl-din thewindow (meaning hold down thectrlkey and typed. If you want a new xterm, just typexterm&in any existing xterm window, or chooseterminalfrom theApplicationsmenu, and a new BASIC SKILLS5will pop up. Your instructor can show you how to move and resize windows or turn them you have an xterm on your screen, click the mouse in its window to activate it. Youare now ready to log in to the course server. If you happen to be on a Unix workstation withthe course data and software installed locally, you can just skip the login step.)

8 This is one ofthe beauties of X and Unix the system doesn t really care which computer is actually doing thecalculation. This remark applies equally to OSX Macs, provided that Unix versions of the coursesoftware have been properly let s assume that you need to log on to the course server. You ll need an account to gofurther: a userid and a password. If you already have an account onclimate, you can use that. Ifnot,you can get one of the pre-assigned accounts from the TA. Once you have this data, you canlog in. To log in, just issue the commandssh -X -l<USERID> xterm, where<USERID>is the userid for the course account. Then give your password at theprompt. The-Xoption tells the server to forward graphical commands to the local X windowingsystem for handling.

9 On many Linux systems, this option is turned on by default, but it neverhurts to include it explicitly. For the more recent versions of Linux, you usessh -Yinstead of-X,so try that if things don t work About the Python Shell and idlePython is an interpreted language, which means you just type in plain text to aninterpreter, andthings happen. There is no compilation step, as in languages such ascorFORTRAN. To start upthe Python interpreter,just typepythonfrom the command line onclimate. You ll get a prompt,and can start typing in Python commands. Try typing *3+ see what happens. Toexit the Python interpreter, , you ll probably want to put your Python programs, or at least your functiondefinitions, in a file you create and edit with a text editor, and then load it into Python later.

10 Thissaves you having to re-type everything every time you run. The standard Unix implementationof Python provides anintegrated development environmentcalledidle, which bundles a Pythoninterpreter window with a Python -aware text editor. To start upidleon a machine you aresharing with otheridleusers, log in to the server from an xterm and typeidle -n. (The-noption keepsidlefrom running a separate copy of Python for executing the stuff you run in itsinterpreter window. For technical reasons it is necessary to do this if more than one user is usingidleat a time. Except when debugging very complicated code, you probably won t notice thedifference that the-noption makes) You will get a Python shell window, which is an ordinaryPython interpreter except that it allows some limited editing capabilities.


Related search queries