Skip to content

Instantly share code, notes, and snippets.

View alfcrisci's full-sized avatar

Alfonso alfcrisci

View GitHub Profile
import sys
import shutil
import requests
from datetime import datetime
if len(sys.argv) != 3 :
print "Usage: python retrieve_cam.py url name"
sys.exit (1)
photo_ls=list.files(path = "images", pattern = "jpg",all.files=T,full.names = T, recursive =T,ignore.case = T)
image2html=function(file_image,alt="photo") {
lsfileh=gsub("\\....$",".html",file_image)
lsfileh=gsub(".*./","",lsfileh)
write(paste0('<!DOCTYPE html><html><body><img src="',file_image,'"'," ",'alt="',alt,'"></body></html>'),file=lsfileh)
}
res=sapply(photo_ls,function(x) image2html(x))
segmented_lines=function(lines) {
cSl <- coordinates(lines)
in_nrows <- lapply(cSl, function(x) sapply(x, nrow))
outn <- sapply(in_nrows, function(y) sum(y-1))
res <-list()
i <- 1
for (j in seq(along=cSl)) {
for (k in seq(along=cSl[[j]])) {
for (l in 1:(nrow(cSl[[j]][[k]])-1)) {
@alfcrisci
alfcrisci / readtopowrfout.r
Created January 9, 2018 11:24
how to read HGT at surface level in WRF ARW model aka model surface elevation
# devtools::install_github("mccreigh/rwrfhydro")
library(raster)
library(mapview)
library(htmlwidgets)
library(rwrfhydro)
# HGT.nc is wrfout netcdf file
# put password of NASA services
library(ASIP)
retrieve_aster_hdf=function(file,user='',password='')
{download.file(url=paste0("http://e4ftl01.cr.usgs.gov/ASTT/AST_L1T.003/",
substr(file,16,19),".",
substr(file,12,13),".",
substr(file,14,15),
"/",file,'.hdf'),
stack_MODIS_MOD13Q1=function(x,pixelreliab=0,file.remove=F) {
require(MODIS)
require(gdalUtils)
require(rgdal)
mod <- getSds(x,method="gdal")
names=list(gsub(".hdf","_NDVI.tif",x),gsub(".hdf","_EVI.tif",x),gsub(".hdf","_RELIAB.tif",x),gsub(".hdf","_NDVI_Q.tif",x),gsub(".hdf","_EVI_Q.tif",x))
ndvi <- raster(readGDAL(mod$SDS4gdal[1], as.is=TRUE))*0.0001
calc_climatology_stack=function(temp) {
require(raster)
res=list()
res$mean_WT=calc(temp,mean,na.rm=T);
res$sd_WT=calc(temp,sd,na.rm=T);
res$q33=calc(temp,fun=function(x) quantile(x,probs=c(0.33),na.rm=T));
res$median=calc(temp,fun=function(x) quantile(x,probs=c(0.5),na.rm=T));
res$q66=calc(temp,fun=function(x) quantile(x,probs=c(0.66),na.rm=T));
return(res)
}
aa=read.csv("2.csv",header = F)
# V1 dist
# V2 quota
attach(aa)
piece.formula <- function(var.name, knots) {
formula.sign <- rep(" - ", length(knots))
formula.sign[knots < 0] <- " + "
paste(var.name, "+",
paste("I(pmax(", var.name, formula.sign, abs(knots), ", 0))",
require(gdalUtils)
require(rgdal)
require(rgeos)
require(Hmisc)
require(overpass)
#' retrieve_adm3_bound
#'
#' @description Retrieve by Overpass API query the bounding box of italian municipalities
#'
pandoc -s -S --bibliography biblioHeatwave.bib --csl=copernicus-publications.csl -f latex -o twit_caldo.docx template.tex