Skip to content

Instantly share code, notes, and snippets.

@hakimabdi
hakimabdi / semantic_segmentation.ipynb
Created March 10, 2022 18:57 — forked from mortcanty/semantic_segmentation.ipynb
Semantic_Segmentation.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hakimabdi
hakimabdi / MKtrend.R
Last active January 5, 2024 00:49
This function performs a Mann-Kendall trend test with associated p-values on a time seris of gridded satellite data
#############################################################################################
# title : Perform a Mann-Kendall trend test of satellite image time series
# purpose : Mann-Kendall test of monotonic trend and associated statistical significance
# author : Abdulhakim Abdi (@HakimAbdi)
# input : Raster stack/brick comprising a time series of observations
# output : Raster object of monotoic trend (Kendall's tau), significance or both (i.e. brick)
# data : Test data: https://1drv.ms/u/s!AsHsKb_qtbkwg4ti8pJCxvUer9rMqg?e=BGcH1K
# notes : Depending on the time series, it is might be useful prewhiten the data to remove serial correlation
# : prior to extracting the trend. See blog post on www.hakimabdi.com for more information.
#############################################################################################
#####################################################################################################
# title : Machine learning exercise for Sentinel-2 data
# purpose : Implementing a machine learning workflow in R
# author : Abdulhakim M. Abdi (Twitter: @HakimAbdi / www.hakimabdi.com)
# input : A multi-temporal raster stack of Sentinel-2 data comprising scenes from four dates
# output : One classified land cover map from each of three machine learning algorithms
# Note 1 : This brief tutorial assumes that you are already well-grounded in R concepts and are
# : familiar with image classification procedure and terminology
# Reference : Please cite Abdi (2020): "Land cover and land use classification performance of machine learning
# : algorithms in a boreal landscape using Sentinel-2 data" in GIScience & Remote Sensing if you find this
##############################################################################
# title : mosaicGTiffs.R
# purpose : Takes in projected GeoTIFF outputs from projHDF2GTiff or
# : other GeoTIFFS and mosaics them into on larger file
# author : Abdulhakim Abdi (@HakimAbdi)
# input : Individual GeoTIFF files
# output : A mosaicked GeoTIFF file with a larger extent
##############################################################################
mosaicGTiffs = function(proj.loc, gtiffs, mosaicName, overwrite){
##############################################################################
# title : projHDF2GTiff.R
# purpose : Converts desired HDF layer to a GeoTIFF and projects it
# author : Abdulhakim Abdi (@HakimAbdi)
# input : HDF-EOS files
# output : Projected GeoTIFF files
##############################################################################
projHDF2GTiff = function(loc, hdfs, gtiffs, lyr, fromSRS, toSRS){
if("gdalUtils" %in% rownames(installed.packages()) == FALSE){
@hakimabdi
hakimabdi / gridcorts
Last active July 16, 2023 04:57
This function correlates time series data to produce correlation and significance grids based on the chosen method.
#############################################################################################
# title : Gridded Correlation of Time Series Raster Data (Gridcorts)
# purpose : Pixelwise time series correlation and significance based on Pearson's r,
# : Spearman's rho or Kendall's tau
# author : Abdulhakim Abdi (@HakimAbdi)
# input : Raster brick comprising two time series of equal number of layers
# output : Raster object of pixelwise correlation, significance or both (i.e. brick)
# : based on the chosen method
# update : Minor based suggestion from Tao Xiong of Northeast Normal University in China.
# data : Test data: https://1drv.ms/u/s!AsHsKb_qtbkwgvoQuHnPaFazPr_XnA?e=fJ9fue
@hakimabdi
hakimabdi / pload
Last active January 30, 2021 15:23
This function is for the installation and loading of R packages.. If an R package is not installed, the function will install it using the Austrian CRAN mirror (you can change that), and if a package is already installed, it will be loaded.
#################################################################################################
# title : pload.R
# purpose : Install and load uninstalled packages, or load installed ones.
# author : Abdulhakim Abdi (@HakimAbdi)
# input : Package name in quotes
# output : Installation and loading of uninstalled packages, or loading of installed ones.
#################################################################################################
pload <- function(x){
if(x %in% rownames(installed.packages()))
@hakimabdi
hakimabdi / ManhattanLST.r
Last active January 30, 2021 15:23
Converts Landsat ETM+ thermal imagery to degrees Celsius. See associated blog post here: http://www.hakimabdi.com/20111030/estimating-land-surface-temperature-from-landsat-thermal-imagery/
#########################################################################################
# title : ManhattanLST.R
# purpose : Converts Landsat ETM+ thermal imagery to degrees Celsius
# author : Abdulhakim Abdi (@HakimAbdi)
# input : Landsat TM / ETM+ band 6
# output : Land surface temperature map in degrees Celsius
#########################################################################################
# Install and load the required packages
install.packages(c("rgdal" "sp", "raster"), repos='http://cran.r-project.org')
@hakimabdi
hakimabdi / GIMMS3g_LAI_FPAR_Binary2Geotiff.r
Last active January 30, 2021 15:23
This code ingests binary GIMMS FAPAR and LAI data and converts them to GeoTIFFs. The data was produced by the Climate and Vegetation Research Group of Boston University. The GIMMS data are available from: http://cliveg.bu.edu/modismisr/lai3g-fpar3g.html
#########################################################################################
# This code ingests binary GIMMS FAPAR and LAI data and converts them to GeoTIFFs.
# The data was produced by the Climate and Vegetation Research Group of Boston University.
# The GIMMS data are available from: http://cliveg.bu.edu/modismisr/lai3g-fpar3g.html
# title : GIMMS3g_LAI_FPAR_Binary2Geotiff.r
# purpose : Converts binary GIMMS FAPAR/LAI to GeoTIFFs
# author : Abdulhakim Abdi (@HakimAbdi)
# input : Binary 8-bit unsigned integer with ieee-be byte order
# output : Georeferenced TIFF, ArcGIS-ready files