Example #1
0
def test_load_lut_from_badobject():
    try:
        emodulus.load_lut({"test": "nonesense"})
    except ValueError:
        pass
    else:
        assert False, "dict should not be supported"
Example #2
0
def test_load_lut_from_badpath():
    try:
        emodulus.load_lut("peter/pan.txt")
    except ValueError:
        pass
    else:
        assert False, "dict should not be supported"
Example #3
0
def test_load_lut_from_path():
    ref_lut, ref_meta = emodulus.load_lut("FEM-2Daxis")
    path = resource_filename("dclab.features.emodulus",
                             emodulus.load.INTERNAL_LUTS["LE-2D-FEM-19"])
    lut2, meta2 = emodulus.load_lut(path)
    assert np.all(ref_lut == lut2)
    assert ref_meta == meta2
Example #4
0
def test_load_lut_from_array():
    ref_lut, ref_meta = emodulus.load_lut("FEM-2Daxis")
    lut2, meta2 = emodulus.load_lut((ref_lut, ref_meta))
    assert np.all(ref_lut == lut2)
    assert ref_meta == meta2
    assert ref_lut is not lut2, "data should be copied"
    assert ref_meta is not meta2, "meta data should be copied"
Example #5
0
def test_bad_lut_data():
    try:
        emodulus.load_lut("bad_string_asdkubhasd")
    except ValueError:
        pass
    else:
        assert False, "Invalid `lut_data` results in ValueError"
Example #6
0
def test_extrapolate():
    """Test whether spline interpolation gives reasonable results"""
    lut, _ = emodulus.load_lut("FEM-2Daxis")

    area_norm = lut[:, 0].max()
    emodulus.normalize(lut[:, 0], area_norm)

    deform_norm = lut[:, 1].max()
    emodulus.normalize(lut[:, 1], deform_norm)

    np.random.seed(47)
    more_than_5perc = []
    valid_ones = 0

    for _ in range(100):
        # pick a few values from the LUT
        ids = np.random.randint(0, lut.shape[0], 10)
        area_um = lut[ids, 0]
        deform = lut[ids, 1]
        # set the emodulus to zero
        emod = np.nan * np.zeros(deform.size)
        # "extrapolate" within the grid using the spline
        emodulus.extrapolate_emodulus(
            lut=lut,
            datax=area_um,
            deform=deform,
            emod=emod,
            deform_norm=deform_norm,
            inplace=True)
        valid = ~np.isnan(emod)
        valid_ones += np.sum(valid)
        res = np.abs(lut[ids, 2] - emod)[valid]/lut[ids, 2][valid]
        if np.sum(res > .05):
            more_than_5perc.append([ids, res])

    assert len(more_than_5perc) == 0
    assert valid_ones == 149
Example #7
0
    # row label (medium)
    for jj in range(3):
        pos = axes[jj][0].get_position()
        x = pos.x0 - .11
        y = pos.y0 + pos.height / 2
        fig.text(x,
                 y,
                 media[jj],
                 ha='left',
                 va='center',
                 rotation=90,
                 fontsize=10,
                 fontweight="bold")

    # plot the LUTs channel-wise
    lut_base, lut_meta = emodulus.load_lut(lut_name)
    deform = np.linspace(lut_base[:, 1].min(),
                         lut_base[:, 1].max(),
                         grid_size,
                         endpoint=True)
    area_um = np.linspace(lut_base[:, 0].min(),
                          lut_base[:, 0].max(),
                          grid_size,
                          endpoint=True)
    for jj, medium in enumerate(media):  # rows
        for ii, flow_rate in enumerate(matrix[channel_width]):  # columns
            area_um_scaled = emodulus.scale_linear.scale_area_um(
                area_um=area_um,
                channel_width_in=lut_meta["channel_width"],
                channel_width_out=channel_width)
            aa, dd = np.meshgrid(area_um_scaled, deform)