0% found this document useful (0 votes)
15 views46 pages

01 Computers and Programs

Uploaded by

mentarialfalah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views46 pages

01 Computers and Programs

Uploaded by

mentarialfalah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Class overview today - September 4, 2023

• A taste of Python

• Introductions and practical course information

• Elements of a computer and computer programs

• An introduction to our course computing environment

• A taste of Python

Python for geo-people www.helsinki.fi/yliopisto 2


Geo-Python
A taste of Python
Lecturer: David Whipp
[email protected]

4.9.2023

Python for geo-people www.helsinki.fi/yliopisto 3


Who are we?

• Lecturers

• Dave Whipp - Geo-Python

• Kamyar Hasanzadeh - AutoGIS

• Assistants

• Mikko Kangasmaa

• Aino Schulz

• Veeti Sihvola

• Leevi Tuikka

Python for geo-people www.helsinki.fi/yliopisto 4


Course websites

• Geo-Python/AutoGIS 1 (Period I)
https://geo-python.github.io

• AutoGIS 2 (Period II)


https://autogis.github.io

• Intro to Quantitative Geology (Period II)


https://introqg.github.io

Python for geo-people www.helsinki.fi/yliopisto 5


Class meetings in Period I

• On-site lessons

• Mondays 9:15-12:00

• Optional work sessions

• Thursdays 12:15-16:00

• Fridays 10:15-14:00

• You can feel free to attend either work session (or both)

Python for geo-people www.helsinki.fi/yliopisto 6


“AUTOGIS”

PERIOD 1:
• GEOG-329-1, Automating GIS-processes 1, Geo-Python
• Introduction to programming, data analysis and visualization

PERIOD 2:
• GEOG-329-2, Automating GIS-processes 2, Geography
• Spatial data management, analysis and visualization

5 + 5 ECTS
2
longitudinal profile 1.8). The Boreal surface is a high-elevation, low-
h (km) model fit relief plateau that dips to the west at 1◦ (Fig-
ure 1.8b). The Chagoopa Plateau is an interme-
1 diate topographic ‘‘bench’’ that is restricted to
Introduction to Quantitative Geology
bedrock alluvial
the major river canyons and inset into the Bo-
real Plateau (Webb, 1946; Jones, 1987). Figure 1.8b
0
0 5 10 15 20 maps the maximum extents of the Chagoopa
x (km) and Boreal Plateaux based on elevation ranges
of 1750--2250 m (Chagoopa) and 2250--3500 m a.s.l.
Fig 1.6 (a) Shaded-relief image of the Hanaupah Canyon (Boreal). Associated with each surface are promi-
drainage network and alluvial fan. Location of longitudinal nent knickpoints along major rivers. Knickpoints
profile shown as white curve. (b) Longitudinal profile of main along the North Fork Kern River, for example
Hanaupah Canyon channel, together with best-fit to Eq. (1.8).
Diffusion

(Figure 1.9b), occur at elevations of 1600--2100 m
Introduction to Quantitative Geology
and 2500--3300 m a.s.l. The stepped nature of the
Advection 2
@h @ h (GEOM2021), Master’s Program in Geology
Sierra Nevada topography is generally considered
=  (a) to be the result of two pulses of Cenozoic and/or
bedrock
@t @x 2 and Geophysics
late Cretaceous uplift (Clark et al., 2005; Pelletier,
channel 2007c). According to this model, two major knick-
t3

t2 t1
Basic geostatistics and applying numerical
points were created during uplift, each initiating
a wave of incision that is still propagating head-
t1 models written in Python to explore
(b) ward towards the range crest.
alluvial
channel t2t1 geochronological data and geological
Recent work has highlighted the importance
t2 tt3
3 of abrasion in controlling bedrock channel evo-
processes
lution. In the abrasion process it is sediment, not
water, that acts as the primary erosional agent.
Diffusion
Fig 1.7 Schematic diagrams of the evolution of (a) bedrock
and1.7,
Fig. (b) alluvial channels
Pelletier, 2008through time, illustrating the
• 5 ECTS
In the stream-power model, the erosive power is
assumed to be a power function of drainage area.
advective behavior of bedrock channels and the diffusive Although sediment flux increases with drainage
behavior of alluvial channels. area, upstream relief also plays an important role
in controlling sediment flux. As such, the stream-
power model does not adequately represent the
throughout the reach. If drainage area is uni- abrasion process. Sklar and Dietrich (2001, 2004)
form and n = 1 is assumed, the erosionPython ratefor geo-people
developed a saltation-abrasion model to quan-
www.helsinki.fi/yliopisto 8
is proportional to the channel slope according tify this process of bedrock channel erosion. In-
Who are you?

