31Populate a sim_inspiral table with random draws from an ASCII table.
33from optparse
import Option, OptionParser
35from igwn_ligolw
import ligolw
36from igwn_ligolw
import lsctables
37import igwn_ligolw.utils.process
47 (
'time_geocent_gps',
'i4'),
48 (
'time_geocent_gps_ns',
'i4'),
51 (
'pol_ellipse_angle',
'f8'),
52 (
'pol_ellipse_e',
'f8'),
55 (
'egw_over_rsquared',
'f8'),
56 (
'waveform_number',
'i8'),
60 """Determine name of input: either the sole positional command line argument,
63 infilename =
'/dev/stdin'
67 parser.error(
"Too many command line arguments.")
71 for name
in possible_names:
72 if name
in params: params[params.index(name)] = desired_name
87 params = samples.dtype.names
89 has_dur=
'duration' in params
90 has_frequency =
'frequency' in params
94 duration=[i/sqrt(2)/np.pi/j
for (i,j)
in zip(q,samples[
'frequency'])]
98 duration = samples[
'duration']
100 q=[sqrt(2)*np.pi*i*j
for (i,j)
in zip(duration,samples[
'frequency'])]
106if __name__ ==
"__main__":
107 parser = OptionParser(
108 description = __doc__,
109 usage =
"%prog [options] [INPUT]",
111 Option(
"-o",
"--output", metavar=
"FILE.xml",
112 help=
"name of output XML file"),
113 Option(
"--num-of-injs", metavar=
"NUM", type=int, default=200,
114 help=
"number of injections"),
115 Option(
"--approx", metavar=
"APPROX", default=
"SineGaussianF",
116 help=
"approximant to be injected"),
117 Option(
"--taper", metavar=
"TAPER", default=
"TAPER_NONE",
118 help=
"Taper methods for injections"),
119 Option(
"--flow", metavar=
"FLOW", type=float, default=
None,
120 help=
"Taper methods for injections"),
124 opts, args = parser.parse_args()
128 with open(infilename,
'r')
as inp:
129 params = inp.readline().split()
131 samples = np.loadtxt(inp, dtype=[(p, np.float)
for p
in params])
135 selection = np.arange(N)
136 np.random.shuffle(selection)
137 samples = samples[selection]
140 injections = np.zeros((N,), dtype=sim_inspiral_dt)
149 if 'alpha' in params:
151 injections[
'pol_ellipse_angle'] = samples[
'alpha']
152 elif 'pol_ellipse_angle' in params:
153 injections[
'pol_ellipse_angle'] = samples[
'pol_ellipse_angle']
155 injections[
'pol_ellipse_angle'] =
None
157 if 'polar_eccentricity' in params:
158 injections[
'pol_ellipse_e']= samples[
'polar_eccentricity']
159 elif 'pol_ellipse_e' in params:
160 injections[
'pol_ellipse_e']= samples[
'pol_ellipse_e']
162 injections[
'pol_ellipse_e']=
None
164 print(samples[
'pol_ellipse_e'])
165 print(injections[
'pol_ellipse_e'])
166 if 'bandwidth' in params:
167 injections[
'bandwidth'] = samples[
'bandwidth']
169 injections[
'bandwidth'] = np.nan
171 injections[
'time_geocent_gps'] = np.modf(samples[
'time'])[1]
172 injections[
'time_geocent_gps_ns'] = np.modf(samples[
'time'])[0] * 10**9
173 elif 'time_min' in params
and 'time_max' in params:
174 est_time=samples[
'time_min']+0.5*(samples[
'time_max']-samples[
'time_min'])
175 injections[
'time_geocent_gps'] = np.modf(est_time)[1]
176 injections[
'time_geocent_gps_ns'] = np.modf(est_time)[0] * 10**9
179 injections[
'waveform'] = [opts.approx
for i
in range(N)]
181 injections[
'frequency'] = samples[
'frequency']
183 injections[
'frequency']=[np.nan
for i
in samples[
'ra']]
184 injections[
'duration'] = dur
187 injections[
'hrss'] = samples[
'hrss']
189 injections[
'hrss'] = np.exp(samples[
'loghrss'])
190 injections[
'ra'] = samples[
'ra']
191 injections[
'dec'] = samples[
'dec']
192 injections[
'psi'] = samples[
'psi']
195 xmldoc = ligolw.Document()
196 xmldoc.appendChild(ligolw.LIGO_LW())
197 proc = igwn_ligolw.utils.process.register_to_xmldoc(doc, sys.argv[0], {})
200 timeslide_table = lsctables.New(lsctables.TimeSlideTable)
201 timeslide_id = timeslide_table.append_offsetvector(
202 {
'H1':0,
'V1':0,
'L1':0,
'H2':0}, proc)
204 sim_table = lsctables.New(lsctables.SimBurstTable)
205 xmldoc.childNodes[0].appendChild(timeslide_table)
206 xmldoc.childNodes[0].appendChild(sim_table)
210 row = sim_table.RowType()
211 for slot
in row.__slots__: setattr(row, slot, 0)
212 sim_table.append(row)
215 for i,row
in enumerate(sim_table):
216 row.process_id = proc.process_id
217 row.simulation_id = sim_table.get_next_id()
218 row.time_slide_id = timeslide_id
220 for field
in injections.dtype.names:
221 vals = injections[field]
222 for row, val
in zip(sim_table, vals): setattr(row, field, val)
225 output_file = open(opts.output,
'w')
226 xmldoc.write(output_file)
def compute_duration_parameterizations(samples)
def standardize_param_name(params, possible_names, desired_name)
def standardize_param_names(params)
def get_input_filename(parser, args)
Determine name of input: either the sole positional command line argument, or /dev/stdin.