def injections_from_cli(opts): """Gets injection parameters from the inference file(s). Parameters ---------- opts : argparser Argparser object that has the command-line objects to parse. Returns ------- FieldArray Array of the injection parameters from all of the input files given by ``opts.input_file``. """ input_files = opts.input_file if isinstance(input_files, str): input_files = [input_files] parameters, _ = parse_parameters_opt(opts.parameters) if parameters is None: with InferenceFile(input_files[0], 'r') as fp: parameters = fp.variable_params injections = None # loop over all input files getting the injection files for input_file in input_files: # read injections from HDF input file as FieldArray these_injs = inject.InjectionSet( input_file, hdf_group=opts.injection_hdf_group, ).table.view(FieldArray) if injections is None: injections = these_injs else: injections = injections.append(these_injs) # check if need extra parameters than parameters stored in injection file _, ts = transforms.get_common_cbc_transforms(parameters, injections.fieldnames) # add parameters not included in injection file injections = transforms.apply_transforms(injections, ts) return injections
from matplotlib import pyplot injection_file_name = "injection.xml.gz" ii = 0 fig = pyplot.figure() for ifo in ['H1', 'L1', 'V1', 'I1', 'K1']: ii += 1 delta_t = 1. / 2048 fmin = 20 from pycbc import inject injf = inject.InjectionSet(injection_file_name) h = injf.make_strain_from_inj_object(injf.table[0], delta_t, ifo, f_lower=fmin) ax = fig.add_subplot(5, 1, ii) ax.plot(h.sample_times.numpy(), h) ax.set_xlim(h.sample_times[int(len(h.sample_times) / 2.)], h.sample_times[-1]) pyplot.title("%s" % ifo) pyplot.ylabel("Strain") #pyplot.xlim(xmin,xmax) pyplot.xlabel("GPS Time (s)") pyplot.tight_layout() pyplot.show("hold") pyplot.savefig("det_strain.png") print "Figure saved as det_strain.png"
gps_time = sargs['tc'] except KeyError: gps_time = map_values['tc'] xmin = float(opts.min_xlim) xmax = 0.05 # whitened strain x = wh_strain.sample_times.numpy() - gps_time y = wh_strain # ax.plot(x, y, colors[ifo], lw=1.5, zorder=1) ylim = get_ylim(y, x, xmin, xmax) if opts.injection_file: # get the injection values from pycbc import inject, io injf = inject.InjectionSet(opts.injection_file) ti = injf.make_strain_from_inj_object( injf.table[0], wh_strain.delta_t, ifo, f_lower=gen.current_params['f_lower']) fi = ti.to_frequencyseries(delta_f=gen.current_params['delta_f']) if len(fi) < len(psd): fi.resize(len(psd)) elif len(psd) < len(fi): fi = fi[:len(psd)] fi /= asd ti = fi.to_timeseries() ax.plot(ti.sample_times.numpy() - gps_time, ti.data, 'b-',