Python for Spatial Analysis - PY4SA
School of Geography and Sustainable Development
Python and R as the tools as the programming languages to master as spatial data researcher
You will fail
, but that is ok, it is part of the process.Don't be afraid
of it.A Python script is a sequence of instructions. The structure and arrangement of the instructions are referred to as syntax. Python instructions use various language elements, including data types, statements, and functions.
Modules
are collections of related code that contain variables, definitions, and instructions.libraries
are typically specialised and enable you to perform higher-level tasks related to those specialities.Pandas
enables you to work with tabular data, NumPy
grant the ability to make advanced mathematical and scientific computations, and Matplotlib
allows you to visualise data graphically.There are many ways to write and run a python script:
Running a python Script
Running a python Script
9
Hello world
Ingredients
for this courseLot of attractive packages (it’s like the seasoning) Like in any recipe, the right ingredients define the dish’s success; In here; installing your components appropriately will help run the python scripts correctly.
Conda
is an open-source package and environment management system that runs on Windows, macOS, and Linux.Miniconda
is a minimal installer for conda. It is a small version of Anaconda that includes only conda, Python, the packages they depend on, and a small number of other useful packages, including pip, zlib and a few others.Learn more: Jupyter, VS Code, Text Editors
Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents. Created in 2004, Markdown is now one of the world’s most popular markup languages.
Jupyter Lab
Git
is open-source software for version control, which means that it tracks changes to your files as you work on them over time.
Similar to track changes
feature in a word document, except you must choose which versions to include in the tracking—it is not automatic.
It can be tricky, and we may or may not have issues; it happens to everyone. Widely used in academia and industry.
GitHub is a web-based version control system which uses Git, the open-source version control software. It provides a place for developers to host and share their projects — a space to save earlier iterations and collaborate with other developers, colleagues, or co-workers.
It can be used even to host websites, research projects, portfolios, data, and more.
It is widely popular and can be a way to get a job nowadays in the GIScience field.
Git and GitHub
Let us calculate the distance between U St Andrews
and Edinburgh
, but in kms
85.61710080000002
85.61710080000002
We can now reuse the variable MileToKms
in the next cell without having to define it again!
42.195390336
Variables actually have a type
, which defines the way it is stored. The basic types are:
To remember! We can’t do arithmetic operations on variables of different types. Therefore, make sure that you are always aware of your variables types! You can find the type of a variable by adding type()
. For example: type(x)
.
int
Luckily, Python offers us a way of converting variables to different types!
Casting – the operation of converting a variable to a different type
30
Similar methods exist for other data types: int()
, float()
, str()
What would be the result?
'1020'
(Arithmetic, Logical, Comparison)
Are unordered, changeable, indexed, and do not allow duplicate elements. In contrast to lists each value is also assigned with key.
Values can be selected using the associated key. You can also use the key to define a value to change.
Are unordered, changeable, indexed, and do not allow duplicate elements. In contrast to lists each value is also assigned with key.
Values can be selected using the associated key. You can also use the key to define a value to change.
{'code': 'GG3209', 'Name': 'Spatial Analysis with Python'}
Spatial Analysis with Python
{'code': 461, 'Name': 'Spatial Analysis with Python'}
Similar to lists; however, they must be declared
. In this course, we will primarily work with NumPy arrays, which will be discussed in more detail in a later module.
[1, 2, 3, 4]
1
3
[1, 7, 3, 4]
#
(Python for Data Analysis)[https://wesmckinney.com/book/]
Module GG3209 - Second Part