Skip to content
Snippets Groups Projects
Commit b3ebcd05 authored by Peter Alexander's avatar Peter Alexander
Browse files

Cluster scripts updated

parent cef322ed
No related branches found
No related tags found
No related merge requests found
...@@ -7,8 +7,10 @@ fi ...@@ -7,8 +7,10 @@ fi
cd $1 cd $1
concatLcFile=lc_concat.txt concatLcFile=lc_concat.txt
concatPriceFile=price_concat.txt concatPriceFile=price_concat.txt
concatLUFile=LandUseSummary.csv
echo "Scenario,Year,Cropland,Pasture,ManForest,UnmanForest,Natural,EnergyCrop,FertCrop,IrrigCrop" > $concatLcFile echo "Scenario,Year,Cropland,Pasture,ManForest,UnmanForest,Natural,EnergyCrop,FertCrop,IrrigCrop" > $concatLcFile
echo "Scenario,Year,Crop,Imports,Exports,Price,Stocks" > $concatPriceFile echo "Scenario,Year,Crop,Imports,Exports,Price,Stocks" > $concatPriceFile
echo "Scenario,cropType,yield,irrig,fert,otherint,area,Year" > $concatLUFile
find . -name "*lc.txt"|while read fname; do find . -name "*lc.txt"|while read fname; do
scenarioDir="$(dirname $fname)" scenarioDir="$(dirname $fname)"
...@@ -29,4 +31,11 @@ find . -name "*lc.txt"|while read fname; do ...@@ -29,4 +31,11 @@ find . -name "*lc.txt"|while read fname; do
test $j -eq 1 && ((j=j+1)) && continue test $j -eq 1 && ((j=j+1)) && continue
echo "${scenario},$line" >> $concatPriceFile echo "${scenario},$line" >> $concatPriceFile
done < $scenarioDir/prices.txt done < $scenarioDir/prices.txt
k=1
while read -r line
do
test $k -eq 1 && ((k=k+1)) && continue
echo "${scenario},$line" >> $concatLUFile
done < $scenarioDir/LandUseSummary.csv
done done
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#$ -l h_vmem=8G #$ -l h_vmem=8G
#$ -R y #$ -R y
if [ $# -ne 1 ]; then if [ $# -lt 1 ]; then
echo need 1 argument to specify config/output directory echo need 1 argument to specify config/output directory
exit 0 exit 0
fi fi
...@@ -21,3 +21,13 @@ echo "starting" ...@@ -21,3 +21,13 @@ echo "starting"
java -Xmx1G -XX:+PrintGC -classpath /exports/csce/eddie/geos/groups/LURG/models/gams/gams24.7_linux_x64_64_sfx/apifiles/Java/api/GAMSJavaAPI.jar:/exports/csce/eddie/geos/groups/LURG/models/PLUM/classes -DBUILDVER=$buildver -DCONFIG_FILE=/exports/csce/eddie/geos/groups/LURG/models/PLUM/output/$1/config.properties ac.ed.lurg.ModelMain java -Xmx1G -XX:+PrintGC -classpath /exports/csce/eddie/geos/groups/LURG/models/gams/gams24.7_linux_x64_64_sfx/apifiles/Java/api/GAMSJavaAPI.jar:/exports/csce/eddie/geos/groups/LURG/models/PLUM/classes -DBUILDVER=$buildver -DCONFIG_FILE=/exports/csce/eddie/geos/groups/LURG/models/PLUM/output/$1/config.properties ac.ed.lurg.ModelMain
echo "finished" echo "finished"
module load R
R < /exports/csce/eddie/geos/groups/LURG/models/PLUM/plumv2/scripts/summariseLandUseOneSim.R --no-save --args $1
if [[ $* == *-NoP* ]]; then
echo "Not pruning outputs"
else
echo "Pruning outputs, to save disk space"
/exports/csce/eddie/geos/groups/LURG/models/PLUM/plumv2/scripts/pruneOutputs.sh /exports/csce/eddie/geos/groups/LURG/models/PLUM/output/$1
fi
require(data.table)
cropIntensitySummary = function (luDt, cropType) {
yDt = luDt[cropland > 0,
list( irrig = get(paste0(cropType, '_IQ')),
fert = get(paste0(cropType, '_FQ')),
otherint = get(paste0(cropType, '_OI')),
thisCropFact = get(paste0(cropType, '_A')),
allCropFact = cropland/area,
area = get(paste0(cropType, '_A'))*cropland,
yield = get(paste0(cropType, '_Y'))) ]
# yDt[thisCropFact>0.05 & allCropFact > 0.03, list(cropType = cropType, yield=sum(area * yield)/sum(area),
yDt[thisCropFact>0, list(cropType = cropType, yield=sum(area * yield)/sum(area),
irrig=sum(area * irrig)/sum(area),
fert=sum(area * fert)/sum(area),
otherint=sum(area * otherint)/sum(area),
area = sum(area)) ]
}
summariseLandUseOutput = function(simDir, writeFile=TRUE) {
years = list.files(simDir, pattern="[0-9]+")
cropSumDt = NULL
for (year in years) {
fileName = file.path(simDir, year, 'LandUse.txt')
if (file.exists(fileName)) {
print (paste("Processing", year, "from", fileName))
luDt = data.table(read.table(fileName, header=TRUE))
for (cropType in c('maize', 'rice', 'wheat', 'energycrops', 'oilcrops', 'pulses', 'starchyRoots')) {
cropSummary = cropIntensitySummary(luDt, cropType)
if (nrow(cropSummary) >0)
cropSumDt = rbind(cropSumDt, cbind(cropSummary, year=year))
}
} else {
print(paste("Can't find file, so skipping:", fileName))
}
}
resDt = rbind(cropSumDt, cropSumDt[cropType != 'energycrops', list(cropType='avgExcEC',
yield=sum(yield*area)/sum(area),
irrig=sum(irrig*area)/sum(area),
fert=sum(fert*area)/sum(area),
otherint=sum(otherint*area)/sum(area),
area=sum(area)), by=year])
resDt = rbind(resDt, cropSumDt[, list(cropType='avgIncEC',
yield=sum(yield*area)/sum(area),
irrig=sum(irrig*area)/sum(area),
fert=sum(fert*area)/sum(area),
otherint=sum(otherint*area)/sum(area),
area=sum(area)), by=year])
if (writeFile) write.table(resDt, file.path(simDir, "LandUseSummary.csv"), sep=",", row.names=FALSE, quote=FALSE)
resDt
}
baseOutputDir="/exports/csce/eddie/geos/groups/LURG/models/PLUM/output" # "~/Downloads"
ensemble = commandArgs(trailingOnly = TRUE)[1]
ensDir=file.path(baseOutputDir, ensemble)
if (dir.exists(ensDir)) {
print(paste(ensDir, "exists. Processing"))
summariseLandUseOutput(simDir = ensDir)
} else {
print(paste(ensDir, "does not exist. Stopping"))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment