Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -48,6 +49,7 @@
import nl.overheid.aerius.shared.domain.calculation.MetDatasetType;
import nl.overheid.aerius.shared.domain.calculation.MetSurfaceCharacteristics;
import nl.overheid.aerius.shared.domain.calculation.NCACalculationOptions;
import nl.overheid.aerius.shared.domain.calculation.PermitLowerBoundType;
import nl.overheid.aerius.shared.domain.v2.characteristics.adms.ADMSLimits;

/**
Expand Down Expand Up @@ -176,6 +178,25 @@ void testReadCalculationSetOptionsDuplicateOptions() {
assertEquals("somewhere else", options.getNcaCalculationOptions().getPermitArea(), "PermitArea");
}

@Test
void testOwN2000ReadCalculationSetOptions() {
final FeatureCollection featureCollection = mock(FeatureCollection.class);
final MetaData metaData = mock(MetaData.class);
final IsCalculationMetaData calculationMetaData = mock(IsCalculationMetaData.class);
final List<IsGmlProperty<IsCalculationOption>> suppliedOptions = new ArrayList<>();

suppliedOptions.add(mockCalculationOption("permit_lower_bound", "policy"));
when(featureCollection.getMetaData()).thenReturn(metaData);
when(calculationMetaData.getOptions()).thenAnswer(a -> suppliedOptions);
when(metaData.getCalculation()).thenReturn(calculationMetaData);
final GMLCalculationSetOptionsReader reader = new GMLCalculationSetOptionsReader(featureCollection);

final CalculationSetOptions options = reader.readCalculationSetOptions(Theme.OWN2000);
assertNotNull(options, "returned options shouldn't be null");
assertSame(PermitLowerBoundType.POLICY, options.getOwN2000CalculationOptions().getPermitLowerBoundType(),
"Should have read the Permit Lower Bound.");
}

/**
* @param spatiallyVaryingRoughness Test spatiallyVaryingRoughness. if null it should be true, else follow boolean value
*/
Expand Down Expand Up @@ -279,7 +300,7 @@ void testReadCalculationSetOptionsEmptyOptions() {
}

