Skip to content
Snippets Groups Projects
ModelConfig.java 9.2 KiB
Newer Older
package ac.ed.lurg;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

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());
		}
	}
	
	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);
	}
	
Peter Alexander's avatar
Peter Alexander committed
	@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
Peter Alexander's avatar
Peter Alexander committed
	public static final String BASE_DIR = getProperty("BASE_DIR");  // this must to be set in config file
Peter Alexander's avatar
Peter Alexander committed
	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");
	public static final String DATA_DIR = getProperty("DATA_DIR", BASE_DIR + File.separator + "data");
	public static final String GAMS_MODEL = getProperty("GAMS_MODEL", BASE_DIR + File.separator + "GAMS/IntExtOpt.gms");
	public static final boolean CLEANUP_GAMS_DIR = getBooleanProperty("CLEANUP_GAMS_DIR", true);

Peter Alexander's avatar
Peter Alexander committed
	// Country (non-gridded) data
	public static final String DEMAND_CURVES_FILE = DATA_DIR + File.separator + "com_curves.csv";
Peter Alexander's avatar
Peter Alexander committed
	public static final String SSP_FILE = DATA_DIR + File.separator + "ssp.csv";	
Peter Alexander's avatar
Peter Alexander committed
	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 COMMODITY_DATA_FILE = DATA_DIR + File.separator + "con_prod_c_and_m.csv";
Peter Alexander's avatar
Peter Alexander committed
	public static final String BIOENERGY_DEMAND_FILE = DATA_DIR + File.separator + "bio_demand.csv";
Peter Alexander's avatar
Peter Alexander committed

Peter Alexander's avatar
Peter Alexander committed
	public static final String YIELD_DIR = getProperty("YIELD_DIR");
	public static final boolean CHANGE_YIELD_DATA_YEAR = getBooleanProperty("CHANGE_YIELD_DATA_YEAR", true);
	public static final int LPJG_MONITOR_TIMEOUT_SEC = getIntProperty("LPJG_MONITOR_TIMEOUT", 60*60*2);
Peter Alexander's avatar
Peter Alexander committed
	public static final String ANPP_FILENAME = getProperty("ANPP_FILENAME", "anpp_plum.out");
	public static final String YIELD_FILENAME = getProperty("YIELD_FILENAME", "yield_plum.out");
Peter Alexander's avatar
Peter Alexander committed
	// Spatial (gridded) data
	public static final double CELL_SIZE_X = getDoubleProperty("CELL_SIZE_X", 3.0);
	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", "3deg");
	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_FILE = SPATIAL_DATA_DIR + File.separator + "netfract_hurtt_2000.txt";
	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_3deg.txt";
	public static final String IRRIG_MAX_WATER_FILENAME = getProperty("IRRIG_MAX_WATER_FILENAME", "gsirr_1996_2005_100kgNha_3deg");
	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";
Peter Alexander's avatar
Peter Alexander committed
	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);
	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);
	// Fertiliser application rates in kg/ha
	public static final double MIN_FERT_AMOUNT = 5;
	public static final double MID_FERT_AMOUNT = 20;
	public static final double MAX_FERT_AMOUNT = 200;
	// Other model parameters
	public static final boolean CHANGE_DEMAND_YEAR = getBooleanProperty("CHANGE_DEMAND_YEAR", true);
	public static final String SSP_SCENARIO = getProperty("SSP_SCENARIO", "SSP1_v9_130325");
	public static final double MAX_IMPORT_CHANGE = getDoubleProperty("MAX_IMPORT_CHANGE", 0.1);
	public static final double PASTURE_HARVEST_FRACTION = getDoubleProperty("PASTURE_HARVEST_FRACTION", 0.25);
Peter Alexander's avatar
Peter Alexander committed
	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 double LAND_CHANGE_ENERGY = getDoubleProperty("LAND_CHANGE_COST", 1.0);
	public static final double MIN_FEED_RATE = getDoubleProperty("MIN_FEED_RATE", 0.15);
	public static final double SEED_AND_WASTE_FRACTION = getDoubleProperty("SEED_AND_WASTE_FRACTION", 0.15);  

	public static final double MARKET_LAMBA = getDoubleProperty("MARKET_LAMBA", 0.3); // controls international market price adjustment rate
	public static final double POPULATION_AGGREG_LIMIT = getDoubleProperty("POPULATION_AGGREG_LIMIT", 40.0);  // in millions, smaller countries are aggregated on a regional basis
	public static final double UNHANDLED_CROP_AREA = getDoubleProperty("UNHANDLED_CROP_AREA", 0.4);

	public static final double OTHER_INTENSITY_COST = getDoubleProperty("OTHER_INTENSITY_COST", 0.5);
	public static final double OTHER_INTENSITY_PARAM = getDoubleProperty("OTHER_INTENSITY_PARAM", 5.0);

Peter Alexander's avatar
Peter Alexander committed
	public static final double IRRIG_COST_SCALE_FACTOR = getDoubleProperty("IRRIG_COST_SCALE_FACTOR", 0.01);
	public static final double FERTILISER_COST_PER_T = getDoubleProperty("FERTILISER_COST_PER_T", 0.87 * 1.4 * 2); // £900/t N *  1.4$/£ * 2NPK/N
	public static final double FERTILISER_MAX_COST = FERTILISER_COST_PER_T * MAX_FERT_AMOUNT/1000;
Peter Alexander's avatar
Peter Alexander committed
	public static final double DOMESTIC_PRICE_MARKUP = getDoubleProperty("DOMESTIC_PRICE_MARKUP", 1.4);
	public static final double TRANSPORT_LOSSES = getDoubleProperty("TRANSPORT_LOSSES", 0.1);  // in international trade
	public static final double TRADE_BARRIER_FACTOR = getDoubleProperty("TRADE_BARRIER_FACTOR", 1.4);  // price factor in international trade, transport cost and real trade barriers
	public static final int NUM_CEREAL_CATEGORIES = getIntProperty("NUM_CEREAL_CATEGORIES", 5);
	public static final int NUM_PASTURE_CATEGORIES = getIntProperty("NUM_PASTURE_CATEGORIES", 1);

	public static final boolean DEBUG_LIMIT_COUNTRIES = getBooleanProperty("DEBUG_LIMIT_COUNTRIES", false);
	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 int NUM_CALIBRATION_ITERATIONS = getIntProperty("NUM_CALIBRATION_ITERATIONS", 1);