Skip to content

Commit

Permalink
updated BIOCRO start.runs and write.config functions; complete workfl…
Browse files Browse the repository at this point in the history
…ow runs, still need to test that it gives useful (valid) output
  • Loading branch information
dlebauer committed Feb 1, 2013
1 parent a4dd155 commit 32df813
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 38 deletions.
3 changes: 1 addition & 2 deletions models/biocro/R/start.runs.BIOCRO.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ start.runs.BIOCRO <- function(runid) {
BioGro_result <- BioGro(weather2, photoControl=pp)

write.csv(with(BioGro_result, data.frame(DayofYear, Hour, ThermalT, Stem, Leaf, Root)),
file=file.path(outdir, "result.csv"))
file=file.path(outdir, runid, "result.csv"))
file.copy(file.path(rundir, "README.txt"), file.path(outdir, "README.txt"))
setwd(cwd)
}

#==================================================================================================#
Expand Down
11 changes: 5 additions & 6 deletions models/biocro/R/write.configs.BIOCRO.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ PREFIX_XML <- '<?xml version="1.0"?>\n<!DOCTYPE config SYSTEM "ed.dtd">\n'
##' @return matrix or dataframe with values transformed
##' @author David LeBauer
convert.samples.BIOCRO <- function(trait.samples){
if(is.list(trait.samples)){
trait.samples <- as.data.frame(trait.samples)
}

if(is.list(trait.samples)) trait.samples <- as.data.frame(trait.samples)
## first rename variables
trait.names <- colnames(trait.samples)
trait.names[trait.names == "Vcmax"] <- "vmax"
Expand Down Expand Up @@ -65,19 +64,19 @@ write.config.BIOCRO <- function(defaults,
as.character)
biocro.traits <- names(biocro.trait.values)
constants <- defaults$pft$constants
parms.xml <- listToXml(constants, "pft")
photoparm.names <- names(constants$photoParms)
for(parm.type in names(constants)){
parm.names <- names(constants[[parm.type]])
for(parm in parm.names) {
if(parm %in% biocro.traits){
xmlChildren(parms.xml[[parm.type]][[parm]]) <- biocro.trait.values[[parm]]
constants[[parm.type]][[parm]] <- biocro.trait.values[[parm]]
}
}
}
parms.xml <- listToXml(constants, "pft")
location.xml <- listToXml(list(latitude = settings$run$site$lat,
longitude = settings$run$site$lon),
"location")

slashdate <- function(x) substr(gsub("-", "/", x), 1, 10)
simulationPeriod.xml <- listToXml(
list(dateofplanting = slashdate(settings$run$start.date),
Expand Down
12 changes: 8 additions & 4 deletions models/biocro/inst/pecan.biocro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<name>biocro.saof</name>
<outdir>/tmp/out/saof/</outdir>
<constants>
<canopyParms>
<canopyParms>
<Sp>1.7</Sp>
<SpD> 0.0 </SpD>
<nlayers> 0.0 </nlayers>
Expand Down Expand Up @@ -109,13 +109,17 @@
<random.effects>FALSE</random.effects>
</meta.analysis>
<ensemble>
<size>2</size>
<size>10</size>
</ensemble>
<sensitivity.analysis>
<quantiles>
<sigma>3</sigma>
<sigma>2</sigma>
<sigma>1</sigma>
<sigma>0</sigma>
<!-- <sigma>1</sigma>
<sigma>-1</sigma>-->
<sigma>-1</sigma>
<sigma>-2</sigma>
<sigma>-3</sigma>
</quantiles>
<variable>Stem</variable>
<start.year>2004</start.year>
Expand Down
145 changes: 145 additions & 0 deletions models/biocro/inst/tests/test.pecan.biocro.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?xml version="1.0"?>
<pecan>
<outdir>/tmp/out/run/</outdir>
<rundir>/tmp/out/run/</rundir>
<pfts>
<pft>
<name>biocro.saof</name>
<outdir>/tmp/out/saof/</outdir>
<constants>
<canopyParms>
<Sp>1.7</Sp>
<SpD> 0.0 </SpD>
<nlayers> 0.0 </nlayers>
<kd> 0.0 </kd>
<chi.l> 0.0 </chi.l>
<mResp1> 0.0 </mResp1>
<mResp2> 0.0 </mResp2>
<heightfactor> 0.0 </heightfactor>
</canopyParms>
<nitroParms>
<iLeafN>2.0</iLeafN>
<kLN>0.5</kLN>
<Vmax.b1>0.0</Vmax.b1>
<alpha.b1>0.0</alpha.b1>
<kpLN>0.2</kpLN>
<lnb0>-5</lnb0>
<lnb1>18</lnb1>
<lnFun>0</lnFun>
</nitroParms>
<photoParms>
<vmax> 0.0 </vmax>
<alpha> 0.0 </alpha>
<kparm> 0.0 </kparm>
<theta> 0.0 </theta>
<beta> 0.0 </beta>
<Rd> 0.0 </Rd>
<Catm> 0.0 </Catm>
<b0> 0.0 </b0>
<b1> 0.0 </b1>
<ws> 0.0 </ws>
</photoParms>
<soilParms>
<FieldC> -1.0 </FieldC>
<WiltP> -1.0 </WiltP>
<phi1> 0.01 </phi1>
<phi2> 10 </phi2>
<soilDepth> 1.0 </soilDepth>
<iWatCont> 0.0 </iWatCont>
<soilType> 6 </soilType>
<soilLayers> 1 </soilLayers>
<soilDepth> 5.0 </soilDepth>
<hydrDist> 0.0 </hydrDist>
<wsFun> 0 </wsFun>
<scsf> 1.0 </scsf>
<transResp> 5000000 </transResp>
<leafPotTh> -800 </leafPotTh>
<rfl> 0.2 </rfl>
<rsec> 0.2 </rsec>
<rsdf> 0.44 </rsdf>
</soilParms>
<seneParms>
<senleaf> 3000 </senleaf>
<senstem> 3500 </senstem>
<senRoot> 4000 </senRoot>
</seneParms>
<phenoParms>
<tp1> 562 </tp1>
<tp2> 1312 </tp2>
<tp3> 2063</tp3>
<tp4> 2676</tp4>
<tp5> 3211</tp5>
<tp6> 7000</tp6>
<kLeaf1> 0.33 </kLeaf1>
<kStem1> 0.37 </kStem1>
<kRoot1> 0.3 </kRoot1>
<kRhizome1> -0.008 </kRhizome1>
<kLeaf2> 0.14 </kLeaf2>
<kStem2> 0.85 </kStem2>
<kRoot2> 0.01 </kRoot2>
<kRhizome2> -0.0005 </kRhizome2>
<kLeaf3> 0.01</kLeaf3>
<kStem3> 0.63 </kStem3>
<kRoot3> 0.01</kRoot3>
<kRhizome3> 0.35 </kRhizome3>
<kLeaf4> 0.01 </kLeaf4>
<kStem4> 0.63 </kStem4>
<kRoot4> 0.01</kRoot4>
<kRhizome4>0.35 </kRhizome4>
<kLeaf5> 0.01 </kLeaf5>
<kStem5> 0.63 </kStem5>
<kRoot5> 0.01</kRoot5>
<kRhizome5> 0.35</kRhizome5>
<kLeaf6> 0.01 </kLeaf6>
<kStem6> 0.63 </kStem6>
<kRoot6> 0.01 </kRoot6>
<kRhizome6> 0.35</kRhizome6>
</phenoParms>
</constants>
</pft>
</pfts>
<database>
<userid>bety</userid>
<passwd>bety</passwd>
<name>bety</name>
<location>localhost</location>
</database>
<meta.analysis>
<iter>3000</iter>
<random.effects>FALSE</random.effects>
</meta.analysis>
<ensemble>
<size>2</size>
</ensemble>
<sensitivity.analysis>
<quantiles>
<sigma>0</sigma>
<!-- <sigma>1</sigma>
<sigma>-1</sigma>-->
</quantiles>
<variable>Stem</variable>
<start.year>2004</start.year>
<end.year>2004</end.year>
</sensitivity.analysis>
<model>
<name>BIOCRO</name>
<id></id>
</model>
<run>
<site>
<id>288</id>
<name>Sapelo Island</name>
<lat>31.40</lat>
<lon>-81.37</lon>
<met>NULL</met>
</site>
<folder>/tmp/out/run/</folder>
<start.date>2004-01-01 06:00:00</start.date>
<end.date>2005-12-31 05:59:00</end.date>
<host>
<name>localhost</name>
<rundir>/tmp/out/run/</rundir>
<outdir>/tmp/out/run/</outdir>
</host>
</run>
</pecan>
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
settings.xml <- system.file("pecan.biocro.xml", package = "PEcAn.BIOCRO")
settings <- read.settings(settings.xml)

samples <- structure(list(
biocro.saof = structure(list(
samples <- list(
biocro.saof = (data.frame(
Vcmax = c(31.9, 42.4, 57.0),
cuticular_cond = c(1800, 4380, 10700),
SLA = c(8.5, 8.9, 9.2),
leaf_respiration_rate_m2 = c(1.0, 1.9, 3.6),
stomatal_slope.BB = c(2.7, 3.3, 3.9)),
row.names = c("15.866", "50", "84.134"),
.Names = c("Vcmax", "cuticular_cond", "SLA", "leaf_respiration_rate_m2", "stomatal_slope.BB"), class = "data.frame")), .Names = "biocro.saof")
stomatal_slope.BB = c(2.7, 3.3, 3.9),
row.names = c("15.866", "50", "84.134"))))

test_that("convert.samples.BIOCRO works", {
biocro.parms <- convert.samples.BIOCRO(samples$biocro.saof)
Expand All @@ -23,32 +21,20 @@ test_that("convert.samples.BIOCRO works", {
## re-create bug #1491
test.list <- list(vmax = 1, b0 = 2)
convert.samples.BIOCRO(test.list) ## this should work
stop("fake error")
expect_true(FALSE)

})

test_that("write.configs.BIOCRO produces expected output",{
trait.values = samples$biocro.saof["50", ]
write.config.BIOCRO(defaults = settings$pfts,
trait.values = samples$biocro.saof["50", ],
settings = settings,
run.id = "")
config <- file.path(settings$outdir, "data.xml")
xmlParse(config)

})

test_that("run.write.configs produces expected output for BIOCRO",{
PEcAn.utils::run.write.configs("BIOCRO")
runids <- basename(list.dirs(path = settings$outdir,
full.names = FALSE,
recursive = FALSE))
runid <- max(as.numeric(runids), na.rm = TRUE)

config <- file.path(settings$outdir, runid, "data.xml")
xmlParse(config)

config.xml <- xmlParse(config)
config.list <- xmlToList(config.xml)
biocro.trait.values <- convert.samples.BIOCRO(trait.values)
expect_equal(biocro.trait.values[["vmax"]], as.numeric(config.list$pft$photoParms[["vmax"]]))
expect_equal(biocro.trait.values[["b0"]], as.numeric(config.list$pft$photoParms[["b0"]]))
expect_equal(biocro.trait.values[["b1"]], as.numeric(config.list$pft$photoParms[["b1"]]))
expect_equal(biocro.trait.values[["Rd"]], as.numeric(config.list$pft$photoParms[["Rd"]]))
})



0 comments on commit 32df813

Please sign in to comment.