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

Read country region

parent 6333d27d
No related branches found
No related tags found
No related merge requests found
......@@ -119,7 +119,7 @@ public class ModelConfig {
public static final int START_TIMESTEP = getIntProperty("START_TIMESTEP", 0);
public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 1);
public static final int TIMESTEP_SIZE = getIntProperty("END_TIMESTEP", 35);
public static final int TIMESTEP_SIZE = getIntProperty("END_TIMESTEP", 40);
public static final int BASE_YEAR = getIntProperty("BASE_YEAR", 2010);
public static final double MAX_IMPORT_CHANGE = getDoubleProperty("MAX_IMPORT_CHANGE", 0.1);
......@@ -127,7 +127,7 @@ public class ModelConfig {
public static final String SSP_SCENARIO = getProperty("SSP_SCENARIO", "SSP5_v9_130325");
// Output
public static final boolean WRITE_JPEG_IMAGES = getBooleanProperty("WRITE_JPEG_IMAGES", Boolean.TRUE);
public static final boolean WRITE_JPEG_IMAGES = getBooleanProperty("WRITE_JPEG_IMAGES", false);
public static final int LPJG_MONITOR_TIMEOUT_SEC = getIntProperty("LPJG_MONITOR_TIMEOUT", 60*60*2);
public static final String TOTAL_LAND_COVER_FILE = OUTPUT_DIR + File.separator + "total_lc.txt";
......
package ac.ed.lurg;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
......@@ -131,20 +130,23 @@ public class ModelMain {
totalWorldInputCost.incrementValue(c, d.getProdCost());
}
/* after first timestep should look at trade balance and adjust appropriately
for (CropType crop : CropType.values()) {
CommodityData cd = result.getCommoditiesData().get(crop);
double netImport = cd.getNetImports();
if (netImport > 0)
totalImportCommodities.incrementValue(crop, netImport);
else
totalExportCommodities.incrementValue(crop, -netImport);
} */
}
prevWorldInputCost = totalWorldInputCost.divideBy(totalQuantity);
// after first timestep should look at trade balance and adjust appropriately
/* for (CropType crop : CropType.values()) {
CommodityData cd = result.getCommoditiesData().get(crop);
double netImport = cd.getNetImports();
if (netImport > 0)
totalImportCommodities.incrementValue(crop, netImport);
else
totalExportCommodities.incrementValue(crop, -netImport);
} */
// output results
outputTimestepResults(timestep, globalIntensityRaster, globalCropAreaRaster, globalLocationIdRaster, yieldSurfaces);
writeMarketFile(timestep, globalCropAreaRaster);
......@@ -240,19 +242,19 @@ public class ModelMain {
}.writeOutput(ModelConfig.WRITE_JPEG_IMAGES);
outputAreas(year, cropAreaRaster, CropType.MAIZE); */
// outputAreas(timestep.getYear(), cropAreaRaster, CropType.WHEAT);
// outputAreas(timestep.getYear(), cropAreaRaster, CropType.PASTURE);
outputLandCover(timestep.getYear(), cropAreaRaster, LandCoverType.CROPLAND);
outputLandCover(timestep.getYear(), cropAreaRaster, LandCoverType.PASTURE);
}
private void outputAreas(int year, RasterSet<AreasItem> cropAreaRaster, final CropType crop) {
new RasterOutputer<AreasItem>(cropAreaRaster, crop.getGamsName() + "Area" + year) {
private void outputLandCover(int year, RasterSet<AreasItem> cropAreaRaster, final LandCoverType lcType) {
new RasterOutputer<AreasItem>(cropAreaRaster, lcType.getName() + "Area" + year) {
@Override
public Double getValue(RasterKey location) {
AreasItem area = results.get(location);
if (area == null)
return null;
return area.getCropArea(crop);
return area.getLandCoverArea(lcType);
}
@Override
......@@ -308,11 +310,11 @@ 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 Americaxx") || country.getCountryName().equals("Russian Federationxx") || country.getCountryName().equals("China")) ) { //|| country.getCountryName().equals("China")
// continue;
// }
if (demandManager.getPopulation(country, 2010) < 50 || countryExclusionList.contains(country.getCountryName())) {
if (demandManager.getPopulation(country, 2010) < 8 || countryExclusionList.contains(country.getCountryName())) {
LogWriter.printlnError("Skipping " + country);
continue;
}
......
......@@ -6,13 +6,14 @@ public class Country {
private String countryName;
private String iso3CharCode;
private int iso3NumCode;
private String region;
public Country(String countryName, String iso3CharCode, int iso3NumCode) {
public Country(String countryName, String iso3CharCode, int iso3NumCode, String region) {
super();
this.countryName = countryName;
this.iso3CharCode = iso3CharCode;
this.iso3NumCode = iso3NumCode;
this.region = region;
}
public String getIso3CharCode() {
......
......@@ -12,6 +12,7 @@ import ac.ed.lurg.utils.LogWriter;
public class CountryManager {
private static final int NAME_COL = 0;
private static final int CHAR_CODE_COL = 1;
private static final int REGION_COL = 2;
private static final int NUM_CODE_COL = 4;
private final Map<String, Country> nameMap = new HashMap<String, Country>();
......@@ -30,7 +31,7 @@ public class CountryManager {
String filename = ModelConfig.COUNTRY_CODES_FILE;
try {
BufferedReader fitReader = new BufferedReader(new FileReader(filename));
String line, name, charCode;
String line, name, charCode, region;
int numCode;
fitReader.readLine(); // read header
......@@ -42,9 +43,10 @@ public class CountryManager {
name = tokens[NAME_COL];
charCode = tokens[CHAR_CODE_COL];
region = tokens[REGION_COL];
numCode = Integer.parseInt(tokens[NUM_CODE_COL]);
Country c = new Country(name, charCode, numCode);
Country c = new Country(name, charCode, numCode, region);
nameMap.put(name, c);
numCodeMap.put(numCode, c);
}
......
......@@ -22,7 +22,7 @@ public class GamsLocationTest {
}
private void run() {
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true);
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123, "R1"), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true);
GamsLocationInput gamsInput = new GamsLocationInput(new Timestep(0), getYields(), getPreviousArea(), getIrrigationCosts(), countryLevelInputs);
GamsLocationOptimiser opti = new GamsLocationOptimiser(gamsInput);
......
......@@ -71,7 +71,6 @@ public class GamsRasterOptimiser {
return theCopy;
}
@SuppressWarnings("unused")
private void checkedTotalAreas(RasterSet<AreasItem> areaRaster, String comment) {
for (LandCoverType l : LandCoverType.values()) {
double total = 0;
......@@ -95,10 +94,8 @@ public class GamsRasterOptimiser {
AreasItem prevAreaAggItem = prevAreasAgg.get(locId);
Set<RasterKey> keys = mapping.get(locId);
checkedTotalAreas(newAreaRaster.popSubsetForKeys(new RasterSet<AreasItem>(newAreaRaster.getHeaderDetails()), keys), locId + " before");
// if (DEBUG) LogWriter.println("Processing location id " + locId);
// if (DEBUG)
checkedTotalAreas(newAreaRaster.popSubsetForKeys(new RasterSet<AreasItem>(newAreaRaster.getHeaderDetails()), keys), locId + " before");
double pastureChange = newAreaAggItem.getLandCoverArea(LandCoverType.PASTURE) - prevAreaAggItem.getLandCoverArea(LandCoverType.PASTURE);
double croplandChange = newAreaAggItem.getLandCoverArea(LandCoverType.CROPLAND) - prevAreaAggItem.getLandCoverArea(LandCoverType.CROPLAND);
......@@ -139,7 +136,8 @@ public class GamsRasterOptimiser {
if (shortfall > 0.00001)
LogWriter.printlnError("This should never happen, due to GAMS constraint. Not able to incorporate all changes, as not enough forest or natural areas left: " + locId + ": " + shortfall);
checkedTotalAreas(newAreaRaster.popSubsetForKeys(new RasterSet<AreasItem>(newAreaRaster.getHeaderDetails()), keys), locId + " after");
// if (DEBUG)
checkedTotalAreas(newAreaRaster.popSubsetForKeys(new RasterSet<AreasItem>(newAreaRaster.getHeaderDetails()), keys), locId + " after");
for (RasterKey key : keys) {
AreasItem newAreasRasterItem = newAreaRaster.get(key);
......
......@@ -18,7 +18,7 @@ public class GamsRasterTest extends GamsLocationTest {
}
private void run() {
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true);
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new Country("Test", "TES", 123, "R1"), getProjectedDemand(), getWorldInputEnergy(), getBaseNetImport(), null, null, true);
GamsRasterInput input = new GamsRasterInput(new Timestep(0), getYieldRaster(), getPreviousAreaRaster(), getIrrigationCost(), countryLevelInputs);
GamsRasterOptimiser opti = new GamsRasterOptimiser(input);
......
......@@ -19,7 +19,7 @@ public enum CropType {
PULSES("Pulses + (Total)", "pulses"),
STARCHY_ROOTS("Starchy Roots + (Total)", "starchyRoots"),
MEAT("meatmilkeggs", "meat", true, true),
PASTURE("pasture", "pasture", false, false);
PASTURE("pasture", "pasture", false, false); // confusing having a land cover and a crop type. Needed here for yields (but not used for cropland area fractions).
private String faoName;
private String gamsName;
......
......@@ -37,7 +37,7 @@ public abstract class RasterOutputer<D extends RasterItem> {
BufferedWriter fileWriter = null;
try {
String fullPathFileName = ModelConfig.OUTPUT_DIR + File.separator + fileName + ".txt";
String fullPathFileName = ModelConfig.OUTPUT_DIR + File.separator + fileName + ".asc";
fileWriter = new BufferedWriter(new FileWriter(fullPathFileName,false));
String nullDataString = results.getHeaderDetails().getNodataString();
......
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