NASSP Masters 5003F - Computational Astronomy - 2009 Lecture 8 Some further unix & python tips Good programming habits Catalog cross-matching Bayesian.

Slides:



Advertisements
Similar presentations
CST8177 bash Scripting Chapters 13 and 14 in Quigley's "UNIX Shells by Example"
Advertisements

Cluster Computing at IQSS Alex Storer, Research Technology Consultant.
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
NASSP Masters 5003F - Computational Astronomy Lecture 5: source detection. Test the null hypothesis (NH). –The NH says: let’s suppose there is no.
Understanding bash Prof. Chris GauthierDickey COMP 2400, Fall 2008.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
Shell Programming. Shell Scripts (1) u Basically, a shell script is a text file with Unix commands in it. u Shell scripts usually begin with a #! and.
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.
BIF703 stdin, stdout, stderr Redirection. stdin, stdout, stderr Recall the Unix philosophy “do one thing well”. Unix has over one thousand commands (utilities)
An Introduction to Unix Shell Scripting
Lecture 1 NASSP Masters 5003S - Computational Astronomy Me: Ian Stewart Room 521, James building
General Programming Introduction to Computing Science and Programming I.
NASSP Masters 5003F - Computational Astronomy UNIX* intro We’ll use the ‘command line’ – windows are for wimps. The unix ‘shell’: –This is what.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
NASSP Masters 5003F - Computational Astronomy Lecture 3 First, a bit more python. Then some noise statistics.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
Linux+ Guide to Linux Certification, Third Edition
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
Hands-on Introduction to R. We live in oceans of data. Computers are essential to record and help analyse it. Competent scientists speak C/C++, Java,
Quiz 15 minutes Open note, open book, open computer Finding the answer – working to get it – is what helps you learn I don’t care how you find the answer,
Hey, Ferb, I know what we’re gonna do today! Aims: Use formatted printing. Use the “while” loop. Understand functions. Objectives: All: Understand and.
NASSP Masters 5003S - Computational Astronomy Lecture 2 More python. –Good books: “Learning Python”, Lutz & Ascher, O’Reilly (the ‘rat book’); “Python.
Intro Python: Variables, Indexing, Numbers, Strings.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
A Genomics View of Unix. General Unix Tips To use the command line start X11 and type commands into the “xterm” window A few things about unix commands:
 The point estimators of population parameters ( and in our case) are random variables and they follow a normal distribution. Their expected values are.
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
Basics of Biostatistics for Health Research Session 1 – February 7 th, 2013 Dr. Scott Patten, Professor of Epidemiology Department of Community Health.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Python Let’s get started!.
Lecture 8 Source detection NASSP Masters 5003S - Computational Astronomy
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Lecture 10 The catalog of sources –Resolved sources –Selection biases –Luminosity (and mass) functions –Volume- vs flux-limited surveys. Cross-matching.
Lecture 7 Conditional Scripting and Importing/Exporting.
Assigning Values 1. $ set One Two Three [Enter] $echo $1 $2 $3 [Enter] 2. $set `date` [Enter] $echo $1 $2 $3 [Enter] 3. $echo $1 $2 $3 $4 $5 $6 [Enter]
Unix Fundamentals CS 127. File navigation cd - change directory cd /var/log cd /etc/apache2 cd ~/Desktop ~ is a shortcut for the home directory.
CSC Programming for Science Lecture 18: More Data Files.
Batch Files Flow of Control to Strengthen Copyright © by Curt Hill.
LECTURE 2 Python Basics. MODULES So, we just put together our first real Python program. Let’s say we store this program in a file called fib.py. We have.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Linux Administration Working with the BASH Shell.
 Prepared by: Eng. Maryam Adel Abdel-Hady
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
Chapters 13 and 14 in Quigley's "UNIX Shells by Example"
Introduction to Computing Science and Programming I
Prepared by: Eng. Maryam Adel Abdel-Hady
Unix Scripting Session 4 March 27, 2008.
The Linux Operating System
stdin, stdout, stderr Redirection
Tips for Writing Free Response Questions on the AP Statistics Exam
CSE 303 Concepts and Tools for Software Development
Tips for Writing Free Response Questions on the AP Statistics Exam
Sarah Diesburg Operating Systems CS 3430
Python Lessons 13 & 14 Mr. Kalmes.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Coding Concepts (Basics)
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
CISC101 Reminders Assignment 3 due today.
CMPT 120 Lecture 4 – Unit 1 – Chatbots
Presentation transcript:

