Python for Astronomers. Week 1- Basic Python

Similar documents
Week Two. Arrays, packages, and writing programs

History. Terminology. Opening a Terminal. Introduction to the Unix command line GNOME

Essential Linux Shell Commands

Programming Studio #1 ECE 190

User Guide Version 2.0

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

Introduction to Unix - Lab Exercise 0

Unit 10. Linux Operating System

Introduction to the Linux Command Line

Chapter 4. Unix Tutorial. Unix Shell

1. The Mac Environment in Sierra Hall 1242

1. The Mac Environment in SIE 1222

Session 1: Accessing MUGrid and Command Line Basics

Programming Studio #1 ECE 190

Shell Programming Overview

Integer Representation. Variables. Real Representation. Integer Overflow/Underflow

Introduction to Linux. Fundamentals of Computer Science

CS CS Tutorial 2 2 Winter 2018

Lab Working with Linux Command Line

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.

COMS 6100 Class Notes 3

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Unit 13. Linux Operating System Debugging Programs

Unix background. COMP9021, Session 2, Using the Terminal application, open an x-term window. You type your commands in an x-term window.

Introduction: What is Unix?

Mills HPC Tutorial Series. Linux Basics I

CSC111 Computer Science II

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

Fundamentals: Expressions and Assignment

Linux Command Line Primer. By: Scott Marshall

Unix Filesystem. January 26 th, 2004 Class Meeting 2

A QUICK GUIDE TO PROGRAMMING FOR THE WEB. ssh (then type your UBIT password when prompted)

Introduction. File System. Note. Achtung!

Common UNIX Commands. Unix. User Interfaces. Unix Commands Winter COMP 1270 Computer Usage II 9-1. Using UNIX. Unix has a command line interface

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

SECTION -C. Getting Started with UNIX

5/8/2012. Creating and Changing Directories Chapter 7

The Command Line. Matthew Bender. September 10, CMSC Command Line Workshop. Matthew Bender (2015) The Command Line September 10, / 25

Topic 1: Introduction

Files

Introduction of Linux

Connecting to ICS Server, Shell, Vim CS238P Operating Systems fall 18

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

Physics REU Unix Tutorial

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

Introduction to Linux and Supercomputers

last time in cs recitations. computer commands. today s topics.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

The Directory Structure

CS Fundamentals of Programming II Fall Very Basic UNIX

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

When you first log in, you will be placed in your home directory. To see what this directory is named, type:

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

Python Programming Exercises 1

Part I. Introduction to Linux

Introduction to UNIX command-line

Operating System Interaction via bash

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Linux Shell Script. J. K. Mandal

Introduction to Linux Workshop 1

Introduction to the UNIX command line

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

PDS Lab Section 16 Autumn Tutorial 1. Unix Commands pwd The pwd command displays the full pathname of the current directory.

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Introduction to Unix: Fundamental Commands

CHEM5302 Fall 2015: Introduction to Maestro and the command line

Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny.

Parallel Programming Pre-Assignment. Setting up the Software Environment

3/13/2012. ESc101: Introduction to Computers and Programming Languages

Introduc)on to Linux Session 2 Files/Filesystems/Data. Pete Ruprecht Research Compu)ng Group University of Colorado Boulder

Unix Tutorial Haverford Astronomy 2014/2015

Bash command shell language interpreter

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

Chapter-3. Introduction to Unix: Fundamental Commands

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

Virtual Machine. Linux flavor : Debian. Everything (except slides) preinstalled for you.

CMSC 201 Spring 2018 Lab 01 Hello World

Getting Started With Linux and Fortran Part 3

Python for Astronomers

An Introduction to Unix

A Brief Introduction to the Linux Shell for Data Science

Linux Bootcamp Fall 2015

Linux Introduction Martin Dahlö Valentin Georgiev

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Working with Basic Linux. Daniel Balagué

TNM093 Practical Data Visualization and Virtual Reality Laboratory Platform

Helpful Tips for Labs. CS140, Spring 2015

CS50 Supersection (for those less comfortable)

