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

Tweaks to FPU

parent 15d259f5
Branches
Tags
No related merge requests found
......@@ -2,7 +2,9 @@ BASE_DIR=/Users/peteralexander/Documents/R_Workspace/UNPLUM/hind1970
INITAL_LAND_COVER_FILENAME=hurtt_1970.txt
BASE_YEAR=1970
SSP_SCENARIO=NOT_NEEDED
YIELD_DIR=/Users/peteralexander/Documents/LURG/LPJ/29May2017/LPJG_PLUM_expt1.1_1961-2015_ipsl_LUfixes_10patchesFrom5patches_forED_20170528170903
YIELD_DIR=/Users/peteralexander/Documents/LURG/LPJ/Aug2017/LPJG_PLUM_expt1.1_1961-2015_ipsl_irrV6104_b20170728
#LPJG_PLUM_expt1.1_1961-2015_ipsl_LUfixes_10patchesFrom5patches_forED_20170528170903
#YIELD_DIR=/Users/peteralexander/Documents/LURG/LPJ/19Jan2017/LPJG_PLUM_expt1.1_1971-2005_forED
#YIELD_DIR=/Users/peteralexander/Documents/LURG/LPJ/IPSL/LPJG_PLUM_expt1.1_1966-2005_ipsl_lessIO_forED
......@@ -11,7 +13,7 @@ GAMS_MODEL=/Users/peteralexander/Documents/R_Workspace/UNPLUM/GAMS/IntExtOpt.gms
DEBUG_LIMIT_COUNTRIES=false
DEBUG_COUNTRY_NAME=India & Sri Lanka
DEBUG_JUST_DEMAND_OUTPUT=true
DEBUG_JUST_DEMAND_OUTPUT=false
IS_CALIBRATION_RUN = false
END_TIMESTEP=1
......
......
......@@ -553,7 +553,7 @@ public class ModelMain {
private IrrigationRasterSet getFixedIrrigationData() {
IrrigationRasterSet fixedIrrigData = new IrrigationRasterSet(desiredProjection);
IrrigationRasterSet fixedIrrigData = new IrrigationRasterSet(desiredProjection, fpuManager);
new IrrigiationCostReader(fixedIrrigData).getRasterDataFromFile(ModelConfig.IRRIGATION_COST_FILE);
return fixedIrrigData;
}
......@@ -562,7 +562,7 @@ public class ModelMain {
String rootDir = timestep.getYearSubDir(ModelConfig.YIELD_DIR);
new IrrigationMaxAmountReader(currentIrrigationData, yieldSurfaces).getRasterDataFromFile(rootDir + File.separator + ModelConfig.IRRIG_MAX_WATER_FILENAME);
new RunOffReader(currentIrrigationData).getRasterDataFromFile(rootDir + File.separator + ModelConfig.IRRIG_RUNOFF_FILE);
currentIrrigationData.updateConstraintByFPU(fpuManager, timestep);
currentIrrigationData.updateConstraintByFPU(timestep);
return currentIrrigationData;
}
......
......
......@@ -22,20 +22,13 @@ public class FPUManager {
private static final int YEAR_COL = 1;
private static final int USAGE_COL = 2;
RasterSet<IntegerRasterItem> fpuBoundaries;
RasterSet<IntegerRasterItem> fpuBoundaries; // better if these were private
Map<IntegerRasterItem, List<RasterKey>> fpuMap;
Map<Integer, Map<Integer, Double>> fpuOtherUses;
private Map<Integer, Map<Integer, Double>> fpuOtherUses;
public FPUManager(RasterHeaderDetails desiredProjection) {
getFPUBoundaryRaster(desiredProjection);
fpuMap = CollectionHelper.invertMap(fpuBoundaries);
readOtherUses();
}
public void getFPUBoundaryRaster(RasterHeaderDetails desiredProjection) {
fpuBoundaries = new RasterSet<IntegerRasterItem>(desiredProjection) {
private static final long serialVersionUID = -8620255271155259176L;
protected IntegerRasterItem createRasterData() {
return new IntegerRasterItem(0);
}
......@@ -43,6 +36,9 @@ public class FPUManager {
FPUBoundaryReader fpuReader = new FPUBoundaryReader(fpuBoundaries);
fpuReader.getRasterDataFromFile(ModelConfig.FPU_BOUNDARIES_FILE);
fpuMap = CollectionHelper.invertMap(fpuBoundaries);
readOtherUses();
}
@SuppressWarnings("serial")
......@@ -87,11 +83,15 @@ public class FPUManager {
fpuOtherUses = usageMap;
}
public List<RasterKey> getKeysFor(IntegerRasterItem fpu) {
List<RasterKey> getKeysFor(IntegerRasterItem fpu) {
List<RasterKey> keys = fpuMap.get(fpu);
if (keys == null)
keys = new ArrayList<RasterKey>();
return keys;
}
public double getOtherWaterUse(Integer fpuId, Integer year) {
Double d = fpuOtherUses.get(fpuId).get(year);
return d;
}
}
......@@ -5,7 +5,6 @@ import java.util.Map;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.Timestep;
import ac.ed.lurg.utils.LogWriter;
import ac.sac.raster.IntegerRasterItem;
import ac.sac.raster.RasterHeaderDetails;
import ac.sac.raster.RasterKey;
......@@ -14,16 +13,18 @@ import ac.sac.raster.RasterSet;
public class IrrigationRasterSet extends RasterSet<IrrigationItem> {
private static final long serialVersionUID = 4794790389538053286L;
private FPUManager fpuManager;
public IrrigationRasterSet(RasterHeaderDetails header) {
public IrrigationRasterSet(RasterHeaderDetails header, FPUManager fpuManager) {
super(header);
this.fpuManager = fpuManager;
}
protected IrrigationItem createRasterData() {
return new IrrigationItem();
}
public void updateConstraintByFPU(FPUManager fpuManager, Timestep timestep) {
public void updateConstraintByFPU(Timestep timestep) {
Collection<RasterKey> fpuKeys;
Collection<IntegerRasterItem> keyset = fpuManager.fpuMap.keySet();
......@@ -31,11 +32,12 @@ public class IrrigationRasterSet extends RasterSet<IrrigationItem> {
int yearsOfIrrigChange = (timestep.getTimestep() - ModelConfig.START_TIMESTEP) * ModelConfig.TIMESTEP_SIZE;
double waterAvailabilityAdj = 1.0 + yearsOfIrrigChange * ModelConfig.WATER_AVAILIBILITY_RATE_OF_CHANGE;
int year = timestep.getYear();
if (year < 2001) year = 2001; // we don't have other water use before this date
for (IntegerRasterItem fpu : keyset) {
fpuKeys = fpuManager.getKeysFor(fpu);
RasterSet<IrrigationItem> irrigData = this.createSubsetForKeys(fpuKeys);
RasterSet<IrrigationItem> irrigData = createSubsetForKeys(fpuKeys);
double fpuRunOff = 0.0;
double otherUses = 0.0;
double waterAvailForIrrigPerCell = 0.0;
......@@ -48,26 +50,20 @@ public class IrrigationRasterSet extends RasterSet<IrrigationItem> {
* 0.01;
cellCount++;
}
}
Double fpuRunOffAvailable = fpuRunOff * ModelConfig.ENVIRONMENTAL_WATER_CONSTRAINT;
otherUses = fpuManager.fpuOtherUses.get(fpu.getInt()).get(year) * waterAvailabilityAdj;
if (fpuRunOffAvailable - otherUses < 0) {
otherUses = fpuManager.getOtherWaterUse(fpu.getInt(), year) * waterAvailabilityAdj;
if (fpuRunOffAvailable - otherUses < 0)
waterAvailForIrrigPerCell = 0;
} else
else
waterAvailForIrrigPerCell = (fpuRunOffAvailable - otherUses) / cellCount;
for (Map.Entry<RasterKey, IrrigationItem> entry : irrigData.entrySet()) {
if (entry.getValue() != null) {
if (entry.getValue() != null)
entry.getValue().setIrrigConstraint(waterAvailForIrrigPerCell);
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment