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

Write out marker files

parent 96ddba74
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ public class ModelConfig {
public static final boolean SUPPRESS_STD_OUTPUT = getBooleanProperty("SUPPRESS_STD_OUTPUT", Boolean.FALSE);
public static final String BASE_DIR = getProperty("BASE_DIR", "/Users/peteralexander/Documents/R_Workspace/UNPLUM");
public static final String BASE_DIR = getProperty("BASE_DIR"); // this must to be set in config file
public static final String TEMP_DIR = getProperty("TEMP_DIR", BASE_DIR + File.separator + "temp");
public static final String OUTPUT_DIR = getProperty("OUTPUT_DIR", BASE_DIR + File.separator + "output");
......@@ -96,7 +96,7 @@ public class ModelConfig {
public static final String COMMODITY_DATA_FILE = DATA_DIR + File.separator + "con_prod_c_and_m.csv";
// yield data
public static final String YIELD_DIR = "/Users/peteralexander/Documents/LURG/LPJ/tom-July2015";
public static final String YIELD_DIR = getProperty("YIELD_DIR");
// Spatial (gridded) data
public static final String SPATIAL_DATA_DIR = DATA_DIR; // + File.separator + "tinyTest";
......@@ -107,7 +107,7 @@ public class ModelConfig {
public static final int START_TIMESTEP = getIntProperty("START_TIMESTEP", 0);
public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 0);
public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 1);
public static final int BASE_YEAR = getIntProperty("BASE_YEAR", 2010);
public static final double MAX_IMPORT_CHANGE = getDoubleProperty("MAX_IMPORT_CHANGE", 0.2);
......
......@@ -19,7 +19,6 @@ import ac.ed.lurg.demand.DemandManager;
import ac.ed.lurg.landuse.AreasItem;
import ac.ed.lurg.landuse.CropUsageData;
import ac.ed.lurg.landuse.IntensitiesItem;
import ac.ed.lurg.landuse.Intensity;
import ac.ed.lurg.landuse.IrrigationCostItem;
import ac.ed.lurg.landuse.IrrigiationCostReader;
import ac.ed.lurg.landuse.LandCoverItem;
......@@ -73,13 +72,14 @@ public class ModelMain {
}
private void doTimestep(int timestep) {
YieldRaster yieldSurfaces = getYieldSurfaces(timestep);
int year = ModelConfig.BASE_YEAR + timestep;
LogWriter.println("Timestep: " + timestep + ", year:" + year);
YieldRaster yieldSurfaces = getYieldSurfaces(year); // this will wait for the marker file from LPJ if configured to do so
// YieldResponsesItem yresp = yieldSurfaces.getFromCoordinates(-50.0, -4.0);
// LogWriter.printlnError("Test key: " + yresp.getYieldMax(CropType.CEREALS) + ", " + yresp.getYieldFertOnly(CropType.CEREALS) + ", " + yresp.getYieldIrrigOnly(CropType.CEREALS));
int year = ModelConfig.BASE_YEAR + timestep;
LogWriter.println("Timestep: " + timestep + ", year:" + year);
CropToDoubleMap totalQuantity = new CropToDoubleMap();
CropToDoubleMap totalWorldInputCost = new CropToDoubleMap();
......@@ -246,9 +246,9 @@ public class ModelMain {
// DEBUG code
// if (!(country.getCountryName().equals("United States of Americaxx") || country.getCountryName().equals("Russian Federationxx") || country.getCountryName().equals("China")) ) { //|| country.getCountryName().equals("China")
// continue;
// }
if (!(country.getCountryName().equals("United States of America") || country.getCountryName().equals("Russian Federation") || country.getCountryName().equals("China")) ) { //|| country.getCountryName().equals("China")
continue;
}
if (demandManager.getPopulation(country, 2010) < 50 || countryExclusionList.contains(country.getCountryName())) {
LogWriter.printlnError("Skipping " + country);
......@@ -300,20 +300,8 @@ public class ModelMain {
return initLC;
}
private YieldRaster getYieldSurfaces(int timestep) {
/* String rootDir = ModelConfig.YIELD_DIR + File.separator + (timestep + ModelConfig.BASE_YEAR) + File.separator;
YieldRaster yieldSurfaces = null;
for (CropType cropType : CropType.values()) {
String cropDir = rootDir + cropType.getGamsName() + File.separator;
for (YieldType yieldType : YieldType.values()) {
YieldResponseMapReader yieldReader = new YieldResponseMapReader(yieldSurfaces, yieldType, cropType);
yieldSurfaces = (YieldRaster)yieldReader.getRasterDataFromFile(cropDir + yieldType.getFileName());
}
} */
LPJYieldResponseMapReader yieldReader = new LPJYieldResponseMapReader(ModelConfig.YIELD_DIR, desiredProjection);
private YieldRaster getYieldSurfaces(int year) {
LPJYieldResponseMapReader yieldReader = new LPJYieldResponseMapReader(ModelConfig.YIELD_DIR + File.separator + year, desiredProjection);
for (FertiliserRate fr : FertiliserRate.values()) {
yieldReader.getRasterDataFromFile(fr);
......
......@@ -2,6 +2,7 @@ package ac.ed.lurg.output;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map.Entry;
......@@ -32,24 +33,48 @@ public class LpjgOutputer {
}
public void writeOutput() {
writeLandCoverAndCrop();
String outputDirName = ModelConfig.OUTPUT_DIR + File.separator + year;
File outputDir = new File(outputDirName);
outputDir.mkdirs();
writeLandCoverAndCrop(outputDirName);
writeIntensity(outputDirName);
writeMarkerFile(outputDirName, false);
}
private void writeIntensity(String outputDirName) {
// TODO Auto-generated method stub
}
public void writeLandCoverAndCrop() {
private void writeMarkerFile(String outputDirName, boolean errorStatus) {
File markerFile = new File(outputDirName + File.separator + (errorStatus ? "error" : "done"));
try {
if (!markerFile.exists())
new FileOutputStream(markerFile).close();
markerFile.setLastModified(System.currentTimeMillis());
}
catch (IOException e) {
LogWriter.printlnError("Problem writing marker file");
}
}
public void writeLandCoverAndCrop(String outputDir) {
BufferedWriter landCoverWriter = null;
BufferedWriter cropFractWriter = null;
try {
String landCoverFileName = ModelConfig.OUTPUT_DIR + File.separator + "LandCoverFract" + year + ".txt";
String landCoverFileName = outputDir + File.separator + "LandCoverFract.txt";
landCoverWriter = new BufferedWriter(new FileWriter(landCoverFileName, false));
landCoverWriter.write("Lon Lat CROPLAND PASTURE NATURAL");
landCoverWriter.newLine();
String cropFractionFileName = ModelConfig.OUTPUT_DIR + File.separator + "CropFract" + year + ".txt";
String cropFractionFileName = outputDir + File.separator + "CropFract.txt";
cropFractWriter = new BufferedWriter(new FileWriter(cropFractionFileName, false));
cropFractWriter.write("Lon Lat TeWWirr TeSWirr TeCoirr TrRiirr");
cropFractWriter.newLine();
for (Entry<RasterKey, AreasItem> entry : cropAreaRaster.entrySet()) {
RasterKey key = entry.getKey();
AreasItem item = entry.getValue();
......@@ -70,7 +95,7 @@ public class LpjgOutputer {
isSpringWheat = yieldSurfaces.get(key).isSpringWheat();
else
LogWriter.printlnError("LpjgOutputer: Can't find YieldResponsesItem for " + key);
double lpjWinterWheatFrac = item.getCropFraction(CropType.OILCROPS, isSpringWheat ? null : CropType.WHEAT);
double lpjSpringWheatFrac = item.getCropFraction(CropType.SOYBEAN, CropType.PULSES, CropType.STARCHY_ROOTS, isSpringWheat ? CropType.WHEAT : null);
double lpjCornFrac = item.getCropFraction(CropType.MAIZE, CropType.SOYBEAN);
......
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