Last active
May 3, 2023 08:42
-
-
Save breinbaas/36da19a6bc306d42b206b19b7215db9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Union, Optional | |
from pathlib import Path | |
import sys | |
# 'Hack' to add the geolib path so Python can find the adjusted geolib code | |
PATH_TO_ADJUSTED_GEOLIB = r"D:\Documents\Development\Github\GEOLib" | |
if not PATH_TO_ADJUSTED_GEOLIB in sys.path: | |
sys.path.append(PATH_TO_ADJUSTED_GEOLIB) | |
import geolib as gl | |
from geolib.models.dstability.internal import AnalysisTypeEnum | |
def calculate_stix(stixfile: Union[str, Path]) -> Optional[float]: | |
m = gl.DStabilityModel() | |
try: | |
m.parse(Path(stixfile)) | |
except Exception as e: | |
raise ValueError( | |
f"Could not open file '{stixfile}' for reading. Got error '{e}'" | |
) | |
m.execute() | |
analysis_type = m.datastructure.calculationsettings[0].AnalysisType | |
if analysis_type in [ | |
AnalysisTypeEnum.BISHOP_BRUTE_FORCE, | |
AnalysisTypeEnum.SPENCER_GENETIC, | |
AnalysisTypeEnum.UPLIFT_VAN_PARTICLE_SWARM | |
]: | |
fos = m.output[0].FactorOfSafety | |
else: | |
raise ValueError(f"Unhandled model, we only extract the FOS from Bishop Brute Force, Spencer Genetic Algorithm and Uplift Van Particle Swarm.") | |
return fos | |
def test(): | |
print("Testing bishop brute force...") | |
assert round(calculate_stix("./testdata/A147_0230_bbf.stix"), 3) == 1.098 | |
print("Succes") | |
print("Testing spencer genetic algorithm...") | |
assert round(calculate_stix("./testdata/A147_0230_sga.stix"), 3) == 1.723 | |
print("Succes") | |
print("Testing uplift van particle swarm...") | |
assert round(calculate_stix("./testdata/A147_0230_ups.stix"), 3) == 1.093 | |
print("Succes") | |
if __name__ == "__main__": | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment