Prerequisites

1 Course Prerequisites

This course assumes working knowledge with R or Python for research. We assume that you are already comfortable with an integrated development environment (IDE), such as RStudio or VS Code. You must have a GitHub account and it will be beneficial to be familiar with the concepts of version control, although we will cover these in the course.

Familiarity with referencing software such as Zotero (recommended) and bibliography file formats such as BibTeX will be beneficial, but not essential.

2 Software Prerequisites

You should bring a laptop with the following software installed and tested to check it works:

  • Quarto (minimum version: 1.5.45)
  • A tested R or Python installation or both (note: if you have Docker installed you should be able to run R and Python inside a devcontainer, works best with VS Code)
  • RStudio or VS Code
    • If you will use VS Code for the course, you need the following extensions:
      • The R extension reditorsupport.r if using R
      • The Python extension ms-python.python if using Python
      • The quarto extention quarto.quarto
  • Git, installed with one of the following packages:
  • The gh command-line tool (see cli.github.com for installation and set-up instructions)

4 Testing your setup

You can test your setup by running the following code in R or Python.

options(repos = c(CRAN = "https://cloud.r-project.org"))
if (!require("remotes")) install.packages("remotes")
pkgs = c(
    "sf",
    "tidyverse",
    "tmap",
    "data.table",
    "stats19",
    "quarto",
    "stplanr",
    "osmextract",
    "zonebuilder"
)
pkgs_to_install = pkgs[!pkgs %in% installed.packages()[, "Package"]]
if (length(pkgs_to_install) > 0) {
  install.packages(pkgs_to_install)
}
library(tidyverse)
zones = zonebuilder::zb_zone("Lisbon", n_circles = 3)
study_area = zones |>
  sf::st_union()
extra_tags = c(
  "maxspeed",
  "lit",
  "cycleway"
)
osm_network = osmextract::oe_get(
  place = "Lisbon, Portugal",
  boundary = study_area,
  boundary_type = "clipsrc",
  extra_tags = extra_tags
)
osm_network |>
  select(maxspeed) |>
  plot()

sf::write_sf(study_area, "lisbon_study_area.geojson")
Warning in CPL_write_ogr(obj, dsn, layer, driver,
as.character(dataset_options), : GDAL Error 6: DeleteLayer() not supported by
this dataset.
import osmnx as ox
import geopandas as gpd
import matplotlib.pyplot as plt
import shapely

study_point = shapely.Point(-9.1393, 38.7223)  # Latitude and Longitude for Lisbon
study_geom = gpd.GeoSeries([study_point], crs=4326)
study_polygon = study_geom.to_crs(epsg=3857).buffer(6000).to_crs(epsg=4326).unary_union
study_polygon_gpd = gpd.GeoDataFrame(geometry=[study_polygon], crs="EPSG:4326")
# Read-in geosjon already saved from R
study_polygon = gpd.read_file("lisbon_study_area.geojson")
# study_polygon_gpd.explore()
tags = {"highway": True, "maxspeed": True, "lit": True, "cycleway": True}
gdf = ox.features_from_polygon(study_polygon, tags)
gdf = gdf[gdf.geom_type.isin(["LineString", "MultiLineString"])]
gdf = gdf.to_crs(epsg=3857)
gdf.plot(column="maxspeed", figsize=(10, 10), legend=True)
plt.show()

Output of the Python setup test showing a visualization of road network data from Lisbon

Let us know how you get on and let us know if you have any issues getting set up, either by email, or (preferably) via the Discussion forum on GitHub associated with this course repository at github.com/tdscience/course/discussions.

Reuse