Skip to content

Instantly share code, notes, and snippets.

View alfcrisci's full-sized avatar

Alfonso alfcrisci

View GitHub Profile
# % bash mode
# cdo -selvar,mslp zoom_mslp2018.nc pp.nc
# % qui seleziono per togliere variabili a bischero.
# cdo griddes mslp.nc >oldgrid.txt
# % ottengo info sulla grid
# % dopo cambio xsize ysize e gridsize nel file txt che ho creato
# % Occhio devono essere coerenti.Salvo come newgrid.txt
library(raster)
library(sp)
library(spatialEco)
library(XLConnect)
###############################################################################
setwd("")
ras1<-raster('fileA')
ras2<-raster('fileB')
###############################################################################
@alfcrisci
alfcrisci / ecoODE.R
Created August 1, 2020 09:48 — forked from emhart/ecoODE.R
Examples of ODE's in R from classic ecological models with a simple M-W extension on I
#' Description: Code using deSolve for some simple ecological ODE models
#' There are 3 examples, one is a simple LV Pred-Prey example with plots
#' The next is a Macarthur-Wilson model with plots of both the species curve and the equlibrium points
#' The last plot is a quick crack at putting stochasticity into the model by adding oscillations in I with t.
#' LV code is modified from a blog post here: http://assemblingnetwork.wordpress.com/2013/01/31/two-species-predator-prey-systems-with-r/
#' Other additions are my own
#'
#' Author: Edmund Hart
#' Date: 3/28/2013
#' E-mail: edmund.m.hart@gmail.com
library(plantnet)
key="" # get keys
imageURL=c("https://munapptplants.github.io/plants_2020/plant_orchi_munap1.jpeg",
"https://munapptplants.github.io/plants_2020/plant_orchi_munap2.jpeg")
classifications <- identify(key, imageURL)
# install.packages("xts","zoo","growthrates","rio","R0")
library(xts)
library(zoo)
library(growthrates)
library(rio)
library(R0)
###############################################################################################################################################################################
# retrieve data
process_UKCP12km=function(file,res=12000,bandN=1) {
require(raster)
require(proj4)
tmn<-suppressWarnings(raster(file,band=bandN))
lon=unique(coordinates(tmn)[,1])
lat=sort(unique(coordinates(tmn)[,2]))
xyGrid<-matrix(c(rep(lon,length(lat)),rep(lat,each=length(lon))),ncol=2)
xyGrid.wgs84<-proj4::project(xyGrid,proj="+proj=ob_tran +o_proj=longlat +lon_0=378 +o_lon_p=0 +o_lat_p=39.25 +a=6371229 +b=6371229 +to_meter=0.0174532925199 +wktext",inverse=T) #to project in latlong
xyGrid.wgs84<-SpatialPointsDataFrame(coords=xyGrid.wgs84,data=data.frame(z=values(flip(tmn,direction='y'))),proj4string=CRS('+init=epsg:4326'))
xyGrid_3035<-spTransform(xyGrid.wgs84,CRS('+init=epsg:3035'))
exportXYZ=function(r,nameout="outfile,txt",sep="\t") {
require(sp)
require(raster)
m=data.frame(sp::coordinates(r),z=raster::getValues(r))
write.table(m, file=nameout,sep=sep , col.names = F, row.names = F)
}
@alfcrisci
alfcrisci / GCMSAgilentDfileImport
Created February 26, 2019 14:28 — forked from benmarwick/GCMSAgilentDfileImport
Function to import Agilent GCMS Chemstation D files in R
##' Function readDFile
##'
##' Function readDFile
##' @param pathname the pathname of the directory containing the data to import
##' @return outData Output is a matrix of ion counts with rows as scantime and
##' columns as mass, and the respective values as labels
##' @export
readDFile<-function(pathname){
filename<-file.path(pathname,'DATA.MS')
month2season=function(x,mseq="DJF",label=F){
result=x
res=list()
for ( i in 1:12) {
res[[i]]=which(x==i)
}
labels=c(1,2,3,4)
if(label==T) {labels=c("DJF","MAM","JJA","SON")}
export UDUNITS2_XML_PATH=/usr/share/xml/udunits/udunits2.xml > etc/environement