Skip to content

sgnl.svd_bank

This module contains methods for reading in SVD bank files.

group(inlist, parts)

! group a list roughly according to the distribution in parts, e.g.

A = list(range(12)) B = [2,3] for g in group(A,B): ... print(g) ... [0, 1][2, 3] [4, 5][6, 7, 8] [9, 10, 11]

Source code in sgnl/svd_bank.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
def group(inlist, parts):
    """!
    group a list roughly according to the distribution in parts, e.g.

    >>> A = list(range(12))
    >>> B = [2,3]
    >>> for g in group(A,B):
    ...     print(g)
    ...
    [0, 1]
    [2, 3]
    [4, 5]
    [6, 7, 8]
    [9, 10, 11]
    """
    mult_factor = len(inlist) // sum(parts) + 1
    inlist_copy = copy.deepcopy(inlist)
    for p in parts:
        for _j in range(mult_factor):
            if not inlist_copy:
                break
            yield inlist_copy[:p]
            del inlist_copy[:p]

horizon_distance_func(banks)

Takes a dictionary of objects returned by read_banks keyed by instrument

Source code in sgnl/svd_bank.py
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
def horizon_distance_func(banks):
    """
    Takes a dictionary of objects returned by read_banks keyed by instrument
    """
    # span is [15 Hz, 0.85 * Nyquist frequency]
    # find the Nyquist frequency for the PSD to be used for each
    # instrument.  require them to all match
    nyquists = set((max(bank.get_rates()) / 2.0 for bank in banks))
    if len(nyquists) != 1:
        warnings.warn(
            "all banks should have the same Nyquist frequency to define a consistent "
            "horizon distance function (got {})".format(
                ", ".join(f"{rate:g}" for rate in sorted(nyquists))
            ),
            stacklevel=2,
        )
    # assume default 4 s PSD.  this is not required to be correct, but
    # for best accuracy it should not be larger than the true value and
    # for best performance it should not be smaller than the true
    # value.
    deltaF = 1.0 / 4.0
    # use the minimum template id as the cannonical horizon function
    template_id, m1, m2, s1z, s2z = preferred_horizon_distance_template(banks)

    return template_id, HorizonDistance(
        15.0,
        0.85 * max(nyquists),
        deltaF,
        m1,
        m2,
        spin1=(0.0, 0.0, s1z),
        spin2=(0.0, 0.0, s2z),
    )

parse_bank_files(svd_banks, verbose, snr_threshold=None, fast=False)

given a dictionary of lists of svd template bank file names parse them into a dictionary of bank classes

Source code in sgnl/svd_bank.py
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
def parse_bank_files(svd_banks, verbose, snr_threshold=None, fast=False):
    """
    given a dictionary of lists of svd template bank file names parse them
    into a dictionary of bank classes
    """

    banks = {}

    for instrument, filename in svd_banks.items():
        for n, bank in enumerate(
            read_banks(
                filename,
                contenthandler=DefaultContentHandler,
                verbose=verbose,
                fast=fast,
            )
        ):
            # Write out sngl inspiral table to temp file for
            # trigger generator
            # FIXME teach the trigger generator to get this
            # information a better way
            bank.template_bank_filename = tempfile.NamedTemporaryFile(
                suffix=".xml.gz", delete=False
            ).name
            xmldoc = ligolw.Document()
            # FIXME if this table reference is from a DB this
            # is a problem (but it almost certainly isn't)
            xmldoc.appendChild(ligolw.LIGO_LW()).appendChild(
                bank.sngl_inspiral_table.copy()
            ).extend(bank.sngl_inspiral_table)
            ligolw_utils.write_filename(
                xmldoc, bank.template_bank_filename, verbose=verbose
            )
            xmldoc.unlink()  # help garbage collector
            bank.logname = "%sbank%d" % (instrument, n)
            banks.setdefault(instrument, []).append(bank)
            if snr_threshold is not None:
                bank.snr_threshold = snr_threshold

    # FIXME remove when this is no longer an issue
    if not banks:
        raise ValueError(
            "Could not parse bank files into valid bank dictionary.\n\t- Perhaps you"
            " are using out-of-date svd bank files?  Please ensure that they were"
            " generated with the same code version as the parsing code"
        )
    return banks

parse_svdbank_string(bank_string)

parses strings of form

H1:bank1.xml,H2:bank2.xml,L1:bank3.xml

into a dictionary of lists of bank files.

Source code in sgnl/svd_bank.py
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
def parse_svdbank_string(bank_string):
    """
    parses strings of form

    H1:bank1.xml,H2:bank2.xml,L1:bank3.xml

    into a dictionary of lists of bank files.
    """
    out = {}
    if bank_string is None:
        return out
    for b in bank_string.split(","):
        ifo, bank = b.split(":")
        if ifo in out:
            raise ValueError("Only one svd bank per instrument should be given")
        out[ifo] = bank
    return out