Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit fe35db1

Browse files
authored
Merge pull request #1216 from cbworden/realz_data
Realz data
2 parents 9e3bdb8 + 9269fdf commit fe35db1

File tree

5 files changed

+114
-15
lines changed

5 files changed

+114
-15
lines changed

azure-pipelines.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ jobs:
2828
#MacOS_11_Python38:
2929
#imageName: 'macos-11'
3030
#python.version: '3.8'
31+
MacOS_12_Python39:
32+
imageName: 'macos-latest'
33+
python.version: '3.9'
34+
MacOS_12_Python310:
35+
imageName: 'macos-latest'
36+
python.version: '3.10'
3137
MacOS_11_Python39:
3238
imageName: 'macos-11'
3339
python.version: '3.9'
@@ -68,15 +74,18 @@ jobs:
6874
echo "MacOS 10.14"
6975
else
7076
export CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
71-
echo "MacOS 10.15 or MacOS 11"
77+
echo "MacOS 10.15 or MacOS 11 or MacOS 12"
7278
fi
7379
fi
7480
echo $(Agent.NAME)
7581
echo $(python.version)
82+
echo "Conda is " $CONDA " user is " $USER
7683
bash install.sh -p $(python.version)
7784
displayName: Create environment
7885
79-
- bash: conda init bash
86+
- bash: |
87+
echo "##vso[task.prependpath]$CONDA/bin"
88+
conda init bash
8089
displayName: Init conda for bash
8190
8291
- bash: |

install.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ package_list=(
157157
"python=$py_ver"
158158
"$CC_PKG"
159159
"cartopy>=0.20"
160+
"clang>=12.0.1"
160161
"configobj>=5.0.6"
161162
"cython>=0.29.23"
162163
"defusedxml>=0.7.1"
@@ -178,11 +179,11 @@ package_list=(
178179
"ps2ff>=1.5.2"
179180
"psutil>=5.6.7"
180181
"pyproj>=2.6.1"
181-
"pytest>=6.2.4"
182-
"pytest-cov>=2.12.1"
182+
"pytest==6.2.4"
183+
"pytest-azurepipelines==0.8.0"
184+
"pytest-cov==2.12.1"
185+
"pytest-faulthandler==2.0.1"
183186
"python-daemon>=2.3.0"
184-
"pytest-faulthandler>=2.0.1"
185-
"pytest-azurepipelines>=0.8.0"
186187
"pyzmq"
187188
"rasterio>=1.2.5"
188189
"scikit-image>=0.16.2"

setup.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
22
from distutils.core import setup
33
import os.path
4-
import versioneer
4+
5+
# import versioneer
56
from distutils.extension import Extension
67
from Cython.Distutils import build_ext
78
from Cython.Build import cythonize
@@ -13,7 +14,7 @@
1314
if shutil.which("clang") is None:
1415
os.environ["CC"] = "gcc"
1516
else:
16-
os.environ["CC"] = "clang"
17+
os.environ["CC"] = "/usr/bin/clang"
1718

1819
sourcefiles = ["shakemap/c/pcontour.pyx", "shakemap/c/contour.c"]
1920

@@ -37,12 +38,12 @@
3738
),
3839
]
3940

40-
cmdclass = versioneer.get_cmdclass()
41-
cmdclass["build_ext"] = build_ext
41+
# cmdclass = versioneer.get_cmdclass()
42+
# cmdclass["build_ext"] = build_ext
4243

4344
setup(
4445
name="shakemap",
45-
version=versioneer.get_version(),
46+
# version=versioneer.get_version(),
4647
description="USGS Near-Real-Time Ground Motion Mapping",
4748
author="Bruce Worden, Mike Hearne, Eric Thompson",
4849
@@ -93,6 +94,7 @@
9394
"bin/sm_sync",
9495
"bin/fix_netcdf",
9596
],
96-
cmdclass=cmdclass,
97+
# cmdclass=cmdclass,
98+
cmdclass={"build_ext": build_ext},
9799
ext_modules=cythonize(ext_modules),
98100
)

shakemap/coremods/model.py

