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
03d90590
Commit
03d90590
authored
2 years ago
by
Clayton, Brandon Scott
Browse files
Options
Downloads
Patches
Plain Diff
move some to NshmTests
parent
8ea5743a
No related branches found
No related tags found
2 merge requests
!681
Production Release | nshmp-haz
,
!680
NSHM Unit Tests
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java
+19
-73
19 additions, 73 deletions
...t/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java
with
19 additions
and
73 deletions
src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java
+
19
−
73
View file @
03d90590
...
...
@@ -9,11 +9,8 @@ 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
;
...
...
@@ -30,37 +27,12 @@ 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.gmm.Imt
;
import
gov.usgs.earthquake.nshmp.site.NshmpSite
;
import
gov.usgs.earthquake.nshmp.model.NshmTests.Nshm
;
/**
* Utilities to run tests on a NSHM.
*/
class
NshmTestUtils
{
/* Alaska test sites */
private
static
final
List
<
NamedLocation
>
ALASKA_LOCATIONS
=
List
.
of
(
NshmpSite
.
ANCHORAGE_AK
);
/* CONUS test sites */
private
static
final
List
<
NamedLocation
>
CONUS_LOCATIONS
=
List
.
of
(
NshmpSite
.
LOS_ANGELES_CA
,
NshmpSite
.
SAN_FRANCISCO_CA
,
NshmpSite
.
SEATTLE_WA
,
NshmpSite
.
SALT_LAKE_CITY_UT
,
NshmpSite
.
RENO_NV
,
NshmpSite
.
NEW_MADRID_MO
,
NshmpSite
.
BOSTON_MA
,
NshmpSite
.
NEW_YORK_NY
,
NshmpSite
.
CHICAGO_IL
);
/* Hawaii test sites */
private
static
final
List
<
NamedLocation
>
HAWAII_LOCATIONS
=
List
.
of
(
NshmpSite
.
HILO_HI
,
NshmpSite
.
HONOLULU_HI
,
NshmpSite
.
KAILUA_KONA_HI
);
private
static
final
Set
<
Imt
>
IMTS
=
EnumSet
.
of
(
Imt
.
PGA
,
Imt
.
SA0P2
,
Imt
.
SA1P0
,
Imt
.
SA5P0
);
private
static
final
Path
DATA_PATH
=
Paths
.
get
(
"src/test/resources/e2e"
);
private
static
final
double
TOLERANCE
=
1
e
-
12
;
...
...
@@ -69,6 +41,11 @@ class NshmTestUtils {
.
setPrettyPrinting
()
.
create
();
/**
* Generate results for all {@link NSHM}s
*
* Run "./gradlew nshms" to first download all NSHMs
*/
public
static
void
main
(
String
[]
args
)
throws
IOException
{
for
(
Nshm
nshm
:
Nshm
.
values
())
{
/* Initialize and shut down executor to generate results. */
...
...
@@ -86,7 +63,7 @@ class NshmTestUtils {
static
final
void
testNshm
(
Nshm
nshm
)
{
NshmModel
nshmModel
=
loadModel
(
nshm
);
for
(
NamedLocation
location
:
nshm
.
locations
)
{
for
(
NamedLocation
location
:
nshm
.
locations
()
)
{
compareCurves
(
nshmModel
,
location
);
}
...
...
@@ -129,12 +106,13 @@ class NshmTestUtils {
}
}
private
static
Map
<
String
,
XySequence
>
generateActual
(
NshmModel
nshmModel
,
private
static
Map
<
String
,
XySequence
>
generateActual
(
NshmModel
nshmModel
,
NamedLocation
location
)
{
Site
site
=
Site
.
builder
().
location
(
location
.
location
()).
build
();
CalcConfig
config
=
CalcConfig
.
copyOf
(
nshmModel
.
model
.
config
())
.
imts
(
nshmModel
.
nshm
.
imts
)
.
imts
(
nshmModel
.
nshm
.
imts
()
)
.
build
();
Hazard
hazard
=
HazardCalcs
.
hazard
(
...
...
@@ -156,20 +134,14 @@ class NshmTestUtils {
return
new
NshmModel
(
nshm
,
ModelLoader
.
load
(
nshm
.
modelPath
),
ModelLoader
.
load
(
nshm
.
modelPath
()
),
Executors
.
newFixedThreadPool
(
cores
));
}
private
static
String
resultFilename
(
String
modelName
,
int
year
,
NamedLocation
loc
)
{
return
modelName
+
"-"
+
year
+
"-"
+
loc
.
name
()
+
".json"
;
}
private
static
Map
<
String
,
XySequence
>
readExpected
(
NshmModel
nshmModel
,
NamedLocation
loc
)
{
String
filename
=
resultFilename
(
nshmModel
.
nshm
.
modelName
,
nshmModel
.
nshm
.
year
,
loc
);
Path
resultPath
=
DATA_PATH
.
resolve
(
nshmModel
.
nshm
.
modelName
).
resolve
(
filename
);
Path
resultPath
=
DATA_PATH
.
resolve
(
nshmModel
.
nshm
.
modelName
())
.
resolve
(
nshmModel
.
nshm
.
resultFilename
(
loc
));
JsonObject
obj
=
null
;
try
(
BufferedReader
br
=
Files
.
newBufferedReader
(
resultPath
))
{
...
...
@@ -188,24 +160,22 @@ class NshmTestUtils {
}
private
static
void
writeExpecteds
(
NshmModel
nshmModel
)
throws
IOException
{
for
(
NamedLocation
location
:
nshmModel
.
nshm
.
locations
)
{
for
(
NamedLocation
location
:
nshmModel
.
nshm
.
locations
()
)
{
Map
<
String
,
XySequence
>
xyMap
=
generateActual
(
nshmModel
,
location
);
String
json
=
GSON
.
toJson
(
xyMap
);
writeExpected
(
nshmModel
.
nshm
.
modelName
,
nshmModel
.
nshm
.
year
,
location
,
json
);
writeExpected
(
nshmModel
.
nshm
,
location
,
json
);
}
}
private
static
void
writeExpected
(
String
modelName
,
int
year
,
Nshm
nshm
,
NamedLocation
loc
,
String
json
)
throws
IOException
{
String
filename
=
resultFilename
(
modelName
,
year
,
loc
);
Path
modelDir
=
DATA_PATH
.
resolve
(
modelName
);
Path
modelDir
=
DATA_PATH
.
resolve
(
nshm
.
modelName
());
if
(!
Files
.
exists
(
modelDir
))
{
Files
.
createDirectories
(
modelDir
);
}
Path
resultPath
=
modelDir
.
resolve
(
f
ilename
);
Path
resultPath
=
modelDir
.
resolve
(
nshm
.
resultF
ilename
(
loc
)
);
Files
.
write
(
resultPath
,
json
.
getBytes
());
}
...
...
@@ -231,28 +201,4 @@ class NshmTestUtils {
this
.
exec
=
exec
;
}
}
static
enum
Nshm
{
ALASKA_2023
(
"nshm-alaska-3.a.0"
,
ALASKA_LOCATIONS
,
IMTS
),
CONUS_2018
(
"nshm-conus-5.2.0"
,
CONUS_LOCATIONS
,
IMTS
),
CONUS_2023
(
"nshm-conus-6.a.3"
,
CONUS_LOCATIONS
,
IMTS
),
HAWAII_2021
(
"nshm-hawaii-2.0.2"
,
HAWAII_LOCATIONS
,
IMTS
);
private
final
Path
modelPath
;
private
final
String
modelName
;
private
final
List
<
NamedLocation
>
locations
;
private
final
Set
<
Imt
>
imts
;
private
final
int
year
;
Nshm
(
String
modelName
,
List
<
NamedLocation
>
locations
,
Set
<
Imt
>
imts
)
{
this
.
locations
=
locations
;
this
.
imts
=
imts
;
this
.
modelName
=
modelName
;
this
.
modelPath
=
Paths
.
get
(
"nshms"
,
modelName
);
this
.
year
=
Integer
.
parseInt
(
name
().
split
(
"_"
)[
1
]);
}
}
}
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