Skip to content

Commit

Permalink
unit test corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
mjunkin committed Oct 8, 2024
1 parent 4de445b commit 2372f33
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.stream.Stream;

Expand All @@ -19,6 +20,7 @@
import ca.bc.gov.nrs.vdyp.model.BaseVdypSpecies;
import ca.bc.gov.nrs.vdyp.model.BecDefinition;
import ca.bc.gov.nrs.vdyp.model.LayerType;
import ca.bc.gov.nrs.vdyp.model.MatrixMap2;
import ca.bc.gov.nrs.vdyp.model.PolygonIdentifier;
import ca.bc.gov.nrs.vdyp.model.PolygonMode;
import ca.bc.gov.nrs.vdyp.model.Sp64Distribution;
Expand Down Expand Up @@ -183,53 +185,61 @@ public void writePolygonWithSpeciesAndUtilization(VdypPolygon polygon) throws IO

private void calculateCuVolumeLessDecayWastageBreakage(VdypLayer layer, BecDefinition bec) {

for (VdypSpecies s : layer.getSpecies().values()) {

String sp0 = s.getGenus();
var breakageEquationGroup = controlMap.getBreakageEquationGroups().get(sp0, bec.getAlias());

var breakageCoefficients = controlMap.getNetBreakageMap().get(breakageEquationGroup);
var a1 = breakageCoefficients.getCoe(1);
var a2 = breakageCoefficients.getCoe(2);
var a3 = breakageCoefficients.getCoe(3);
var a4 = breakageCoefficients.getCoe(4);

var speciesCuVolumeLessDWBByUtilization = s
.getCloseUtilizationVolumeNetOfDecayWasteAndBreakageByUtilization();

var speciesCuVolumeLessDWBSum = 0.0f;
for (UtilizationClass uc : UtilizationClass.UTIL_CLASSES) {
var ba = s.getBaseAreaByUtilization().get(uc);
var tph = s.getTreesPerHectareByUtilization().get(uc);
var dq = (ba > 0) ? BaseAreaTreeDensityDiameter.quadMeanDiameter(ba, tph) : 0.0f;
var cuVolume = s.getCloseUtilizationVolumeByUtilization().get(uc);
var cuVolumeLessDW = s.getCloseUtilizationVolumeNetOfDecayAndWasteByUtilization().get(uc);

var breakagePercent = FloatMath.clamp(a1 + a2 * FloatMath.log(dq), a3, a4);
var breakage = Math.min(breakagePercent / 100.0f * cuVolume, cuVolumeLessDW);
if (cuVolumeLessDW <= 0.0f) {
speciesCuVolumeLessDWBByUtilization.set(uc, 0.0f);
} else {
var cuVolumeLessDWBforUc = cuVolumeLessDW - breakage;
speciesCuVolumeLessDWBByUtilization.set(uc, cuVolumeLessDWBforUc);
speciesCuVolumeLessDWBSum += cuVolumeLessDWBforUc;
}
}

speciesCuVolumeLessDWBByUtilization.set(UtilizationClass.SMALL, 0.0f);
speciesCuVolumeLessDWBByUtilization.set(UtilizationClass.ALL, speciesCuVolumeLessDWBSum);
}

var layerCuVolumeLessDWBByUtilization = layer
.getCloseUtilizationVolumeNetOfDecayWasteAndBreakageByUtilization();
for (UtilizationClass uc : UtilizationClass.values()) {
var layerCuVolumeLessDWBSum = 0.0f;
// Technically, BreakageEquationGroups are not required. If missing, it will not be
// possible for this method to do its work; but, it's still not an error.
try {
var beg = controlMap.getBreakageEquationGroups();

for (VdypSpecies s : layer.getSpecies().values()) {

String sp0 = s.getGenus();
int breakageEquationGroup = beg.get(sp0, bec.getAlias());

var breakageCoefficients = controlMap.getNetBreakageMap().get(breakageEquationGroup);
var a1 = breakageCoefficients.getCoe(1);
var a2 = breakageCoefficients.getCoe(2);
var a3 = breakageCoefficients.getCoe(3);
var a4 = breakageCoefficients.getCoe(4);

var speciesCuVolumeLessDWBByUtilization = s
.getCloseUtilizationVolumeNetOfDecayWasteAndBreakageByUtilization();
layerCuVolumeLessDWBSum += speciesCuVolumeLessDWBByUtilization.get(uc);

var speciesCuVolumeLessDWBSum = 0.0f;
for (UtilizationClass uc : UtilizationClass.UTIL_CLASSES) {
var ba = s.getBaseAreaByUtilization().get(uc);
var tph = s.getTreesPerHectareByUtilization().get(uc);
var dq = (ba > 0) ? BaseAreaTreeDensityDiameter.quadMeanDiameter(ba, tph) : 0.0f;
var cuVolume = s.getCloseUtilizationVolumeByUtilization().get(uc);
var cuVolumeLessDW = s.getCloseUtilizationVolumeNetOfDecayAndWasteByUtilization().get(uc);

var breakagePercent = FloatMath.clamp(a1 + a2 * FloatMath.log(dq), a3, a4);
var breakage = Math.min(breakagePercent / 100.0f * cuVolume, cuVolumeLessDW);
if (cuVolumeLessDW <= 0.0f) {
speciesCuVolumeLessDWBByUtilization.set(uc, 0.0f);
} else {
var cuVolumeLessDWBforUc = cuVolumeLessDW - breakage;
speciesCuVolumeLessDWBByUtilization.set(uc, cuVolumeLessDWBforUc);
speciesCuVolumeLessDWBSum += cuVolumeLessDWBforUc;
}
}

speciesCuVolumeLessDWBByUtilization.set(UtilizationClass.SMALL, 0.0f);
speciesCuVolumeLessDWBByUtilization.set(UtilizationClass.ALL, speciesCuVolumeLessDWBSum);
}

var layerCuVolumeLessDWBByUtilization = layer
.getCloseUtilizationVolumeNetOfDecayWasteAndBreakageByUtilization();
for (UtilizationClass uc : UtilizationClass.values()) {
var layerCuVolumeLessDWBSum = 0.0f;
for (VdypSpecies s : layer.getSpecies().values()) {
var speciesCuVolumeLessDWBByUtilization = s
.getCloseUtilizationVolumeNetOfDecayWasteAndBreakageByUtilization();
layerCuVolumeLessDWBSum += speciesCuVolumeLessDWBByUtilization.get(uc);
}
layerCuVolumeLessDWBByUtilization.set(uc, layerCuVolumeLessDWBSum);
}
layerCuVolumeLessDWBByUtilization.set(uc, layerCuVolumeLessDWBSum);
} catch (NoSuchElementException e) {
// continue
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ void testStandardPath() throws ProcessingException {
// Results from VDYP7:
// Matchers.arrayContaining(45.7382965f, 0.410145015f, 5.13646269f, 29.8279209f, 5.91424417f,
// 4.44952154f)
Matchers.arrayContaining(45.738297f, 0.40698984f, 5.096949f, 29.598465f, 5.8687477f, 4.4152927f)
Matchers.arrayContaining(45.738297f, 0.41014498f, 5.136462f, 29.827923f, 5.914244f, 4.4495215f)
);
assertThat(
slice(lps.getBank().treesPerHectare, UtilizationClass.ALL),
// Results from VDYP7:
// Matchers.arrayContaining(594.113831f, 5.14728308f, 84.0494843f, 286.714783f, 167.523376f,
// 50.6789017f)
Matchers.arrayContaining(594.1138f, 5.156134f, 83.67636f, 287.08746f, 167.45839f, 50.735443f)
Matchers.arrayContaining(594.1138f, 5.1511745f, 84.04451f, 286.7145f, 167.52345f, 50.680126f)
);
assertThat(
slice(lps.getBank().quadMeanDiameters, UtilizationClass.ALL),
// Results from VDYP7:
// Matchers.arrayContaining(31.3083534f, 31.8518562f, 27.8945656f, 36.3949814f, 21.201519f, 33.4347534f)
Matchers.arrayContaining(31.308353f, 31.701859f, 27.84895f, 36.231186f, 21.12391f, 33.28734f)
Matchers.arrayContaining(31.308353f, 31.83982f, 27.89539f, 36.395f, 21.201513f, 33.43435f)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void testStandardPath() throws ProcessingException, ValueParseException {
// VDYP7 value is 0.892216682f, 11.5443392f, 64.3765259f, 13.3774729f, 9.80944252f
assertThat(
ForwardTestUtils.toFloatArray(lps.getBank().percentagesOfForestedLand),
is(arrayContaining(0.0f, 0.88982296f, 11.1437235f, 64.712654f, 12.831146f, 9.653382f))
is(arrayContaining(0.0f, 0.8967212f, 11.230113f, 65.214325f, 12.930618f, 9.728219f))
);
}
}

0 comments on commit 2372f33

Please sign in to comment.