SlideShare una empresa de Scribd logo
1 de 24
Python for geo-people
www.helsinki.fi/yliopist
o
Automating GIS-processes
FEC 2017
Lecturers: Vuokko Heikinheimo & Henrikki Tenkanen
vuokko.heikinheimo@helsinki.fi
henrikki.tenkanen@helsinki.fi
6.3.2017
Materials: Henrikki Tenkanen, David Whipp, Vuokko Heikinheimo
www.helsinki.fi/yliopist
o
Python for geo-people
Goals of the course
There are basically four goals in this intensive course
1. Introduce the Python programming language
2. Develop basic programming skills
3. Discuss essential (good) programming practices needed by
young scientists
4. Introduce automatization of different GIS tasks in Python
www.helsinki.fi/yliopist
o
Python for geo-people
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
www.helsinki.fi/yliopist
o
Python for geo-people
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 - I’m not 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
www.helsinki.fi/yliopist
o
Python for geo-people
Why learn to program?
• Rather than being restricted to using existing software,
you will have the ability to develop 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.)
www.helsinki.fi/yliopist
o
Python for geo-people
Python can be called directly from ArcGIS
www.helsinki.fi/yliopist
o
Python for geo-people
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…)
www.helsinki.fi/yliopist
o
Python for geo-people
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)
www.helsinki.fi/yliopist
o
Python for geo-people
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)
www.helsinki.fi/yliopist
o
Python for geo-people
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/yliopist
o
Programming
“Computer programming (often shortened to programming) is a process
that leads from an original formulation of a computing problem to
executable computer programs. Programming involves activities such as
analysis, developing understanding, generating algorithms, verification of
requirements of algorithms including their correctness and resources
consumption, and implementation (commonly referred to as coding) of
algorithms in a target programming language.”
-Wikipedia (2015)
“A program is like a recipe. It contains a list of ingredients (called
variables) and a list of directions (called statements) that tell the
computer what to do with the variables.”
- Webopedia (2015)
www.helsinki.fi/yliopist
o
Python for geo-people
What is a program?
• A program is a detailed
list of step-by-step
instructions telling the
computer exactly what to
do
• The program can be
changed to alter what the
computer will do when
the code is executed
• Software is another name
for a program
# 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
Fortran punchcard
Python source code
www.helsinki.fi/yliopist
o
Python for geo-people
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
• 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/yliopist
o
High level
programming
Low level
programming
Less code
More code
Slower
Faster
Various different programming languages exist
• Python
• Perl
• Ruby
• JavaScript
• Java
• C++
• C
• Fortran
+ Many others
Programming languages remind our spoken languages!
• There are different ways to express the same meaning
• Some languages are more similar to each other than others
• After learning one language it is easier to learn other ones!
Programming
Moikka, Hello, Hej, Hallo, Hola
echo ”Moikka”, print(”Hello”), console.log(”Hej”),
puts(”Hallo”), System.out.println(”Hola”)
Spoken languages Programming languages
Python for geo-people
www.helsinki.fi/yliopist
o
Python is:
• General purpose
• High level
• Cross-platform
• Open source
• Multi-paradigm: Object oriented / imperative / functional / procedural / reflective
• Uses dynamic type-checking
Why to learn / use Python?
• Easy to learn (a good programming language for the beginners)
• Easy to read and understand – elegant code
• Powerful enough – used in scientific programming
• Countless ready-made modules / libraries to use (also GIS stuff)
• Supportive, large and helpful user community
• Widely supported in different GIS-softwares
- ArcGIS, QGIS, Erdas Imagine, IDRISI, uDig, ILWIS, PostGIS …
• Extremely useful for automating GIS processes
Programming
www.helsinki.fi/yliopist
o
Python for geo-people
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)
www.helsinki.fi/yliopist
o
Python for geo-people
Let’s consider an example
• As an American, David 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 he doesn’t always
know what he should wear to work when he finds
weather reports with temperatures in degrees Celsius
• A simple program could help
www.helsinki.fi/yliopist
o
Python for geo-people
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
www.helsinki.fi/yliopist
o
Python for geo-people
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
www.helsinki.fi/yliopist
o
Python for geo-people
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
www.helsinki.fi/yliopist
o
Python for geo-people
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
www.helsinki.fi/yliopist
o
Python for geo-people
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
www.helsinki.fi/yliopist
o
Python for geo-people
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
www.helsinki.fi/yliopist
o
Python for geo-people
References
Zelle, J. M. (2010). Python programming: an introduction to computer science (2nd ed.). Franklin,
Beedle & Associates, Inc.

Más contenido relacionado

La actualidad más candente

Software Carpentry for the Geophysical Sciences
Software Carpentry for the Geophysical SciencesSoftware Carpentry for the Geophysical Sciences
Software Carpentry for the Geophysical Sciences
Aron Ahmadia
 
Embracing Diversity: Searching over Multiple Languages - Suneel Marthi, Red H...
Embracing Diversity: Searching over Multiple Languages - Suneel Marthi, Red H...Embracing Diversity: Searching over Multiple Languages - Suneel Marthi, Red H...
Embracing Diversity: Searching over Multiple Languages - Suneel Marthi, Red H...
Lucidworks
 

La actualidad más candente (18)

Python – The Fastest Growing Programming Language
Python – The Fastest Growing Programming LanguagePython – The Fastest Growing Programming Language
Python – The Fastest Growing Programming Language
 
Open & reproducible research - What can we do in practice?
Open & reproducible research - What can we do in practice?Open & reproducible research - What can we do in practice?
Open & reproducible research - What can we do in practice?
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
Python programming
Python programmingPython programming
Python programming
 
Python, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for EngineersPython, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for Engineers
 
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
 
11 Unit1 Chapter 1 Getting Started With Python
11   Unit1 Chapter 1 Getting Started With Python11   Unit1 Chapter 1 Getting Started With Python
11 Unit1 Chapter 1 Getting Started With Python
 
IPython: A Modern Vision of Interactive Computing (PyData SV 2013)
IPython: A Modern Vision of Interactive Computing (PyData SV 2013)IPython: A Modern Vision of Interactive Computing (PyData SV 2013)
IPython: A Modern Vision of Interactive Computing (PyData SV 2013)
 
Software Carpentry for the Geophysical Sciences
Software Carpentry for the Geophysical SciencesSoftware Carpentry for the Geophysical Sciences
Software Carpentry for the Geophysical Sciences
 
Seminar report On Python
Seminar report On PythonSeminar report On Python
Seminar report On Python
 
python for linguists
python for linguistspython for linguists
python for linguists
 
First python project
First python projectFirst python project
First python project
 
Python
PythonPython
Python
 
Embracing Diversity: Searching over Multiple Languages - Suneel Marthi, Red H...
Embracing Diversity: Searching over Multiple Languages - Suneel Marthi, Red H...Embracing Diversity: Searching over Multiple Languages - Suneel Marthi, Red H...
Embracing Diversity: Searching over Multiple Languages - Suneel Marthi, Red H...
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
Lets learn Python !
Lets learn Python !Lets learn Python !
Lets learn Python !
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on python
 

Destacado

Generations of Programming Languages
Generations of Programming LanguagesGenerations of Programming Languages
Generations of Programming Languages
Tarun Sharma
 
Programming logic controllers (plc)
Programming  logic controllers (plc)Programming  logic controllers (plc)
Programming logic controllers (plc)
Sudhir Reddy
 
Automationcontrol7
Automationcontrol7Automationcontrol7
Automationcontrol7
liyanagek
 

Destacado (20)

How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 
Generations of Programming Languages
Generations of Programming LanguagesGenerations of Programming Languages
Generations of Programming Languages
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YU
 
Fuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional ProgrammingFuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional Programming
 
BTCONCEPT.BIZ MAKE MONEY WITH BITCOIN
BTCONCEPT.BIZ MAKE MONEY WITH BITCOIN  BTCONCEPT.BIZ MAKE MONEY WITH BITCOIN
BTCONCEPT.BIZ MAKE MONEY WITH BITCOIN
 
