Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/vdyp 443 #70

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8050fd1
Add Vdyp Back, create VdypBackApplication stub and VdypProcessingAppl…
smithkm Sep 26, 2024
a4ae14a
Adapting forward code for back
smithkm Oct 4, 2024
5fdf9bc
Merge remote-tracking branch 'origin/feature/forward-final' into feat…
smithkm Oct 4, 2024
0e6bf39
Add python cach directory to git ignore list
smithkm Oct 4, 2024
dc35b80
Back Prep
smithkm Oct 4, 2024
392069b
Merge remote-tracking branch 'origin/feature/forward-final' into feat…
smithkm Oct 8, 2024
d01d3c0
Merge remote-tracking branch 'origin/feature/forward-final' into feat…
smithkm Oct 11, 2024
1082ad4
Backprep
smithkm Oct 17, 2024
f8f55aa
Consolidate Bank in common
smithkm Oct 17, 2024
03685e9
Consolidate Bank in common
smithkm Oct 17, 2024
51774cd
Improve Bank unit tests
smithkm Oct 18, 2024
2253e45
Merge remote-tracking branch 'origin/main' into feature/VDYP-443
smithkm Oct 18, 2024
3ed2b79
Fix formatting
smithkm Oct 18, 2024
c5efff3
Move VDYP Model object parsers from forward to common
smithkm Oct 18, 2024
a718fb3
Unit test for back processing engine
smithkm Oct 21, 2024
8f6a28b
Merge remote-tracking branch 'origin/feature/VDYP-443' into feature/V…
smithkm Oct 21, 2024
abedb9e
Working on unit tests for parser
smithkm Oct 21, 2024
d7e3768
Merge branch 'feature/VDYP-443' of github.com:bcgov/VDYP into feature…
smithkm Oct 21, 2024
2c36b84
Unit tests for Utilization parser
smithkm Oct 22, 2024
f8fad2a
Unit test for parsing species
smithkm Oct 23, 2024
365f8c5
Unit test for polygon parser
smithkm Oct 23, 2024
d0c9d22
Refactor to eliminate duplication and branches that were reducing tes…
smithkm Oct 23, 2024
999597d
Unit test for polygon ID parser
smithkm Oct 23, 2024
29ac998
Unit test for processor base class
smithkm Oct 24, 2024
4adebb5
Unit test for LayerProcessingState
smithkm Oct 25, 2024
4ae7c0e
Fix typo in age inference
smithkm Oct 25, 2024
96eeb56
Unit test for building a layer from a bank
smithkm Oct 28, 2024
138043d
Cleanign up warnings
smithkm Oct 28, 2024
ba5bc5f
Merge remote-tracking branch 'origin/main' into feature/VDYP-443
smithkm Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<module>vdyp-sindex</module>
<module>vdyp-si32</module>
<module>vdyp-forward</module>
<module>vdyp-back</module>
</modules>

<build>
Expand Down
116 changes: 116 additions & 0 deletions lib/vdyp-back/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>vdyp-back</artifactId>
<packaging>jar</packaging>

<name>Variable Density Yield Project - Back</name>
<url>http://maven.apache.org</url>

<parent>
<groupId>ca.bc.gov.nrs.vdyp</groupId>
<artifactId>vdyp-lib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>ca.bc.gov.nrs.vdyp</groupId>
<artifactId>vdyp-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.bc.gov.nrs.vdyp</groupId>
<artifactId>vdyp-forward</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>ca.bc.gov.nrs.vdyp</groupId>
<artifactId>vdyp-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ca.bc.gov.nrs.vdyp</groupId>
<artifactId>vdyp-forward</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ca.bc.gov.nrs.vdyp</groupId>
<artifactId>vdyp-si32</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<filters>
<filter>src/main/resources/application.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ca.bc.gov.nrs.vdyp</groupId>
<artifactId>vdyp-buildtools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package ca.bc.gov.nrs.vdyp.back;

import static java.lang.Math.max;
import static java.lang.Math.min;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;