NASSP Masters 5003F - Computational Astronomy Lecture 8 Some further unix & python tips Good programming habits Catalog cross-matching Bayesian variability test

NASSP Masters 5003F - Computational Astronomy More Unix tips and tricks: redirection. How to redirect your output: –If I do –I get –etc. But if I do –I apparently don’t get anything. But! Look inside file99: –etc. $ ls > file99 benne.html Desktop Examples pic26867.jpg $ more file99 benne.html Desktop $ ls

NASSP Masters 5003F - Computational Astronomy More Unix tips and tricks: redirection. The > character redirects the output of ls (or any other command) from the screen to the named file. Careful! It will overwrite any pre-existing file of that name. If you just want to add stuff to the end of an existing file, use >> instead of >. To redirect errors, you have to be more elaborate. But we won’t worry about that. If you want to send the output to another command, use | (called a ‘pipe’). Eg a2ps | lp -dljuct

NASSP Masters 5003F - Computational Astronomy Dots in Unix. A dot. in Unix has several different functions, depending on context. 1.Here it is just part of a filename: 2.Here is the first character in the name of a ‘hidden’ file (ls won’t list these – but ls –a will): 3.Here it means run the script called fred: 4.Here it means the present working directory: bignob.py.bashrc $. fred $ export PATH=/usr/bin:. $ ls./* Note the space!

NASSP Masters 5003F - Computational Astronomy Double dots in Unix. Two dots in a row means the directory 1 higher up the tree from here. It can save you some typing. Eg the following: –If I want to cd back to comp_astron, there’s two ways to do it. The long way: –Or the short way: $ pwd /home/ims/doc/teaching/comp_astron $ ls code latex figures $ cd code $ pwd /home/ims/doc/teaching/comp_astron/code $ cd /home/ims/doc/teaching/comp_astron $ cd../

NASSP Masters 5003F - Computational Astronomy The tilde ~ This is another symbol which has a meaning which depends on context. 1.Here it means the file is a backup. The shell makes these under certain conditions. They record the file before your last change. Obviously this can be useful! 2.Here it is shorthand for your home directory. As an aside, cd with no arguments always takes you direct to home: $ cd ~/doc/teaching some_file_name~ $ cd

NASSP Masters 5003F - Computational Astronomy Another few cm of the python. The range function – it is a bit tricky. Note the following: Function returns. Note: This is a tuple. It is better to be explicit... >>> print range(3) [0, 1, 2] >>> print range(0,3) [0, 1, 2] >>> def some_func(arg1,arg2):... a = arg1 + arg2... b = arg1 – arg2... return a, b... >>> c = some_func(42, 2) >>> print c (44, 40)

NASSP Masters 5003F - Computational Astronomy Another few cm of the python. Also in the function call: –is better than You can also force it to return a list: >>> def some_func(arg1,arg2):... a = arg1 + arg2... b = arg1 – arg2... return (a, b) >>> (summ, diff) = some_func(42, 2) >>> c = some_func(42, 2) >>> def anuther_func(arg1,arg2):... a = arg1 + arg2... b = arg1 – arg2... return [a, b]... >>> c = anuther_func(20, 19) >>> print c [39, 1]

NASSP Masters 5003F - Computational Astronomy Another few cm of the python. The for statement - most of you know this way: But you can also do this: Saves a bit of typing. >>> mylist = [‘peas’,’beans’,’dead dog’] >>> for i in range(len(mylist)):... item = mylist[i]... print item... peas beans dead dog >>> mylist = [‘peas’,’beans’,’dead dog’] >>> for item in mylist:... print item... peas beans dead dog

NASSP Masters 5003F - Computational Astronomy Good vs. EVIL programming habits. The good: –Make your code as unspecialized as possible. –Chunk tasks into functions and modules. The bad: –GOTO – python has abolished this statement. –Equality testing against reals. Eg Only do this against zero. –Leaving some values untested, eg: if (myvar == 7.2): if (nuddervar < 5.9): # do something elif (nuddervar > 5.9): # do something else

NASSP Masters 5003F - Computational Astronomy Good vs. EVIL programming habits. The bad continued: –Changing function arguments. Eg –This is actually only ugly...BAD is doing it with lists. Try the following: –Using reserved words for variable names. The ugly: –Too-short variable names. def hobbit_state(bilbo, sam): sam = ‘hungry’ >>> def moonshine(list_of_moons):... list_of_moons.append(‘half’)... >>> mondlicht = [‘new’,’blue’] >>> moonshine(mondlicht) >>> print mondlicht

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching It sometimes happens that you have 2 lists of objects, which you want to cross-match. –Maybe the lists are sources observed at different frequencies. –The situation also arises in simulations. I’ll deal with the simulations situation first, because it is easier. –So: we start with a bunch of simulated sources. Let’s keep it simple and assume they all have the same brightness. –We add noise, then see how many we can find.

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching –In order to know how well our source- detection machinery is working, we need to match each detection with one of the input sources. How do we do this? How do we know the ‘matched’ source is the ‘right one’?...I haven’t done a rigorous search of the literature yet – these are just my own ideas. CAVEAT:

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching Black: simulated sources Red: 1 of many detections (with 68% confidence interval). This case seems clear.

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching But what about these cases? No matches inside confidence interval. Too many matches inside confidence interval.

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching Or these? Is any a good match?Which is ‘nearest’?

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching My conclusion: 1.The shape of the confidence intervals affects which source is ‘nearest’. 2.The size of the confidence intervals has nothing to do with the probability that the ‘nearest’ match is non-random. 1.‘Nearest neighbour’ turns out to be a slipperier concept than we at first think. To see this, imagine that we have now 1 spatial dimension and 1 flux dimension:

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching S x S x Which is the best match??? This makes more sense. Let’s then define r as: Source 5?Or source 8?

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching 2.As for the probability... well, what is the null hypothesis in this case? –Answer: that the two catalogs have no relation to each other. –So, we want the probability that, with a random distribution of the simulated sources, a source would lie as close or closer to the detected source than r nearest. –This is given by: –where ρ is the expected density of sim sources and V is the volume inside r nearest. P null = 1 – exp(- ρ V)

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching So the procedure for matching to a simulated catalog is: 1.For each detection, find the input source for which r is smallest. 2.Calculate the probability of the null hypothesis from P null = 1 – exp(-ρV). 3.Discard those sources for which P null is greater than a pre-decided (low) cutoff. What about the general situation of matching between different catalogs?

NASSP Masters 5003F - Computational Astronomy Catalog cross-matching ASCA data – M Akiyama et al (2003)

NASSP Masters 5003F - Computational Astronomy Bayesian variability analysis

NASSP Masters 5003F - Computational Astronomy Bayesian variability analysis

NASSP Masters 5003F - Computational Astronomy Bayesian variability analysis

NASSP Masters 5003F - Computational Astronomy Bayesian variability analysis

NASSP Masters 5003F - Computational Astronomy Bayesian variability analysis

NASSP Masters 5003F - Computational Astronomy Bayesian variability analysis

NASSP Masters 5003F - Computational Astronomy Bayesian variability analysis J D Scargle (1998)