easel LANGUAGE REFERENCE MANUAL

Transcription:

Python for Astronomers Week 1- Basic Python

UNIX UNIX is the operating system of Linux (and in fact Mac). It comprises primarily of a certain type of file-system which you can interact with via the terminal (command line). Navigating a file-system via command line take some getting used to, but ultimately it provides much higher efficiency than a GUI (where you would open multiple folder windows)

An Example Directory Tree A server/computer running over UNIX has a directory tree like this, with main directories, and various subdirectories within. To access any specific directory, you can use the UNIX command cd and the full path location of your directory i.e: cd /home/jelkner/webappdev/ unix/notes

The cd Command Additionally, you can use the command cd without any arguments to return to the home directory of your user. This is different than /home. Each person with access to a server/ computer has an account name, and YOUR home directory is typically the one in the filesystem with your name on it- so if i were kjcole, typing cd <enter> would take me to /home/kjcole.

Some shortcuts with cd To move only one/two levels in the tree there are some shortcuts >> cd.. will take you out one directory (i.e., from unix to webappdev) If you are in /unix, typing cd notes will take you into notes* Aside: You can use pwd to see exactly where you are in a tree at any time.

Some shortcuts with cd You can string these shortcuts together from your current directory. If you were in unix, cd../.. would take you to /jelkner If you were in /webappdev, cd unix/notes would take you to notes.

Moving and Copying Use the mv command to move a file. The syntax is (if you were in /notes): >>mv lesson1.txt /home/kjcole/ public_html i.e: mv filename new-name new location (in the example I chose not to rename it along the way) mv also used to rename files cp uses the same syntax.

Deleting files and Directories To delete a file, use the rm command: rm filename To delete an empty directory you can use rmdir directory name The recursive lets you delete a directory and all files within: >>rm -r /home/jeljner/ webappdev/unix/notes

Other useful commands ls: list all files/folders in the current directory pwd: print the current directory * : wildcard (shown best with examples) ssh: allows you to log in to a remote server scp: allows you to copy files to/from a remote server

Python Python is a high level programming language that is useful particularly for data analysis and plotting Python is one of the easier languages to learn; being high level means there s less archaic syntactical expressions for things-it reads closely to plain english Programming in python (or any language) comes down to a combination of data-types being saved into variables, control-flow/ conditionals and loops handling the data, and plotting the outputs (or saving them to/from files).

ipython interpreter We just demonstrated how python can be used as a calculator, performing basic arithmetic (+, -, /, *, ^). We saw that 1/2 produced a result of 0. This comes down to a question of data-types, so we should try to understand the different ones available to us

Datatypes Integers: Counting numbers (1,2,3, ). Math performed with integers has to produce an integer (hence the rounding error). Floats: Any number with a decimal (1., 2., 3.1456, ). Floats take up more memory, but 1./2 will produce the right response. If any one number in a calculation is a float, any other integers will be converted to floats. strings: Anything contained in quotes. Usually used to introduce words like python, and are often used in the syntax for loading data files.

Datatypes Lists: lists of any data-type, contained in brackets: >> list1 = [1,2,3.,[4,5,6], cat, dog, 8] Arrays: a numpy datatype, like a list but where all values have to be numbers. Arrays can be easily mathematically manipulatedmultiplication by an array will multiply every value in the array by that number element wise. >>array_1 = np.array([1., 5., 8.]) Booleans: either true or false.

Variables Variables allow us to store objects of the data-types mentioned for use in calculations- for example we already declared the variables list1 and array_1. Variables give us the capacity to work with a 1000 entry list as a single letter, without having to type out all the entries each time. To declare a variable, you pick a name for it, and set it equal to its value

Recasting Within certain parameters, you can recast a variable of one type into another, using the name of the datatype. For example, ints can be cast as floats, floats can be cast as ints, floats/ints can be cast as strings, strings containing only numbers can be cast as floats/ ints, etc. This is useful if you want to change the datatype of a variable after you have declared it (even if you no longer know what its value is since it has been calculated upon).