PK ëŽtCOAßœ œ # astropy4herts-latest/searchindex.jsSearch.setIndex({objects:{},terms:{code:[0,1],downloaded_fil:2,execut:1,enter:[1,2],skip:1,laptop:0,becaus:1,bring:0,session:1,comma:1,abil:1,equival:1,follow:2,help:[0,1,2],write:1,privat:0,explicitli:1,just:[0,1,2],copyright:[1,2],solut:0,jan:2,platform:2,window:2,mail:0,darwin:[1,2],over:1,bin:2,non:1,get:[0,1,2],python:[0,1,2],credit:[1,2],cover:0,quickref:1,answer:2,cannot:0,stackoverflow:0,veri:1,nov:1,now:1,brows:0,licens:[1,2],name:1,document:0,like:2,edit:1,command:1,list:0,previou:1,"try":1,twice:1,necessari:1,mode:1,arrow:1,contain:1,quick:1,output:1,introduct:1,page:2,emerg:[0,2],pleas:0,x86_64:2,set:1,often:1,replac:1,twitter:0,some:0,back:1,see:1,"export":2,anaconda:2,download:2,click:2,out:1,even:1,affili:0,what:[0,1],record:1,file:[0,1,2],feedback:0,astroqueri:0,access:1,state:1,print:1,"new":2,irc:0,reproduc:1,note:[0,1],refer:1,encourag:0,astronomi:0,run:[0,1],navig:1,onli:1,standard:1,extens:1,add:1,conda:2,ipython:[0,1],path:2,valu:1,about:[0,1],last:1,fit:0,launch:1,script:1,thing:1,anacondac:2,mani:1,assign:1,first:[1,2],rehash:2,own:1,celesti:0,extra:1,press:[1,2],overview:[0,1],sometim:1,put:1,instruct:2,alreadi:2,done:1,linux:2,instal:[0,2],open:2,your:[0,1,2],unit:0,from:1,spam:1,interact:1,doubl:2,question:[0,2],system:1,messag:[1,2],start:[0,1],workshop:0,call:1,includ:1,statement:1,tom:2,termin:2,conveni:1,type:[1,2],more:[0,1,2],"function":[0,1],shell:1,lot:0,relat:0,continu:1,coordin:0,link:0,too:1,sens:0,univers:0,line:[1,2],editor:1,present:1,"case":1,multi:1,have:2,"default":[1,2],displai:1,histori:1,defin:1,"while":1,limit:1,can:[0,1],separ:1,problem:0,purpos:0,similar:2,aplpi:[0,2],featur:1,prompt:[1,2],tab:1,creat:1,give:0,readi:1,favorit:1,ani:[0,1],indic:1,packag:[0,1],tag:0,explor:1,tabl:0,pip:2,well:1,option:[0,2],bash:2,gcc:[1,2],multipl:1,want:1,etc:1,when:1,detail:1,same:1,prepend:1,hertfordshir:0,handl:0,complex:1,build:[1,2],which:1,test:[1,2],instead:1,you:[0,1,2],eventu:1,simpl:0,accept:1,complet:1,variabl:1,astropi:[0,2],http:[],distribut:2,though:1,symbol:1,after:1,them:1,did:1,befor:1,mac:2,notebook:0,user:2,previous:2,end:2,enhanc:1,"class":1,org:[],practic:1,scientif:2,doc:[],request:1,object:1,quantiti:0,inform:[1,2],exampl:1,combin:1,thi:[0,1],time:1,appl:[1,2],inc:[1,2],dot:1},objtypes:{},titles:["University of Hertfordshire Astropy Workshop","Running Python code","Optional: Emergency Installation"],objnames:{},filenames:["index","running","emergency_install"]})PK ëŽtCó$ô‰Ž Ž astropy4herts-latest/search.html
To run Python code interactively, you can use the standard Python prompt, which can be launched by typing python in your standard shell:
$ python
Python 2.7.2 (default, Nov 5 2011, 20:09:20)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
The >>> indicates that Python is ready to accept commands. If you type a = 1 then press enter, this will assign the value 1 to a. If you then type a you will see the value of a (this is equivalent to print a):
>>> a = 1
>>> a
1
The Python shell can execute any Python code, even multi-line statements, though it is often more convenient to use Python non-interactively for such cases.
The default Python shell is limited, and in practice, you will want instead to use the IPython (or interactive Python) shell. This is an add-on package that adds many features to the default Python shell, including the ability to edit and navigate the history of previous commands, as well as the ability to tab-complete variable and function names. To start up IPython, type:
$ ipython
Python 2.7.2 (default, Nov 5 2011, 20:09:20)
Type "copyright", "credits" or "license" for more information.
IPython 0.11 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]:
The first time you start up IPython, it will display a message which you can skip over by pressing ENTER. The >>> symbols are now replaced by In [x], and output, when present, is prepended with Out [x]. If we now type the same commands as before, we get:
In [1]: a = 1
In [2]: a
Out[2]: 1
If you now type the up arrow twice, you will get back to a = 1.
While the interactive Python mode is very useful to exploring and trying out code, you will eventually want to write a script to record and reproduce what you did, or to do things that are too complex to type in interactively (defining functions, classes, etc.). To write a Python script, just use your favorite code editor to put the code in a file with a .py extension. For example, we can create a file called test.py containing:
a = 1
print a
We can then run the script on the command-line with:
$ python test.py
1
Note: The print statement is necessary, because typing a on its own will only print out the value in interactive mode. In scripts, the printing has to be explicitly requested with the print command. To print multiple variables, just separate them with a comma after the print command:
print a, 1.5, "spam"
It can sometimes be useful to run a script to set things up, and to continue in interactive mode. This can be done using the %run IPython command to run the script, which then gets executed. The IPython session then has access to the last state of the variables from the script:
$ ipython
Python 2.7.2 (default, Nov 5 2011, 20:09:20)
Type "copyright", "credits" or "license" for more information.
IPython 0.11 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: %run test.py
1
In [2]: a + 1
Out[2]: 2
If you already have a Scientific Python distribution, but not Astropy and APLpy, just do:
pip install astropy
pip install aplpy
If you have not previously installed a Scientific Python distribution, use the following instructions for an EMERGENCY scientific Python install :-)
Go to the Anaconda Downloads page.
Download the file for your platform
On Linux or Mac, do:
bash <downloaded_file>
and answer the questions with the default by just pressing <enter>. At the end of the install, you will get a message like:
export PATH=/Users/tom/anaconda/bin:$PATHFollow these instructions, rehash or open a new terminal, and then test that if you type python, you get a prompt similar to:
Python 2.7.3 |AnacondaCE 1.3.1 (x86_64)| (default, Jan 10 2013, 12:10:41) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>with AnacondaCE in the first line.
On Windows, double click the .exe file to install.
Install Astropy with:
conda install astropy
pip install aplpy
Note
Please bring your laptop to the workshop!
The purpose of this workshop is to give you an overview of functionality in Astropy, and get you started with some simple problems. There is a lot of functionality that we cannot cover in this workshop, so I encourage you to browse the Astropy Documentation to get a sense of what it can be used for!