Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nshmp-ws-static
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-ws-static
Commits
dfe35955
Commit
dfe35955
authored
3 years ago
by
Clayton, Brandon Scott
Browse files
Options
Downloads
Patches
Plain Diff
Add prescision
parent
1af197bc
No related branches found
No related tags found
2 merge requests
!109
Production Release
,
!107
AASHTO Updates
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/NetcdfUtils.java
+18
-63
18 additions, 63 deletions
.../gov/usgs/earthquake/nshmp/netcdf/reader/NetcdfUtils.java
with
18 additions
and
63 deletions
src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/NetcdfUtils.java
+
18
−
63
View file @
dfe35955
package
gov.usgs.earthquake.nshmp.netcdf.reader
;
package
gov.usgs.earthquake.nshmp.netcdf.reader
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkArgument
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkState
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkState
;
...
@@ -9,17 +8,24 @@ import java.util.Arrays;
...
@@ -9,17 +8,24 @@ import java.util.Arrays;
import
com.google.common.math.DoubleMath
;
import
com.google.common.math.DoubleMath
;
import
gov.usgs.earthquake.nshmp.Maths
;
import
gov.usgs.earthquake.nshmp.data.XySequence
;
import
gov.usgs.earthquake.nshmp.data.XySequence
;
import
gov.usgs.earthquake.nshmp.geo.Location
;
import
gov.usgs.earthquake.nshmp.geo.LocationList
;
import
gov.usgs.earthquake.nshmp.geo.LocationList
;
import
gov.usgs.earthquake.nshmp.netcdf.data.BoundingData
;
import
gov.usgs.earthquake.nshmp.netcdf.data.StaticData
;
import
ucar.ma2.DataType
;
import
ucar.ma2.DataType
;
import
ucar.nc2.Group
;
import
ucar.nc2.Group
;
public
class
NetcdfUtils
{
public
class
NetcdfUtils
{
/** TODO: Have this be dynamic from NetCDF file */
public
static
final
int
LOCATION_PRECISION
=
3
;
/** TODO: Have this be dynamic from NetCDF file */
public
static
final
int
GROUND_MOTION_PRECISION
=
3
;
/** TODO: Have this be dynamic from NetCDF file */
public
static
final
int
HAZARD_PRECISION
=
5
;
// Tolerance for longitude/latitude comparisons
// Tolerance for longitude/latitude comparisons
static
final
double
LOCATION_TOLERANCE
=
0.000001
;
static
final
double
LOCATION_TOLERANCE
=
0.000001
;
...
@@ -76,38 +82,6 @@ public class NetcdfUtils {
...
@@ -76,38 +82,6 @@ public class NetcdfUtils {
return
calcFrac
(
a
[
i
],
a
[
i
+
1
],
t
);
return
calcFrac
(
a
[
i
],
a
[
i
+
1
],
t
);
}
}
/**
* Check whether bounding ground motions contain the same: Site classes, IMTs
* per each site class, and ground motions.
*
* @param a static data A
* @param b static B
*/
static
void
checkBoundingGroundMotion
(
StaticData
<
XySequence
>
a
,
StaticData
<
XySequence
>
b
)
{
checkState
(
a
.
size
()
==
b
.
size
(),
"Maps are not the same size"
);
checkState
(
a
.
keySet
().
containsAll
(
b
.
keySet
()),
"Site classes do not match"
);
a
.
keySet
().
forEach
(
key
->
checkXySequence
(
a
.
get
(
key
),
b
.
get
(
key
)));
}
/**
* Checks bounding hazard maps contain the same: Site classes, IMTs per each
* site class, and ground motions per each IMT
*
* @param boundingData The bounding ground motions
*/
static
void
checkBoundingGroundMotions
(
BoundingData
<
XySequence
>
boundingData
,
Location
location
)
{
checkArgument
(
boundingData
.
containsKey
(
location
),
"Location not in bounding hazards"
);
boundingData
.
keySet
().
stream
()
.
filter
(
loc
->
loc
.
equals
(
location
))
.
forEach
(
key
->
{
checkBoundingGroundMotion
(
boundingData
.
get
(
location
),
boundingData
.
get
(
key
));
});
}
/**
/**
* Check that the X values are identical.
* Check that the X values are identical.
*
*
...
@@ -120,6 +94,14 @@ public class NetcdfUtils {
...
@@ -120,6 +94,14 @@ public class NetcdfUtils {
"Hazard curves xValues are not the same"
);
"Hazard curves xValues are not the same"
);
}
}
static
XySequence
cleanData
(
XySequence
data
,
int
precision
)
{
var
xs
=
data
.
xValues
().
map
(
x
->
Double
.
isNaN
(
x
)
?
x
:
Maths
.
roundToDigits
(
x
,
precision
)).
toArray
();
var
ys
=
data
.
yValues
().
map
(
y
->
Double
.
isNaN
(
y
)
?
y
:
Maths
.
roundToDigits
(
y
,
precision
)).
toArray
();
return
XySequence
.
create
(
xs
,
ys
);
}
/**
/**
* Get a 1D array from a netCDF group.
* Get a 1D array from a netCDF group.
*
*
...
@@ -208,33 +190,6 @@ public class NetcdfUtils {
...
@@ -208,33 +190,6 @@ public class NetcdfUtils {
return
(
String
[])
get1DArray
(
group
,
key
,
DataType
.
STRING
);
return
(
String
[])
get1DArray
(
group
,
key
,
DataType
.
STRING
);
}
}
/*
* Linear interpolation of data values to a target point
*/
static
StaticData
<
XySequence
>
linearInterpolateGroundMotions
(
StaticData
<
XySequence
>
v1
,
StaticData
<
XySequence
>
v2
,
double
frac
)
{
checkBoundingGroundMotion
(
v1
,
v2
);
var
targetMap
=
StaticData
.<
XySequence
>
builder
();
v1
.
keySet
().
forEach
(
siteClass
->
{
var
v1Data
=
v1
.
get
(
siteClass
).
yValues
().
toArray
();
var
v2Data
=
v2
.
get
(
siteClass
).
yValues
().
toArray
();
var
target
=
new
double
[
v1Data
.
length
];
for
(
int
i
=
0
;
i
<
v1Data
.
length
;
i
++)
{
target
[
i
]
=
v1Data
[
i
]
*
(
1
-
frac
)
+
v2Data
[
i
]
*
frac
;
}
var
xValues
=
v1
.
get
(
siteClass
).
xValues
().
toArray
();
targetMap
.
put
(
siteClass
,
XySequence
.
create
(
xValues
,
target
));
});
return
targetMap
.
build
();
}
public
static
class
Key
{
public
static
class
Key
{
public
static
final
String
DESCRIPTION
=
"description"
;
public
static
final
String
DESCRIPTION
=
"description"
;
public
static
final
String
GRID_STEP
=
"gridStep"
;
public
static
final
String
GRID_STEP
=
"gridStep"
;
...
...
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