From caac3d80de343ee1b9375bc2ea8dc8532cf030bd Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Tue, 3 Jul 2018 11:51:58 +1000
Subject: [PATCH] Adds methods to set from a CSV file

---
 tupak/gw/detector.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/tupak/gw/detector.py b/tupak/gw/detector.py
index 5895119ee..97a319f92 100644
--- a/tupak/gw/detector.py
+++ b/tupak/gw/detector.py
@@ -408,7 +408,7 @@ class InterferometerStrainData(object):
     def set_from_open_data(
             self, name, start_time, duration=4, outdir='outdir', cache=True,
             **kwargs):
-        """ Set the strain data from a open LOSC data
+        """ Set the strain data from open LOSC data
 
         This sets the time_domain_strain attribute, the frequency_domain_strain
         is automatically calculated after a low-pass filter and Tukey window
@@ -439,6 +439,19 @@ class InterferometerStrainData(object):
         self.set_from_gwpy_timeseries(timeseries)
         self._check_maximum_frequency()
 
+    def set_from_csv(self, filename):
+        """ Set the strain data from a csv file
+
+        Parameters
+        ----------
+        filename: str
+            The path to the file to read in
+
+        """
+        timeseries = gwpy.timeseries.TimeSeries.read(filename, format='csv')
+        self.set_from_gwpy_timeseries(timeseries)
+        self._check_maximum_frequency()
+
     def _infer_frequency_domain_dependence(
             self, sampling_frequency, duration, frequency_array):
         """ Helper function to figure out if the frequency_array, or
@@ -745,6 +758,17 @@ class Interferometer(object):
             duration=duration, start_time=start_time,
             channel_name=channel_name, buffer_time=buffer_time)
 
+    def set_strain_data_from_csv(self, filename):
+        """ Set the `Interferometer.strain_data` from a csv file
+
+        Parameters
+        ----------
+        filename: str
+            The path to the file to read in
+
+        """
+        self.strain_data.set_from_csv(filename)
+
     def set_strain_data_from_zero_noise(
             self, sampling_frequency, duration, start_time=0):
         """ Set the `Interferometer.strain_data` to zero noise
-- 
GitLab