Skip to content

Instantly share code, notes, and snippets.

View h-a-graham's full-sized avatar

Hugh Graham h-a-graham

View GitHub Profile
@GMoncrieff
GMoncrieff / how_i_work.md
Last active April 27, 2024 10:46
How I do ML with geospatial data

How I do machine learning with geospatial data

I have a couple of AI/ML projects related to mapping things, often conservation related, with remote sensing data. Some details and packages will vary, but the process below describes how I generally approach these types of problems. Some of these tools I have only touched briefly, but I like them, and this is more an outline of how I would like to approach a new project than a retrospective look at my previous work.

We use AWS, so it makes sense to use datasets and services that are already hosted on AWS. The data discovery and loading part of this process would look somewhat different if we were using Azure and Planetary Computer, and very different if we were using GCP and Earth Engine.

Compute

All of my analysis will be done using python on an AWS VM in the same region as my data on S3, Probably using VSCode on Sagemaker or [JupyterLab](https://docs.aws.amazo

Here is some code to explore the variety available in calculating area across various packages.

x <- rnaturalearth::ne_countries(country = c("Greenland", "Spain"), returnclass = "sf")
as.numeric(sf::st_area(x))/1e6

## Greenland 2.166e6 km²  -41, 72
## Spain     505990 km²   -2, 40
@mikemahoney218
mikemahoney218 / tidy_geocomp.R
Last active August 31, 2022 07:21
Proof-of-concept replication of https://geocompr.robinlovelace.net/spatial-cv.html with tidymodels
# 12.5 Spatial CV (with spatialsample)
library(tidymodels)
library(spatialsample)
library(sf)
data("lsl", "study_mask", package = "spDataLarge")
lsl <- lsl |>
st_as_sf(coords = c("x", "y"), crs = "EPSG:32717")
ta <- terra::rast(system.file("raster/ta.tif", package = "spDataLarge"))
@anthonynorth
anthonynorth / data_pipeline.R
Last active March 21, 2022 22:44
gb rivers
library(dplyr)
library(sf)
if (!file.exists("rivers_gb.rds")) {
download.file(
"https://beaver-net-app.s3.eu-west-2.amazonaws.com/gb_rivers/rivers_gb.rds",
"rivers_gb.rds"
)
}
@ctesta01
ctesta01 / weekday_effect_on_reported_COVID_deaths.R
Last active February 14, 2022 19:00
Plot the weekday variation in reported COVID-19 deaths in the United States
library(readr)
library(ggdist)
library(tidyverse)
library(magrittr)
library(cowplot)
library(ISOweek)
df <- readr::read_csv("https://github.com/nytimes/covid-19-data/raw/master/rolling-averages/us.csv")
df %<>% mutate(wday = lubridate::wday(lubridate::ymd(date)))
weekdays <- c('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
@mdsumner
mdsumner / reprojecting-geotiff-zoom.md
Created December 7, 2021 12:45
py rasterio from an R user perspective
  library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1
edge0 <- function(x, y, ndiscr = 18) {
  dx <- if(length(x) > 1) diff(x) else diff(y)
  sf::st_set_crs(sf::st_segmentize(sf::st_sfc(sf::st_linestring(cbind(x, y))), dx/ndiscr), 
               "OGC:CRS84")
}
north <- function(x = c(-180, 180), y = 90, ndiscr = 18) {
 edge0(x, y, ndiscr)  
@tylermorganwall
tylermorganwall / submarine_cable_map.R
Last active April 19, 2024 07:36
Submarine Cable Map Dataviz
library(geojsonsf)
library(sf)
library(rayrender)
#Data source: https://github.com/telegeography/www.submarinecablemap.com
cables = geojson_sf("cable-geo.json")
cablescene = list()
counter = 1
for(i in 1:length(cables$geometry)) {
alos <- "/vsicurl/https://opentopography.s3.sdsc.edu/raster/AW3D30/AW3D30_global.vrt"
##eng_wales in Hugh's example (but I reduce the dimensions, for now)
g <- list(extent = c(82667.22, 655646.4, 5337.574, 657533.7), dimension = c(28575, 29006), projection = "EPSG:27700")
library(gdalio)
gdalio_set_default_grid(g)
source(system.file("raster_format/raster_format.codeR", package = "gdalio", mustWork = TRUE))
r <- gdalio_raster(alos)
@z3tt
z3tt / github.R
Last active April 30, 2024 15:38
Configure GitHub for Rstudio
#### 1. Sign up at GitHub.com ################################################
## If you do not have a GitHub account, sign up here:
## https://github.com/join
# ----------------------------------------------------------------------------
#### 2. Install git ##########################################################
## If you do not have git installed, please do so: