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

Add biomass test to POSEIDON #89

Merged
merged 10 commits into from
Dec 6, 2023
2 changes: 1 addition & 1 deletion POSEIDON/inputs/epo_inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package uk.ac.ox.oxfish.biology.tuna;

import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import uk.ac.ox.oxfish.biology.Species;
import uk.ac.ox.oxfish.geography.currents.CurrentPatternMapSupplier;
import uk.ac.ox.oxfish.model.FishState;
import uk.ac.ox.oxfish.model.scenario.EpoAbundanceScenario;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.stream.Collectors;

import static uk.ac.ox.oxfish.utility.csv.CsvParserUtil.recordStream;

/**
* Test to see if the simulated biomass is the same as the expected biomass for the first 4 quarters.
* Expected biomasses are generated in the preprocessing pipeline as "biomass_test.csv".
*/
public class EpoBiologyOnlyScenarioAllSpeciesTest {

private final Path testInputs = Paths.get(
"inputs", "epo_inputs", "tests"
);

private final Path biologyTestFile = testInputs.resolve("biomass_test.csv");

@Test
public void testRunBiologyOnlyScenario() {
final EpoAbundanceScenario scenario = new EpoAbundanceScenario();

final FishState fishState = new FishState();
fishState.setScenario(scenario);
scenario.getFadMap().setCurrentPatternMapSupplier(CurrentPatternMapSupplier.EMPTY);

fishState.start();

System.out.println("SeaTiles: " + fishState.getMap().getAllSeaTiles().size());
norellia marked this conversation as resolved.
Show resolved Hide resolved

final Species bet = fishState.getSpecies("Bigeye tuna");
final Species yft = fishState.getSpecies("Yellowfin tuna");
final Species skj = fishState.getSpecies("Skipjack tuna");


System.out.println("breakpoint");

Map<Integer, Map<String, Double>> expectedBiomass = recordStream(biologyTestFile)
.collect(Collectors.groupingBy(
norellia marked this conversation as resolved.
Show resolved Hide resolved
record -> record.getInt("day"),
Collectors.toMap(record -> record.getString("species"), record -> record.getDouble("biomass"))
));

Map<Species, double[][]> speciesAbundances =
ImmutableMap.of(
bet, fishState.getTotalAbundance(bet),
yft, fishState.getTotalAbundance(yft),
skj, fishState.getTotalAbundance(skj)
);

Map<Species, double[][]> speciesDeaths =
norellia marked this conversation as resolved.
Show resolved Hide resolved
ImmutableMap.of(
bet, fishState.getTotalAbundance(bet),
yft, fishState.getTotalAbundance(yft),
skj, fishState.getTotalAbundance(skj)
);

System.out.println("File found, start stepping model");

do {
System.out.println(fishState.getStep());
if (expectedBiomass.containsKey(fishState.getStep())) {
speciesAbundances.forEach((s, abundance) -> {
norellia marked this conversation as resolved.
Show resolved Hide resolved
System.out.println(fishState.getStep() + " " + fishState.getTotalBiomass(s) / 1000);
System.out.println("Estimated biomass");
Assertions.assertEquals(
expectedBiomass.get(fishState.getStep()).get(s.getCode()),
fishState.getTotalBiomass(s),
1000000
norellia marked this conversation as resolved.
Show resolved Hide resolved
);
});
}
/*System.out.println(fishState.getStep() + " " + fishState.getTotalBiomass(yft) / 1000);
norellia marked this conversation as resolved.
Show resolved Hide resolved
final double[][] totalAbundanceYFT = fishState.getTotalAbundance(yft);
for (int i = 0; i < totalAbundanceYFT.length; i++) {
for (int j = 0; j < totalAbundanceYFT[0].length - 1; j++) {

deaths[i][j] = prevAbundYFT[i][j] - totalAbundanceYFT[i][j + 1];
}
}
System.out.println("Yellowfin estimated");

prevAbundYFT = fishState.getTotalAbundance(yft);

Assertions.assertEquals(expectedBiomass.get(fishState.getStep()).get("YFT"), fishState.getTotalBiomass(yft), 1000000);


System.out.println(fishState.getStep() + " " + fishState.getTotalBiomass(skj) / 1000);
final double[][] totalAbundanceSKJ = fishState.getTotalAbundance(skj);
for (int i = 0; i < totalAbundanceSKJ.length; i++) {
for (int j = 0; j < totalAbundanceSKJ[0].length - 1; j++) {
deaths[i][j] = prevAbundSKJ[i][j] - totalAbundanceSKJ[i][j + 1];
}
}
System.out.println("Skipjack estimated");

prevAbundSKJ = fishState.getTotalAbundance(skj);

Assertions.assertEquals(expectedBiomass.get(fishState.getStep()).get("SKJ"), fishState.getTotalBiomass(skj), 1000000);*/
fishState.schedule.step(fishState);
} while (fishState.getYear() < 1);
}
}



nicolaspayette marked this conversation as resolved.
Show resolved Hide resolved
Loading