Bitcoin, The New Great Opportunity for Entrepreneurs on the Internet
Bitcoin, The New Great Opportunity for Entrepreneurs on the InternetBitcoin, The New Great Opportunity for Entrepreneurs on the Internet
Bitcoin, The New Great Opportunity for Entrepreneurs on the Internet
 
Understanding bitcoin
Understanding bitcoinUnderstanding bitcoin
Understanding bitcoin
 
Bitcoin: the future money, or a scam?
Bitcoin: the future money, or a scam?Bitcoin: the future money, or a scam?
Bitcoin: the future money, or a scam?
 
Programmable Money - Visual Guide to Bitcoin as a Technology
Programmable Money - Visual Guide to Bitcoin as a TechnologyProgrammable Money - Visual Guide to Bitcoin as a Technology
Programmable Money - Visual Guide to Bitcoin as a Technology
 
Bitcoin Startup Malaysia
Bitcoin Startup MalaysiaBitcoin Startup Malaysia
Bitcoin Startup Malaysia
 
Intro to bitcoin march 2013
Intro to bitcoin march 2013Intro to bitcoin march 2013
Intro to bitcoin march 2013
 
C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo datta
 
Bitcoin
BitcoinBitcoin
Bitcoin
 
Plc programming with fbd
Plc programming with fbdPlc programming with fbd
Plc programming with fbd
 
Programmable logic controllers
Programmable logic controllersProgrammable logic controllers
Programmable logic controllers
 
Why Bitcoin's Rate of Adoption is Only Going to Increase
Why Bitcoin's Rate of Adoption is Only Going to IncreaseWhy Bitcoin's Rate of Adoption is Only Going to Increase
Why Bitcoin's Rate of Adoption is Only Going to Increase
 
Eee3420 lecture01 rev2011
Eee3420 lecture01 rev2011Eee3420 lecture01 rev2011
Eee3420 lecture01 rev2011
 
Eee3420 lecture03 rev2011
Eee3420 lecture03 rev2011Eee3420 lecture03 rev2011
Eee3420 lecture03 rev2011
 
Programming logic controllers (plc)
Programming  logic controllers (plc)Programming  logic controllers (plc)
Programming logic controllers (plc)
 
Automationcontrol7
Automationcontrol7Automationcontrol7
Automationcontrol7
 

Similar a FEC2017-Introduction-to-programming

Python programming ppt.pptx
Python programming ppt.pptxPython programming ppt.pptx
Python programming ppt.pptx
nagendrasai12
 
PYTHON UNIT 1
PYTHON UNIT 1PYTHON UNIT 1
PYTHON UNIT 1
nagendrasai12
 

Similar a FEC2017-Introduction-to-programming (20)

An Introduction To Python - Python, Print()
An Introduction To Python - Python, Print()An Introduction To Python - Python, Print()
An Introduction To Python - Python, Print()
 
Programming for data science in python
Programming for data science in pythonProgramming for data science in python
Programming for data science in python
 
Python as Web Development
Python as Web Development Python as Web Development
Python as Web Development
 
Introduction to Python Programming Basics
Introduction  to  Python  Programming BasicsIntroduction  to  Python  Programming Basics
Introduction to Python Programming Basics
 
2015 bioinformatics python_introduction_wim_vancriekinge_vfinal
2015 bioinformatics python_introduction_wim_vancriekinge_vfinal2015 bioinformatics python_introduction_wim_vancriekinge_vfinal
2015 bioinformatics python_introduction_wim_vancriekinge_vfinal
 
python Certification Training in marthahalli
python Certification Training in marthahallipython Certification Training in marthahalli
python Certification Training in marthahalli
 
Python
PythonPython
Python
 
Learning Python
Learning PythonLearning Python
Learning Python
 
introduction to Python (for beginners)
introduction to Python (for beginners)introduction to Python (for beginners)
introduction to Python (for beginners)
 
Python with dataScience
Python with dataSciencePython with dataScience
Python with dataScience
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Why Python in required in Civil Engineering
Why Python in required in Civil EngineeringWhy Python in required in Civil Engineering
Why Python in required in Civil Engineering
 