• We’d like to know a bit about who you are, and ask that you
direct your web browser or phone to a real-time poll at
https://geo-python.github.io/poll

Python for geo-people www.helsinki.fi/yliopisto 9


Goals of this part of the course

There are basically three goals in this part of the course

1. Introduce the Python programming language

2. Develop basic programming skills

3. Discuss essential (good) programming practices needed by


young scientists

Python for geo-people www.helsinki.fi/yliopisto 10


Some motivation

• See https://geo-python-site.readthedocs.io/en/latest/lessons/L1/
motivation.html

Python for geo-people www.helsinki.fi/yliopisto 11


Goals of this lecture

• Provide an overview of basic computing practices, and why


you should learn them

• Define computers and programming languages, and how


they operate

• Look at the components of a computer program and a


strategy for writing your own code

Python for geo-people www.helsinki.fi/yliopisto 12


Learning to program

• A significant part of this course will be development of basic


programming skills that will help you write and use simple
numerical models

• I know you’re not computer scientists - we aren’t either

• Our goal is take small steps to learn together

• Do you really need to know how to program? Yes.

• You might not be a superstar, but learning to write


simple codes can be very useful

Python for geo-people www.helsinki.fi/yliopisto 13


Why learn to program?

• Geology and geography are becoming increasingly quantitative


and basic programming skills are one of the fundamental skills
that will help you be a better scientist

Python for geo-people www.helsinki.fi/yliopisto 14


Why learn to program?

• You can extend existing software by developing your own


solutions when solutions do not exist or are inefficient

• Many software packages offer the ability to extend their


capabilities by adding your own short programs (e.g.,
ArcGIS, ParaView, Google Earth, etc.)
Python for geo-people www.helsinki.fi/yliopisto 15
You can interact with GIS software using Python

Python console in QGIS


Python for geo-people www.helsinki.fi/yliopisto 16
Why learn to program?

• Believe it or not, programming is fun! It


involves

• Breaking complex problems down into


simpler pieces

• Developing a strategy for solving the


problem

• Testing your solution

• All of this can be exciting and rewarding


(when the code works…)

Python for geo-people www.helsinki.fi/yliopisto 17


The scientific method…
…and how programming can make you a better scientist

1. Define a question

2. Gather information and resources (observe)

3. Form an explanatory hypothesis

4. Test the hypothesis by performing an experiment and collecting


data in a reproducible manner

5. Analyze the data

6. Interpret the data and draw conclusions that serve as a starting


point for new hypothesis

7. Publish results
8. Retest (frequently done by other scientists)

Python for geo-people www.helsinki.fi/yliopisto 18


Learning to program can help us…

1. Define a question

2. Gather information and resources (observe)

3. Form an explanatory hypothesis

4. Test the hypothesis by performing an experiment and


collecting data in a reproducible manner

5. Analyze the data

6. Interpret the data and draw conclusions that serve as a starting


point for new hypothesis

7. Publish results
8. Retest (frequently done by other scientists)

Python for geo-people www.helsinki.fi/yliopisto 19


Good programming practices can help us…

1. Define a question

2. Gather information and resources (observe)

3. Form an explanatory hypothesis

4. Test the hypothesis by performing an experiment and collecting


data in a reproducible manner

5. Analyze the data

6. Interpret the data and draw conclusions that serve as a starting


point for new hypothesis

7. Publish results

8. Retest (frequently done by other scientists)

Python for geo-people www.helsinki.fi/yliopisto 20


What is a computer?

Python for geo-people www.helsinki.fi/yliopisto 21


What is a computer?

• Let’s crowdsource: https://geo-python.github.io/poll

• Add your thoughts on what comprises a computer

• Vote for options you support

Python for geo-people www.helsinki.fi/yliopisto 22


What is a computer?

Output
CPU Devices

Input
Devices

Main Secondary
Memory Memory

Figure 1.1, Zelle, 2010

• Figure . : Functional View of a Computer.


A computer is a machine that stores and manipulates
information under the control of a changeable program
tional science (using powerful computers to model scientific data), databases,
software engineering, web and multimedia design, management information
systems, and computer security. Wherever computing is done, the skills and
knowledge of computer science are being applied.

You don’t have to know all the details of how a computer works to be a successful
programmer, but understanding the underlying principles will help you master
the steps we go through to put our programs into action. It’s a bit like driving a
car. Knowing a littlePython
aboutforinternal
geo-peoplecombustion engines
www.helsinki.fi/yliopisto
helps to explain why you 23

have to do things like fill the gas tank, start the engine, step on the accelerator,
What is a computer?

Output
CPU Devices

Input
Devices

Main Secondary
Memory Memory

Figure 1.1, Zelle, 2010

• Figure . : Functional View of a Computer.


