Skip to content

Commit

Permalink
pequenas mudanças nas funções e comandos de teste (p.e.x para garanti…
Browse files Browse the repository at this point in the history
…r que se volte oa diretorio de trabalho original)
  • Loading branch information
piklprado committed Oct 23, 2014
1 parent 35c06fd commit ef8ca16
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
21 changes: 14 additions & 7 deletions Analytical-pckg.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
multiRun=function(PATH="~/Desktop/Comb-0001",nrep=10,b0,d0,m0,inc.b,inc.d,step,radius,dens.t,config,N0,lands=land,tm=100)
multiRun=function(PATH,nrep=10,b0,d0,m0,inc.b,inc.d,step,radius,dens.t,config,N0,lands=land,tm=100)
{
dir.create(PATH)
oldpath <- getwd()
dir.create(PATH, recursive=TRUE)
setwd(PATH)
for(i in 1:nrep)
{
Expand All @@ -21,10 +22,10 @@ multiRun=function(PATH="~/Desktop/Comb-0001",nrep=10,b0,d0,m0,inc.b,inc.d,step,r
tempo=tm,
out.code=i)
}

#Nt.reps=Nt.data(wdir=PATH,intervals=1,tmax=tm)
#plot.Nt(data=Nt.reps,growth=b0-d0,sum.incl=inc.b+inc.d)
#return(Nt.reps)
setwd(oldpath)
}

# land <- Landscape(cover=1,type="b",cell.size=100)
Expand Down Expand Up @@ -59,6 +60,7 @@ Support <- function(taxa.basal=0.6, taxa.morte=0.1, incl.birth=0.5/0.01,
# Get N(t) data
####################
Nt.data=function(wdir,intervals=1,tmax){
oldpath <- getwd()
setwd(wdir)
files=dir()
Nt.arr=array(0,c(tmax+1,2,length(files)))
Expand Down Expand Up @@ -95,6 +97,7 @@ Nt.data=function(wdir,intervals=1,tmax){
Nt.arr[,2,i]=Nt[1:(tmax+1),2]
}
return(Nt.arr)
setwd(oldpath)
}
# Nt.test=Nt.data("~/Desktop/Comb-0004",tmax=50)

Expand Down Expand Up @@ -146,7 +149,8 @@ dist.front=function(data,ind=10)
# Get velocity(t) data
#########################
velocity=function(work.dir="~/Desktop/Comb-0003",tmax=50,nrep=20,intervals=1)
{
{
oldpath <- getwd()
setwd(work.dir)
files=dir()
vels.arr=matrix(0,tmax,(nrep+1))
Expand Down Expand Up @@ -180,6 +184,7 @@ velocity=function(work.dir="~/Desktop/Comb-0003",tmax=50,nrep=20,intervals=1)
} else {vels.arr[,i+1]= diff(front[,2])}# front[-1,2]/front[-1,1]
}
return(vels.arr)
setwd(oldpath)
}

