From bf67011c403fb90a9fbd1159bff936005221ea71 Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Wed, 20 Jun 2018 11:48:46 +1000
Subject: [PATCH] Adds helper function to infer duration and sf

---
 tupak/core/utils.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tupak/core/utils.py b/tupak/core/utils.py
index 3dd360485..a9e220855 100644
--- a/tupak/core/utils.py
+++ b/tupak/core/utils.py
@@ -33,6 +33,31 @@ def get_sampling_frequency(time_series):
         return 1. / (time_series[1] - time_series[0])
 
 
+def get_sampling_frequency_and_duration_from_frequency_array(frequency_array):
+    """
+    Calculate sampling frequency and duration from a frequency array
+
+    Returns
+    -------
+    sampling_frequency, duration:
+
+    Raises
+    -------
+    ValueError: If the frequency_array is not evenly sampled.
+
+    """
+
+    tol = 1e-10
+    if np.ptp(np.diff(frequency_array)) > tol:
+        raise ValueError("Your frequency series was not evenly sampled")
+
+    number_of_frequencies = len(frequency_array)
+    delta_freq = frequency_array[1] - frequency_array[0]
+    duration = 1 / delta_freq
+    sampling_frequency = 2 * number_of_frequencies / duration
+    return sampling_frequency, duration
+
+
 def create_time_series(sampling_frequency, duration, starting_time=0.):
     """
 
-- 
GitLab