A computer is a machine that stores and manipulates
information under the control of a changeable program
tional science (using powerful computers to model scientific data), databases,


software engineering, web and multimedia design, management information
Information
systems, and computer security.can be input,
Wherever modified
computing is done,into a new/useful
the skills and form
and output
knowledge of computer sciencefor our applied.
are being interpretation

You don’t have to know all the details of how a computer works to be a successful
programmer, but understanding the underlying principles will help you master
the steps we go through to put our programs into action. It’s a bit like driving a
car. Knowing a littlePython
aboutforinternal
geo-peoplecombustion engines
www.helsinki.fi/yliopisto
helps to explain why you 24

have to do things like fill the gas tank, start the engine, step on the accelerator,
What is a computer?

Output
CPU Devices

Input
Devices

Main Secondary
Memory Memory

Figure 1.1, Zelle, 2010

Figure . : Functional View of a Computer.


• A computer is a machine that stores and manipulates
information
tional science under
(using powerful the control
computers of a changeable
to model scientific program
data), databases,
software engineering, web and multimedia design, management information


systems, and computer security. Wherever computing is done, the skills and
Controlled by a computer program that can be
knowledge of computer science are being applied.
modified

You don’t have to know all the details of how a computer works to be a successful
programmer, but understanding the underlying principles will help you master
the steps we go through to put our programs into action. It’s a bit like driving a
car. Knowing a littlePython
aboutforinternal
geo-peoplecombustion engines
www.helsinki.fi/yliopisto
helps to explain why you 25

have to do things like fill the gas tank, start the engine, step on the accelerator,
What are computers good at?

• Well-defined, clear tasks

• Add 2 + 2 and return the


>>> print(2 + 2) answer
4

>>> print(“2 + 2 =“,2 + 2) • Data storage/manipulation


2 + 2 = 4

• Repetitive calculations

• Processing data or instructions


Python for geo-people www.helsinki.fi/yliopisto 26
What are computers good at?

Python prompt Print function • Well-defined, clear tasks

• Add 2 + 2 and return the


>>> print(2 + 2) answer
4
Returned value

>>> print(“2 + 2 =“,2 + 2) • Data storage/manipulation


2 + 2 = 4

• Repetitive calculations

• Processing data or instructions


Python for geo-people www.helsinki.fi/yliopisto 27
What aren’t computers good at?

• Abstract or poorly defined tasks

• Calculate pi

Python for geo-people www.helsinki.fi/yliopisto 28


What aren’t computers good at?

3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 0628620899


8628034825 3421170679 8214808651 3282306647 0938446095 5058223172 5359408128 4811174502
8410270193 8521105559 6446229489 5493038196 4428810975 6659334461 2847564823 3786783165
2712019091 4564856692 3460348610 4543266482 1339360726 0249141273 7245870066 0631558817
4881520920 9628292540 9171536436 7892590360 0113305305 4882046652 1384146951 9415116094
3305727036 5759591953 0921861173 8193261179 3105118548 0744623799 6274956735 1885752724
8912279381 8301194912 9833673362 4406566430 8602139494 6395224737 1907021798 6094370277
0539217176 2931767523 8467481846 7669405132 0005681271 4526356082 7785771342 7577896091
7363717872 1468440901 2249534301 4654958537 1050792279 6892589235 4201995611 2129021960
8640344181 5981362977 4771309960 5187072113 4999999837 2978049951 0597317328 1609631859
5024459455 3469083026 4252230825 3344685035 2619311881 7101000313 7838752886 5875332083
8142061717 7669147303 5982534904 2875546873 1159562863 8823537875 9375195778 1857780532
1712268066 1300192787 6611195909 2164201989
The first 1000 digits of pi

• Abstract or poorly defined tasks

• Calculate pi

Python for geo-people www.helsinki.fi/yliopisto 29


What aren’t computers good at?
Lumi supercomputer
~200,000 cores
www.lumi-supercomputer.eu/

• Tasks that are not computable

• Computer, where are my car keys?

• Some problems simply cannot be solved, or require too


much computing power
Python for geo-people www.helsinki.fi/yliopisto 30
What is a program?

Fortran punchcard

# Define plot variables


misfit = NA_data[:,0]
var1 = NA_data[:,1]
var2 = NA_data[:,2]
var3 = NA_data[:,3]
clrmin = round(min(misfit),3)
clrmax = round(min(misfit),2)
trans = 0.75
ptsize = 40 Python source code

Python for geo-people www.helsinki.fi/yliopisto 31


What is a program?

Fortran punchcard
• A program is a detailed list
of step-by-step instructions
telling the computer exactly
what to do

# Define plot variables • The program can be


