diff --git a/R/format.data/Makefile b/R/format.data/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d644d4af2691b6589f0dc3038f82e407a6507fbe --- /dev/null +++ b/R/format.data/Makefile @@ -0,0 +1,71 @@ +ROOT := ../.. + +all: Spain Swiss US BCI + +BCI: $(ROOT)/output/process/BCI/tree.csv + +$(ROOT)/output/process/BCI/tree.csv: $(shell find ../../data/raw/BCI -type f) BCI.R + Rscript BCI.R + +Canada: $(ROOT)/output/process/Canada/tree.csv + +$(ROOT)/output/process/Canada/tree.csv: $(shell find ../../data/raw/Canada -type f) Canada.R + Rscript Canada.R + +France: $(ROOT)/output/process/France/tree.csv + +$(ROOT)/output/process/France/tree.csv: $(shell find ../../data/raw/France -type f) France.R + Rscript France.R + +Fushan: $(ROOT)/output/process/Fushan/tree.csv + +$(ROOT)/output/process/Fushan/tree.csv: $(shell find ../../data/raw/Fushan -type f) Fushan.R + Rscript Fushan.R + +NSW: $(ROOT)/output/process/NSW/tree.csv + +$(ROOT)/output/process/NSW/tree.csv: $(shell find ../../data/raw/NSW -type f) NSW.R + Rscript NSW.R + +NVS: $(ROOT)/output/process/NVS/tree.csv + +$(ROOT)/output/process/NVS/tree.csv: $(shell find ../../data/raw/NVS -type f) NVS.R + Rscript NVS.R + +Paracou: $(ROOT)/output/process/Paracou/tree.csv + +$(ROOT)/output/process/Paracou/tree.csv: $(shell find ../../data/raw/Paracou -type f) Paracou.R + Rscript Paracou.R + +Spain: $(ROOT)/output/process/Spain/tree.csv + +$(ROOT)/output/process/Spain/tree.csv: $(shell find ../../data/raw/Spain -type f) Spain.R + Rscript Spain.R + +Sweden: $(ROOT)/output/process/Sweden/tree.csv + +$(ROOT)/output/process/Sweden/tree.csv: $(shell find ../../data/raw/Sweden -type f) Sweden.R + Rscript Sweden.R + +Swiss: $(ROOT)/output/process/Swiss/tree.csv + +$(ROOT)/output/process/Swiss/tree.csv: $(shell find ../../data/raw/Swiss -type f) Swiss.R + Rscript Swiss.R + +US: $(ROOT)/output/process/US/tree.csv + +$(ROOT)/output/process/US/tree.csv: $(shell find ../../data/raw/US -type f) US.R + Rscript US.R + + +# This susbtitution rule should work as rule, but not, why not? +# $(ROOT)/output/process/%/tree.csv: ../../data/raw/%/* %.R +# Rscript %.R + +# Is based on this which does work +# %-tree.csv: %/* %/*/* %.R +# Rscript $*.R + +# cat((sprintf("%s: ../../output/process/%s/tree.csv\n +# ../../output/process/%s/tree.csv: $(shell find ../../data/raw/%s -type f) %s.R +# \tRscript %s.R\n\n",s,s,s,s,s,s)), file="temp.txt") diff --git a/R/format.data/Spain.R b/R/format.data/Spain.R index a8b481811a25568f33ca98e3238a004f0af0db07..ed58774b2638321a176b81e3b4c7149011d67a7b 100644 --- a/R/format.data/Spain.R +++ b/R/format.data/Spain.R @@ -1,9 +1,15 @@ +#!/usr/bin/env Rscript + ### MERGE spain DATA Edited by FH rm(list = ls()) source("format.fun.R") library(reshape) +<<<<<<< HEAD dir.create("../../output/process/Spain", recursive=TRUE,showWarnings=FALSE) +======= +dir.create("../../output/process/Spain", recursive=TRUE, showWarnings = FALSE) +>>>>>>> Makefile for data processing ######################### READ DATA read individuals tree data data.spain <- read.table("../../data/raw/Spain/Tree_data_SFI_aug13_alldata.txt", @@ -19,7 +25,11 @@ res.quant.boot <- t(sapply(levels(factor(data.spain[["SP_code"]])), FUN = f.quan data.max.height <- data.frame(sp = rownames(res.quant.boot), Max.height.mean = res.quant.boot[, 1], Max.height.sd = res.quant.boot[, 2], Max.height.nobs = res.quant.boot[, 3], stringsAsFactors =FALSE) rm(res.quant.boot) +<<<<<<< HEAD write.csv(data.max.height, file = "../../output/process/Spain/data.max.height.csv") ## I was planning to save processed data in that folder +======= +write.csv(data.max.height, file = "../../output/process/Spain/max.height.csv") ## I was planning to save processed data in that folder +>>>>>>> Makefile for data processing ################################## FORMAT INDIVIDUAL TREE DATA @@ -112,4 +122,4 @@ vec.abio.var.names <- c("MAT", "PP", "PET") vec.basic.var <- c("obs.id","tree.id", "sp", "sp.name", "cluster","plot", "ecocode", "D", "G", "dead", "year", "htot", "Lon", "Lat", "perc.dead","census","weights") data.tree <- subset(data.spain, select = c(vec.basic.var, vec.abio.var.names)) -write.csv(data.tree,file="../../output/process/Spain/data.tree.csv") +write.csv(data.tree,file="../../output/process/Spain/tree.csv") diff --git a/R/format.data/Sweden.R b/R/format.data/Sweden.R index 1e87fcef792294153a974b46cd076e039dcc9550..87abe8953fcda8a010440b56d147a76a82002a5b 100644 --- a/R/format.data/Sweden.R +++ b/R/format.data/Sweden.R @@ -122,7 +122,4 @@ data.swe <- merge(data.swe,data.frame(plot=names(perc.dead),perc.dead=perc.dead) vec.basic.var <- c("obs.id","tree.id", "sp", "sp.name","cluster","plot", "ecocode", "D", "G", "dead", "year", "htot", "Lon", "Lat", "perc.dead","weights","census") data.tree <- subset(data.swe, select = c(vec.basic.var)) -write.csv(data.tree,file="../../output/process/Sweden/data.tree.csv") - - - +write.csv(data.tree,file="../../output/process/Sweden/tree.csv") diff --git a/R/format.data/Swiss.R b/R/format.data/Swiss.R index cacf2d5d429b73be8c9e42a172db25f7e2e66a69..3cfd9699fd9fad3bac45f1232e958f2d6b4ff685 100644 --- a/R/format.data/Swiss.R +++ b/R/format.data/Swiss.R @@ -1,3 +1,5 @@ +#!/usr/bin/env Rscript + ### MERGE Swiss DATA rm(list = ls()) source("format.fun.R") @@ -59,7 +61,11 @@ res.quant.boot <- suppressWarnings(t(sapply(levels(factor(data.swiss[["sp"]])), data.max.height <- data.frame(code = rownames(res.quant.boot), Max.height.mean = res.quant.boot[, 1], Max.height.sd = res.quant.boot[, 2], Max.height.nobs = res.quant.boot[, 3], stringsAsFactors =FALSE) rm(res.quant.boot) +<<<<<<< HEAD write.csv(data.max.height,file='../../output/process/Swiss/data.max.height.csv') +======= +write.csv(data.max.height,file='../../output/process/Swiss/max.height.csv') +>>>>>>> Makefile for data processing ########################################## FORMAT INDIVIDUAL TREE DATA data.swiss$G <- 10 * (data.swiss$dbh_diff)/data.swiss$year ## diameter growth in mm per year @@ -92,4 +98,5 @@ vec.abio.var.names <- c("MAT", "MAP", "swb") vec.basic.var <- c("obs.id","tree.id", "sp","sp.name", "cluster", "plot", "ecocode", "D", "G", "dead", "year", "htot", "Lon", "Lat", "perc.dead", "weights","census") data.tree <- subset(data.swiss, select = c(vec.basic.var, vec.abio.var.names)) -write.csv(data.tree,file="../../output/process/Swiss/data.tree.csv") +write.csv(data.tree,file="../../output/process/Swiss/tree.csv") +warnings() diff --git a/R/format.data/US.R b/R/format.data/US.R index 37b5b4a5c9b69239d4aed72b3887d2acbe4471cd..cac12685f35307561f2dea3f15f6c06e66663c78 100644 --- a/R/format.data/US.R +++ b/R/format.data/US.R @@ -5,7 +5,6 @@ source("format.fun.R") dir.create("../../output/process/US", recursive=TRUE,showWarnings=FALSE) - ### read species names species.clean <- read.csv("../../data/raw/US/REF_SPECIES.CSV", stringsAsFactors = FALSE) ## select column to keep @@ -99,6 +98,6 @@ vec.abio.var.names <- c("MAT", "MAP") vec.basic.var <- c("obs.id","tree.id", "sp","sp.name", "cluster", "plot", "ecocode", "D", "G", "dead", "year", "htot", "Lon", "Lat", "perc.dead", "weights","census") data.tree <- subset(data.us, select = c(vec.basic.var, vec.abio.var.names)) -write.csv(data.tree,file="../../output/process/US/data.tree.csv") +write.csv(data.tree,file="../../output/process/US/tree.csv") rm(data.us) gc()