From a464095f2a6690e0c4cad19a527a38aba4644220 Mon Sep 17 00:00:00 2001 From: Claudio Satriano Date: Fri, 5 Apr 2024 13:06:25 +0200 Subject: [PATCH] `print_families`: determine duration units based on average duration --- CHANGELOG.md | 1 + requake/families/print_families.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52800e6..895ffc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Copyright (c) 2021-2024 Claudio Satriano - Filter catalog files on reading using the criteria in the config file - Improved time axes in `plot_timespans` and `plot_slip` for short time intervals +- `print_families`: autoset duration units based on the average duration ## v0.4.1 - 2024-03-11 diff --git a/requake/families/print_families.py b/requake/families/print_families.py index d2ca04a..ed8957b 100644 --- a/requake/families/print_families.py +++ b/requake/families/print_families.py @@ -33,6 +33,19 @@ def print_families(config): logger.error(msg) rq_exit(1) + # determine duration units + average_duration = np.mean([f.duration for f in families]) + avg_duration_in_days = average_duration * 365 + if 30 < avg_duration_in_days < 365: + duration_multiplier = 12 + duration_units = 'm' + elif 1 < avg_duration_in_days < 30: + duration_multiplier = 365 + duration_units = 'd' + elif avg_duration_in_days < 1: + duration_multiplier = 365 * 24 + duration_units = 'h' + headers = [ 'family', 'nevents', @@ -41,7 +54,7 @@ def print_families(config): 'depth (km)', 'start time', 'end time', - 'duration (y)', + f'duration ({duration_units})', 'slip rate (cm/y)' ] table = [] @@ -58,7 +71,7 @@ def print_families(config): family.depth, family.starttime, family.endtime, - family.duration + family.duration*duration_multiplier ] slip = [mag_to_slip_in_cm(config, ev.mag) for ev in family] cum_slip = np.cumsum(slip)