Skip to content
Snippets Groups Projects
Commit c5d3d962 authored by R0slyn's avatar R0slyn
Browse files

changes to irrigation set up, new class IrrigationRasterSet

parent 9cdf2905
Branches
Tags
No related merge requests found
......@@ -33,10 +33,9 @@ import ac.ed.lurg.demand.DemandManagerFromFile;
import ac.ed.lurg.demand.DemandManagerSSP;
import ac.ed.lurg.landuse.CropUsageData;
import ac.ed.lurg.landuse.CropUsageReader;
import ac.ed.lurg.landuse.IrrigationConstraintReader;
import ac.ed.lurg.landuse.IrrigationItem;
import ac.ed.lurg.landuse.IrrigationMaxAmountReader;
import ac.ed.lurg.landuse.IrrigiationCostReader;
import ac.ed.lurg.landuse.IrrigationRasterSet;
import ac.ed.lurg.landuse.LandCoverItem;
import ac.ed.lurg.landuse.LandCoverReader;
import ac.ed.lurg.landuse.LandUseItem;
......@@ -75,7 +74,7 @@ public class ModelMain {
private Map<CropType, GlobalPrice> prevWorldPrices;
private Map<CropType, Double> prevStockLevel;
private RasterSet<LandUseItem> prevLandUseRaster;
private RasterSet<IrrigationItem> currentIrrigationData;
private IrrigationRasterSet currentIrrigationData;
private RasterSet<LandUseItem> globalLandUseRaster;
private RasterSet<IntegerRasterItem> clusterIdRaster;
......@@ -99,7 +98,7 @@ public class ModelMain {
tradeManager = new TradeManager(compositeCountryManager);
fpuManager = new FPUManager(desiredProjection);
currentIrrigationData = getFixedIrrigationData();
currentIrrigationData = new IrrigationRasterSet(desiredProjection);
countryBoundaryRaster = getCountryBoundaryRaster();
clusterIdRaster = (ModelConfig.IS_CALIBRATION_RUN) ? new RasterSet<IntegerRasterItem>(desiredProjection) : getClusterRaster();
......@@ -551,28 +550,15 @@ public class ModelMain {
return yieldReader.getRasterData(timestep);
}
/** Get irrigation data components that don't change over time */
private RasterSet<IrrigationItem> getFixedIrrigationData() {
RasterSet<IrrigationItem> irigData = new RasterSet<IrrigationItem>(desiredProjection) {
private static final long serialVersionUID = 8393130687550888654L;
protected IrrigationItem createRasterData() {
return new IrrigationItem();
}
};
new IrrigiationCostReader(irigData).getRasterDataFromFile(ModelConfig.IRRIGATION_COST_FILE);
// new IrrigationConstraintReader(irigData).getRasterDataFromFile(ModelConfig.IRRIGATION_CONSTRAINT_FILE);
return irigData;
}
private RasterSet<IrrigationItem> getUpdateIrrigationData(Timestep timestep, YieldRaster yieldSurfaces) {
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);
fpuManager.handleFPU(currentIrrigationData, timestep); //this is altering currentIrrigationData irrigConstraint(s) based on runoff and industrial use through time
currentIrrigationData.updateConstraintByFPU(fpuManager, timestep);
return currentIrrigationData;
}
private Map<CropType,Double> getInitialStockLevels(){
Map<CropType, Double> initialStockLevels = new StockReader().read();
initialStockLevels.put(CropType.ENERGY_CROPS, 0.0);
......
......
......@@ -14,7 +14,6 @@ import ac.ed.lurg.country.gams.GamsRasterInput;
import ac.ed.lurg.country.gams.GamsRasterOptimiser;
import ac.ed.lurg.country.gams.GamsRasterOutput;
import ac.ed.lurg.demand.AbstractDemandManager;
import ac.ed.lurg.demand.DemandManagerSSP;
import ac.ed.lurg.landuse.CropUsageData;
import ac.ed.lurg.landuse.IrrigationItem;
import ac.ed.lurg.landuse.LandUseItem;
......
......
package ac.ed.lurg.landuse;
import java.util.Map;
import ac.sac.raster.AbstractRasterReader;
import ac.sac.raster.IntegerRasterItem;
import ac.sac.raster.RasterSet;
......
......
......@@ -4,13 +4,11 @@ import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.Timestep;
import ac.ed.lurg.utils.CollectionHelper;
import ac.ed.lurg.utils.LazyHashMap;
import ac.ed.lurg.utils.LogWriter;
......@@ -97,50 +95,5 @@ public class FPUManager {
return keys;
}
public void handleFPU(RasterSet<IrrigationItem> allIrrigData, Timestep timestep) {
Collection<RasterKey> fpuKeys;
Collection<IntegerRasterItem> keyset = fpuMap.keySet();
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();
for (IntegerRasterItem fpu : keyset) {
fpuKeys =getKeysFor(fpu);
RasterSet<IrrigationItem> irrigData = allIrrigData.createSubsetForKeys(fpuKeys);
double fpuRunOff = 0.0;
double otherUses = 0.0;
double waterAvailForIrrigPerCell = 0.0;
int cellCount = 0;
for (Map.Entry<RasterKey, IrrigationItem> entry : irrigData.entrySet()) {
if (entry.getValue() != null) {
fpuRunOff += entry.getValue().getRunOff()*fpuBoundaries.getAreaMha(entry.getKey())*0.01;
cellCount++;
}
}
Double fpuRunOffAvailable = fpuRunOff*0.4 * ModelConfig.ENVIRONMENTAL_WATER_CONSTRAINT; //0.4 from elliott paper
otherUses = fpuOtherUses.get(fpu.getInt()).get(year) * waterAvailabilityAdj;
if (fpuRunOffAvailable - otherUses < 0){
waterAvailForIrrigPerCell = 0;
}
else waterAvailForIrrigPerCell = (fpuRunOffAvailable - otherUses) / cellCount;
for (Map.Entry<RasterKey, IrrigationItem> entry : irrigData.entrySet()) {
if (entry.getValue() != null) {
entry.getValue().setIrrigConstraint(waterAvailForIrrigPerCell);
}
}
}
}
}
package ac.ed.lurg.landuse;
import java.util.Collection;
import java.util.Map;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.Timestep;
import ac.sac.raster.IntegerRasterItem;
import ac.sac.raster.RasterHeaderDetails;
import ac.sac.raster.RasterKey;
import ac.sac.raster.RasterSet;
public class IrrigationRasterSet extends RasterSet<IrrigationItem>{
private static final long serialVersionUID = 4794790389538053286L;
public IrrigationRasterSet(RasterHeaderDetails header) {
super(header);
new IrrigiationCostReader(this).getRasterDataFromFile(ModelConfig.IRRIGATION_COST_FILE); //this isn't very nice in here...
}
protected IrrigationItem createRasterData() {
return new IrrigationItem();
}
public void updateConstraintByFPU(FPUManager fpuManager, Timestep timestep) {
Collection<RasterKey> fpuKeys;
Collection<IntegerRasterItem> keyset = fpuManager.fpuMap.keySet();
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();
for (IntegerRasterItem fpu : keyset) {
fpuKeys =fpuManager.getKeysFor(fpu);
RasterSet<IrrigationItem> irrigData = this.createSubsetForKeys(fpuKeys);
double fpuRunOff = 0.0;
double otherUses = 0.0;
double waterAvailForIrrigPerCell = 0.0;
int cellCount = 0;
for (Map.Entry<RasterKey, IrrigationItem> entry : irrigData.entrySet()) {
if (entry.getValue() != null) {
fpuRunOff += entry.getValue().getRunOff()*fpuManager.fpuBoundaries.getAreaMha(entry.getKey())*0.01;
cellCount++;
}
}
Double fpuRunOffAvailable = fpuRunOff*0.4 * ModelConfig.ENVIRONMENTAL_WATER_CONSTRAINT; //0.4 from elliott paper
otherUses = fpuManager.fpuOtherUses.get(fpu.getInt()).get(year) * waterAvailabilityAdj;
if (fpuRunOffAvailable - otherUses < 0){
waterAvailForIrrigPerCell = 0;
}
else waterAvailForIrrigPerCell = (fpuRunOffAvailable - otherUses) / cellCount;
for (Map.Entry<RasterKey, IrrigationItem> entry : irrigData.entrySet()) {
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