Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,6 @@ setup.sh
# SMT demo outputs
openquake/smt/demos/outputs_demo_comparison
openquake/smt/demos/outputs_demo_residual_analysis
openquake/smt/demos/outputs_demo_station_analysis
openquake/smt/demos/outputs_demo_station_analysis
pytest.ini
.claude/settings.local.json
10 changes: 7 additions & 3 deletions openquake/bin/wkf_boxcounting_h3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function parse_commandline()
help = "weighting option for events [one, mfd, completeness]"
arg_type = String
default = "one"
"--return_empty_cells", "-e"
help = "if set, include empty cells in the output"
action = :store_true
end

return parse_args(s)
Expand All @@ -53,9 +56,10 @@ function main()
end

# Running boxcounting
PSHAModelBuilder.boxcounting(args["cat"], args["h3_level"],
args["mapping"], args["config"],
args["folder_out"], args["year_end"], args["weighting"]);
PSHAModelBuilder.boxcounting(args["cat"], args["h3_level"],
args["mapping"], args["config"],
args["folder_out"], args["year_end"], args["weighting"];
return_empty_cells=args["return_empty_cells"]);

end

Expand Down
13 changes: 7 additions & 6 deletions openquake/mbi/wkf/distribute_seismicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ def main(
smooth_folder,
config,
folder_out,
eps_b=0.0,
eps_rate=0.0,
fraction_flat=0.0
*,
eps_b: float=0.0,
eps_rate: float=0.0,
fraction_flat: float=0.0
):
"""
Distributes the rates using the output of a seismicity smoothing function.
Expand All @@ -49,9 +50,9 @@ def main(
smooth_folder,
config,
folder_out,
eps_b,
eps_rate,
fraction_flat
eps_b=eps_b,
eps_rate=eps_rate,
fraction_flat=fraction_flat
)

main.smooth_folder = "Folder containing CSV files from smoothing algorithm"
Expand Down
55 changes: 29 additions & 26 deletions openquake/wkf/seismicity/distribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import os
import glob
import math
import logging
import argparse

try:
Expand All @@ -43,12 +44,8 @@


def _distribute_total_rates(
aGR: float,
bGR: float,
fname_in: str,
fname_out: str,
fraction_flat: float
):
aGR: float, bGR: float, fname_in: str, fname_out: str, fraction_flat: float
):
"""
Distributes the seismicity specified by the aGR and bGR parameters
over an irregular grid and writes a .csv with the coordinates of each
Expand Down Expand Up @@ -81,41 +78,43 @@ def _distribute_total_rates(
assert abs(1.0 - weights.sum()) < 1e-10

# Total activity rate
total_activity_rate = (10.0 ** aGR)
total_activity_rate = 10.0**aGR

# Flat contribution
flat_contr = np.full_like(
weights.values,
total_activity_rate * fraction_flat / len(weights.values),
dtype=float
weights.values,
total_activity_rate * fraction_flat / len(weights.values),
dtype=float,
)

# Compute the smoothed seismicity component and add the flat part
aGR_points = np.log10(
total_activity_rate * weights.values * fraction_smooth +
flat_contr)
total_activity_rate * weights.values * fraction_smooth + flat_contr
)
bGR_points = np.full_like(aGR_points, bGR, dtype=float)

# Creating output DataFrame
outdf = pd.DataFrame({
"lon": points_df["lon"],
"lat": points_df["lat"],
"agr": aGR_points,
"bgr": bGR_points
})
outdf = pd.DataFrame(
{
"lon": points_df["lon"],
"lat": points_df["lat"],
"agr": aGR_points,
"bgr": bGR_points,
}
)

# Write output
outdf.to_csv(fname_out, index=False)


def _distribute_rates(
folder_smooth: str,
fname_config: str,
folder_out: str,
eps_b: float = 0.0,
eps_rate: float = 0.0,
fraction_flat: float = 0.0
):
folder_smooth: str,
fname_config: str,
folder_out: str,
eps_b: float = 0.0,
eps_rate: float = 0.0,
fraction_flat: float = 0.0,
):
"""

:param folder_smooth:
Expand Down Expand Up @@ -145,7 +144,11 @@ def _distribute_rates(

# bgr
sigma_b = src_cfg.get("bgr_sig", 0.0)
bgr = src_cfg["bgr"] + sigma_b * eps_b
try:
bgr = src_cfg["bgr"] + sigma_b * eps_b
except KeyError: # not defined perhaps due to low seismicity
logging.warning(f"{source_id} does not have bgr defined")
continue

# If rmag exists → support uncertainty on rate
if "rmag" in src_cfg:
Expand Down
3 changes: 3 additions & 0 deletions openquake/wkf/seismicity/smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def create_smoothing_per_zone(fname_points: str, fname_polygons: str,
if len(use) > 0:
use=get_list(use)

if len(skip) > 0:
skip=get_list(skip)

# Create a geodataframe with the point sources
df = pd.read_csv(fname_points)
gdf = gpd.GeoDataFrame(df.drop(['lon', 'lat'], axis=1), crs='epsg:4326',
Expand Down