Commit e260114d authored by Daniel Williams's avatar Daniel Williams
Browse files

Added the ability to load PSDs.

parent 0878be6d
Loading
Loading
Loading
Loading

minke/noise.py

0 → 100644
+40 −0
Original line number Diff line number Diff line
import numpy as np
import lal, lalsimulation
import matplotlib.pyplot as plt

class PSD():
    """
    Create a power spectral distribution from a file which specifies
    the PSD.

    """

    def __init__(self, filename, fmin = 20, fmax = 3000, df = 0.1):
        """
        Load in the PSD file, assuming that it is in units of Hertz and strain.
        """

        N = int((fmax - fmin) / df)
        self.psd = lal.CreateREAL8FrequencySeries('psd', 
                                                  lal.LIGOTimeGPS(0,0),
                                                  fmin,
                                                  df,
                                                  lal.HertzUnit,
                                                  N)
        lalsimulation.SimNoisePSDFromFile(self.psd, fmin, filename)

        

    def plot(self):
        """
        Plot the PSD
        """

        fmin = self.psd.f0
        length = len(self.psd.data.data)
        df = self.psd.deltaF
        frequencies = np.linspace(fmin, fmin + length * df, length)

        f = plt.semilogy(frequencies, self.psd.data.data)

        return f
+19 −2
Original line number Diff line number Diff line
@@ -138,6 +138,20 @@ class Waveform(object):
            
        return hp, hx, hp0, hx0 

    def _generate_for_detector(self, ifos, sample_rate = 16384.0, nsamp = 2000):
        data = []
        # Loop through each interferometer
        for ifo in ifos:
            # Make the timeseries
            h_resp = lal.CreateREAL8TimeSeries("inj time series", lal.LIGOTimeGPS(0,0), 0, 1.0/sample_rate, lal.StrainUnit, nsamp)
            hp, hx = self._generate(half=True)[:2]
            # Get and apply detector response
            det = lalsimulation.DetectorPrefixToLALDetector(ifo)
            h_tot = lalsimulation.SimDetectorStrainREAL8TimeSeries(hp, hx, self.params['ra'], self.params['dec'], self.params['psi'], det)
            # Inject the waveform into the overall timeseries
            lalsimulation.SimAddInjectionREAL8TimeSeries(h_resp, h_tot, None)
            return h_resp


    def _row(self, sim=None, slide_id=1):
        """
@@ -630,6 +644,9 @@ class Scheidegger2010(Supernova):
        #if not (theta, phi) in self.combinations:
        #    raise IOError("There is no file for this combination of rotations.")
        



    def _generate(self):
        """

@@ -652,8 +669,8 @@ class Scheidegger2010(Supernova):

        data_hp = np.loadtxt(numrel_file_hp)
        data_hx = np.loadtxt(numrel_file_hx)
        data_hp = data_hp.T
        data_hx = data_hx.T
        #data_hp = data_hp.T
        #data_hx = data_hx.T
        times = data_hp[0]
        times -= times[0]

+1 −0
Original line number Diff line number Diff line
numpy
scipy
matplotlib
pandas

scripts/measure_snr.py

0 → 100644
+10 −0
Original line number Diff line number Diff line
import minke
from minke import mdctools, sources, distribution, noise
import lalsimulation

sg = sources.SineGaussian(10, 1000, 1e-23, "linear", 1126620016)

o1psd = noise.PSD("/home/daniel/LIGO-P1200087-v18-AdV_EARLY_HIGH.txt")


print lalsimulation.MeasureSNR(sg._generate_for_detector(['L1']), o1psd.psd)
+6 −1
Original line number Diff line number Diff line
@@ -15,7 +15,12 @@ with open('HISTORY.rst') as history_file:
    history = history_file.read()

requirements = [
    # TODO: put package requirements here
    
    'numpy',
    'matplotlib',
    'pandas',
    'scipy',
    'pylal',    
]

test_requirements = [