python classes in thane
python classes in thanepython classes in thane
python classes in thane
 
A Whirlwind Tour Of Python
A Whirlwind Tour Of PythonA Whirlwind Tour Of Python
A Whirlwind Tour Of Python
 
Introduction to Agile Software Development & Python
Introduction to Agile Software Development & PythonIntroduction to Agile Software Development & Python
Introduction to Agile Software Development & Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python programming ppt.pptx
Python programming ppt.pptxPython programming ppt.pptx
Python programming ppt.pptx
 
PYTHON UNIT 1
PYTHON UNIT 1PYTHON UNIT 1
PYTHON UNIT 1
 
Agile Languages for Rapid Prototyping
Agile Languages for Rapid PrototypingAgile Languages for Rapid Prototyping
Agile Languages for Rapid Prototyping
 
Python_basics_tuples_sets_lists_control_loops.ppt
Python_basics_tuples_sets_lists_control_loops.pptPython_basics_tuples_sets_lists_control_loops.ppt
Python_basics_tuples_sets_lists_control_loops.ppt
 

Último

Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Sérgio Sacani
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptx
MohamedFarag457087
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virus
NazaninKarimi6
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
seri bangash
 
CYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptxCYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptx
Silpa
 
LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.
Silpa
 
Human genetics..........................pptx
Human genetics..........................pptxHuman genetics..........................pptx
Human genetics..........................pptx
Silpa
 
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
Scintica Instrumentation
 

Último (20)

Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptx
 
Dr. E. Muralinath_ Blood indices_clinical aspects
Dr. E. Muralinath_ Blood indices_clinical  aspectsDr. E. Muralinath_ Blood indices_clinical  aspects
Dr. E. Muralinath_ Blood indices_clinical aspects
 
Role of AI in seed science Predictive modelling and Beyond.pptx
Role of AI in seed science  Predictive modelling and  Beyond.pptxRole of AI in seed science  Predictive modelling and  Beyond.pptx
Role of AI in seed science Predictive modelling and Beyond.pptx
 
GBSN - Biochemistry (Unit 2)
GBSN - Biochemistry (Unit 2)GBSN - Biochemistry (Unit 2)
GBSN - Biochemistry (Unit 2)
 
Genome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxGenome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptx
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virus
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
 
CYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptxCYTOGENETIC MAP................ ppt.pptx
CYTOGENETIC MAP................ ppt.pptx
 
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIACURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
 
Gwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRL
Gwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRLGwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRL
Gwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRL
 
Climate Change Impacts on Terrestrial and Aquatic Ecosystems.pptx
Climate Change Impacts on Terrestrial and Aquatic Ecosystems.pptxClimate Change Impacts on Terrestrial and Aquatic Ecosystems.pptx
Climate Change Impacts on Terrestrial and Aquatic Ecosystems.pptx
 
FAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceFAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical Science
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.
 
LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.
 
Human genetics..........................pptx
Human genetics..........................pptxHuman genetics..........................pptx
Human genetics..........................pptx
 
300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx
 
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
(May 9, 2024) Enhanced Ultrafast Vector Flow Imaging (VFI) Using Multi-Angle ...
 
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRingsTransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
TransientOffsetin14CAftertheCarringtonEventRecordedbyPolarTreeRings
 
Genetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditionsGenetics and epigenetics of ADHD and comorbid conditions
Genetics and epigenetics of ADHD and comorbid conditions
 

