Skip to content

Commit

Permalink
Add more chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Aug 18, 2024
1 parent 13db385 commit 74b0402
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 24 deletions.
6 changes: 6 additions & 0 deletions _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ parts:
maxdepth: 2
chapters:
- file: book/geospatial/01_get_started
- caption: Labs
numbered: false
maxdepth: 2
chapters:
- file: book/labs/instructions
- file: book/labs/lab_01
36 changes: 36 additions & 0 deletions book/labs/instructions.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Submission Instructions\n",
"\n",
"1. Click on the ![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg) button at the top of each lab notebook. This will open the lab in Google Colab.\n",
"2. Copy the notebook to your Google Drive. The notebook will be saved to **My Drive -> Colab Notebooks -> Copy of lab_x.ipynb**. You can change the filename back to **lab_x.ipynb**.\n",
"\n",
" ![](https://i.imgur.com/1bxdiTz.png)\n",
"3. Follow the directions on the lab notebook and write code to complete the exercises.\n",
"4. When you are finished, Click on **Runtime -> Restart and run all**. Make sure that you notebook runs well and all code cell outputs are shown. \n",
"\n",
" ![](https://i.imgur.com/6juNLRG.png)\n",
"\n",
"5. Click on the **Share** button in the top right corner and change the notebook general access from Restrcted to **Anyone with the link**. \n",
"\n",
" ![](https://i.imgur.com/FmNZSdx.png)\n",
"6. Click on the **Copy link** button.\n",
"\n",
" ![](https://i.imgur.com/3v1DNoj.png)\n",
"7. Open Chrome Incognito mode, paste the link to the address bar and press Enter. Make sure that you can preview the notebook content. Otherwise, you might need to save a copy of the notebook from Colab to your Google Drive. \n",
"8. Copy the link and paste it to the Lab Submission page on Canvas and submit."
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
28 changes: 28 additions & 0 deletions book/labs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.2
---

# Submission Instructions

1. Click on the ![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg) button at the top of each lab notebook. This will open the lab in Google Colab.
2. Copy the notebook to your Google Drive. The notebook will be saved to **My Drive -> Colab Notebooks -> Copy of lab_x.ipynb**. You can change the filename back to **lab_x.ipynb**.

