Skip to content

Commit

Permalink
use long name for display of variables (github PecanProject#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
robkooper committed Jun 30, 2013
1 parent e7b8096 commit 6ebbe8a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
10 changes: 7 additions & 3 deletions utils/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
##' @param nsoil nsoil if dimension requests it
##' @return ncvar based on MstMIP definition
##' @author Rob Kooper
mstmipvar <- function(name, lat=NA, lon=NA, time=NA, nsoil=NA) {
mstmipvar <- function(name, lat=NA, lon=NA, time=NA, nsoil=NA, silent=FALSE) {
data(mstmip_vars, package="PEcAn.utils")
var <- mstmip_vars[mstmip_vars$Variable.Name==name,]
dims <- list()
Expand All @@ -34,7 +34,9 @@ mstmipvar <- function(name, lat=NA, lon=NA, time=NA, nsoil=NA) {
data(mstmip_local, package="PEcAn.utils")
var <- mstmip_local[mstmip_local$Variable.Name==name,]
if (nrow(var) == 0) {
logger.info("Don't know about variable", name, " in mstmip_vars in PEcAn.utils")
if (!silent) {
logger.info("Don't know about variable", name, " in mstmip_vars in PEcAn.utils")
}
return(ncvar_def(name, "", list(time), -999, "NOT FOUND IN mstmip_vars or mstmip_local"))
}
}
Expand All @@ -52,7 +54,9 @@ mstmipvar <- function(name, lat=NA, lon=NA, time=NA, nsoil=NA) {
} else if (vd == 'na') {
# skip
} else {
logger.info("Don't know dimension for", vd, "for variable", name)
if (!silent) {
logger.info("Don't know dimension for", vd, "for variable", name)
}
}
}
ncvar <- ncvar_def(name, as.character(var$Units), dims, -999)
Expand Down
23 changes: 9 additions & 14 deletions web/finished.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,12 @@
if (count($y) == 0) {
continue;
}
print " runplot['$key']['$x'] = Array(";
$first = true;
print " runplot['$key']['$x'] = {};\n";
foreach($y as $s) {
if ($first) {
print "'$s'";
} else {
print ", '$s'";
}
$first = false;
$kv = explode(" ", $s, 2);
if ($kv[1] == '') $kv[1] = $kv[0];
print " runplot['$key']['$x']['{$kv[0]}'] = '${kv[1]}';\n";
}
print ");\n";
}
}
?>
Expand All @@ -183,8 +178,8 @@ function resize() {
if ($("#stylized").height() < $(window).height()) {
$("#stylized").height($(window).height() - 5);
}
$("#output").height($(window).height() - 1);
$("#output").width($(window).width() - $('#stylized').width() - 5);
$("#output").height($(window).height() - 1);
$("#output").width($(window).width() - $('#stylized').width() - 5);
}

function prevStep() {
Expand Down Expand Up @@ -265,10 +260,10 @@ function updateOutputRun(run) {
}

function updateOutputYear(run, year) {
$.each(runplot[run][year], function(key, value) {
$.each(runplot[run][year], function(key, value) {
$('#outvar')
.append($("<option></option>")
// .attr("value",key)
.attr("value",key)
.text(value));
});
}
Expand Down Expand Up @@ -314,7 +309,7 @@ function startsWith(haystack, needle) {
<input id="home" type="button" value="Show Run Output" onclick="showRunOutput($('#outrun')[0].value, $('#outfile')[0].value);" />

<label>Year</label>
<select id="outyear" onChange="updateOuputYear($('#outrun')[0].value, $('#outyear')[0].value);">>
<select id="outyear" onChange="updateOuputYear($('#outrun')[0].value, $('#outyear')[0].value);">
</select>
<div class="spacer"></div>

Expand Down
4 changes: 2 additions & 2 deletions web/plot.netcdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data.fetch <- function(var, nc, fun=mean) {

# some precomputations
indices <- 0:length(nc$dim[['time']]$vals)
aggrlist <- list(floor(nc$dim[['time']]$vals))
aggrlist <- list(floor(nc$dim[['time']]$vals))

# aggregate the data
data <- ncvar_get(nc, var)
Expand Down Expand Up @@ -122,7 +122,7 @@ plot.netcdf <- function(datafile, year, yvar, xvar='time', width=800, height=600
title(xlab=attr(xval_mean, "lbl"))
title(ylab=attr(yval_mean, "lbl"))
if (xvar == "time") {
title(main=paste(yvar, "for", year))
title(main=paste(nc$var[[yvar]]$longname, "for", year))
} else {
title(main=paste(xvar, "VS", yvar, "for", year))
}
Expand Down
1 change: 1 addition & 0 deletions web/runpecan.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
fwrite($fh, " </site>" . PHP_EOL);
fwrite($fh, " <start.date>${startdate}</start.date>" . PHP_EOL);
fwrite($fh, " <end.date>${enddate}</end.date>" . PHP_EOL);
fwrite($fh, " <dbfiles>${output_folderi}</dbfiles>" . PHP_EOL);
fwrite($fh, " <host>" . PHP_EOL);
fwrite($fh, " <name>${hostname}</name>" . PHP_EOL);
fwrite($fh, " </host>" . PHP_EOL);
Expand Down
4 changes: 3 additions & 1 deletion web/workflow_stage3.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ options(error=quote({
status.start("OUTPUT")
convert.outputs(settings$model$name, settings)
# special for web, print all nc vars
data(mstmip_vars, package="PEcAn.utils")
for (runid in readLines(con=file.path(settings$rundir, "runs.txt"))) {
for(file in list.files(path=file.path(settings$modeloutdir, runid), pattern="*.nc")) {
nc <- nc_open(file.path(settings$modeloutdir, runid, file))
for(v in sort(names(nc$var))) {
cat(v, file=file.path(settings$modeloutdir, runid, paste(file, "var", sep=".")), append=TRUE, sep="\n")
name <- mstmipvar(v, silent=TRUE)['longname']
cat(paste(v, name), file=file.path(settings$modeloutdir, runid, paste(file, "var", sep=".")), append=TRUE, sep="\n")
}
nc_close(nc)
}
Expand Down

0 comments on commit 6ebbe8a

Please sign in to comment.