####################
Expand Down Expand Up @@ -276,6 +281,7 @@ plot.sdXY=function(FILE="output-00001.txt",Dcoef,tmax=50,name="Standard Deviatio
multi.run.cP=function(PATH="~/Desktop/TWoTests/Critical_Patch/Comb-01",nrep=20,b0=0.007,d0=0.004,m0=0.8,inc.b=0,inc.d=0,
step=500,radius=0,dens.t=0,config=0,N0=20,tm=1000,lands.range=c(-5000,5000,1000))
{
oldpath <- getwd()
dir.create(PATH)
setwd(PATH)
Dcoef=m0*(step^2)/4
Expand Down Expand Up @@ -310,10 +316,11 @@ multi.run.cP=function(PATH="~/Desktop/TWoTests/Critical_Patch/Comb-01",nrep=20,b
setwd(PATH)
}
return(land.sides)
setwd(oldpath)
}

multi.run.cP(nrep=50)
multi.run.cP(PATH="~/Desktop/TWoTests/Critical_Patch/Comb-03",lands.range=c(2000,17000,1000),nrep=50)
##multi.run.cP(nrep=50)
##multi.run.cP(PATH="TWoTests/Critical_Patch/Comb-03",lands.range=c(2000,17000,1000),nrep=50)

data.Acrit=function(PATH="~/Desktop/TWoTests/Critical_Patch/Comb-01",nreps=50,tmaxi=1000)
{
Expand Down Expand Up @@ -363,4 +370,4 @@ plot.Acrit=function(object,move=0.8,step=500,growth=0.003,N0=20,range=c(-17000,1

#################################
###### Fragmented Landscape Tests
#################################
#################################
62 changes: 33 additions & 29 deletions Tests.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## source("TWoLife.R") ## calls the C++ sources with parallel.
source("Analytical-pckg.R")
##########################################
########## Set of Parameteres Combinations
##########################################
Expand Down Expand Up @@ -79,11 +81,12 @@ params=data.frame(b0=b0s,d0=d0s,movem.rate=m0s,incl.birth=incl.bs,incl.death=inc
dens.type=d.types,initial.config=i.configs,N0=N0s,death.matrix=d.matrix,tmax=times)
# params$b0[51]
# dim(params)
## Create a directory for the output files, here named TWotests
land <- Landscape(cover=1,type="b",cell.size=100)
combs=1:51
for (i in combs)
{
multiRun(PATH=paste("~/Desktop/TWoTests/Comb-",CODE[i],sep=""),
multiRun(PATH=paste("./TWoTests/Comb-",CODE[i],sep=""),
nrep=20,
b0=params$b0[i],
d0=params$d0[i],
Expand Down Expand Up @@ -142,43 +145,44 @@ titles

###############
####### Plots
## First create a directory for the plots (./TWoResults here)
###############
paths=paste("~/Desktop/TWoTests/Comb-",CODE,sep="")
paths=paste("./TWoTests/Comb-",CODE,sep="")
paths
ind1=c(1,4,2,5,3,6)

pdf("~/Desktop/TWoResults/Nt/Nt_Simple-Birth-Death.pdf",width = 8,height = 12)
pdf("./TWoResults/Nt/Nt_Simple-Birth-Death.pdf",width = 8,height = 12)
par(mfrow=c(3,2))
for(i in ind1)
{
teste=Nt.data(wdir = paths[i],tmax=params$tmax[i])
setwd("~/Desktop/TWoResults/Nt")
setwd("./TWoResults/Nt")
plot.Nt(teste,growth=params$b0[i]-params$d0[i],sum.incl = params$incl.birth[i]+params$incl.death[i],name = titles[i])
}
par(mfrow=c(1,1))
dev.off()

ind=c(19:23,25)

pdf("~/Desktop/TWoResults/Nt/Nt_General-Birth-Death-gd2.pdf",width = 8,height = 12)
pdf("./TWoResults/Nt/Nt_General-Birth-Death-gd2.pdf",width = 8,height = 12)
par(mfrow=c(3,2))
for(i in ind)
{
teste=Nt.data(wdir = paths[i],tmax=params$tmax[i])
setwd("~/Desktop/TWoResults/Nt")
setwd("./TWoResults/Nt")
plot.Nt(teste,growth=params$b0[i]-params$d0[i],sum.incl = params$incl.birth[i]+params$incl.death[i],name = titles[i])
}
par(mfrow=c(1,1))
dev.off()

ind=c(19:23,25)

pdf("~/Desktop/TWoResults/Nt/Nt_General-Birth-Death-ld.pdf",width = 8,height = 12)
pdf("./TWoResults/Nt/Nt_General-Birth-Death-ld.pdf",width = 8,height = 12)
par(mfrow=c(3,2))
for(i in ind)
{
teste=Nt.data(wdir = paths[i],tmax=params$tmax[i])
setwd("~/Desktop/TWoResults/Nt")
setwd("./TWoResults/Nt")
plot.Nt(teste,growth=params$b0[i]-params$d0[i],sum.incl = params$incl.birth[i]+params$incl.death[i],name = titles[i])
}
par(mfrow=c(1,1))
Expand All @@ -189,19 +193,19 @@ dev.off()
#################
#################
ind=27:29
pdf("~/Desktop/TWoResults/Velocity/Vel_Simple-Random-Walk.pdf",width = 8,height = 8)
pdf("./TWoResults/Velocity/Vel_Simple-Random-Walk.pdf",width = 8,height = 8)
par(mfrow=c(2,2))
for(i in ind)
{
teste=velocity(work.dir = paths[i],tmax = params$tmax[i],nrep = 50)
setwd("~/Desktop/TWoResults/Velocity")
setwd("./TWoResults/Velocity")
plot.vel(teste,Dcoef = (params$step.length[i]^2)*params$movem.rate[i]/4, growth=params$b0[i]-params$d0[i],
name = titles[i])
}
par(mfrow=c(1,1))
dev.off()
#######################
pdf("~/Desktop/TWoResults/Distribution/Dist_Simple-Random-Walk.pdf",width = 8,height = 12)
pdf("./TWoResults/Distribution/Dist_Simple-Random-Walk.pdf",width = 8,height = 12)
par(mfrow=c(length(ind),2))
for(i in ind)
{
Expand All @@ -214,97 +218,97 @@ dev.off()
###############
###############
ind=c(30,33,31,34,32,35)
pdf("~/Desktop/TWoResults/Velocity/Vel_Skellam-b.pdf",width = 8,height = 12)
pdf("./TWoResults/Velocity/Vel_Skellam-b.pdf",width = 8,height = 12)
par(mfrow=c(3,2))
for(i in ind)
{
Dcoefs=(params$step.length[i]^2)*params$movem.rate[i]/4
growths=params$b0[i]-params$d0[i]
teste=velocity(work.dir = paths[i],tmax = params$tmax[i],nrep = 50)
setwd("~/Desktop/TWoResults/Velocity")
setwd("./TWoResults/Velocity")
plot.vel(teste,Dcoef = Dcoefs, b0=params$b0[i],d0=params$d0[i], yrange = c(-1,30),name = titles[i])
}
par(mfrow=c(1,1))
dev.off()
###
pdf("~/Desktop/TWoResults/Nt/Nt_Skellam.pdf",width = 8,height = 12)
pdf("./TWoResults/Nt/Nt_Skellam.pdf",width = 8,height = 12)
par(mfrow=c(3,2))
for(i in ind)
{
teste=Nt.data(wdir = paths[i],tmax=params$tmax[i])
setwd("~/Desktop/TWoResults/Nt")
setwd("./TWoResults/Nt")
plot.Nt(teste,growth=params$b0[i]-params$d0[i],sum.incl = params$incl.birth[i]+params$incl.death[i],name = titles[i])
}
par(mfrow=c(1,1))
dev.off()


ind=c(36:43)
pdf("~/Desktop/TWoResults/Velocity/Vel_Fisher-gd-b.pdf",width = 8,height = 16)
pdf("./TWoResults/Velocity/Vel_Fisher-gd-b.pdf",width = 8,height = 16)
par(mfrow=c(4,2))
for(i in ind)
{
Dcoefs=(params$step.length[i]^2)*params$movem.rate[i]/4
growths=params$b0[i]-params$d0[i]
teste=velocity(work.dir = paths[i],tmax = params$tmax[i],nrep = 20)
setwd("~/Desktop/TWoResults/Velocity")
setwd("./TWoResults/Velocity")
plot.vel(teste,Dcoef = Dcoefs, b0=params$b0[i],d0=params$d0[i], yrange = c(-100,100),name = titles[i])
}
par(mfrow=c(1,1))
dev.off()
pdf("~/Desktop/TWoResults/Nt/Nt_Fisher-gd.pdf",width = 8,height = 12)
pdf("./TWoResults/Nt/Nt_Fisher-gd.pdf",width = 8,height = 12)
par(mfrow=c(4,2))
for(i in ind)
{
teste=Nt.data(wdir = paths[i],tmax=params$tmax[i])
setwd("~/Desktop/TWoResults/Nt")
setwd("./TWoResults/Nt")
plot.Nt(teste,growth=params$b0[i]-params$d0[i],sum.incl = params$incl.birth[i]+params$incl.death[i],name = titles[i])
}
par(mfrow=c(1,1))
dev.off()

ind=c(44:47)
pdf("~/Desktop/TWoResults/Velocity/Vel_Fisher-ld.pdf",width = 8,height = 8)
pdf("./TWoResults/Velocity/Vel_Fisher-ld.pdf",width = 8,height = 8)
par(mfrow=c(2,2))
for(i in ind)
{
teste=velocity(work.dir = paths[i],tmax = params$tmax[i],nrep = 20)
setwd("~/Desktop/TWoResults/Velocity")
setwd("./TWoResults/Velocity")
plot.vel(teste,Dcoef = (params$step.length[i]^2)*params$movem.rate[i]/4, growth=params$b0[i]-params$d0[i],name = titles[i])
}
par(mfrow=c(1,1))
dev.off()
pdf("~/Desktop/TWoResults/Nt/Nt_Fisher-ld.pdf",width = 8,height = 8)
pdf("./TWoResults/Nt/Nt_Fisher-ld.pdf",width = 8,height = 8)
par(mfrow=c(2,2))
for(i in ind)
{
teste=Nt.data(wdir = paths[i],tmax=params$tmax[i])
setwd("~/Desktop/TWoResults/Nt")
setwd("./TWoResults/Nt")
plot.Nt(teste,growth=params$b0[i]-params$d0[i],sum.incl = params$incl.birth[i]+params$incl.death[i],name = titles[i])
}
par(mfrow=c(1,1))
dev.off()

ind=c(48:51)
pdf("~/Desktop/TWoResults/Velocity/Vel_Fisher-ld-c2b.pdf",width = 8,height = 8)
pdf("./TWoResults/Velocity/Vel_Fisher-ld-c2b.pdf",width = 8,height = 8)
par(mfrow=c(2,2))
for(i in ind)
{
Dcoefs=(params$step.length[i]^2)*params$movem.rate[i]/4
growths=params$b0[i]-params$d0[i]
teste=velocity(work.dir = paths[i],tmax = params$tmax[i],nrep = 20)
setwd("~/Desktop/TWoResults/Velocity")
setwd("./TWoResults/Velocity")
plot.vel(teste,Dcoef = Dcoefs, b0=params$b0[i],d0=params$d0[i], yrange = c(-150+2*sqrt(growths*Dcoefs),50+2*sqrt(growths*Dcoefs)),
name = titles[i])
}
par(mfrow=c(1,1))
dev.off()
pdf("~/Desktop/TWoResults/Nt/Nt_Fisher-ld-c2.pdf",width = 8,height = 8)
pdf("./TWoResults/Nt/Nt_Fisher-ld-c2.pdf",width = 8,height = 8)
par(mfrow=c(2,2))
for(i in ind)
{
teste=Nt.data(wdir = paths[i],tmax=params$tmax[i])
setwd("~/Desktop/TWoResults/Nt")
setwd("./TWoResults/Nt")
plot.Nt(teste,growth=params$b0[i]-params$d0[i],sum.incl = params$incl.birth[i]+params$incl.death[i],
name = titles[i])
}
Expand All @@ -313,9 +317,9 @@ dev.off()

#####################
#####################
testes=data.Acrit("~/Desktop/TWoTests/Critical_Patch/Comb-02")
testes=data.Acrit("./TWoTests/Critical_Patch/Comb-02")

pdf("~/Desktop/TWoResults/Acrit/Skellam_Comb-02.pdf",width = 8,height = 5)
pdf("./TWoResults/Acrit/Skellam_Comb-02.pdf",width = 8,height = 5)
plot.Acrit(teste[[1]])
dev.off()

0 comments on commit ef8ca16

Please sign in to comment.