Beispiel #1
0
def test_create_expr_mask_size_error(mask):
    """What happens when the mask][True] and vals arrays have different sizes?

    This should be an error but currently isn't.
    """

    with pytest.raises(ValueError) as exc:
        utils.create_expr([1, 2, 3, 4], mask)

    assert str(exc.value) == 'mask array mis-match with vals'
Beispiel #2
0
def test_create_expr_missing_nomask():
    """Simple test of create_expr with no mask with missing data"""

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    chans = chans[(chans < 12) | (chans > 13)]
    out = utils.create_expr(chans)
    assert out == "1-11,14-19"
Beispiel #3
0
def test_create_expr_mask_delim():
    """Simple test of create_expr with an identity mask."""

    chans = numpy.arange(1, 10, dtype=numpy.int16)
    mask = numpy.ones(9, dtype=bool)
    out = utils.create_expr(chans, mask, delim='::')
    assert out == "1::9"
Beispiel #4
0
def test_create_expr_missing_multiple1_nomask():
    """Simple test of create_expr with no mask with missing data"""

    chans = numpy.asarray([1, 2, 4, 6, 7, 10, 18], dtype=numpy.int16)
    out = utils.create_expr(chans)

    assert out == "1-2,4,6-7,10,18"
Beispiel #5
0
def test_create_expr_missing_mask():
    """Simple test of create_expr with an identity with missing data"""

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    filt = (chans < 12) | (chans > 13)
    out = utils.create_expr(chans[filt], filt)
    assert out == "1-11,14-19"
Beispiel #6
0
 def get_filter(self, format='%.4f', delim=':'):
     # for derived intergrated classes, this will return values in center of
     # bin.
     x = self.get_x(filter=True)
     mask = numpy.ones(len(x), dtype=bool)
     if numpy.iterable(self.mask):
         mask = self.mask
     return create_expr(x, mask, format, delim)
Beispiel #7
0
 def get_filter(self, format='%.4f', delim=':'):
     # for derived intergrated classes, this will return values in center of
     # bin.
     x = self.get_x(filter=True)
     mask = numpy.ones(len(x), dtype=bool)
     if numpy.iterable(self.mask):
         mask = self.mask
     return create_expr(x, mask, format, delim)
Beispiel #8
0
def test_create_expr_mask_dropend():
    """End is masked out"""

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    filt = chans < 5

    vals = numpy.arange(19) * 0.01 + 0.4
    out = utils.create_expr(vals[filt], filt, format='%4.2f')
    assert out == "0.40-0.43"
Beispiel #9
0
def test_create_expr_missing_mask_nonchannels():
    """What happens if the input is not in channel units?"""

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    filt = (chans < 12) | (chans > 13)

    vals = numpy.arange(19) * 0.01 + 0.4
    out = utils.create_expr(vals[filt], filt, format='%4.2f')
    assert out == "0.40-0.50,0.53-0.58"
Beispiel #10
0
def test_create_expr_mask_dropend2():
    """End is masked out"""

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    filt = (chans < 15) & ((chans < 8) | (chans > 11))

    vals = numpy.arange(19) * 0.01 + 0.4
    out = utils.create_expr(vals[filt], filt, format='%4.2f')
    assert out == "0.40-0.46,0.51-0.53"
Beispiel #11
0
def test_create_expr_mask_drop():
    """mask all the things (but leave some data!)"""

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    filt = (chans > 5) & (chans < 15) & ((chans < 10) | (chans > 12))

    vals = numpy.arange(19) * 0.01 + 0.4
    out = utils.create_expr(vals[filt], filt, format='%4.2f')
    assert out == "0.45-0.48,0.52-0.53"
Beispiel #12
0
def test_create_expr_mask_dropstart2():
    """Start is masked out"""

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    filt = (chans > 3) & ((chans < 8) | (chans > 10))

    vals = numpy.arange(19) * 0.01 + 0.4
    out = utils.create_expr(vals[filt], filt, format='%4.2f')
    assert out == "0.43-0.46,0.50-0.58"
Beispiel #13
0
def test_create_expr_missing_end_nomask():
    """Simple test of create_expr with no mask with missing data

    Ends with a single bin.
    """

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    chans = chans[chans != 18]
    out = utils.create_expr(chans)
    assert out == "1-17,19"
Beispiel #14
0
def test_create_expr_missing_start_nomask():
    """Simple test of create_expr with no mask with missing data

    Have a single bin, then missing data, then the rest
    """

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    chans = chans[chans != 2]
    out = utils.create_expr(chans)
    assert out == "1,3-19"
Beispiel #15
0
def test_create_expr_mask_singlebin(idx):
    """mask all the things (but leave one bin)"""

    filt = numpy.zeros(19, dtype=bool)
    filt[idx] = True

    vals = numpy.arange(19) * 0.01 + 0.4
    out = utils.create_expr(vals[filt], filt, format='%4.2f')
    expected = "{:4.2f}".format(vals[filt][0])
    assert out == expected
Beispiel #16
0
def test_create_expr_missing_start2_mask():
    """How does this compare to nomask version?"""

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    filt = chans != 3

    vals = numpy.arange(19) * 0.01 + 0.4
    out = utils.create_expr(vals[filt], filt, format='%4.2f')

    assert out == "0.40-0.41,0.43-0.58"
Beispiel #17
0
def test_create_expr_mask_singlebins():
    """several single bin"""

    filt = numpy.zeros(19, dtype=bool)
    filt[0] = True
    filt[2] = True
    filt[16] = True
    filt[18] = True

    vals = numpy.arange(19) * 0.01 + 0.4
    out = utils.create_expr(vals[filt], filt, format='%4.2f')
    assert out == "0.40,0.42,0.56,0.58"
Beispiel #18
0
def test_create_expr_missing_nomask_nonchannels():
    """What happens if the input is not in channel units?"""

    chans = numpy.arange(1, 20, dtype=numpy.int16)
    filt = (chans < 12) | (chans > 13)

    vals = numpy.arange(19) * 0.01 + 0.4
    out = utils.create_expr(vals[filt], format='%4.2f')

    # I am not sure this is the correct output, but it's what
    # we create.
    #
    vs = ['{:4.2f}'.format(v) for v in vals[filt]]
    expected = ','.join(vs)
    assert out == expected
Beispiel #19
0
def test_create_expr_nomask():
    """Simple test of create_expr with no mask."""

    chans = numpy.arange(1, 10, dtype=numpy.int16)
    out = utils.create_expr(chans)
    assert out == "1-9"
Beispiel #20
0
def test_create_expr_singleton(val, expected):
    """Simple test of create_expr with no mask."""

    out = utils.create_expr(numpy.asarray([val]))
    assert out == expected
Beispiel #21
0
def test_create_expr_empty_mask():
    """What happens if the mask is all masked out"""
    mask = numpy.zeros(5, dtype=bool)

    out = utils.create_expr([], mask)
    assert out == ""
Beispiel #22
0
def test_create_expr_nomask_delim():
    """Simple test of create_expr with no mask."""

    chans = numpy.arange(1, 10, dtype=numpy.int16)
    out = utils.create_expr(chans, delim='::')
    assert out == "1::9"
Beispiel #23
0
def test_create_expr_empty():
    """Simple test of create_expr with no mask."""

    out = utils.create_expr([])
    assert out == ""