FEC2017-Introduction-to-programming

  • 1. Python for geo-people www.helsinki.fi/yliopist o Automating GIS-processes FEC 2017 Lecturers: Vuokko Heikinheimo & Henrikki Tenkanen vuokko.heikinheimo@helsinki.fi henrikki.tenkanen@helsinki.fi 6.3.2017 Materials: Henrikki Tenkanen, David Whipp, Vuokko Heikinheimo
  • 2. www.helsinki.fi/yliopist o Python for geo-people Goals of the course There are basically four goals in this intensive course 1. Introduce the Python programming language 2. Develop basic programming skills 3. Discuss essential (good) programming practices needed by young scientists 4. Introduce automatization of different GIS tasks in Python
  • 3. www.helsinki.fi/yliopist o Python for geo-people 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
  • 4. www.helsinki.fi/yliopist o Python for geo-people 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 - I’m not 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
  • 5. www.helsinki.fi/yliopist o Python for geo-people Why learn to program? • Rather than being restricted to using existing software, you will have the ability to develop 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.)
  • 6. www.helsinki.fi/yliopist o Python for geo-people Python can be called directly from ArcGIS
  • 7. www.helsinki.fi/yliopist o Python for geo-people 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…)
  • 8. www.helsinki.fi/yliopist o Python for geo-people 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)
  • 9. www.helsinki.fi/yliopist o Python for geo-people 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)
  • 10. www.helsinki.fi/yliopist o Python for geo-people 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)
  • 11. Python for geo-people www.helsinki.fi/yliopist o Programming “Computer programming (often shortened to programming) is a process that leads from an original formulation of a computing problem to executable computer programs. Programming involves activities such as analysis, developing understanding, generating algorithms, verification of requirements of algorithms including their correctness and resources consumption, and implementation (commonly referred to as coding) of algorithms in a target programming language.” -Wikipedia (2015) “A program is like a recipe. It contains a list of ingredients (called variables) and a list of directions (called statements) that tell the computer what to do with the variables.” - Webopedia (2015)
  • 12. www.helsinki.fi/yliopist o Python for geo-people What is a program? • A program is a detailed list of step-by-step instructions telling the computer exactly what to do • The program can be changed to alter what the computer will do when the code is executed • Software is another name for a program # 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 Fortran punchcard Python source code
  • 13. www.helsinki.fi/yliopist o Python for geo-people 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 • 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
  • 14. Python for geo-people www.helsinki.fi/yliopist o High level programming Low level programming Less code More code Slower Faster Various different programming languages exist • Python • Perl • Ruby • JavaScript • Java • C++ • C • Fortran + Many others Programming languages remind our spoken languages! • There are different ways to express the same meaning • Some languages are more similar to each other than others • After learning one language it is easier to learn other ones! Programming Moikka, Hello, Hej, Hallo, Hola echo ”Moikka”, print(”Hello”), console.log(”Hej”), puts(”Hallo”), System.out.println(”Hola”) Spoken languages Programming languages
  • 15. Python for geo-people www.helsinki.fi/yliopist o Python is: • General purpose • High level • Cross-platform • Open source • Multi-paradigm: Object oriented / imperative / functional / procedural / reflective • Uses dynamic type-checking Why to learn / use Python? • Easy to learn (a good programming language for the beginners) • Easy to read and understand – elegant code • Powerful enough – used in scientific programming • Countless ready-made modules / libraries to use (also GIS stuff) • Supportive, large and helpful user community • Widely supported in different GIS-softwares - ArcGIS, QGIS, Erdas Imagine, IDRISI, uDig, ILWIS, PostGIS … • Extremely useful for automating GIS processes Programming
  • 16. www.helsinki.fi/yliopist o Python for geo-people 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)
  • 17. www.helsinki.fi/yliopist o Python for geo-people Let’s consider an example • As an American, David 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 he doesn’t always know what he should wear to work when he finds weather reports with temperatures in degrees Celsius • A simple program could help
  • 18. www.helsinki.fi/yliopist o Python for geo-people 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
  • 19. www.helsinki.fi/yliopist o Python for geo-people 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
  • 20. www.helsinki.fi/yliopist o Python for geo-people 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
  • 21. www.helsinki.fi/yliopist o Python for geo-people 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
  • 22. www.helsinki.fi/yliopist o Python for geo-people 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
  • 23. www.helsinki.fi/yliopist o Python for geo-people 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
  • 24. www.helsinki.fi/yliopist o Python for geo-people References Zelle, J. M. (2010). Python programming: an introduction to computer science (2nd ed.). Franklin, Beedle & Associates, Inc.