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 442 #87

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 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
c260fd7
Moving executiuon step to general processing engine class
smithkm Oct 31, 2024
e1d43af
Refactoring
smithkm Nov 6, 2024
7432075
Unit testing framework for model objects
smithkm Nov 13, 2024
576ae44
Unit tests for deepEquals matcher for VdypSite
smithkm Nov 13, 2024
7f35fd7
Unit tests for deepEquals matcher for VdypCompatibilityVariables
smithkm Nov 14, 2024
e107666
Unit tests for deep equals matcher for species
smithkm Nov 14, 2024
c603ec6
Species deepEquals unit tests and generalization of *Variable enums a…
smithkm Nov 15, 2024
8344baa
Refactor to use common enum for UC variables
smithkm Nov 18, 2024
9f24b55
Fix predecessor method
smithkm Nov 18, 2024
62cfa12
Fix incorrect UCVs being used after refactor
smithkm Nov 18, 2024
c105a97
Refactor Forward to use common processing state base classes
smithkm Nov 18, 2024
0723605
Unit tests for deep equals matcher for layer
smithkm Nov 19, 2024
6f45153
Unit tests for polygon deep equals
smithkm Nov 19, 2024
7f2e97c
use UtilizationClassVariable accessor enum in place of reflection
smithkm Nov 19, 2024
8703160
Fix error druing CV update
smithkm Nov 19, 2024
9253b83
Bank deep equals
smithkm Nov 23, 2024
7ddbd49
Deep Equals for Bank
smithkm Nov 27, 2024
687280c
Deep Equals for Layer State
smithkm Nov 28, 2024
46e1968
Deep equals for processing state
smithkm Nov 28, 2024
3e972eb
State dump Bank.
smithkm Dec 3, 2024
72906ea
ProcessingState write state for tests
smithkm Dec 4, 2024
d78f01e
Dump state for processing state tests
smithkm Dec 5, 2024
29b662a
Working on refactoring CVSET to move to common package
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,160 @@
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.common.Utils;
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.VdypCompatibilityVariables;
import ca.bc.gov.nrs.vdyp.model.VdypPolygon;
import ca.bc.gov.nrs.vdyp.model.variables.UtilizationClassVariable;
import ca.bc.gov.nrs.vdyp.processing_state.Bank;

public class BackProcessingEngine extends ProcessingEngine<BackProcessingEngine.BackExecutionStep> {

public enum BackExecutionStep implements ProcessingEngine.ExecutionStep<BackExecutionStep> {
// Must be first
NONE, //

GROW, //

// Must be last
ALL; //

@Override
public BackExecutionStep predecessor() throws IllegalStateException {
return Utils.predecessorOrThrow(this, BackExecutionStep.values());
}

@Override
public BackExecutionStep successor() {
return Utils.successorOrThrow(this, BackExecutionStep.values());
}

}

/**
*
* @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, UtilizationClassVariable, 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()), VdypCompatibilityVariables.VOLUME_UTILIZATION_VARIABLES,
(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 : VdypCompatibilityVariables.SMALL_UTILIZATION_VARIABLES) {
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);

}

@Override
public void processPolygon(VdypPolygon polygon, BackExecutionStep lastStepInclusive) throws ProcessingException {
// TODO Auto-generated method stub

}

@Override
protected BackExecutionStep getFirstStep() {
return BackExecutionStep.NONE;
}

@Override
protected BackExecutionStep getLastStep() {
return BackExecutionStep.ALL;
}
}
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,37 @@
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 VdypLayer updateLayerFromBank() {
// TODO Auto-generated method stub
return null;
}

}
Loading
Loading