Ejemplo n.º 1
0
# Add options for individual detectors
for detector in lal.CachedDetectors:
    name = detector.frDetector.name
    prefix = detector.frDetector.prefix
    detectors.append(prefix)
    parser.add_option('--' + prefix, choices=psd_names, metavar='func',
        help='PSD function for {0} detector [optional]'.format(name))

# Parse command line.
opts, args = parser.parse_args()
if args:
    parser.error('Did not expect any positional command line arguments')

psds = {}

n = int(opts.f_max // opts.df)
f = np.arange(n) * opts.df

for detector in detectors:
    psd_name = getattr(opts, detector)
    if psd_name is None:
        continue
    psd_func = getattr(lalsimulation, psd_name_prefix + psd_name)
    series = lal.CreateREAL8FrequencySeries(None, 0, 0, opts.df, lal.SecondUnit, n)
    series.data.data = vectorize_swig_psd_func(psd_func)(f)
    psds[detector] = series

glue.ligolw.utils.write_filename(
    lal.series.make_psd_xmldoc(psds), opts.output,
    gz=(os.path.splitext(opts.output)[-1]==".gz"))
psds = {}

n = int(opts.f_max // opts.df)
f = np.arange(n) * opts.df

for detector in detectors:
    psd_name = getattr(opts, detector)
    scale = 1 / np.square(getattr(opts, detector + '_scale'))
    if psd_name is None:
        continue
    func = getattr(lalsimulation, psd_name_prefix + psd_name)
    series = lal.CreateREAL8FrequencySeries(
        psd_name, 0, 0, opts.df, lal.SecondUnit, n)
    if '(double f) -> double' in func.__doc__:
        series.data.data = vectorize_swig_psd_func(
            psd_name_prefix + psd_name)(f)
    else:
        func(series, 0.0)

        # Find indices of first and last nonzero samples.
        nonzero = np.flatnonzero(series.data.data)
        # FIXME: int cast seems to be needed on old versions of Numpy
        first_nonzero = int(nonzero[0])
        last_nonzero = int(nonzero[-1])

        # Truncate
        series = lal.CutREAL8FrequencySeries(
            series, first_nonzero, last_nonzero - first_nonzero + 1)
        series.f0 = first_nonzero * series.deltaF

        series.name = psd_name
psds = {}

n = int(opts.f_max // opts.df)
f = np.arange(n) * opts.df

for detector in detectors:
    psd_name = getattr(opts, detector)
    scale = 1 / np.square(getattr(opts, detector + '_scale'))
    if psd_name is None:
        continue
    func = getattr(lalsimulation, psd_name_prefix + psd_name)
    series = lal.CreateREAL8FrequencySeries(psd_name, 0, 0, opts.df,
                                            lal.SecondUnit, n)
    if '(double f) -> double' in func.__doc__:
        series.data.data = vectorize_swig_psd_func(psd_name_prefix +
                                                   psd_name)(f)
    else:
        func(series, 0.0)

        # Find indices of first and last nonzero samples.
        nonzero = np.flatnonzero(series.data.data)
        # FIXME: int cast seems to be needed on old versions of Numpy
        first_nonzero = int(nonzero[0])
        last_nonzero = int(nonzero[-1])

        # Truncate
        series = lal.CutREAL8FrequencySeries(series, first_nonzero,
                                             last_nonzero - first_nonzero + 1)
        series.f0 = first_nonzero * series.deltaF

        series.name = psd_name