Skip to content

Commit

Permalink
Merge branch 'master' into adi
Browse files Browse the repository at this point in the history
  • Loading branch information
transientlunatic committed Feb 10, 2017
2 parents f5b1bf9 + 8d28399 commit 3e31966
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 50 deletions.
24 changes: 3 additions & 21 deletions minke/mdctools.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def load_xml(self, filename, full=True, start=None, stop=None):
i += 1
del(sim_burst_table)

def _generate_burst(self, row,rate=16384.0):
def _generate_burst(self,row,rate=16384.0):
"""
Generate the burst described in a given row, so that it can be
measured.
Expand All @@ -199,10 +199,6 @@ def _generate_burst(self, row,rate=16384.0):
# be bypassed for pre-calculated waveforms.
# A more robust solution should be considered.
exceptions = ["Ott+13", "Mueller+12", "Scheidegger+10"]




row = self.waveforms[row]
swig_row = lalburst.CreateSimBurst()
for a in lsctables.SimBurstTable.validcolumns.keys():
Expand All @@ -212,23 +208,9 @@ def _generate_burst(self, row,rate=16384.0):
except TypeError:
print a, getattr(row,a)
continue # the structure is different than the TableRow
#try:
theta, phi = np.cos(swig_row.incl), swig_row.phi

#if swig_row.waveform in exceptions:
# # This is nasty and shouldn't be a long-term fix!!!
# swig_row.numrel_data = row.numrel_data.split('\0')[0]+ "_costheta{:.3f}_phi{:.3f}-full.txt".format(theta, phi)
# print swig_row.numrel_data
#else:
swig_row.numrel_data = row.numrel_data

#for a in lsctables.SimBurstTable.validcolumns.keys():
# print a, getattr(swig_row,a)

hp, hx = lalburst.GenerateSimBurst(swig_row, 1.0/rate)

# FIXME: Totally inefficent --- but can we deep copy a SWIG SimBurst?
# DW: I tried that, and it doesn't seem to work :/
hp0, hx0 = lalburst.GenerateSimBurst(swig_row, 1.0/rate)
return hp, hx, hp0, hx0

Expand Down Expand Up @@ -705,9 +687,9 @@ def generate_pcal(self, mdc, directory, force = False):
h_tot = lalsimulation.SimDetectorStrainREAL8TimeSeries(hp, hx,
sim_burst.ra, sim_burst.dec, sim_burst.psi, det)
# Inject the waveform into the overall timeseries
lalsimulation.SimAddInjectionREAL8TimeSeries(h_resp, h_tot, None)
#lalsimulation.SimAddInjectionREAL8TimeSeries(h_resp, h_tot, None)

data = np.array(h_resp.data.data)
data = np.array(h_tot.data.data)
np.savetxt(filename, data)

class HWFrameSet():
Expand Down
58 changes: 29 additions & 29 deletions minke/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,27 @@ def _generate(self, rate=16384.0, half=False, distance=None):
Generate the burst described in a given row, so that it can be
measured.
Parameters ---------- rate : float The sampling rate of the
signal, in Hz. Defaults to 16384.0Hz
Parameters
----------
rate : float
The sampling rate of the signal, in Hz.
Defaults to 16384.0Hz
half : bool Only compute the hp and hx once if this is true;
half : bool
Only compute the hp and hx once if this is true;
these are only required if you need to compute the cross
products. Defaults to False.
distance : float The distance, in megaparsecs, at which the
injection should be made. Currently only applies to
supernova injections. Returns ------- hp : The strain in
the + polarisation hx : The strain in the x polarisation
hp0 : A copy of the strain in the + polarisation hx0 : A
copy of the strain in the x polarisation
Returns
-------
hp :
The strain in the + polarisation
hx :
The strain in the x polarisation
hp0 :
A copy of the strain in the + polarisation
hx0 :
A copy of the strain in the x polarisation
"""
row = self._row()
swig_row = lalburst.CreateSimBurst()
Expand All @@ -133,7 +141,7 @@ def _generate(self, rate=16384.0, half=False, distance=None):

# Rescale for a given distance
if distance and hasattr(self, supernova):
rescale = 1.0 / (self.file_distance / distance)
rescale = 1.0 / (self.file_distance / row.amplitude)
hp, hx, hp0, hx0 = hp * rescale, hx * rescale, hp0 * rescale,hx0 * rescale

return hp, hx, hp0, hx0
Expand Down Expand Up @@ -430,7 +438,7 @@ def interpolate(self, x_old, y_old, x_new):
interpolator = interp.interp1d(x_old, y_old)
return interpolator(x_new)