+40-3
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ def _computeBias(self):
13451345
self.ccf.getCorrelation(t1_22, t2_22, matrix22)
13461346
sta_phi_flat = sta_phi.flatten()
13471347
make_sigma_matrix(matrix22, sta_phi_flat, sta_phi_flat)
1348-
np.fill_diagonal(matrix22, np.diag(matrix22) + sta_sig_extra**2)
1348+
np.fill_diagonal(matrix22, np.diag(matrix22) + sta_sig_extra ** 2)
13491349
cov_WD_WD_inv = np.linalg.pinv(matrix22)
13501350
#
13511351
# Hold on to some things we'll need later
@@ -1508,6 +1508,13 @@ def _computeMVN(self, imtstr):
15081508
self.outsd[imtstr] = pout_sd[0]
15091509
self.outphi[imtstr] = self.psd[imtstr]
15101510
self.outtau[imtstr] = self.tsd[imtstr]
1511+
# Special stuff for the MMI priors. When we make this apply to other
1512+
# IMTs we'll need to mess around with this block
1513+
if imtstr == "MMI":
1514+
self.MMI_add_uncertainty = np.array([])
1515+
self.MMI_Sigma_HH_YD = np.array([])
1516+
self.MMI_C = np.array([])
1517+
self.MMI_sta_per_ix = np.array([])
15111518
return
15121519

15131520
pout_sd2_phi = np.power(self.psd[imtstr], 2.0)
@@ -1554,6 +1561,14 @@ def _computeMVN(self, imtstr):
15541561
sdsta_phi = sta_phi.flatten()
15551562
matrix12_phi = np.empty(t2_12.shape, dtype=np.double)
15561563
rcmatrix_phi = np.empty(t2_12.shape, dtype=np.double)
1564+
# Allocate the full C matrix only for the desired IMT (MMI). This
1565+
# is for generating realizations. Someday we will want to make this
1566+
# apply to other IMTs and become an optional flag for this module
1567+
# where we save the priors optionally
1568+
# Note: We would have to set up C_complete = {} at the top of the
1569+
# module, and then here, it would be C_complete[imtstr] = ...
1570+
if imtstr == "MMI":
1571+
C_complete = np.empty_like(T_Y0)
15571572
for iy in range(self.smny):
15581573
ss = iy * self.smnx
15591574
se = (iy + 1) * self.smnx
@@ -1631,6 +1646,11 @@ def _computeMVN(self, imtstr):
16311646
sdgrid_tau[iy, :] = np.sum(
16321647
np.multiply(C_tmp1, C, out=C_tmp2), out=s_tmp3, axis=1
16331648
)
1649+
# This is where we would have a flag if we were saving the priors
1650+
# as an option
1651+
if imtstr == "MMI":
1652+
# Save C to complete full size C
1653+
C_complete[ss:se, :] = C
16341654

16351655
mtime += time.time() - time4
16361656
#
@@ -1655,6 +1675,14 @@ def _computeMVN(self, imtstr):
16551675
self.outphi[imtstr] = self.psd[imtstr]
16561676
self.outtau[imtstr] = np.sqrt(sdgrid_tau, out=sdgrid_tau)
16571677

1678+
# Special stuff for the MMI priors. When we make this apply to other
1679+
# IMTs we'll need to mess around with this block
1680+
if imtstr == "MMI":
1681+
self.MMI_add_uncertainty = self.sta_sig_extra[imtstr]
1682+
self.MMI_Sigma_HH_YD = self.cov_HH_yD[imtstr]
1683+
self.MMI_C = C_complete
1684+
self.MMI_sta_per_ix = sta_per_ix
1685+
16581686
self.logger.debug(f"\ttime for {imtstr} distance={ddtime:f}")
16591687
self.logger.debug(f"\ttime for {imtstr} correlation={ctime:f}")
16601688
self.logger.debug(f"\ttime for {imtstr} sigma={stime:f}")
@@ -2108,7 +2136,7 @@ def _fillStationJSON(self):
21082136
else:
21092137
mytau = sdf[key + "_tau"][six]
21102138
myphi = sdf[key + "_phi"][six]
2111-
mysigma = np.sqrt(mytau**2 + myphi**2)
2139+
mysigma = np.sqrt(mytau ** 2 + myphi ** 2)
21122140
mysigma_rock = sdf[key + "_sigma_rock"][six]
21132141
mysigma_soil = sdf[key + "_sigma_soil"][six]
21142142
imt_name = key.lower().replace("_pred", "")
@@ -2305,6 +2333,15 @@ def _storeGriddedData(self, oc):
23052333
self.outphi[key],
23062334
self.outtau[key],
23072335
)
2336+
if key == "MMI":
2337+
sub_groups = ["imts", component, key]
2338+
oc.setArray(sub_groups, "add_uncertainty", self.MMI_add_uncertainty)
2339+
oc.setArray(sub_groups, "Sigma_HH_YD", self.MMI_Sigma_HH_YD)
2340+
oc.setArray(sub_groups, "C", self.MMI_C)
2341+
oc.setArray(sub_groups, "sta_per_ix", self.MMI_sta_per_ix)
2342+
oc.setArray(sub_groups, "sta_phi", self.sta_phi["MMI"])
2343+
oc.setArray(sub_groups, "sta_lons_rad", self.sta_lons_rad["MMI"])
2344+
oc.setArray(sub_groups, "sta_lats_rad", self.sta_lats_rad["MMI"])
23082345
#
23092346
# Directivity
23102347
#
@@ -2561,7 +2598,7 @@ def _adjustResolution(self):
25612598
target_res = (
25622599
-(latspan + lonspan)
25632600
- np.sqrt(
2564-
latspan**2 + lonspan**2 + 2 * latspan * lonspan * (2 * nmax - 1)
2601+
latspan ** 2 + lonspan ** 2 + 2 * latspan * lonspan * (2 * nmax - 1)
25652602
)
25662603
) / (2 * (1 - nmax))
25672604