changed to alter what the
misfit = NA_data[:,0]
var1 = NA_data[:,1]
computer will do when the
var2 = NA_data[:,2] code is executed
var3 = NA_data[:,3]
clrmin = round(min(misfit),3)
clrmax = round(min(misfit),2)
trans = 0.75 • Software is another name
ptsize = 40 for a program
Python source code

Python for geo-people www.helsinki.fi/yliopisto 32


What is a programming language?

• A computer language is what we use to ‘talk’ to a computer

• Unfortunately, computers don’t yet understand our native


languages though chat bots are getting better and better

• A programming language is like a code of instructions for the


computer to follow

• It is exact and unambiguous

• Every structure has a precise form (syntax) and a precise


meaning (semantics)

• Python is just one of many programming languages

Python for geo-people www.helsinki.fi/yliopisto 33


Developing a program

• Coming up with a specific list of instructions for the computer


to follow in order to accomplish a desired task is not easy

• The following list will serve us as a general software


development strategy

1. Analyze the problem

2. Determine specifications

3. Create a design

4. Implement the design

5. Test/debug the program


6. Maintain the program (if necessary)

Python for geo-people www.helsinki.fi/yliopisto 34


Let’s consider an example

• As an American, I was raised in a country that uses Fahrenheit


for temperatures

• 70°F is lovely

• 90°F is hot

• Water freezes at 32°F

• The problem here in Finland is that I don’t always know what I


should wear to work when I find weather reports with
temperatures in degrees Celsius

• I think a simple program could help

Python for geo-people www.helsinki.fi/yliopisto 35


Developing a program

1. Analyze the problem

• Before you can solve a problem, you must figure out exactly
what should be solved

2. Determine specifications

• Describe exactly what the program will do

• Don’t worry about how it will work. Determine the


input and output values and how they should interact in
the program

Python for geo-people www.helsinki.fi/yliopisto 36


Developing a program

1. Analyze the problem

• Before you can solve a problem, you must figure out exactly
what should be solved

2. Determine specifications

• Describe exactly what the program will do

• Don’t worry about how it will work. Determine the


input and output values and how they should interact in
the program

Python for geo-people www.helsinki.fi/yliopisto 37


Developing a program

3. Create a design

• What is the overall structure of the program? How will it


work?

• It is often helpful to write out the code operation in


pseudocode, precise English (or Finnish) describing the
program. Be specific!

4. Implement the design

• If you’ve done a good job with the previous steps, this


should be fairly straightforward. Take your pseudocode and
‘translate’ it into Python

Python for geo-people www.helsinki.fi/yliopisto 38


Developing a program

3. Create a design

• What is the overall structure of the program? How will it


work?

• It is often helpful to write out the code operation in


pseudocode, precise English (or Finnish) describing the
program. Be specific!

4. Implement the design

• If you’ve done a good job with the previous steps, this


should be fairly straightforward. Take your pseudocode and
‘translate’ it into Python

Python for geo-people www.helsinki.fi/yliopisto 39


Developing a program

5. Test/debug the program

• Now you can put your new Python code to the test
(literally) by running it to see whether it reproduces the
expected values

• For any test, you should know the correct values in


advance of running your code. How else can you confirm
it works???

6. Maintain the program

• If you’ve written something that will be shared by other


users, a helpful programmer will continue to add features
that are requested by the users

Python for geo-people www.helsinki.fi/yliopisto 40


Developing a program

5. Test/debug the program

• Now you can put your new Python code to the test
(literally) by running it to see whether it reproduces the
expected values

• For any test, you should know the correct values in


advance of running your code. How else can you confirm
it works???

6. Maintain the program

• If you’ve written something that will be shared by other


users, a helpful programmer will continue to add features
that are requested by the users

Python for geo-people www.helsinki.fi/yliopisto 41


Recap

• What is a computer?

• What is a program?

• What are some of the steps in developing a program?

Python for geo-people www.helsinki.fi/yliopisto 42


Recap

• What is a computer?

• What is a program?

• What are some of the steps in developing a program?

Python for geo-people www.helsinki.fi/yliopisto 43


Recap

• What is a computer?

• What is a program?

• What are some of the steps in developing a program?

Python for geo-people www.helsinki.fi/yliopisto 44


References

Zelle, J. M. (2010). Python programming: an introduction to computer science (2nd ed.). Franklin, Beedle &
Associates, Inc.

Python for geo-people www.helsinki.fi/yliopisto 45


Our first taste of Python

• Open a web browser and navigate to


https://geo-python.github.io/

Python for geo-people www.helsinki.fi/yliopisto 46


Puupyton / Green tree python
• We’ll continue at 10:40 from the course website at
https://geo-python.github.io

Python for geo-people www.helsinki.fi/yliopisto 47

You might also like