def filter_injections_by_mass(injs, mbins, bin_num, bin_type, bin_num2=None):
    '''
    For a given set of injections (sim_inspiral rows), return the subset
    of injections that fall within the given mass range.
    '''
    if bin_type == "Mass1_Mass2":
        m1bins = numpy.concatenate((mbins.lower()[0],
                                    numpy.array([mbins.upper()[0][-1]])))
        m1lo = m1bins[bin_num]
        m1hi = m1bins[bin_num + 1]
        m2bins = numpy.concatenate((mbins.lower()[1],
                                    numpy.array([mbins.upper()[1][-1]])))
        m2lo = m2bins[bin_num2]
        m2hi = m2bins[bin_num2 + 1]
        newinjs = [l for l in injs if
                   ((m1lo <= l.mass1 < m1hi and m2lo <= l.mass2 < m2hi) or
                    (m1lo <= l.mass2 < m1hi and m2lo <= l.mass1 < m2hi))]
        return newinjs

    mbins = numpy.concatenate((mbins.lower()[0],
                               numpy.array([mbins.upper()[0][-1]])))
    mlow = mbins[bin_num]
    mhigh = mbins[bin_num + 1]
    if bin_type == "Chirp_Mass":
        newinjs = [l for l in injs if (mlow <= l.mchirp < mhigh)]
    elif bin_type == "Total_Mass":
        newinjs = [l for l in injs if (mlow <= l.mass1 + l.mass2 < mhigh)]
    elif bin_type == "Component_Mass":
        # here it is assumed that m2 is fixed
        newinjs = [l for l in injs if (mlow <= l.mass1 < mhigh)]
    elif bin_type == "BNS_BBH":
        if bin_num in [0, 2]:
            # BNS/BBH case
            newinjs = [l for l in injs if
                       (mlow <= l.mass1 < mhigh and mlow <= l.mass2 < mhigh)]
        else:
            # NSBH
            newinjs = [l for l in injs if (mbins[0] <= l.mass1 < mbins[1] and
                                           mbins[2] <= l.mass2 < mbins[3])]
            # BHNS
            newinjs += [l for l in injs if (mbins[0] <= l.mass2 < mbins[1] and
                                            mbins[2] <= l.mass1 < mbins[3])]

    return newinjs
def filter_injections_by_mass ( injs , mbins , bin_num , bin_type , bin_num2 = None ) : if bin_type == "Mass1_Mass2" : m1bins = numpy . concatenate ( ( mbins . lower ( ) [ 0 ] , numpy . array ( [ mbins . upper ( ) [ 0 ] [ - 1 ] ] ) ) ) m1lo = m1bins [ bin_num ] m1hi = m1bins [ bin_num + 1 ] m2bins = numpy . concatenate ( ( mbins . lower ( ) [ 1 ] , numpy . array ( [ mbins . upper ( ) [ 1 ] [ - 1 ] ] ) ) ) m2lo = m2bins [ bin_num2 ] m2hi = m2bins [ bin_num2 + 1 ] newinjs = [ l for l in injs if ( ( m1lo <= l . mass1 < m1hi and m2lo <= l . mass2 < m2hi ) or ( m1lo <= l . mass2 < m1hi and m2lo <= l . mass1 < m2hi ) ) ] return newinjs mbins = numpy . concatenate ( ( mbins . lower ( ) [ 0 ] , numpy . array ( [ mbins . upper ( ) [ 0 ] [ - 1 ] ] ) ) ) mlow = mbins [ bin_num ] mhigh = mbins [ bin_num + 1 ] if bin_type == "Chirp_Mass" : newinjs = [ l for l in injs if ( mlow <= l . mchirp < mhigh ) ] elif bin_type == "Total_Mass" : newinjs = [ l for l in injs if ( mlow <= l . mass1 + l . mass2 < mhigh ) ] elif bin_type == "Component_Mass" : newinjs = [ l for l in injs if ( mlow <= l . mass1 < mhigh ) ] elif bin_type == "BNS_BBH" : if bin_num in [ 0 , 2 ] : newinjs = [ l for l in injs if ( mlow <= l . mass1 < mhigh and mlow <= l . mass2 < mhigh ) ] else : newinjs = [ l for l in injs if ( mbins [ 0 ] <= l . mass1 < mbins [ 1 ] and mbins [ 2 ] <= l . mass2 < mbins [ 3 ] ) ] newinjs += [ l for l in injs if ( mbins [ 0 ] <= l . mass2 < mbins [ 1 ] and mbins [ 2 ] <= l . mass1 < mbins [ 3 ] ) ] return newinjs
For a given set of injections (sim_inspiral rows), return the subset
    of injections that fall within the given mass range.