-
Peter Alexander authoredPeter Alexander authored
ModelConfig.java 18.80 KiB
package ac.ed.lurg;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import ac.ed.lurg.types.ModelFitType;
public class ModelConfig {
private Properties configFile;
private static ModelConfig modelConfig;
public static final String CONFIG_FILE = System.getProperty("CONFIG_FILE");
private ModelConfig() {
configFile = new Properties();
try {
System.out.println("Config. file is " + CONFIG_FILE);
if (CONFIG_FILE != null)
configFile.load(new FileInputStream(CONFIG_FILE));
}
catch (IOException e) {
System.err.println("Problems reading config file");
System.err.println(e.getMessage());
}
}
public static String getSetupDetails() {
String buildVerion = System.getProperty("BUILDVER");
StringBuffer sb = new StringBuffer("Build version: " + buildVerion + "\n");
Properties props = getModelConfig().configFile;
Enumeration<?> em = props.keys();
while(em.hasMoreElements()) {
String str = (String) em.nextElement();
sb.append(str + ": " + props.get(str) + "\n");
}
return sb.toString();
}
private static ModelConfig getModelConfig() {
if (modelConfig == null)
modelConfig = new ModelConfig();
return modelConfig;
}
private static String getProperty(String prop) {
return getModelConfig().getProp(prop);
}
private static String getProperty(String prop, String defaultString) {
String propValue = getProperty(prop);
return propValue == null ? defaultString : propValue;
}
private String getProp(String prop) {
return configFile.getProperty(prop);
}
private static Integer getIntProperty(String prop, Integer defaultInt) {
Integer propValue = getModelConfig().getIntProp(prop);
return propValue == null ? defaultInt : propValue;
}
private Integer getIntProp(String prop) {
String v = configFile.getProperty(prop);
return v==null ? null : Integer.valueOf(v);
}
@SuppressWarnings("unused")
private static Long getLongProperty(String prop, Long defaultLong) {
Long propValue = getModelConfig().getLongProp(prop);
return propValue == null ? defaultLong : propValue;
}
private Long getLongProp(String prop) {
String v = configFile.getProperty(prop);
return v==null ? null : Long.valueOf(v);
}
private static Double getDoubleProperty(String prop, Double defaultDouble) {
Double propValue = getModelConfig().getDoubleProp(prop);
return propValue == null ? defaultDouble : propValue;
}
private Double getDoubleProp(String prop) {
String v = configFile.getProperty(prop);
return v==null ? null : Double.valueOf(v);
}
private static Boolean getBooleanProperty(String prop, Boolean defaultBoolean) {
return getModelConfig().getBooleanProp(prop, defaultBoolean);
}
private boolean getBooleanProp(String prop, Boolean defaultBoolean) {
String v = configFile.getProperty(prop);
return v==null ? defaultBoolean : Boolean.valueOf(v);
}
public static final boolean SUPPRESS_STD_OUTPUT = getBooleanProperty("SUPPRESS_STD_OUTPUT", Boolean.FALSE);
// Directory information
public static final String BASE_DIR = getProperty("BASE_DIR"); // this must to be set in config file
public static final String OUTPUT_DIR = getProperty("OUTPUT_DIR", BASE_DIR + File.separator + "output");
public static final String TEMP_DIR = getProperty("TEMP_DIR", OUTPUT_DIR + File.separator + "GamsTmp");
public static final String DATA_DIR = getProperty("DATA_DIR", BASE_DIR + File.separator + "data");
public static final String GAMS_DIR = getProperty("GAMS_DIR", BASE_DIR + File.separator + "GAMS");
public static final String GAMS_MODEL = getProperty("GAMS_MODEL", GAMS_DIR + File.separator + "IntExtOpt.gms");
public static final boolean CLEANUP_GAMS_DIR = getBooleanProperty("CLEANUP_GAMS_DIR", false);
// Country (non-gridded) data
public static final boolean DEMAND_FROM_FILE = getBooleanProperty("DEMAND_FROM_FILE", false); // used in hindcasting
public static final String DEMAND_CURVES_FILE = getProperty("DEMAND_CURVES_FILE", DATA_DIR + File.separator + "com_curves.csv"); // either DEMAND_CURVES_FILE or DEMAND_CONSUMPTION_FILE is used, but not both
public static final String DEMAND_CONSUMPTION_FILE = getProperty("DEMAND_CONSUMPTION_FILE", DATA_DIR + File.separator + "hist_comsump.csv");
public static final String SSP_FILE = DATA_DIR + File.separator + "ssp.csv";
public static final String BASELINE_CONSUMP_FILE = DATA_DIR + File.separator + "base_consump.csv";
public static final String COUNTRY_CODES_FILE = DATA_DIR + File.separator + "country_codes4.csv";
public static final String COUNTRY_DATA_FILE = DATA_DIR + File.separator + "country_data.csv";
public static final String NET_IMPORTS_FILE = DATA_DIR + File.separator + "net_imports.csv";
public static final String BIOENERGY_1GEN_BASE_DEMAND_FILE = DATA_DIR + File.separator + "bio_demand.csv";
public static final String BIOENERGY_FUTURE_DEMAND_FILE = DATA_DIR + File.separator + "bioenergy_futures_BAU.csv";
public static final String TRADE_BARRIERS_FILE = DATA_DIR + File.separator + "tradeBarriers.csv";
public static final String STOCKS_FILE = DATA_DIR + File.separator + "global_stocks.csv";
public static final String FAO_CONSUMPTION_FILE = DATA_DIR + File.separator + "fao_consump.csv";
public static final String COUNTRY_GROUPING_FILE = DATA_DIR + File.separator + "country_groups.csv";
public static final String OTHER_WATER_USES_FILE = DATA_DIR + File.separator + "other_water_uses.csv";
// yield data
public static final String YIELD_DIR_BASE = getProperty("YIELD_DIR_BASE");
public static final String YIELD_DIR_TOP = getProperty("YIELD_DIR_TOP");
public static final String YIELD_DIR = getProperty("YIELD_DIR", YIELD_DIR_BASE + File.separator + YIELD_DIR_TOP);
public static final int LPJG_MONITOR_TIMEOUT_SEC = getIntProperty("LPJG_MONITOR_TIMEOUT", 60*60*2);
public static final String ANPP_FILENAME = getProperty("ANPP_FILENAME", "anpp.out");
public static final String YIELD_FILENAME = getProperty("YIELD_FILENAME", "yield.out");
public static final boolean PASTURE_FERT_RESPONSE_FROM_LPJ = getBooleanProperty("PASTURE_FERT_RESPONSE_FROM_LPJ", false);;
public static final double CALIB_FACTOR_WHEAT = getDoubleProperty("CALIB_FACTOR_WHEAT", 0.988);
public static final double CALIB_FACTOR_MAIZE = getDoubleProperty("CALIB_FACTOR_MAIZE", 0.706);
public static final double CALIB_FACTOR_RICE = getDoubleProperty("CALIB_FACTOR_RICE", 0.978);
public static final double CALIB_FACTOR_OILCROPS = getDoubleProperty("CALIB_FACTOR_OILCROPS", 0.594);
public static final double CALIB_FACTOR_PULSES = getDoubleProperty("CALIB_FACTOR_PULSES", 0.572);
public static final double CALIB_FACTOR_STARCHY_ROOTS = getDoubleProperty("CALIB_FACTOR_STARCHY_ROOTS", 5.832);
public static final double CALIB_FACTOR_MISCANTHUS = getDoubleProperty("CALIB_FACTOR_MISCANTHUS", 2.113);
public static final double CALIB_FACTOR_SRC = getDoubleProperty("CALIB_FACTOR_SRC", Double.NaN);
// Spatial (gridded) data
public static final double CELL_SIZE_X = getDoubleProperty("CELL_SIZE_X", 0.5);
public static final double CELL_SIZE_Y = getDoubleProperty("CELL_SIZE_Y", CELL_SIZE_X);
public static final String SPATIAL_DIR_NAME = getProperty("SPATIAL_DIR_NAME", "halfdeg");
public static final String SPATIAL_DATA_DIR = getProperty("SPATIAL_DATA_DIR", DATA_DIR + File.separator + SPATIAL_DIR_NAME);
public static final String INITAL_LAND_COVER_FILENAME = getProperty("INITAL_LAND_COVER_FILENAME", "hurtt_2010.txt");
public static final String INITAL_LAND_COVER_FILE = SPATIAL_DATA_DIR + File.separator + INITAL_LAND_COVER_FILENAME;
public static final String COUNTRY_BOUNDARY_FILE = SPATIAL_DATA_DIR + File.separator + "country_boundaries.asc";
public static final String IRRIGATION_COST_FILE = SPATIAL_DATA_DIR + File.separator + "irrigation_cost.asc";
public static final String IRRIGATION_CONSTRAINT_FILE = SPATIAL_DATA_DIR + File.separator + "blue_water_available_pseudoCRU_rcp8p5_2004_2013_grid_allhdyro_mm.txt";
public static final String FPU_BOUNDARIES_FILE = SPATIAL_DATA_DIR + File.separator + "FPU.asc";
public static final String FPU_GROUPING_FILE = SPATIAL_DATA_DIR + File.separator + "fpuGrouping.txt";
public static final String IRRIG_MAX_WATER_FILENAME = getProperty("IRRIG_MAX_WATER_FILENAME", "gsirrigation.out");
public static final String IRRIG_RUNOFF_FILE = getProperty("IRRIG_RUNOFF_FILE", "tot_runoff.out");
public static final String PROTECTED_AREAS_FILE = SPATIAL_DATA_DIR + File.separator + "protected_areas.txt";
public static final String HIGH_SLOPE_AREAS_FILE = SPATIAL_DATA_DIR + File.separator + "maxcropfrac2.txt";
// Output
public static final String LAND_COVER_OUTPUT_FILE = OUTPUT_DIR + File.separator + "lc.txt";
public static final String PRICES_OUTPUT_FILE = OUTPUT_DIR + File.separator + "prices.txt";
public static final String DEMAND_OUTPUT_FILE = OUTPUT_DIR + File.separator + "demand.txt";
public static final boolean OUTPUT_FOR_LPJG = getBooleanProperty("OUTPUT_FOR_LPJG", true);
public static final boolean INTERPOLATE_OUTPUT_YEARS = getBooleanProperty("INTERPOLATE_OUTPUT_YEARS", true);
// Calibration related stuff
public static final boolean IS_CALIBRATION_RUN = getBooleanProperty("IS_CALIBRATION_RUN", false);
public static final String SERIALIZED_LAND_USE_FILE = getProperty("SERIALIZED_LAND_USE_FILE", OUTPUT_DIR + File.separator + "landUseRaster.ser");
public static final boolean MARKET_ADJ_PRICE = IS_CALIBRATION_RUN ? false : getBooleanProperty("MARKET_ADJ_PRICE", true);
public static final double INITIAL_PRICE_SHIFT = getDoubleProperty("INITIAL_PRICE_SHIFT", 1.0);
public static final boolean CHANGE_YIELD_DATA_YEAR = IS_CALIBRATION_RUN ? false : getBooleanProperty("CHANGE_YIELD_DATA_YEAR", true);
public static final String CLUSTERED_YIELD_FILE = getProperty("CLUSTERED_YIELD_FILE", OUTPUT_DIR + File.separator + "cluster.asc");
public static final boolean GENERATE_NEW_YIELD_CLUSTERS = getBooleanProperty("GENERATE_NEW_YIELD_CLUSTERS", IS_CALIBRATION_RUN);
// Temporal configuration
public static final int START_TIMESTEP = getIntProperty("START_TIMESTEP", 0);
public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 18);
public static final int TIMESTEP_SIZE = getIntProperty("TIMESTEP_SIZE", 5);
public static final int BASE_YEAR = getIntProperty("BASE_YEAR", 2010);
// Import export limits
public static final double ANNUAL_MAX_IMPORT_CHANGE = IS_CALIBRATION_RUN ? 0.0 : getDoubleProperty("ANNUAL_MAX_IMPORT_CHANGE", 0.02);
public static final double MAX_IMPORT_CHANGE = IS_CALIBRATION_RUN ? 0.0 : getDoubleProperty("MAX_IMPORT_CHANGE", ANNUAL_MAX_IMPORT_CHANGE*TIMESTEP_SIZE);
// Fertiliser application rates in kg/ha
public static final double MIN_FERT_AMOUNT = getDoubleProperty("MIN_FERT_AMOUNT", 0.0);
public static final double MID_FERT_AMOUNT = getDoubleProperty("MID_FERT_AMOUNT", 200.0);
public static final double MAX_FERT_AMOUNT = getDoubleProperty("MAX_FERT_AMOUNT", 1000.0);
public static final int FERT_AMOUNT_PADDING = getIntProperty("FERT_AMOUNT_PADDING", 4);;
// SSP shift parameters
public static final double SSP_POPULATION_FACTOR = getDoubleProperty("SSP_POPULATION_FACTOR", 1.0);
public static final double SSP_GDP_PC_FACTOR = getDoubleProperty("SSP_GDP_PC_FACTOR", 1.0);
// Other model parameters
public static final boolean CHANGE_DEMAND_YEAR = IS_CALIBRATION_RUN ? false : getBooleanProperty("CHANGE_DEMAND_YEAR", true);
public static final double DIETARY_CLOSURE = getDoubleProperty("DIETARY_CLOSURE", 0.0); // Amount diet converges in DIETARY_CLOSURE_GDP_CHANGE rate of GDP shift
public static final double DIETARY_CLOSURE_GDP_CHANGE = getDoubleProperty("DIETARY_CLOSURE_GDP_CHANGE", 2.0); // 2 is double of GDP
public static final double DIETARY_CLOSURE_PARAM = getDoubleProperty("DIETARY_CLOSURE_PARAM", Math.log((1-DIETARY_CLOSURE))/DIETARY_CLOSURE_GDP_CHANGE); // Zero is no dietary closure, number specifies closure rate for changes in GDP per capita, e.g. Math.log(0.5)/2
public static final String SSP_SCENARIO = getProperty("SSP_SCENARIO", "SSP1_v9_130325");
public static final ModelFitType DEMAND_ANIMAL_PROD_FIT = ModelFitType.findByName(getProperty("DEMAND_ANIMAL_PROD_FIT", "loglinear"));
public static final ModelFitType DEMAND_NON_ANIMAL_PROD_FIT = ModelFitType.findByName(getProperty("DEMAND_NON_ANIMAL_PROD_FIT", "loglinear"));
public static final double PASTURE_HARVEST_FRACTION = getDoubleProperty("PASTURE_HARVEST_FRACTION", 0.5);
public static final double MEAT_EFFICIENCY = getDoubleProperty("MEAT_EFFICIENCY", 1.0); // 'meat' is includes feed conversion ratio already, this is tech. change or similar
public static final double IRRIGIATION_EFFICIENCY = getDoubleProperty("IRRIGIATION_EFFICIENCY", 0.5);
public static final int ELLIOTT_BASEYEAR = 2010;
public static final double ENVIRONMENTAL_WATER_CONSTRAINT = getDoubleProperty("ENVIRONMENTAL_WATER_CONSTRAINT", 0.5); // change with care, as due to normalisation it might not have the impact you first imagine
public static final double OTHER_WATER_USE_FACTOR = getDoubleProperty("OTHER_WATER_USE_FACTOR", 1.0);
public static final boolean USE_BLUE_WATER_FILE_IRRIG_CONSTRAINT = getBooleanProperty("USE_BLUE_WATER_FILE_IRRIG_CONSTRAINT", false);;
public static final double LAND_CHANGE_COST = getDoubleProperty("LAND_CHANGE_COST", 0.2);
public static final double CROP_TO_PASTURE_COST_FACTOR = getDoubleProperty("CROP_TO_PASTURE_COST_FACTOR", 1.0);
public static final double AGRI_LAND_EXPANSION_COST_FACTOR = getDoubleProperty("AGRI_LAND_EXPANSION_COST_FACTOR", 1.0);
public static final double CROP_INCREASE_COST = getDoubleProperty("CROP_INCREASE_COST", 0.1 * LAND_CHANGE_COST * AGRI_LAND_EXPANSION_COST_FACTOR);
public static final double PASTURE_DECREASE_COST = getDoubleProperty("PASTURE_DECREASE_COST", LAND_CHANGE_COST);
public static final double CROP_DECREASE_COST = getDoubleProperty("CROP_DECREASE_COST", 1.75 * LAND_CHANGE_COST);
public static final double PASTURE_INCREASE_COST = getDoubleProperty("PASTURE_INCREASE_COST", 0.1 * LAND_CHANGE_COST * CROP_TO_PASTURE_COST_FACTOR * AGRI_LAND_EXPANSION_COST_FACTOR);
public static final double AGRI_EXPANSION_COST_BASE = getDoubleProperty("AGRI_EXPANSION_COST_BASE", 0.04 * LAND_CHANGE_COST * AGRI_LAND_EXPANSION_COST_FACTOR);
public static final double AGRI_EXPANSION_COST_BASE_MANAGED_FOREST = getDoubleProperty("AGRI_EXPANSION_COST_BASE_MANAGED_FOREST", 0.5 * LAND_CHANGE_COST * AGRI_LAND_EXPANSION_COST_FACTOR);
public static final double SEED_AND_WASTE_FRACTION = getDoubleProperty("SEED_AND_WASTE_FRACTION", 0.1);
public static final double TECHNOLOGY_CHANGE_ANNUAL_RATE = getDoubleProperty("TECHNOLOGY_CHANGE_ANNUAL_RATE", 0.002);
public static final int TECHNOLOGY_CHANGE_START_STEP = getIntProperty("TECHNOLOGY_CHANGE_START_STEP", 0);
public static final boolean USE_BIOENERGY_TRAJECTORY = getBooleanProperty("USE_BIOENERGY_TRAJECTORY", false); // false is the old style, i.e. BIOENERGY_CHANGE_ANNUAL_RATE, BIOENERGY_CHANGE_START_YEAR and BIOENERGY_CHANGE_END_YEAR
// original way to specify changes in bioenergy
public static final double BIOENERGY_CHANGE_ANNUAL_RATE = IS_CALIBRATION_RUN ? 0.0 : getDoubleProperty("BIOENERGY_CHANGE_ANNUAL_RATE", 0.10); // 6.2/2.31/20
public static final int BIOENERGY_CHANGE_START_YEAR = getIntProperty("BIOENERGY_CHANGE_START_YEAR", 2010);
public static final int BIOENERGY_CHANGE_END_YEAR = getIntProperty("BIOENERGY_CHANGE_END_YEAR", 2060);
// newer way
public static final boolean ENABLE_GEN2_BIOENERGY = getBooleanProperty("ENABLE_GEN2_BIOENERGY", false);
public static final String BIOENERGY_DEMAND_SCENARIO = getProperty("BIOENERGY_DEMAND_SCENARIO", "BAU");
public static final double BIOENERGY_DEMAND_SHIFT = IS_CALIBRATION_RUN ? 1.0 : getDoubleProperty("BIOENERGY_DEMAND_SHIFT", 1.0);
// public static final double BIOENERGY_HEATING_VALUE_GJ_PER_T = getDoubleProperty("BIOENERGY_HEATING_VALUE_GJ_PER_T", 17.5); // GJ per t DM
public static final double MARKET_LAMBA = getDoubleProperty("MARKET_LAMBA", 0.4); // controls international market price adjustment rate
public static final double POPULATION_AGGREG_LIMIT = getDoubleProperty("POPULATION_AGGREG_LIMIT", 30.0); // in millions, smaller countries are aggregated on a regional basis
public static final boolean PREDEFINED_COUNTRY_GROUPING = getBooleanProperty("PREDEFINED_COUNTRY_GROUPING", true);
public static final double UNHANDLED_CROP_AREA = getDoubleProperty("UNHANDLED_CROP_AREA", 0.3); // includes fruit veg forage crops set aside and failed crop
public static final double OTHER_INTENSITY_COST = getDoubleProperty("OTHER_INTENSITY_COST", 0.6);
public static final double OTHER_INTENSITY_PARAM = getDoubleProperty("OTHER_INTENSITY_PARAM", 3.22);
public static final double IRRIG_COST_SCALE_FACTOR = getDoubleProperty("IRRIG_COST_SCALE_FACTOR", 0.0005);
public static final double FERTILISER_COST_PER_T = getDoubleProperty("FERTILISER_COST_PER_T", 1.8); // $500/t, 18% N/t
public static final double FERTILISER_MAX_COST = FERTILISER_COST_PER_T * MAX_FERT_AMOUNT/1000;
public static final double DOMESTIC_PRICE_MARKUP = getDoubleProperty("DOMESTIC_PRICE_MARKUP", 1.0);
public static final double TRANSPORT_LOSSES = getDoubleProperty("TRANSPORT_LOSSES", 0.05); // in international trade
public static final double TRANSPORT_COST = getDoubleProperty("TRANSPORT_COST", 0.3); // 100 $/t see Wheat Transportation Profile - USDA
public static final double TRADE_BARRIER_FACTOR_DEFAULT = getDoubleProperty("TRADE_BARRIER_FACTOR_DEFAULT", 0.3); // price factor in international trade, transport cost and real trade barriers
public static final double TRADE_BARRIER_ADJ = getDoubleProperty("TRADE_BARRIER_ADJ", 1.0);
public static final boolean ACTIVE_TRADE_BARRIERS = getBooleanProperty("ACTIVE_TRADE_BARRIERS", false); // if set to true read in barrier information from file, otherwise use default as above
public static final boolean PROTECTED_AREAS_ENABLED = getBooleanProperty("PROTECTED_AREAS_ENABLED", true);
public static final double MIN_NATURAL_RATE = getDoubleProperty("MIN_NATURAL_RATE", 0.10);
public static final double MAX_CHINA_LAND_EXPANSION_RATE = getDoubleProperty("MAX_CHINA_LAND_EXPANSION_RATE", 0.011*0.4); // 1.1% max forest change 40% of natural land is forest
public static final boolean DEBUG_JUST_DEMAND_OUTPUT = getBooleanProperty("DEBUG_JUST_DEMAND_OUTPUT", false);
public static final boolean DEBUG_LIMIT_COUNTRIES = getBooleanProperty("DEBUG_LIMIT_COUNTRIES", false);
public static final String DEBUG_COUNTRY_NAME = getProperty("DEBUG_COUNTRY_NAME", "United States of America");
public static final String GAMS_COUNTRY_TO_SAVE = getProperty("GAMS_COUNTRY_TO_SAVE", "China");;
public static final double PASTURE_MAX_IRRIGATION_RATE = getDoubleProperty("DEFAULT_MAX_IRRIGATION_RATE", 50.0); // shouldn't need this but some areas crops don't have a value, but was causing them to be selected
public static final int LPJG_TIMESTEP_SIZE = 5;
public static final int NUM_YIELD_CLUSTERS = getIntProperty("NUM_YIELD_CLUSTERS", 5000);
public static final long RANDOM_SEED = getIntProperty("RANDOM_SEED", 1974329); // any number will do
}