@Test
void testReadCalculationSetOptionsWnb() {
void testNCAReadCalculationSetOptions() {
final FeatureCollection featureCollection = mock(FeatureCollection.class);
final MetaData metaData = mock(MetaData.class);
final IsCalculationMetaData calculationMetaData = mock(IsCalculationMetaData.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public enum CalculationRoadOPS {

/**
* Use OPS to calculate for the entire calculation.
* This gives results outside the scope of WNB.
* This gives results outside the scope of OWN2000.
*/
OPS_ALL
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import nl.overheid.aerius.shared.domain.meteo.Meteo;

/**
* Calculation options related to the WNB theme.
* Calculation options related to the OWN2000 theme.
*/
public class OwN2000CalculationOptions implements Serializable {

private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 2L;

private CalculationRoadOPS roadOPS = CalculationRoadOPS.DEFAULT;
private PermitLowerBoundType permitLowerBoundType;
private double permitLowerBoundValue;
private boolean useMaxDistance;
private boolean forceAggregation;
private Meteo meteo;
Expand All @@ -41,6 +43,34 @@ public class OwN2000CalculationOptions implements Serializable {
private boolean splitSubReceptorWork;
private int splitSubReceptorWorkDistance;

/**
* @return Returns the lower bound type used for permit calculations.
*/
public PermitLowerBoundType getPermitLowerBoundType() {
return permitLowerBoundType;
}

/**
* Set the lower bound type used for permit calculations.
*/
public void setPermitLowerBoundType(final PermitLowerBoundType permitLowerBoundType) {
this.permitLowerBoundType = permitLowerBoundType;
}

/**
* @return Returns the lower bound value used for permit calculations.
*/
public double getPermitLowerBoundValue() {
return permitLowerBoundValue;
}

/**
* Set the lower bound value used for permit calculations.
*/
public void setPermitLowerBoundValue(final double permitLowerBoundValue) {
this.permitLowerBoundValue = permitLowerBoundValue;
}

/**
* @return Returns true if OwN2000 maximum distance 25km calculation is to be applied.
*/
Expand All @@ -49,10 +79,10 @@ public boolean isUseMaxDistance() {
}

/**
* Set if the WNB 25km calculation distance limit should be applied. Default true for WNB.
* Set if the OWN2000 25km calculation distance limit should be applied. Default true for OWN2000.
*/
public void setUseMaxDistance(final boolean uswWNBMaxDistance) {
this.useMaxDistance = uswWNBMaxDistance;
public void setUseMaxDistance(final boolean useMaxDistance) {
this.useMaxDistance = useMaxDistance;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright the State of the Netherlands
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package nl.overheid.aerius.shared.domain.calculation;

import java.util.Locale;

/**
* Enum for identifying calculation lower bounds for permit calculations.
*/
public enum PermitLowerBoundType {
/**
* Arithmetic limitations lower bound.
*/
ARITHMETIC,
/**
* Policy lower bound.
*/
POLICY;

public String toDatabaseString() {
return name().toLowerCase(Locale.ROOT);
}

public static PermitLowerBoundType safeValueOf(final String value) {
try {
return value == null ? null : valueOf(value.toUpperCase(Locale.ROOT));
} catch (final IllegalArgumentException e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/*
* Crown copyright
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package nl.overheid.aerius.util;

import static nl.overheid.aerius.shared.domain.v2.characteristics.adms.ADMSLimits.ADMS_COMPLEX_TERRAIN_DEFAULT;
import static nl.overheid.aerius.shared.domain.v2.characteristics.adms.ADMSLimits.ADMS_PLUME_DEPLETION_NH3_DEFAULT;
import static nl.overheid.aerius.shared.domain.v2.characteristics.adms.ADMSLimits.ADMS_PLUME_DEPLETION_NOX_DEFAULT;
import static nl.overheid.aerius.shared.domain.v2.characteristics.adms.ADMSLimits.MIN_MONIN_OBUKHOV_LENGTH_DEFAULT;
import static nl.overheid.aerius.shared.domain.v2.characteristics.adms.ADMSLimits.PRIESTLEY_TAYLOR_PARAMETER_DEFAULT;
import static nl.overheid.aerius.shared.domain.v2.characteristics.adms.ADMSLimits.ROUGHNESS_DEFAULT;
import static nl.overheid.aerius.shared.domain.v2.characteristics.adms.ADMSLimits.SPATIALLY_VARYING_ROUGHNESS_DEFAULT;
import static nl.overheid.aerius.shared.domain.v2.characteristics.adms.ADMSLimits.SURFACE_ALBEDO_DEFAULT;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import nl.overheid.aerius.shared.domain.calculation.ADMSOptions;
import nl.overheid.aerius.shared.domain.calculation.CalculationSetOptions;
import nl.overheid.aerius.shared.domain.calculation.MetDatasetType;
import nl.overheid.aerius.shared.domain.calculation.MetSurfaceCharacteristics;
import nl.overheid.aerius.shared.domain.calculation.NCACalculationOptions;
import nl.overheid.aerius.shared.domain.calculation.RoadLocalFractionNO2Option;
import nl.overheid.aerius.util.OptionsMetadataUtil.Option;

/**
* Util class to read/write NCA theme meta data options from/to a map into/from the CalculationSetOptions object.
*/
final class NcaOptionsMetadataUtil extends OptionsMetadataUtilBase {

private NcaOptionsMetadataUtil() {
// Util class
}

/**
* Reads the NCA specific {@link CalculationSetOptions} from a map.
*
* @param map The map to read the options from
* @param prefixedOptionsMap map of options that have a prefixed key
* @param options The object to set the options in
*/
static void ncaCalculationSetOptionsFromMap(final Map<Option, String> map, final Map<String, Map<Option, String>> prefixedOptionsMap,
final CalculationSetOptions options) {
final NCACalculationOptions ncaCalculationOptions = options.getNcaCalculationOptions();

NcaOptionsMetadataUtil.ncaOptionsFromMap(ncaCalculationOptions, map, prefixedOptionsMap);
options.getCalculatedSnapshotValues().setDevelopmentPressureClassification(map.get(Option.DEVELOPMENT_PRESSURE_CLASSIFICATION));
}

private static void ncaOptionsFromMap(final NCACalculationOptions options, final Map<Option, String> map,
final Map<String, Map<Option, String>> prefixedOptionsMap) {
options.setProjectCategory(map.get(Option.PROJECT_CATEGORY));
options.setPermitArea(map.get(Option.PERMIT_AREA));
parseListOption(Option.DEVELOPMENT_PRESSURE_SOURCE_IDS, map, options::setDevelopmentPressureSourceIds);
options.setRoadLocalFractionNO2ReceptorsOption(RoadLocalFractionNO2Option.safeValueOf(map.get(Option.ROAD_LOCAL_FRACTION_NO2_RECEPTORS_OPTION)));
options.setRoadLocalFractionNO2PointsOption(RoadLocalFractionNO2Option.safeValueOf(map.get(Option.ROAD_LOCAL_FRACTION_NO2_POINTS_OPTION)));
if (options.getRoadLocalFractionNO2ReceptorsOption() == RoadLocalFractionNO2Option.ONE_CUSTOM_VALUE
|| options.getRoadLocalFractionNO2PointsOption() == RoadLocalFractionNO2Option.ONE_CUSTOM_VALUE) {
options.setRoadLocalFractionNO2(
Optional.ofNullable(map.get(Option.ROAD_LOCAL_FRACTION_NO2_CUSTOM_VALUE)).map(Double::parseDouble).orElse(null));
}

final ADMSOptions admsOptions = options.getAdmsOptions();
admsOptions.setMinMoninObukhovLength(getOrDefault(map, Option.ADMS_MIN_MONIN_OBUKHOV_LENGTH, MIN_MONIN_OBUKHOV_LENGTH_DEFAULT));
admsOptions.setSurfaceAlbedo(getOrDefault(map, Option.ADMS_SURFACE_ALBEDO, SURFACE_ALBEDO_DEFAULT));
admsOptions.setPriestleyTaylorParameter(getOrDefault(map, Option.ADMS_PRIESTLEY_TAYLOR_PARAMETER, PRIESTLEY_TAYLOR_PARAMETER_DEFAULT));

if (map.get(Option.ADMS_MET_SITE_ID) != null) {
admsOptions.setMetSiteId(Integer.parseInt(map.get(Option.ADMS_MET_SITE_ID)));
admsOptions.setMetSiteLatitude(Optional.ofNullable(map.get(Option.ADMS_MET_SITE_LATITUDE)).map(Double::parseDouble).orElse(0.0));
admsOptions.setMetDatasetType(MetDatasetType.safeValueOf(map.get(Option.ADMS_MET_DATASET_TYPE)));
parseListOption(Option.ADMS_MET_YEARS, map, admsOptions::setMetYears);
ncaMetSiteOptions(prefixedOptionsMap, admsOptions, map);
}
admsOptions.setPlumeDepletionNH3(isOrDefault(map, Option.ADMS_PLUME_DEPLETION_NH3, ADMS_PLUME_DEPLETION_NH3_DEFAULT));
admsOptions.setPlumeDepletionNOX(isOrDefault(map, Option.ADMS_PLUME_DEPLETION_NOX, ADMS_PLUME_DEPLETION_NOX_DEFAULT));
admsOptions.setSpatiallyVaryingRoughness(isOrDefault(map, Option.ADMS_SPATIALLY_VARYING_ROUGHNESS, SPATIALLY_VARYING_ROUGHNESS_DEFAULT));
admsOptions.setComplexTerrain(isOrDefault(map, Option.ADMS_COMPLEX_TERRAIN, ADMS_COMPLEX_TERRAIN_DEFAULT));
}

/**
* Read Met Site data. If multiple met years are present the met site options key is expected to be prefixed with the met year.
* If only 1 year or no met year is present the options are not prefixed.
*/
private static void ncaMetSiteOptions(final Map<String, Map<Option, String>> prefixedOptionsMap, final ADMSOptions admsOptions,
final Map<Option, String> map) {
if (admsOptions.getMetYears().size() > 1) {
for (final String metYear : admsOptions.getMetYears()) {
final Map<Option, String> prefixedMap = prefixedOptionsMap.get(metYear);
ncaPutMetSiteOptions(admsOptions, metYear, prefixedMap);
}
} else {
ncaPutMetSiteOptions(admsOptions, "", map);
}
}

private static void ncaPutMetSiteOptions(final ADMSOptions admsOptions, final String metYear, final Map<Option, String> prefixedMap) {
final MetSurfaceCharacteristics msc = MetSurfaceCharacteristics.builder()
.roughness(getOrDefault(prefixedMap, Option.ADMS_MET_SITE_ROUGHNESS, ROUGHNESS_DEFAULT))
.minMoninObukhovLength(getOrDefault(prefixedMap, Option.ADMS_MET_SITE_MIN_MONIN_OBUKHOV_LENGTH,
MIN_MONIN_OBUKHOV_LENGTH_DEFAULT))
.surfaceAlbedo(getOrDefault(prefixedMap, Option.ADMS_MET_SITE_SURFACE_ALBEDO, SURFACE_ALBEDO_DEFAULT))
.priestleyTaylorParameter(getOrDefault(prefixedMap, Option.ADMS_MET_SITE_PRIESTLEY_TAYLOR_PARAMETER,
PRIESTLEY_TAYLOR_PARAMETER_DEFAULT))
.windInSectors(isOrDefault(prefixedMap, Option.ADMS_MET_SITE_WIND_IN_SECTORS, false))
.build();
admsOptions.putMetSiteCharacteristics(metYear, msc);
}

/**
* Put NCA theme options into a map to be stored in the GML.
*
* @param options Object to get the options from
* @param mapToAddTo map to add the options to
* @param addDefaults flag if set to true will add default values when no value is present in the options object
*/
static void ncaCalculationSetOptionsToMap(final CalculationSetOptions options, final Map<String, String> mapToAddTo, final boolean addDefaults) {
ncaOptionsToMap(mapToAddTo, options.getNcaCalculationOptions(), addDefaults);
addValue(mapToAddTo, Option.DEVELOPMENT_PRESSURE_CLASSIFICATION, options.getCalculatedSnapshotValues().getDevelopmentPressureClassification(),
addDefaults);
}

private static void ncaOptionsToMap(final Map<String, String> mapToAddTo, final NCACalculationOptions options, final boolean addDefaults) {
if (options != null) {
addValue(mapToAddTo, Option.ADMS_VERSION, options.getAdmsVersion(), addDefaults);
addValue(mapToAddTo, Option.PROJECT_CATEGORY, options.getProjectCategory(), addDefaults);
addValue(mapToAddTo, Option.PERMIT_AREA, options.getPermitArea(), addDefaults);
if (!options.getDevelopmentPressureSourceIds().isEmpty()) {
addValue(mapToAddTo, Option.DEVELOPMENT_PRESSURE_SOURCE_IDS,
String.join(LIST_OPTION_SEPARATOR, options.getDevelopmentPressureSourceIds()), addDefaults);
}
addValue(mapToAddTo, Option.ROAD_LOCAL_FRACTION_NO2_RECEPTORS_OPTION, options.getRoadLocalFractionNO2ReceptorsOption(), addDefaults);
addValue(mapToAddTo, Option.ROAD_LOCAL_FRACTION_NO2_POINTS_OPTION, options.getRoadLocalFractionNO2PointsOption(), addDefaults);
if (options.getRoadLocalFractionNO2ReceptorsOption() == RoadLocalFractionNO2Option.ONE_CUSTOM_VALUE
|| options.getRoadLocalFractionNO2PointsOption() == RoadLocalFractionNO2Option.ONE_CUSTOM_VALUE) {
addValue(mapToAddTo, Option.ROAD_LOCAL_FRACTION_NO2_CUSTOM_VALUE, options.getRoadLocalFractionNO2(), addDefaults);
}
final ADMSOptions adms = options.getAdmsOptions();

if (adms != null) {
addValue(mapToAddTo, Option.ADMS_MIN_MONIN_OBUKHOV_LENGTH, adms.getMinMoninObukhovLength(), addDefaults);
addValue(mapToAddTo, Option.ADMS_SURFACE_ALBEDO, adms.getSurfaceAlbedo(), addDefaults);
addValue(mapToAddTo, Option.ADMS_PRIESTLEY_TAYLOR_PARAMETER, adms.getPriestleyTaylorParameter(), addDefaults);
addIntValue(mapToAddTo, Option.ADMS_MET_SITE_ID, adms.getMetSiteId(), addDefaults);
if (adms.getMetSiteLatitude() != 0.0) {
addValue(mapToAddTo, Option.ADMS_MET_SITE_LATITUDE, adms.getMetSiteLatitude(), addDefaults);
}
addValue(mapToAddTo, Option.ADMS_MET_DATASET_TYPE, adms.getMetDatasetType(), addDefaults);
ncaAddMetSite(mapToAddTo, addDefaults, adms);
// Always add the following fields to the GML as it also gives an indication if run in demo mode.
addBooleanValue(mapToAddTo, Option.ADMS_PLUME_DEPLETION_NH3, adms.isPlumeDepletionNH3(), true);
addBooleanValue(mapToAddTo, Option.ADMS_PLUME_DEPLETION_NOX, adms.isPlumeDepletionNOX(), true);
addBooleanValue(mapToAddTo, Option.ADMS_SPATIALLY_VARYING_ROUGHNESS, adms.isSpatiallyVaryingRoughness(), true);
addBooleanValue(mapToAddTo, Option.ADMS_COMPLEX_TERRAIN, adms.isComplexTerrain(), true);
}
}
}

/**
* Add Met Site data. If multiple met years are present the met site options key is prefixed with the met year.
* If only 1 year or no met year is present the options are not prefixed.
*/
private static void ncaAddMetSite(final Map<String, String> mapToAddTo, final boolean addDefaults, final ADMSOptions adms) {
final List<String> metYears = adms.getMetYears();
if (!metYears.isEmpty()) {
addValue(mapToAddTo, Option.ADMS_MET_YEARS, String.join(LIST_OPTION_SEPARATOR, metYears), addDefaults);
}
if (metYears.size() > 1) {
for (final String metYear : metYears) {
final String prefix = metYear + OPTION_KEY_SPLIT;
addADMSMetSiteOptions(mapToAddTo, addDefaults, adms.getMetSiteCharacteristics(metYear), prefix);
}
} else {
final String metYear = metYears.isEmpty() ? "" : metYears.get(0);
addADMSMetSiteOptions(mapToAddTo, addDefaults, adms.getMetSiteCharacteristics(metYear), "");
}
}

private static void addADMSMetSiteOptions(final Map<String, String> mapToAddTo, final boolean addDefaults, final MetSurfaceCharacteristics msc,
final String prefix) {

addValue(mapToAddTo, prefix + Option.ADMS_MET_SITE_ROUGHNESS.toKey(), msc.getRoughness(), addDefaults);
addValue(mapToAddTo, prefix + Option.ADMS_MET_SITE_MIN_MONIN_OBUKHOV_LENGTH.toKey(), msc.getMinMoninObukhovLength(), addDefaults);
addValue(mapToAddTo, prefix + Option.ADMS_MET_SITE_SURFACE_ALBEDO.toKey(), msc.getSurfaceAlbedo(), addDefaults);
addValue(mapToAddTo, prefix + Option.ADMS_MET_SITE_PRIESTLEY_TAYLOR_PARAMETER.toKey(), msc.getPriestleyTaylorParameter(), addDefaults);
if (msc.isWindInSectors()) {
addValue(mapToAddTo, prefix + Option.ADMS_MET_SITE_WIND_IN_SECTORS.toKey(), String.valueOf(msc.isWindInSectors()), addDefaults);
}
}
}
Loading