![](https://i.imgur.com/1bxdiTz.png)
3. Follow the directions on the lab notebook and write code to complete the exercises.
4. When you are finished, Click on **Runtime -> Restart and run all**. Make sure that you notebook runs well and all code cell outputs are shown.

![](https://i.imgur.com/6juNLRG.png)

5. Click on the **Share** button in the top right corner and change the notebook general access from Restrcted to **Anyone with the link**.

![](https://i.imgur.com/FmNZSdx.png)
6. Click on the **Copy link** button.

![](https://i.imgur.com/3v1DNoj.png)
7. Open Chrome Incognito mode, paste the link to the address bar and press Enter. Make sure that you can preview the notebook content. Otherwise, you might need to save a copy of the notebook from Colab to your Google Drive.
8. Copy the link and paste it to the Lab Submission page on Canvas and submit.
2 changes: 1 addition & 1 deletion book/python/01_get_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ kernelspec:

There are multiple ways to run Jupyter notebooks. You can either run them locally on your machine or use an online service like Google Colab or Binder.

```{code-cell} ipython3
```{code-cell}
print("Hello, Python!")
```

Expand Down
22 changes: 22 additions & 0 deletions book/python/02_variables.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,28 @@
"cell_type": "markdown",
"id": "29",
"metadata": {},
"source": [
"## Exercise\n",
"\n",
"1. Create a list of tuples, each representing the coordinates (latitude, longitude) of different cities you have visited.\n",
"2. Calculate the centroid of these coordinates.\n",
"3. Create a dictionary to store the centroid's latitude and longitude."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "30",
"metadata": {},
"outputs": [],
"source": [
"# Type your code here"
]
},
{
"cell_type": "markdown",
"id": "31",
"metadata": {},
"source": [
"## Conclusion\n",
"\n",
Expand Down
40 changes: 22 additions & 18 deletions book/python/02_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ In Python, a variable is a symbolic name that is a reference or pointer to an ob

Let's start by creating a simple variable that represents the number of spatial points in a dataset.

```{code-cell} ipython3
```{code-cell}
num_points = 120
```

This variable `num_points` now holds the integer value 120, which we can use in our calculations or logic.

To view the value of the variable, we can use the `print()` function.

```{code-cell} ipython3
```{code-cell}
print(num_points)
```

Expand All @@ -43,42 +43,45 @@ Python supports various data types, which are essential to understand before wor

**a) Integers (int):** These are whole numbers, e.g., 1, 120, -5

```{code-cell} ipython3
```{code-cell}
num_features = 500 # Represents the number of features in a geospatial dataset
```

**b) Floating-point numbers (float):** These are numbers with a decimal point, e.g., 3.14, -0.001, 100.0

```{code-cell} ipython3
```{code-cell}
latitude = 35.6895 # Represents the latitude of a point on Earth's surface
```

**c) Strings (str):** Strings are sequences of characters, e.g., "Hello", "Geospatial Data", "Lat/Long"

```{code-cell} ipython3
```{code-cell}
coordinate_system = "WGS 84" # Represents a commonly used coordinate system
```

**d) Booleans (bool):** Booleans represent one of two values: True or False

```{code-cell} ipython3
```{code-cell}
is_georeferenced = True # Represents whether a dataset is georeferenced or not
```

**e) Lists:** Lists are ordered collections of items, which can be of any data type.

```{code-cell} ipython3
coordinates = [35.6895, 139.6917] # A list representing latitude and longitude of a point
```{code-cell}
coordinates = [
35.6895,
139.6917,
] # A list representing latitude and longitude of a point
```

**f) Dictionaries (dict):** Dictionaries are collections of key-value pairs.

```{code-cell} ipython3
```{code-cell}
feature_attributes = {
"name": "Mount Fuji",
"height_meters": 3776,
"type": "Stratovolcano",
"location": [35.3606, 138.7274]
"location": [35.3606, 138.7274],
}
```

Expand All @@ -88,30 +91,31 @@ Now, let's do some basic operations with these variables.

Adding a constant to the number of features:

```{code-cell} ipython3
```{code-cell}
num_features += 20
print("Updated number of features:", num_features)
```

Converting latitude from degrees to radians (required for some geospatial calculations):

```{code-cell} ipython3
```{code-cell}
import math
latitude_radians = math.radians(latitude)
print("Latitude in radians:", latitude_radians)
```

Adding new coordinates to the list:

```{code-cell} ipython3
```{code-cell}
coordinates.append(34.0522) # Adding latitude of Los Angeles
coordinates.append(-118.2437) # Adding longitude of Los Angeles
print("Updated coordinates:", coordinates)
```

Accessing dictionary elements:

```{code-cell} ipython3
```{code-cell}
mount_fuji_name = feature_attributes["name"]
mount_fuji_height = feature_attributes["height_meters"]
print(f"{mount_fuji_name} is {mount_fuji_height} meters high.")
Expand All @@ -123,18 +127,18 @@ Let's say you are given a list of coordinates and need to calculate the centroid

Example coordinates of four points (latitude, longitude):

```{code-cell} ipython3
```{code-cell}
points = [
[35.6895, 139.6917], # Tokyo
[34.0522, -118.2437], # Los Angeles
[51.5074, -0.1278], # London
[48.8566, 2.3522] # Paris
[51.5074, -0.1278], # London
[48.8566, 2.3522], # Paris
]
```

Calculate the centroid:

```{code-cell} ipython3
```{code-cell}
centroid_lat = sum([point[0] for point in points]) / len(points)
centroid_lon = sum([point[1] for point in points]) / len(points)
centroid = [centroid_lat, centroid_lon]
Expand Down
22 changes: 21 additions & 1 deletion book/python/03_data_structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,27 @@
"id": "23",
"metadata": {},
"source": [
"### Conclusion\n",
"## Exercise\n",
"\n",
"Create a dictionary to store attributes of a geographic feature (e.g., a river or mountain). Include keys for the name, length, and location of the feature. Then, add an additional attribute (e.g., the source of the river or the height of the mountain) and print the dictionary."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "24",
"metadata": {},
"outputs": [],
"source": [
"# Type your code here"
]
},
{
"cell_type": "markdown",
"id": "25",
"metadata": {},
"source": [
"## Conclusion\n",
"\n",
"Understanding and utilizing Python's data structures such as tuples, lists, sets, and dictionaries are fundamental skills in geospatial programming. These structures provide the flexibility and functionality required to manage and manipulate spatial data effectively.\n",
"\n",
Expand Down
23 changes: 19 additions & 4 deletions book/python/03_data_structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ Tuples are immutable sequences, meaning that once a tuple is created, its elemen
For example, a tuple can be used to store the coordinates of a geographic point (latitude, longitude).

```{code-cell} ipython3
point = (35.6895, 139.6917) # Tuple representing a geographic point (latitude, longitude)
point = (
35.6895,
139.6917,
) # Tuple representing a geographic point (latitude, longitude)
```

You can access elements in a tuple using indexing:
Expand All @@ -42,7 +45,11 @@ Lists are ordered, mutable sequences, meaning you can change, add, or remove ele
For example, you can store a list of coordinates representing a path or boundary.

```{code-cell} ipython3
path = [(35.6895, 139.6917), (34.0522, -118.2437), (51.5074, -0.1278)] # List of tuples representing a path
path = [
(35.6895, 139.6917),
(34.0522, -118.2437),
(51.5074, -0.1278),
] # List of tuples representing a path
```

You can add a new point to the path:
Expand Down Expand Up @@ -94,7 +101,7 @@ For example, you can use a dictionary to store attributes of a geospatial featur
city_attributes = {
"name": "Tokyo",
"population": 13929286,
"coordinates": (35.6895, 139.6917)
"coordinates": (35.6895, 139.6917),
} # Dictionary storing attributes of a city
```

Expand All @@ -113,7 +120,15 @@ city_attributes["area_km2"] = 2191 # Adding the area of the city in square kilo
print("Updated city attributes:", city_attributes)
```

### Conclusion
## Exercise

Create a dictionary to store attributes of a geographic feature (e.g., a river or mountain). Include keys for the name, length, and location of the feature. Then, add an additional attribute (e.g., the source of the river or the height of the mountain) and print the dictionary.

```{code-cell} ipython3
# Type your code here
```

## Conclusion

Understanding and utilizing Python's data structures such as tuples, lists, sets, and dictionaries are fundamental skills in geospatial programming. These structures provide the flexibility and functionality required to manage and manipulate spatial data effectively.

Expand Down

0 comments on commit 74b0402

Please sign in to comment.