Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nshmp-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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-lib
Commits
c2c106c1
Commit
c2c106c1
authored
4 years ago
by
Powers, Peter M.
Browse files
Options
Downloads
Patches
Plain Diff
tapered GR mfd temp fix
parent
a14e884e
No related branches found
No related tags found
1 merge request
!140
Lib work
Pipeline
#29466
passed
4 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/gov/usgs/earthquake/nshmp/mfd/Mfd.java
+31
-0
31 additions, 0 deletions
src/main/java/gov/usgs/earthquake/nshmp/mfd/Mfd.java
src/test/java/gov/usgs/earthquake/nshmp/mfd/MfdTests.java
+95
-1
95 additions, 1 deletion
src/test/java/gov/usgs/earthquake/nshmp/mfd/MfdTests.java
with
126 additions
and
1 deletion
src/main/java/gov/usgs/earthquake/nshmp/mfd/Mfd.java
+
31
−
0
View file @
c2c106c1
...
@@ -27,6 +27,7 @@ import gov.usgs.earthquake.nshmp.data.MutableXySequence;
...
@@ -27,6 +27,7 @@ import gov.usgs.earthquake.nshmp.data.MutableXySequence;
import
gov.usgs.earthquake.nshmp.data.Sequences
;
import
gov.usgs.earthquake.nshmp.data.Sequences
;
import
gov.usgs.earthquake.nshmp.data.XyPoint
;
import
gov.usgs.earthquake.nshmp.data.XyPoint
;
import
gov.usgs.earthquake.nshmp.data.XySequence
;
import
gov.usgs.earthquake.nshmp.data.XySequence
;
import
gov.usgs.earthquake.nshmp.mfd.Mfd.Properties.TaperedGr
;
/**
/**
* Entry point for creating a magnitude frequency distribution (MFD). An MFD
* Entry point for creating a magnitude frequency distribution (MFD). An MFD
...
@@ -429,6 +430,10 @@ public final class Mfd {
...
@@ -429,6 +430,10 @@ public final class Mfd {
* @return this {@code Builder} object
* @return this {@code Builder} object
*/
*/
public
Builder
scaleToIncrementalRate
(
double
incrementalRate
)
{
public
Builder
scaleToIncrementalRate
(
double
incrementalRate
)
{
// TODO remove (needs sensitivity testing)
if
(
props
.
type
==
Type
.
GR_TAPER
)
{
return
TaperedGr
.
taperCorrection
(
this
,
incrementalRate
);
}
return
scale
(
checkRate
(
incrementalRate
)
/
mfd
.
y
(
0
));
return
scale
(
checkRate
(
incrementalRate
)
/
mfd
.
y
(
0
));
}
}
...
@@ -453,6 +458,7 @@ public final class Mfd {
...
@@ -453,6 +458,7 @@ public final class Mfd {
mfd
.
transform
(
checkNotNull
(
action
));
mfd
.
transform
(
checkNotNull
(
action
));
return
this
;
return
this
;
}
}
}
}
/**
/**
...
@@ -779,6 +785,13 @@ public final class Mfd {
...
@@ -779,6 +785,13 @@ public final class Mfd {
* directly with a given a-value and by creating a generic taperd MFD
* directly with a given a-value and by creating a generic taperd MFD
* that we then scaleToIncrementalRate() using the given a-value, we
* that we then scaleToIncrementalRate() using the given a-value, we
* correct the tapered MFD by the offset.
* correct the tapered MFD by the offset.
*
* Now, this is how we wished the nshmp-haz implementation behaved, but
* since it doesn't we need an intermediate solution to match nshmp-haz
* until further sensitivity testing through to hazard can be
* undertaken. What we want: after calling scaleToIncrementalRate(), the
* tapered GR MFD rates should match those that would've resulted from
* the direct calculation.
*/
*/
double
grRate
=
Mfds
.
gutenbergRichterRate
(
a
(),
b
(),
builder
.
mfd
.
x
(
0
));
double
grRate
=
Mfds
.
gutenbergRichterRate
(
a
(),
b
(),
builder
.
mfd
.
x
(
0
));
double
tgrRate
=
builder
.
mfd
.
y
(
0
);
double
tgrRate
=
builder
.
mfd
.
y
(
0
);
...
@@ -798,6 +811,24 @@ public final class Mfd {
...
@@ -798,6 +811,24 @@ public final class Mfd {
type
(),
type
(),
super
.
propsString
()
+
", mc="
+
mc
);
super
.
propsString
()
+
", mc="
+
mc
);
}
}
/*
* TODO clean after sensitivity testing for tapered rates when calling
* scale toIncrementalRate() tapered GR values become exact matches to the
* target rate as opposed to the slightly scaled rate resulting from
* creating the tapered GR directly with a given a-value. We want to
* replicate nshmp-haz behavior for now but get rid of it in the not too
* distant future. This is basically reverting the scaling correction
* applied in the builder.
*/
private
static
Builder
taperCorrection
(
Builder
b
,
double
rate
)
{
TaperedGr
p
=
b
.
props
.
getAsGrTaper
();
TaperFunction
taperFn
=
new
TaperFunction
(
p
.
Δm
(),
p
.
b
(),
p
.
mc
);
double
mMin
=
b
.
mfd
.
x
(
0
);
double
taperRate
=
checkRate
(
rate
)
*
taperFn
.
scale
(
mMin
);
return
b
.
scale
(
taperRate
/
b
.
mfd
.
y
(
0
));
}
}
}
private
static
final
double
M_MIN_MOMENT
=
Earthquakes
.
magToMoment
(
4.0
);
private
static
final
double
M_MIN_MOMENT
=
Earthquakes
.
magToMoment
(
4.0
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/gov/usgs/earthquake/nshmp/mfd/MfdTests.java
+
95
−
1
View file @
c2c106c1
...
@@ -10,6 +10,7 @@ import java.io.IOException;
...
@@ -10,6 +10,7 @@ import java.io.IOException;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.util.Arrays
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
...
@@ -202,6 +203,66 @@ class MfdTests {
...
@@ -202,6 +203,66 @@ class MfdTests {
grProps
.
toString
());
grProps
.
toString
());
}
}
/*
* TODO clean
*
* TODO something in the TaperedGR moment based scaling leads to differences
* in the 4th to 5th significant figure that should be better understood, and
* then this main method cleaned out. The results are still pretty close
* overall.
*/
public
static
void
main
(
String
[]
args
)
{
double
bVal
=
0.8
;
double
aVal
=
Math
.
log10
(
4.0
);
double
Δm
=
0.1
;
double
mMin
=
5.0
;
double
mMax
=
8.0
;
double
mc
=
7.5
;
// /* GR direct vs scaled builder comparison */
// System.out.println("Gutenberg Richter");
// Mfd mfd = new GutenbergRichter(aVal, bVal, Δm, mMin, mMax)
// .toBuilder()
// .build();
//
// System.out.println(Arrays.toString(mfd.data().xValues().toArray()));
// System.out.println(Arrays.toString(mfd.data().yValues().toArray()));
//
// double incrRate = Mfds.gutenbergRichterRate(aVal, bVal, 5.05);
// mfd = Mfd.newGutenbergRichterBuilder(bVal, Δm, mMin, mMax)
// .scaleToIncrementalRate(incrRate)
// .build();
//
// System.out.println(Arrays.toString(mfd.data().yValues().toArray()));
/* GR direct vs scaled builder comparison */
System
.
out
.
println
(
"Tapered Gutenberg Richter"
);
Mfd
mfd
=
new
TaperedGr
(
aVal
,
bVal
,
Δm
,
mMin
,
mMax
,
mc
)
.
toBuilder
()
.
build
();
double
[]
directRates
=
mfd
.
data
().
yValues
().
toArray
();
System
.
out
.
println
(
Arrays
.
toString
(
mfd
.
data
().
xValues
().
toArray
()));
System
.
out
.
println
(
Arrays
.
toString
(
directRates
));
double
incrRate
=
Mfds
.
gutenbergRichterRate
(
aVal
,
bVal
,
5.05
);
mfd
=
Mfd
.
newTaperedGutenbergRichterBuilder
(
bVal
,
Δm
,
mMin
,
mMax
,
mc
)
.
scaleToIncrementalRate
(
incrRate
)
.
build
();
double
[]
scaledRates
=
mfd
.
data
().
yValues
().
toArray
();
System
.
out
.
println
(
Arrays
.
toString
(
scaledRates
));
int
size
=
directRates
.
length
;
double
[]
ratios
=
new
double
[
size
];
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
double
ratio
=
100.0
*
(
directRates
[
i
]
/
scaledRates
[
i
]);
ratios
[
i
]
=
ratio
;
}
System
.
out
.
println
(
Arrays
.
toString
(
ratios
));
}
private
static
final
double
[]
TAPERED_GR_M
=
{
private
static
final
double
[]
TAPERED_GR_M
=
{
5.05
,
5.15
,
5.25
,
5.35
,
5.45
,
5.05
,
5.15
,
5.25
,
5.35
,
5.45
,
5.55
,
5.65
,
5.75
,
5.85
,
5.95
,
5.55
,
5.65
,
5.75
,
5.85
,
5.95
,
...
@@ -243,6 +304,39 @@ class MfdTests {
...
@@ -243,6 +304,39 @@ class MfdTests {
5.437829885686743
E
-
7
,
5.437829885686743
E
-
7
,
1.5949675112240326
E
-
7
};
1.5949675112240326
E
-
7
};
/* TODO These match nshmp-haz and should be removed */
private
static
final
double
[]
TAPERED_GR_R_TEMP
=
{
3.648734771264746
E
-
4
,
3.0351155247723867
E
-
4
,
2.5247694248332143
E
-
4
,
2.1003291504182058
E
-
4
,
1.7473503715378214
E
-
4
,
1.4538201763727166
E
-
4
,
1.2097482132130438
E
-
4
,
1.0068266229609009
E
-
4
,
8.381471718000333
E
-
5
,
6.979659287661517
E
-
5
,
5.815074326255645
E
-
5
,
4.848016071724236
E
-
5
,
4.0454775273297684
E
-
5
,
3.3800079282566184
E
-
5
,
2.8287560844165223
E
-
5
,
2.3726576420233305
E
-
5
,
1.9957324528955872
E
-
5
,
1.6844604598702632
E
-
5
,
1.4272075425536471
E
-
5
,
1.213680849238659
E
-
5
,
1.0344152445466782
E
-
5
,
8.803445832444013
E
-
6
,
7.426137715686031
E
-
6
,
6.1294171417451564
E
-
6
,
4.849632254896957
E
-
6
,
3.5675342487878286
E
-
6
,
2.3362943546550987
E
-
6
,
1.2825840184413834
E
-
6
,
5.438860517858617
E
-
7
,
1.5952698054966957
E
-
7
};
@Test
@Test
void
testTaperedGr
()
{
void
testTaperedGr
()
{
...
@@ -262,7 +356,7 @@ class MfdTests {
...
@@ -262,7 +356,7 @@ class MfdTests {
assertTrue
(
xy
.
size
()
==
30
);
assertTrue
(
xy
.
size
()
==
30
);
assertArrayEquals
(
TAPERED_GR_M
,
xy
.
xValues
().
toArray
());
assertArrayEquals
(
TAPERED_GR_M
,
xy
.
xValues
().
toArray
());
/* These end up being very slightly different due to scaling */
/* These end up being very slightly different due to scaling */
assertArrayEquals
(
TAPERED_GR_R
,
xy
.
yValues
().
toArray
(),
1
e
-
17
);
assertArrayEquals
(
TAPERED_GR_R
_TEMP
,
xy
.
yValues
().
toArray
(),
1
e
-
17
);
/* Properties */
/* Properties */
Properties
props
=
new
TaperedGr
(
aVal
,
bVal
,
Δm
,
mMin
,
mMax
,
mc
);
Properties
props
=
new
TaperedGr
(
aVal
,
bVal
,
Δm
,
mMin
,
mMax
,
mc
);
...
...
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