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

339 add support for converting pgd from pga for the earthquake controller #342

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Sorted by option and order to the all project endpoints [#330](https://github.com/IN-CORE/incore-services/issues/330)
- Endpoint to finalized a workflow [#335](https://github.com/IN-CORE/incore-services/issues/335)
- Support for PGD from earthquake hazards [#339](https://github.com/IN-CORE/incore-services/issues/339)

### Fixed
- Bug when adding visualization layers to an empty layer list [#331](https://github.com/IN-CORE/incore-services/issues/331)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,40 @@ public static SeismicHazardResult getGroundMotionAtSite(Earthquake earthquake, M
return new SeismicHazardResult(updatedHazardValue, result.getPeriod(), result.getDemand(), demandUnits);
}

} else if (HazardUtil.PGD.equalsIgnoreCase(hazardType)) {
// First, check if the hazard is directly from the attenuation models or datasets
boolean supported = supportsHazard(earthquake, attenuations, period, hazardType, true);
// If not supported, check if it supports PGA to convert PGA to PGD
if (!supported) {
supported = supportsHazard(earthquake, attenuations, "0.0", "PGA", true);

if (!supported) {
throw new UnsupportedHazardException(hazardType + " is not supported and cannot be converted to given the defined " +
"earthquake");
}
logger.debug(hazardType + " is not directly supported by the earthquake, using PGA to derive " + hazardType);

SeismicHazardResult result = computeGroundMotionAtSite(earthquake, attenuations, site, "0.0",
"PGA", spectrumOverride, amplifyHazard, creator, userGroups, null);
Double updatedHazardVal = null;
if (result.getHazardValue() != null) {
updatedHazardVal = HazardUtil.convertHazard(result.getHazardValue(), "g", 0.0, HazardUtil.PGA, demandUnits,
HazardUtil.PGD);
}
return new SeismicHazardResult(updatedHazardVal, "0.0", HazardUtil.PGD, demandUnits);
} else {
// Before returning the result, make sure the requested demand unit matches the demand unit produced by the EQ
SeismicHazardResult result = computeGroundMotionAtSite(earthquake, attenuations, site, period, hazardType,
spectrumOverride, amplifyHazard, creator, userGroups, demandUnits);
Double updatedHazardValue = null;
if (result.getHazardValue() != null) {
updatedHazardValue = HazardUtil.convertHazard(result.getHazardValue(), result.getUnits(),
Double.parseDouble(result.getPeriod()), result.getDemand(), demandUnits, result.getDemand());
}

return new SeismicHazardResult(updatedHazardValue, result.getPeriod(), result.getDemand(), demandUnits);
}

} else {
// TODO we need to modify this when we support spectrum methods
boolean supported = supportsHazard(earthquake, attenuations, period, hazardType, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,13 @@ public static double getCorrectUnitsOfPGA(double pga, String units0, String unit
public static double getCorrectUnitsOfPGD(double pgd, String units0, String units1) {
if (units0 != null && units0.equalsIgnoreCase(units1)) {
return pgd;
} else if (units_m.equalsIgnoreCase(units0) || "m".equalsIgnoreCase(units0) && units_ft.equalsIgnoreCase(units1)) {
} else if (units_m.equalsIgnoreCase(units0) || "m".equalsIgnoreCase(units0) && (units_ft.equalsIgnoreCase(units1) || "ft".equalsIgnoreCase(units1))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because we have inconsistent definition of feet vs ft?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there is some inconsistency in the static variable definitions (some are abbreviations and some aren't). Also, I wanted to match that a user could request "m" or "meters" so I made it so a user could request "feet" or with the abbreviation "ft".

return pgd * 3.2808399;
} else if (units_m.equalsIgnoreCase(units0) || "m".equalsIgnoreCase(units0) && units_cm.equalsIgnoreCase(units1)) {
return pgd * 100.0;
} else {
} else if (units_m.equalsIgnoreCase(units0) || "m".equalsIgnoreCase(units0) && units_in.equalsIgnoreCase(units1)) {
return pgd * 39.3701;
} else {
// Unknown type
logger.warn("PGD unit type was " + units0 + ", but no conversion is implemented for units of " + units1);
return pgd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,25 @@ public void testGetValuesFromHazardCalc() throws Exception {
// TODO this should come from a mock eq
Earthquake eq = new EarthquakeModel();
SeismicHazardResult result = HazardCalc.getGroundMotionAtSite(eq, attenuations, site, period, demand, HazardUtil.units_g,
0, true, null, "incrtest", "{\"groups\": [\"incore_user\"]}");
0, true, null, "incrtest", "{\"groups\": [\"incore_user\"]}");

double expected = 0.5322;
assertEquals(expected, result.getHazardValue(), expected * 0.05);
assertEquals(result.getDemand(), HazardUtil.SA);
assertEquals(result.getPeriod(), period);
assertEquals(result.getUnits(), HazardUtil.units_g);

// Test PGD from PGA
period = "0.0";
demand = HazardUtil.PGD;
SeismicHazardResult result_pgd = HazardCalc.getGroundMotionAtSite(eq, attenuations, site, period, demand, HazardUtil.units_in,
0, true, null, "incrtest", "{\"groups\": [\"incore_user\"]}");

double expected_pgd = 3.269564;
assertEquals(expected_pgd, result_pgd.getHazardValue(), expected * 0.05);
assertEquals(result_pgd.getDemand(), HazardUtil.PGD);
assertEquals(result_pgd.getPeriod(), period);
assertEquals(result_pgd.getUnits(), HazardUtil.units_in);
}

@Test
Expand Down
Loading