def decompose(self, numrel_file, sample_rate = 16384.0, step_back = 0.01, distance = 10e-3):
def decompose(self, numrel_file, sample_rate = 16384.0, step_back = 0.01):
"""
Produce the spherial harmonic decompositions of a numerical
waveform.
Expand All @@ -447,9 +455,6 @@ def decompose(self, numrel_file, sample_rate = 16384.0, step_back = 0.01, distan
The amount of time, in seconds, of the data which should be included
before the peak amplitude. Defaults to 0.01 sec.
distance : float
The distance, in megaparsecs, from the observer at which the NR waveforms were
simulated. Defaults to 10 kpc (i.e. 10e-3 Mpc).
Returns
-------
Expand Down Expand Up @@ -496,7 +501,7 @@ class Ott2013(Supernova):
The Ott+2013 supernova waveform
"""
waveform = "Ott+13"
def __init__(self, theta, phi, time, sky_dist=uniform_sky, filepath=None, family="s27fheat1p05", decomposed_path=None):
def __init__(self, theta, phi, time, sky_dist=uniform_sky, distance = 10e-3, filepath=None, family="s27fheat1p05", decomposed_path=None):
"""
Parameters
Expand All @@ -518,6 +523,9 @@ def __init__(self, theta, phi, time, sky_dist=uniform_sky, filepath=None, family
The function describing the sky distribution which the injections
should be made over. Defaults to a uniform sky.
distance : float
The distance, in megaparsecs, at which the injection should be made.
filepath : str
The filepath to the folder containing the pre-rotated numerical relativity waveforms.
Expand All @@ -533,14 +541,10 @@ def __init__(self, theta, phi, time, sky_dist=uniform_sky, filepath=None, family
self.params['phi'] = phi
self.params['incl'] = theta
self.sky_dist = sky_dist
self.params['numrel_data'] = filepath #decomposed_path #self.numrel_data
self.params['amplitude'] = distance # We store the distance in the amplitude column because there isn't a distance column
self.params['hrss'] = self.file_distance # Again the hrss value is the distance at which the files are scaled

if not decomposed_path : decomposed_path = filepath+".dec"
if not os.path.isfile(decomposed_path) :
decomposed = self.decompose(filepath, sample_rate = 16384.0, step_back = 0.01, distance = 10e-3)
np.savetxt(decomposed_path, decomposed, header="time (2,-2) (2,-1) (2,0) (2,1) (2,2)", fmt='%.8e')

#self.numrel_data = filepath + "/" + family
self.params['numrel_data'] = decomposed_path #self.numrel_data

def _generate(self):
"""
Expand Down Expand Up @@ -609,13 +613,13 @@ def __init__(self, theta, phi, time, sky_dist=uniform_sky, filepath=None, family
self.sky_dist = sky_dist
if not decomposed_path : decomposed_path = filepath+".dec"
if not os.path.isfile(decomposed_path) :
decomposed = self.decompose(filepath, sample_rate = 16384.0, step_back = 0.01, distance = 10e-3)
decomposed = self.decompose(filepath, sample_rate = 16384.0, step_back = 0.01)
np.savetxt(decomposed_path, decomposed, header="time (2,-2) (2,-1) (2,0) (2,1) (2,2)", fmt='%.8e')

#self.numrel_data = filepath + "/" + family
self.params['numrel_data'] = decomposed_path #self.numrel_data

def decompose(self, numrel_file, sample_rate = 16384.0, step_back = 0.01, distance = 10e-3):
def decompose(self, numrel_file, sample_rate = 16384.0, step_back = 0.01):
"""
Produce the spherial harmonic decompositions of a numerical
waveform.
Expand Down Expand Up @@ -825,7 +829,7 @@ def __init__(self, time, sky_dist=uniform_sky, filepath="signal_s15a2o05_ls.dat"
self.params['incl']=90
self.params['numrel_data'] = decomposed_path

def decompose(self, numrel_file, sample_rate = 16384.0, step_back = 0.01, distance = 10e-3):
def decompose(self, numrel_file, sample_rate = 16384.0, step_back = 0.01):
"""
Produce the spherial harmonic decompositions of the Dimmelmeier numerical
waveform. This is a special case since it is axisymmetric.
Expand All @@ -842,10 +846,6 @@ def decompose(self, numrel_file, sample_rate = 16384.0, step_back = 0.01, distan
The amount of time, in seconds, of the data which should be included
before the peak amplitude. Defaults to 0.01 sec.
distance : fllal.MTSUN_SIoat
The distance, in megaparsecs, from the observer at which the NR waveforms were
simulated. Defaults to 10 kpc (i.e. 10e-3 Mpc).
Returns
-------
decomposition : ndarray
Expand Down

0 comments on commit 3e31966

Please sign in to comment.