From a146c048a15258041f4c47026268085a403e53e1 Mon Sep 17 00:00:00 2001 From: Daniel Williams Date: Wed, 27 Jun 2018 15:52:15 +0100 Subject: [PATCH] Some update for the pull. --- HISTORY.rst | 15 +++++++++ minke/mdctools.py | 73 ++++++++++++++++++++++++++++++++----------- minke/sources.py | 41 +++++++++++++++--------- tests/test_sources.py | 1 + 4 files changed, 97 insertions(+), 33 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 8dee2ab..6a981a0 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,21 @@ History ======= +1.1.1 (2018-03-27) +------------------ +* Made a change to the package meta data to allow upload to PYPI. + +1.1.0 (2018-03-27) +------------------ +"Luce Bay" + +* Added full support for hardware injection production +* Added Yakunin Supernova waveform family +* Added Ringdow waveform support +* Added support for all lscsoft table formats +* Added support for editing xml files +* Added support for String Cusp waveforms + 1.0.1 (2017-01-23) ------------------ * Added provisional support for hardware injection production diff --git a/minke/mdctools.py b/minke/mdctools.py index fcc8ddc..b7d02a4 100644 --- a/minke/mdctools.py +++ b/minke/mdctools.py @@ -36,7 +36,6 @@ import glue.ligolw import gzip import lal, lalframe -from pylal import Fr import numpy as np import pandas as pd @@ -73,6 +72,24 @@ def source_from_row(row): pass return sourceobj +def source_from_dict(params): + sourceobj = sourcemap[params['morphology']].__new__(sourcemap[params['morphology']]) + sourceobj.numrel_data = str("") + params = {} + for attr in dir(row): + if not attr[0] == "_" and not attr[:3] =="get": + #print attr + params[attr] = getattr(row, attr) + setattr(sourceobj, attr, getattr(row, attr)) + sourceobj.params = params + try: + sourceobj.time = row.time_geocent_gps + except: + sourceobj.time = row.geocent_start_time + pass + return sourceobj + + table_types = { # Ad-Hoc "ga" : lsctables.SimBurstTable, @@ -398,11 +415,12 @@ class MDCSet(): The name of the injection in the cWB format """ row = self.waveforms[row] + name = '' numberspart = '' if row.waveform in ("Dimmelmeier+08", "Scheidegger+10", "Mueller+12", "Ott+13", "Yakunin+10"): #print row - numberspart = os.path.basename(row.numrel_data).split('.')[0] + numberspart = os.path.basename(row.params['numrel_data']).split('.')[0] if row.waveform == "Gaussian": numberspart = "{:.3f}".format(row.duration * 1e3) @@ -602,11 +620,19 @@ class Frame(): """ Represents a frame, in order to prepare the injection frames """ - def __init__(self, start, duration, ifo): + def __init__(self, start, duration, ifo, number = -1): + """ + + Parameters + ---------- + number : int + The frame's number within the project. Defaults to -1. + """ self.start = start self.duration = duration self.end = self.start + duration self.ifos = ifo + self.number = -1 def __repr__(self): out = '' @@ -637,7 +663,7 @@ class Frame(): log += "\n" return log - def generate_gwf(self, mdc, directory, channel="SCIENCE", force=False, rate=16384.0): + def generate_gwf(self, mdc, directory, project = "Minke", channel="SCIENCE", force=False, rate=16384.0): """ Produce the gwf file which corresponds to the MDC set over the period of this frame. @@ -650,6 +676,8 @@ class Frame(): "/home/albert.einstein/data/mdc/frames/" would cause the SineGaussian injections to be made in the directories under "/home/albert.einstein/data/mdc/frames/sg" + project : str + The name of the project which this frame is a part of. Defaults to 'Minke'. channel : str The name of the channel which the injections should be made into. This is prepended by the initials for each interferometer, so there will be a channel for each interferometer in the gwf. @@ -663,26 +691,39 @@ class Frame(): """ ifosstr = "".join(set(ifo[0] for ifo in self.ifos)) family = mdc.waveforms[0].waveform + epoch = lal.LIGOTimeGPS(self.start) filename = "{}-{}-{}-{}.gwf".format(ifosstr, family, self.start, self.duration) - + + self.frame = lalframe.FrameNew(epoch = epoch, + duration = self.duration, project='', run=1, frnum=1, + detectorFlags=lal.LALDETECTORTYPE_ABSENT) + + + ifobits = np.array([getattr(lal,"{}_DETECTOR_BIT".format(lal.cached_detector_by_prefix[ifo].frDetector.name.upper())) + for ifo in self.ifos]) + ifoflag = numpy.bitwise_or.reduce(ifobits) + RUN_NUM = -1 # Simulated data should have a negative run number + head_date = str(self.start)[:5] frameloc = directory+"/"+mdc.directory_path()+"/"+head_date+"/" - #print frameloc, filename + mkdir(frameloc) if not os.path.isfile(frameloc + filename) or force: - data = [] - # Define the start point of the time series top be generated for the injection epoch = lal.LIGOTimeGPS(self.start) + frame = lalframe.FrameNew(epoch, self.duration, project, RUN_NUM, self.number, ifoflag) + data = [] # Loop through each interferometer + for ifo in self.ifos: # Calculate the number of samples in the timeseries nsamp = int((self.end-self.start)*rate) # Make the timeseries - h_resp = lal.CreateREAL8TimeSeries("inj time series", epoch, 0, 1.0/rate, lal.StrainUnit, nsamp) + h_resp = lal.CreateREAL8TimeSeries("{}:{}".format(ifo, channel), epoch, 0, 1.0/rate, lal.StrainUnit, nsamp) # Loop over all of the injections corresponding to this frame rowlist = self.get_rowlist(mdc) + if len(rowlist)==0: return for row in rowlist: - sim_burst = mdc.waveforms[row] + sim_burst = mdc.waveforms[row]._row() if sim_burst.hrss > 1: distance = sim_burst.amplitude @@ -694,23 +735,19 @@ class Frame(): # Apply detector response det = lalsimulation.DetectorPrefixToLALDetector(ifo) # Produce the total strains + 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) - # Write out the data to the list which will eventually become our frame - data.append({"name": "%s:%s" % (ifo, channel), - "data": h_resp.data.data, - "start": float(epoch), - "dx": h_resp.deltaT, - "kind": "SIM"}) + lalframe.FrameAddREAL8TimeSeriesSimData(frame, h_resp) # Make the directory in which to store the files # if it doesn't exist already - mkdir(frameloc) + # Write out the frame file - Fr.frputvect(frameloc+filename, data) + lalframe.FrameWrite(frame, frameloc+filename) class HWInj(Frame): diff --git a/minke/sources.py b/minke/sources.py index bfb44a9..625f71d 100644 --- a/minke/sources.py +++ b/minke/sources.py @@ -37,6 +37,10 @@ except ImportError: import matplotlib.pyplot as plt +if "numrel_data" in lsctables.SimBurstTable.validcolumns.keys(): + NROK = True +else: + NROK = False class Waveform(object): @@ -58,7 +62,9 @@ class Waveform(object): for a in self.table_type.validcolumns.keys(): self.params[a] = None - + def __getattr__(self, name): + return self.params[name] + def parse_polarisation(self, polarisation): """ Convert a string description of a polarisation to an ellipse eccentricity and an ellipse angle. @@ -156,11 +162,12 @@ class Waveform(object): continue burstobj.waveform = str(self.waveform) - - if swig_row.numrel_data: - burstobj.numrel_data = str(swig_row.numrel_data) - else: - burstobj.numrel_data = str("") + + if NROK: + if swig_row.numrel_data: + burstobj.numrel_data = str(swig_row.numrel_data) + else: + burstobj.numrel_data = str("") return burstobj @@ -200,10 +207,11 @@ class Waveform(object): for a in self.table_type.validcolumns.keys(): setattr(row, a, self.params[a]) - if self.numrel_data: - row.numrel_data = str(self.numrel_data) - else: - row.numrel_data = self.params['numrel_data'] + if NROK: + if self.numrel_data: + row.numrel_data = str(self.numrel_data) + else: + row.numrel_data = self.params['numrel_data'] row.waveform = self.waveform # Fill in the time @@ -211,6 +219,9 @@ class Waveform(object): # Get the sky locations if not row.ra: row.ra, row.dec, row.psi = self.sky_dist() + row.ra = row.ra[0] + row.dec = row.dec[0] + row.psi = row.psi[0] row.simulation_id = sim.get_next_id() row.waveform_number = random.randint(0,int(2**32)-1) ### !! This needs to be updated. @@ -294,13 +305,13 @@ class SineGaussian(Waveform): """ self._clear_params() self.sky_dist = sky_dist - self.params['hrss'] = hrss - self.params['seed'] = seed - self.params['frequency'] = frequency - self.params['q'] = q + self.hrss = self.params['hrss'] = hrss + self.seed = self.params['seed'] = seed + self.frequency = self.params['frequency'] = frequency + self.q = self.params['q'] = q self.time = time self.polarisation = polarisation - self.params['pol_ellipse_e'], self.params['pol_ellipse_angle'] = self.parse_polarisation(self.polarisation) + self.pol_ellipse_e, self.ellipse_angle = self.params['pol_ellipse_e'], self.params['pol_ellipse_angle'] = self.parse_polarisation(self.polarisation) diff --git a/tests/test_sources.py b/tests/test_sources.py index 0cbfb46..b57ae0c 100755 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -278,6 +278,7 @@ class TestMinkeSupernovaSources(unittest.TestCase): mdcset = mdctools.MDCSet(['L1', 'H1']) mdcset.load_xml('tests/data/ott_test.xml.gz') o1 = mdctools.FrameSet('tests/data/frame_list.dat') + print o1.frames[0].generate_gwf(mdcset, "/home/daniel") mdc_folder = "testout/frames" for o1frame in o1.frames: o1frame.generate_gwf(mdcset, mdc_folder, 'SCIENCE') -- GitLab