Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nshmp-haz
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ghsc
National Seismic Hazard Model Project
nshmp-haz
Commits
3577fbf9
Commit
3577fbf9
authored
3 years ago
by
Powers, Peter M.
Browse files
Options
Downloads
Patches
Plain Diff
parameterized tests
parent
e5abf450
No related branches found
No related tags found
2 merge requests
!611
Production Release | nshmp-haz
,
!604
Nshm repo domain review
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestsLarge.java
+53
-48
53 additions, 48 deletions
.../java/gov/usgs/earthquake/nshmp/model/NshmTestsLarge.java
with
53 additions
and
48 deletions
src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestsLarge.java
+
53
−
48
View file @
3577fbf9
package
gov.usgs.earthquake.nshmp.model
;
import
static
gov
.
usgs
.
earthquake
.
nshmp
.
gmm
.
Imt
.
PGA
;
import
static
gov
.
usgs
.
earthquake
.
nshmp
.
gmm
.
Imt
.
SA0P2
;
import
static
gov
.
usgs
.
earthquake
.
nshmp
.
gmm
.
Imt
.
SA1P0
;
import
static
gov
.
usgs
.
earthquake
.
nshmp
.
gmm
.
Imt
.
SA5P0
;
import
static
gov
.
usgs
.
earthquake
.
nshmp
.
site
.
NshmpSite
.
BOSTON_MA
;
import
static
gov
.
usgs
.
earthquake
.
nshmp
.
site
.
NshmpSite
.
CHICAGO_IL
;
import
static
gov
.
usgs
.
earthquake
.
nshmp
.
site
.
NshmpSite
.
LOS_ANGELES_CA
;
...
...
@@ -11,7 +15,6 @@ import static gov.usgs.earthquake.nshmp.site.NshmpSite.SAN_FRANCISCO_CA;
import
static
gov
.
usgs
.
earthquake
.
nshmp
.
site
.
NshmpSite
.
SEATTLE_WA
;
import
static
java
.
lang
.
Math
.
abs
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertArrayEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
java.io.BufferedReader
;
...
...
@@ -20,16 +23,20 @@ import java.lang.reflect.Type;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.EnumSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
org.junit.jupiter.api.AfterAll
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.MethodSource
;
import
com.google.common.reflect.TypeToken
;
import
com.google.gson.Gson
;
...
...
@@ -38,10 +45,13 @@ import com.google.gson.JsonObject;
import
com.google.gson.JsonParser
;
import
gov.usgs.earthquake.nshmp.NamedLocation
;
import
gov.usgs.earthquake.nshmp.calc.CalcConfig
;
import
gov.usgs.earthquake.nshmp.calc.Hazard
;
import
gov.usgs.earthquake.nshmp.calc.HazardCalcs
;
import
gov.usgs.earthquake.nshmp.calc.Site
;
import
gov.usgs.earthquake.nshmp.data.XySequence
;
import
gov.usgs.earthquake.nshmp.geo.Location
;
import
gov.usgs.earthquake.nshmp.gmm.Imt
;
/**
* Class for end-to-end tests of hazard calculations. These tests require
...
...
@@ -67,61 +77,59 @@ class NshmTestsLarge {
NEW_YORK_NY
,
CHICAGO_IL
);
/*
* These tests use project relative file paths to read/write directly to/from
* the source tree.
*/
private
static
final
Set
<
Imt
>
IMTS
=
EnumSet
.
of
(
PGA
,
SA0P2
,
SA1P0
,
SA5P0
);
private
static
final
String
MODEL_NAME
=
"nshm-conus"
;
private
static
final
int
MODEL_YEAR
=
2018
;
private
static
final
Path
MODEL_PATH
=
Paths
.
get
(
"../"
+
MODEL_NAME
);
private
static
final
Path
DATA_PATH
=
Paths
.
get
(
"src/test/resources/e2e"
);
private
static
final
Gson
GSON
=
new
GsonBuilder
()
.
setPrettyPrinting
()
.
create
();
private
static
ExecutorService
EXEC
;
private
static
ExecutorService
exec
;
private
static
HazardModel
model
;
static
Map
<
Location
,
Map
<
String
,
XySequence
>>
expecteds
;
@BeforeAll
static
void
setUpBeforeClass
()
{
model
=
ModelLoader
.
load
(
MODEL_PATH
);
int
cores
=
Runtime
.
getRuntime
().
availableProcessors
();
EXEC
=
Executors
.
newFixedThreadPool
(
cores
);
exec
=
Executors
.
newFixedThreadPool
(
cores
);
}
@AfterAll
static
void
tearDownAfterClass
()
{
EXEC
.
shutdown
();
exec
.
shutdown
();
}
private
static
final
Path
MODEL_PATH
=
Paths
.
get
(
"../"
);
private
static
final
Path
DATA_PATH
=
Paths
.
get
(
"src/test/resources/e2e"
);
@Test
public
void
testConus2018
()
{
testModel
(
"nshm-conus"
,
2018
,
CONUS_SITES
);
@ParameterizedTest
@MethodSource
(
"siteStream"
)
final
void
testLocation
(
NamedLocation
site
)
{
compareCurves
(
site
);
}
private
static
void
testModel
(
String
modelName
,
int
year
,
List
<
NamedLocation
>
locations
)
{
Path
modelPath
=
MODEL_PATH
.
resolve
(
modelName
);
HazardModel
model
=
ModelLoader
.
load
(
modelPath
);
for
(
NamedLocation
location
:
locations
)
{
compareCurves
(
modelName
,
year
,
model
,
location
);
}
private
static
Stream
<
NamedLocation
>
siteStream
()
{
return
CONUS_SITES
.
stream
();
}
private
static
void
compareCurves
(
String
modelName
,
int
year
,
HazardModel
model
,
NamedLocation
location
)
{
private
static
void
compareCurves
(
NamedLocation
location
)
{
System
.
out
.
println
(
location
);
// String actual = generateActual(model, location);
Map
<
String
,
XySequence
>
actual
=
generateActual
(
model
,
location
);
Map
<
String
,
XySequence
>
actual
=
generateActual
(
location
);
// String expected = readExpected(modelName, year, location);
Map
<
String
,
XySequence
>
expected
=
readExpected
(
modelName
,
year
,
location
);
Map
<
String
,
XySequence
>
expected
=
readExpected
(
location
);
// assertEquals(expected, actual);
assertEquals
(
expected
.
keySet
(),
actual
.
keySet
());
for
(
String
key
:
expected
.
keySet
())
{
// assertEquals(expected.keySet(), actual.keySet());
for
(
String
key
:
actual
.
keySet
())
{
System
.
out
.
println
(
key
);
System
.
out
.
println
(
actual
.
get
(
key
));
}
for
(
String
key
:
actual
.
keySet
())
{
System
.
out
.
println
(
key
);
assertCurveEquals
(
expected
.
get
(
key
),
actual
.
get
(
key
),
TOLERANCE
);
}
}
...
...
@@ -153,17 +161,19 @@ class NshmTestsLarge {
Double
.
valueOf
(
expected
).
equals
(
Double
.
valueOf
(
actual
));
}
private
static
Map
<
String
,
XySequence
>
generateActual
(
HazardModel
model
,
NamedLocation
location
)
{
private
static
Map
<
String
,
XySequence
>
generateActual
(
NamedLocation
location
)
{
Site
site
=
Site
.
builder
().
location
(
location
.
location
()).
build
();
CalcConfig
config
=
CalcConfig
.
copyOf
(
model
.
config
())
.
imts
(
IMTS
)
.
build
();
Hazard
hazard
=
HazardCalcs
.
hazard
(
model
,
model
.
config
()
,
config
,
site
,
EXEC
);
exec
);
Map
<
String
,
XySequence
>
xyMap
=
hazard
.
curves
().
entrySet
().
stream
()
.
collect
(
Collectors
.
toMap
(
...
...
@@ -171,7 +181,6 @@ class NshmTestsLarge {
Entry:
:
getValue
));
return
xyMap
;
// return GSON.toJson(hazard.curves());
}
private
static
String
resultFilename
(
...
...
@@ -182,12 +191,9 @@ class NshmTestsLarge {
return
modelName
+
"-"
+
year
+
"-"
+
loc
.
name
()
+
".json"
;
}
private
static
Map
<
String
,
XySequence
>
readExpected
(
String
modelName
,
int
year
,
NamedLocation
loc
)
{
private
static
Map
<
String
,
XySequence
>
readExpected
(
NamedLocation
loc
)
{
String
filename
=
resultFilename
(
modelName
,
year
,
loc
);
String
filename
=
resultFilename
(
MODEL_NAME
,
MODEL_YEAR
,
loc
);
Path
resultPath
=
DATA_PATH
.
resolve
(
filename
);
JsonObject
obj
=
null
;
...
...
@@ -210,6 +216,7 @@ class NshmTestsLarge {
double
[]
xs
;
double
[]
ys
;
@SuppressWarnings
(
"unused"
)
Curve
(
double
[]
xs
,
double
[]
ys
)
{
this
.
xs
=
xs
;
this
.
ys
=
ys
;
...
...
@@ -221,11 +228,9 @@ class NshmTestsLarge {
int
year
,
List
<
NamedLocation
>
locations
)
throws
IOException
{
Path
modelPath
=
MODEL_PATH
.
resolve
(
modelName
);
HazardModel
model
=
ModelLoader
.
load
(
modelPath
);
for
(
NamedLocation
location
:
locations
)
{
// String json = generateActual(model, location);
Map
<
String
,
XySequence
>
xyMap
=
generateActual
(
model
,
location
);
Map
<
String
,
XySequence
>
xyMap
=
generateActual
(
location
);
String
json
=
GSON
.
toJson
(
xyMap
);
writeExpected
(
modelName
,
year
,
location
,
json
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment