-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdata2csv.sh
executable file
·50 lines (41 loc) · 1.21 KB
/
rdata2csv.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# T Carman, Spring 2019
# This script is for converting PEcAn .Rdata output files to
# .csv so that they can be easily imported to Python's Pandas
# library for further analysis and plotting.
function usage() {
echo "Usage:
$ ./rdata2csv.sh path/to/pecan/dir
"
}
if [[ $# -ne 1 ]]; then
echo "Invalid arguments! Must pass one path to a pecan run directory."
usage
exit
fi
WORKING_DIR=$1
echo Looking for files in "$WORKING_DIR"
# And finally, convert from .Rdata to csv so we can easily read with pandas.
# This works, but leaves .Rdata in the csv filename
for F in $(find $WORKING_DIR -name "ensemble.ts.[0-9]*.Rdata")
do
cat <<EOF > oneoffR.R
setwd("$(dirname $F)")
load("$(basename $F)")
write.table(ensemble.ts, "$(basename $F).csv", sep=",")
EOF
Rscript --vanilla oneoffR.R
done
for F in $(find $WORKING_DIR -name "sensitivity.results*.Rdata")
do
cat <<EOF > oneoffR.R
setwd("$(dirname $F)")
load("$(basename $F)")
for (PFTNAME in names(sensitivity.results)) {
new_file_name <- paste0("$(basename $F)", ".", PFTNAME, ".csv")
print(new_file_name)
write.table(sensitivity.results[[PFTNAME]][["variance.decomposition.output"]], new_file_name, sep=",")
}
EOF
Rscript --vanilla oneoffR.R
done