utils/hdf2dict.py

+50
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ def get_result_dict(filename):
4141
'ymax': the maximum latitude of the grid
4242
'ymin': the minimum latitude of the grid
4343
The grids themselves will be of dimension (ny x nx) (rows x cols).
44+
In addition to the above grids, the following arrays will be returned:
45+
'Sigma_HH_YD': A numpy array, see below for possible values.
46+
'Sigma_HH_YD_metadata': This will always be 'None'.
47+
'C': A numpy array, see below for possible values.
48+
'C_metadata': This will always be 'None'.
49+
'add_uncertainty': A numpy array, see below for possible values.
50+
'add_uncertainty_metadata': This will always be 'None'.
51+
'sta_per_ix': A numpy array, see below for possible values.
52+
'sta_per_ix_metadata': This will always be 'None'.
53+
These arrays will have the following contents:
54+
'None': If this function is run on an older version of shake_results.hdf
55+
that was produced by model.py before it generated the output
56+
needed to produce these arrays.
57+
'[]': I.e., empty arrays. When the shakemap contained no input station data
58+
sufficient to generate the arrays.
59+
...: Arrays of shapes appropriate to the input and output data dimensions.
60+
It is incumbent upon the user to make proper use of these arrays.
4461
"""
4562
ddict = {}
4663
hdfobj = h5py.File(filename, "r+")
@@ -52,6 +69,21 @@ def get_result_dict(filename):
5269
for key, value in dset.attrs.items():
5370
metadata[key] = value
5471
ddict[name + "_metadata"] = metadata
72+
for name in (
73+
"add_uncertainty",
74+
"Sigma_HH_YD",
75+
"C",
76+
"sta_per_ix",
77+
"sta_phi",
78+
"sta_lons_rad",
79+
"sta_lats_rad",
80+
):
81+
ddict[name + "_metadata"] = None
82+
try:
83+
dset = group[name]
84+
ddict[name] = dset[()].astype(np.float64)
85+
except Exception:
86+
ddict[name] = None
5587

5688
hdfobj.close()
5789
return ddict
@@ -63,6 +95,24 @@ def get_result_dict(filename):
6395

6496
print("ddict keys: ", ddict.keys())
6597
print()
98+
for key in ddict.keys():
99+
if ddict[key] is None:
100+
print(f"ddict {key} is None")
101+
for name in ("mean", "std", "phi", "tau"):
102+
print(f"{name} shape is {(ddict[name].shape)}")
103+
for key in (
104+
"add_uncertainty",
105+
"Sigma_HH_YD",
106+
"C",
107+
"sta_per_ix",
108+
"sta_phi",
109+
"sta_lons_rad",
110+
"sta_lats_rad",
111+
):
112+
if ddict[key] is None:
113+
print(f"{key} shape is None")
114+
else:
115+
print(f"{key} shape is {(ddict[key].shape)}")
66116
print("Metadata:")
67117
print(ddict["mean_metadata"].items())
68118
print()

0 commit comments

Comments
 (0)