Skip to content

Instantly share code, notes, and snippets.

View xuanlongma's full-sized avatar

Richard Xuanlong Ma xuanlongma

View GitHub Profile
@xuanlongma
xuanlongma / read_trmm_3b43.R
Last active December 15, 2015 07:49
read TRMM 3B43 V7 data
## TRMM 3B43 Monthly precipitation does NOT need flip (which 3B42 need)
r.trmm <- raster(nrows = 400, ncols = 1440, xmn = 0, xmx = 360, ymn =
-50, ymx = 50, crs="+proj=longlat +datum=WGS84")
r.trmm[] <- readBin(files.input, 'double', n = 576000, size = 4,
endian = 'big')
## TRMM 3B42
## r.trmm <- flip(rotate(r.trmm), 'y')
@xuanlongma
xuanlongma / pandoc_md_html_bib_math.sh
Created May 12, 2013 11:49
Command line to convert markdown to html with bibliography and LaTeX math correctly displayed.
pandoc --bibliography=bibtex.bib --mathjax --parse-raw -s inpud.md -o output.html
@xuanlongma
xuanlongma / pandoc_multi_input.md
Last active September 21, 2024 15:16
Combine multiple input files when using Pandoc

If multiple input files are given, pandoc will concatenate them all (with blank lines between them) before parsing. -- from Pandoc website

Pandoc command: pandoc -s input1.md input2.md input3.md -o output.html

@xuanlongma
xuanlongma / gdal_reproject.R
Created May 24, 2013 08:21
change the projection using GDAL library
## a tiff file
input <- "modis.evi.tif"
output <- "modis.evi.reprojected.tif"
## GDAL command line for reprojection
proj.cmd.warp <- 'gdalwarp -t_srs \'+proj=latlong +datum=WGS84\' -r near -overwrite'
## Invoke the system GDAL command
system(command = paste(proj.cmd.warp, input, output, sep = ' '))
# Script for question posted on Stack Overflow
# Load relevant libraries
library(ggplot2)
library(raster)
library(gridExtra)
vplayout <- function(x, y) {
viewport(layout.pos.row = x, layout.pos.col = y)
}
@xuanlongma
xuanlongma / nc2tiff.R
Last active March 30, 2024 20:01
From netCDF to GeoTIFF using R
require(ncdf)
require(raster)
## Input: a netCDF file
file.nc <- 'rain.nc'
## Output: a GeoTIFF file
file.tiff <- 'rain.tiff'
## Import netCDF
@xuanlongma
xuanlongma / doybacktodate.R
Last active December 29, 2015 05:39
covert day-of-year back to date object
strptime('2008201', format = '%Y%j')
## or
as.Date('2008201', format = '%Y%j')