NASSP Masters 5003F - Computational Astronomy - 2009 UNIX* intro We’ll use the ‘command line’ – windows are for wimps. The unix ‘shell’: –This is what.

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
Guide To UNIX Using Linux Third Edition
Very Quick & Basic Unix Steven Newhouse Unix is user-friendly. It's just very selective about who its friends are.
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Linux & Shell Scripting Small Group Lecture 4 How to Learn to Code Workshop group/ Erin.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Homework Reading Programming Assignments
1 Day 3 Directories Files Moving & Copying. 2 Case Sensitive First thing to learn about UNIX is that everything is case sensitive. Thus the files: –enda.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Computing II - Problem Session - 1. Some Notes on Input/Output. In C++ you used two primary functions to manage console-directed Input and Output.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
An Introduction to Unix Shell Scripting
Lecture 1 NASSP Masters 5003S - Computational Astronomy Me: Ian Stewart Room 521, James building
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
CPSC 217 T03 Week I Part #1: Unix and HELLO WORLD Hubert (Sathaporn) Hu.
NASSP Masters 5003F - Computational Astronomy Lecture 8 Some further unix & python tips Good programming habits Catalog cross-matching Bayesian.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Before we start…Getting Started. UST Outline History Getting Started Basic commands (command line) Operations on Files and Directories Input and Output.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
ENEE150 – 0202 ANDREW GOFFIN Introduction to ENEE150.
Getting started: Basics Outline: I.Connecting to cluster: ssh II.Connecting outside UCF firewall: VPN client III.Introduction to Linux IV.Intoduction to.
NASSP Masters 5003S - Computational Astronomy Lecture 2 More python. –Good books: “Learning Python”, Lutz & Ascher, O’Reilly (the ‘rat book’); “Python.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Reading None.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
Chapter Three The UNIX Editors.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Introduction to Programming Using C An Introduction to Operating Systems.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
 Last lesson, the Windows Operating System was discussed along with the Windows command shell  Unix is a computer operating system, that similarly manages.
Dr. Sajib Datta Jan 16,  The website is up.  Course lectures will be uploaded there ◦ Check regularly for assignments and update.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Learning Unix/Linux Based on slides from: Eric Bishop.
Linux Administration Working with the BASH Shell.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
CMSC 104, Version 9/011 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Reading None.
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
Introduction to Unix for FreeSurfer Users
CS1010: Intro Workshop.
Department of Computer Engineering
Ruby: An Introduction Created by Yukihiro Matsumoto in 1993 (named after his birthstone) Pure OO language (even the number 1 is an instance of a class)
UNIX The Basics Source:
Andy Wang Object Oriented Programming in C++ COP 3330
Introduction to Python
The Command Prompt Commands are the way to “do things” in Unix
Guide To UNIX Using Linux Third Edition
LING 408/508: Computational Techniques for Linguists
Operating Systems and Using Linux
Operating Systems and Using Linux
Chapter Four UNIX File Processing.
Andy Wang Object Oriented Programming in C++ COP 3330
UNIX/LINUX Commands Using BASH Copyright © 2017 – Curt Hill.
Linux Shell Script Programming
Introduction to Bash Programming, part 3
Presentation transcript:

NASSP Masters 5003F - Computational Astronomy UNIX* intro We’ll use the ‘command line’ – windows are for wimps. The unix ‘shell’: –This is what lets you send commands to the system. –Generally bash or csh. –Do ‘printenv SHELL’ to find out yours. –Some differences at the < 10% level. –bash is ‘more professional’. * Unix and linux look very similar to the user so I will use the terms interchangeably.

NASSP Masters 5003F - Computational Astronomy The UNIX file structure The ‘prompt’ - this is what UNIX shows you when it is ready to receive a new command. Directory, file and path: –Directory names often have ‘/’s. Eg ‘/home/ims’ –File names don’t. Eg ‘clever_code.py’ File names may have a dot then a 2- to 4-letter suffix which gives you a hint about the file type. It is not a good idea to include spaces in Unix file or directory names. Use an underscore instead. –The full name for a file includes the directory where it is located, and is called a path name. Eg /home/ims/clever_code.py

NASSP Masters 5003F - Computational Astronomy UNIX shell commands pwd –present working directory - tells you where you are in the file system. cd –change pwd to directory ‘name’. mkdir –makes a new directory. rmdir –removes (deletes) the named directory.

NASSP Masters 5003F - Computational Astronomy UNIX shell commands ls –list the files in the pwd. cp –copies the named file. mv –equals cp followed by rm. But mv can also move directories. rm –removes (deletes) the named file. Note that each of the last three can erase files – so Back up your work!

NASSP Masters 5003F - Computational Astronomy UNIX shell commands –How to log in (securely!) to another computer. exit, logout –How to log out (pretty obvious). scp, rsync –ways to transfer files from one computer to another. man –gives you a ‘manual’, ie a lot of documentation (sometimes more than you really wanted!) for the named command.

NASSP Masters 5003F - Computational Astronomy Other interesting UNIX topics: Environment variables (eg SHELL, PYTHONPATH) The file named.bashrc (note the dot). –Try ‘more.bashrc’ Wild cards - * and ?. –Try: touch fred touch bert touch mary ls *e* –Should list all files which have names matching the pattern ‘anything, then an e, then anything.’ This will get fred and bert but not mary.

NASSP Masters 5003F - Computational Astronomy File types TypeSuffix TextVarious Code (specialized text files).f,.f90,.c,.cpp,.py, etc Flexible Image Transport System (FITS) Often.fit, but can vary Acroread output.pdf Postscript.ps ImagesEg.gif,.jpg,.png Compressed by gzip.gz ASCII Binary

NASSP Masters 5003F - Computational Astronomy FITS = Flexible Image Transport System This will be the default data format for this course. See: Primary HDU Extension 3 Extension 2 Extension 1 etc… Header-Data Units Data Header Data 2880-byte blocks etc… “Cards” … Unused cards of last header block filled with spaces (ASCII 32) or Binary table: ‘Image’ Unused bytes of last data block filled with spaces (ASCII 32) KEYWORD = VALUE / [UNIT] COMMENT

NASSP Masters 5003F - Computational Astronomy Text editors vi –non-windows, but abstruse commands. pico –non-windows, fairly user-friendly. emacs, xemacs –the editor of choice for many, but I don’t like it. gedit –my favourite. IDE for python coding… maybe ok… Whichever you choose – ***** Back up your work!! *****

NASSP Masters 5003F - Computational Astronomy Python

NASSP Masters 5003F - Computational Astronomy Python is a ‘scripting language’, which roughly translated means: –python code doesn’t have to be ‘compiled’; –it’s pretty slow. is an ‘object-oriented’ (OO) language. Some OO code can look pretty wacky. But relax! you won’t have to write any*. #!/usr/bin/env python – huh..? *probably not, anyway.

NASSP Masters 5003F - Computational Astronomy Python Python insists on ‘block indenting’. This means if you start any block, like an if statement, or a for loop, you have to indent within the block. The relaxation of this indenting is the way python recognizes the end of the block. You don’t have to run python as a script, you can also use it interactively. Type python at your normal unix prompt and you’ll get a new ‘sergeant’ prompt >>>. You can enter your python statements then line by line. Type ‘control-d’ to get out when you’re finished.

NASSP Masters 5003F - Computational Astronomy Large chunks of python The script you run on the command line, which consists of a single ascii file, is the ‘main program’. Obviously you need a ‘main’ to get anything done. But if your program is long, you may want to disperse some your code into subsidiary files, which are called from the main program. These secondary files are known as modules. They are called via the import statement.

NASSP Masters 5003F - Computational Astronomy How python finds your modules Suppose you have some neat code in a module named huge_brane.py which you keep in a directory named /home/me/src. You want a separate program slogger.py to be able to make use of this module. At the command line, do: Within your code slogger.py include the line Note that you leave off the.py bit. export PYTHONPATH=/home/me/src from huge_brane import *

NASSP Masters 5003F - Computational Astronomy Smaller chunks of python Within a module the largest chunks are functions. The syntax of a typical function is Note the ‘:’ and the indenting – typical for any block in python. Relax the indenting for the 1 st statement after the end of the function. You call the function from the main code like: def myfunction(foo, bar, bert): # some stuff here return ‘some value’ # optional newvar = myfunction(foo, bar, bert)

NASSP Masters 5003F - Computational Astronomy Python variables Python ‘scalar’ data types: –real –integer –string –boolean (‘True’ or ‘False’) –object (ie something with internal structure) BUT the python philosophy is to ignore this distinction as far as possible. Variables are not ‘declared’ as with other languages. Python sets (or resets, if necessary) the type of a variable to fit whatever data you try to load into it.

NASSP Masters 5003F - Computational Astronomy Python variables Ways to arrange several objects: –A single one is called a scalar. –A list: elements numbered*, data types can be different. –A tuple: similar to a list but written with round brackets rather than square. –A dictionary: elements accessed by a key, data types can be different; curly brackets. These groupings are themselves objects. *Python numbering starts from zero. (, 3.14, ‘fred’,…) {‘foo’:, ‘pi’:3.14, ‘him’:’fred’…} [, 3.14, ‘fred’,…]

NASSP Masters 5003F - Computational Astronomy Python operations They are mostly pretty standard. ‘Change in place’ can be a trap. Eg, type ‘python’ at the prompt, then try: This should print ‘4’. Now try: You’ll get ‘[999,2,3]’. Cf mutability… >>>a=4 >>>b=a >>>a=3 >>>print b >>>aa=[1,2,3] >>>bb=aa >>>aa[0]=999 >>>print bb

NASSP Masters 5003F - Computational Astronomy Trouble with ‘change in place’ Type:Mutable?Avoid the problem by: Simple scalarNo Scalar objectIt depends.. Use copy module ListYes bb=aa[:] TupleNo DictionaryYes bb=aa.copy()

NASSP Masters 5003F - Computational Astronomy OO OO programming is the business of constructing objects. This is done via the class statement. You probably won’t need to use this. However, objects themselves are inescapable in python – if you don’t make them, someone else will. In fact, almost everything in python is an object.

NASSP Masters 5003F - Computational Astronomy OO Objects have two extra features: 1.Attributes, which have names separated from the object name by a dot, eg fred.height is an attribute named height which belongs to object type of which fred is an example. 2.Methods: these are attributes which are functions. Like any function they can accept arguments, and must still be written with empty brackets even if there are no arguments. Eg the append() method of lists and the copy() method of dictionaries.

NASSP Masters 5003F - Computational Astronomy Python control structures if : # do some stuff elif : # you can have 0 or more of these # do some other stuff else: # you can have 0 or 1 of these # third lot of stuff while : # do loop stuff break # optional – dumps out and avoids the ‘else’. continue # like ‘goto while’. else: # optional - processing after normal loop exit. # stuff to do after normal loop exit for in : # etc There is NO ‘goto’ statement in python. This is a feature. Anything after a # is a comment.

NASSP Masters 5003F - Computational Astronomy Python ins and outs We’re going to mostly read our data from FITS files, using a module called pyfits. – ware/pyfits We’ll crunch up the data using a module called numpy. – For graphical output we’ll use module ppgplot, (2 ps) which is a (fairly crude) wrapper to a package called PGPLOT. – –