import ca.bc.gov.nrs.vdyp.application.ProcessingEngine;
import ca.bc.gov.nrs.vdyp.application.ProcessingException;
import ca.bc.gov.nrs.vdyp.application.StandProcessingException;
import ca.bc.gov.nrs.vdyp.back.processing_state.BackProcessingState;
import ca.bc.gov.nrs.vdyp.model.ComponentSizeLimits;
import ca.bc.gov.nrs.vdyp.model.LayerType;
import ca.bc.gov.nrs.vdyp.model.MatrixMap2;
import ca.bc.gov.nrs.vdyp.model.MatrixMap2Impl;
import ca.bc.gov.nrs.vdyp.model.Region;
import ca.bc.gov.nrs.vdyp.model.UtilizationClass;
import ca.bc.gov.nrs.vdyp.model.UtilizationClassVariable;
import ca.bc.gov.nrs.vdyp.model.VolumeVariable;
import ca.bc.gov.nrs.vdyp.processing_state.Bank;

public class BackProcessingEngine extends ProcessingEngine {

/**
*
* @throws StandProcessingException
*/
// BACKPREP
void prepare(BackProcessingState state) throws ProcessingException {

// Copy the basal area for the veteran layer if it exists to the polygon state

state.setBaseAreaVeteran(
state.getVeteranLayerProcessingState().map(vetState -> vetState.getBank().basalAreas[0][0 + 1])
);

// Copy slices of the compatibility variables for the primary layer to the polygon state

var primaryState = state.getPrimaryLayerProcessingState();

int specCount = primaryState.getNSpecies();

@SuppressWarnings("unchecked")
MatrixMap2<UtilizationClass, VolumeVariable, Float>[] cvVolume = new MatrixMap2[specCount + 1];
@SuppressWarnings("unchecked")
Map<UtilizationClass, Float>[] cvBasalArea = new Map[specCount + 1];
@SuppressWarnings("unchecked")
Map<UtilizationClass, Float>[] cvQuadraticMeanDiameter = new Map[specCount + 1];
@SuppressWarnings("unchecked")
Map<UtilizationClassVariable, Float>[] cvPrimaryLayerSmall = new Map[specCount + 1];

for (int i = 0; i < primaryState.getNSpecies(); i++) {
final int specIndex = i + 1;
cvVolume[specIndex] = new MatrixMap2Impl<>(
List.of(UtilizationClass.values()), List.of(VolumeVariable.values()),
(uc, vv) -> primaryState.getCVVolume(specIndex, uc, vv, LayerType.PRIMARY)
);

cvBasalArea[specIndex] = new EnumMap<>(UtilizationClass.class);
cvQuadraticMeanDiameter[specIndex] = new EnumMap<>(UtilizationClass.class);
cvPrimaryLayerSmall[specIndex] = new EnumMap<>(UtilizationClassVariable.class);

for (var uc : UtilizationClass.values()) {
cvBasalArea[specIndex].put(uc, primaryState.getCVBasalArea(specIndex, uc, LayerType.PRIMARY));
cvQuadraticMeanDiameter[specIndex]
.put(uc, primaryState.getCVQuadraticMeanDiameter(specIndex, uc, LayerType.PRIMARY));
}

for (var ucv : UtilizationClassVariable.values()) {
cvPrimaryLayerSmall[specIndex].put(ucv, primaryState.getCVSmall(specIndex, ucv));
}

}

state.setCompatibilityVariableDetails(cvVolume, cvBasalArea, cvQuadraticMeanDiameter, cvPrimaryLayerSmall);

Bank primaryBank = state.getPrimaryLayerProcessingState().getBank();
Region polygonRegion = state.getCurrentBecZone().getRegion();

ComponentSizeLimits[] limits = new ComponentSizeLimits[primaryState.getNSpecies() + 1];
float[] finalDiameters = new float[primaryState.getNSpecies() + 1];

int ucIndexAll = UtilizationClass.ALL.ordinal(); // Intentionally use ordinal instead of index.

finalDiameters[0] = primaryBank.quadMeanDiameters[0][ucIndexAll];
for (int i = 0; i < primaryState.getNSpecies(); i++) {
final int specIndex = i + 1;

finalDiameters[specIndex] = primaryBank.quadMeanDiameters[specIndex][0];

final var originalLimits = state.getEstimators()
.getLimitsForHeightAndDiameter(primaryBank.speciesNames[specIndex], polygonRegion);

final float specQuadMeanDiameter = primaryBank.quadMeanDiameters[specIndex][ucIndexAll];
final float specLoreyHeight = primaryBank.loreyHeights[specIndex][ucIndexAll];

final float quadMeanDiameterLoreyHeightRatio = specQuadMeanDiameter / specLoreyHeight;

final float loreyHeightMaximum = max(originalLimits.loreyHeightMaximum(), specLoreyHeight);
final float quadMeanDiameterMaximum = max(originalLimits.quadMeanDiameterMaximum(), specQuadMeanDiameter);

final float minQuadMeanDiameterLoreyHeightRatio = min(
originalLimits.minQuadMeanDiameterLoreyHeightRatio(), quadMeanDiameterLoreyHeightRatio
);
final float maxQuadMeanDiameterLoreyHeightRatio = max(
originalLimits.maxQuadMeanDiameterLoreyHeightRatio(), quadMeanDiameterLoreyHeightRatio
);

limits[specIndex] = new ComponentSizeLimits(
loreyHeightMaximum, quadMeanDiameterMaximum, minQuadMeanDiameterLoreyHeightRatio,
maxQuadMeanDiameterLoreyHeightRatio
);

}
state.setLimits(limits);
state.setFinalQuadMeanDiameters(finalDiameters);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ca.bc.gov.nrs.vdyp.back;

import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

import ca.bc.gov.nrs.vdyp.application.Pass;
import ca.bc.gov.nrs.vdyp.application.ProcessingException;
import ca.bc.gov.nrs.vdyp.application.Processor;
import ca.bc.gov.nrs.vdyp.io.FileResolver;
import ca.bc.gov.nrs.vdyp.io.parse.control.BaseControlParser;
import ca.bc.gov.nrs.vdyp.model.VdypPolygon;

public class BackProcessor extends Processor {

@Override
protected BaseControlParser getControlFileParser() {
// TODO Auto-generated method stub
return null;
}

@Override
public void process(
Set<Pass> vdypPassSet, Map<String, Object> controlMap, Optional<FileResolver> outputFileResolver,
Predicate<VdypPolygon> polygonFilter
) throws ProcessingException {
// TODO Auto-generated method stub

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ca.bc.gov.nrs.vdyp.back;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ca.bc.gov.nrs.vdyp.application.VdypApplicationIdentifier;
import ca.bc.gov.nrs.vdyp.application.VdypProcessingApplication;

public class VdypBackApplication extends VdypProcessingApplication<BackProcessor> {

static {
initLogging(VdypBackApplication.class);
}

static final Logger logger = LoggerFactory.getLogger(VdypBackApplication.class);

public static final String DEFAULT_VDYP_CONTROL_FILE_NAME = "vdyp.ctr";

public static void main(final String... args) {

var app = new VdypBackApplication();
System.exit(app.run(args));
}

@Override
protected BackProcessor getProcessor() {
return null; // TODO
}

@Override
public String getDefaultControlFileName() {
return DEFAULT_VDYP_CONTROL_FILE_NAME;
}

@Override
public VdypApplicationIdentifier getId() {
return VdypApplicationIdentifier.VDYP_BACK;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ca.bc.gov.nrs.vdyp.back.processing_state;

import java.util.function.Predicate;

import ca.bc.gov.nrs.vdyp.application.ProcessingException;
import ca.bc.gov.nrs.vdyp.forward.controlmap.ForwardResolvedControlMap;
import ca.bc.gov.nrs.vdyp.model.LayerType;
import ca.bc.gov.nrs.vdyp.model.VdypLayer;
import ca.bc.gov.nrs.vdyp.model.VdypPolygon;
import ca.bc.gov.nrs.vdyp.model.VdypSpecies;
import ca.bc.gov.nrs.vdyp.processing_state.LayerProcessingState;
import ca.bc.gov.nrs.vdyp.processing_state.ProcessingState;

public class BackLayerProcessingState
extends LayerProcessingState<ForwardResolvedControlMap, BackLayerProcessingState> {

protected BackLayerProcessingState(
ProcessingState<ForwardResolvedControlMap, BackLayerProcessingState> ps, VdypPolygon polygon,
LayerType subjectLayerType
) throws ProcessingException {
super(ps, polygon, subjectLayerType);
// TODO Auto-generated constructor stub
}

@Override
protected Predicate<VdypSpecies> getBankFilter() {
// TODO Auto-generated method stub
return x -> true;
}

@Override
protected void applyCompatibilityVariables(VdypSpecies species, int i) {
// TODO Auto-generated method stub

}

@Override
protected VdypLayer updateLayerFromBank() {
// TODO Auto-generated method stub
return null;
}

}
Loading
Loading