Ejemplo n.º 1
0
def test_scaling():
    # Test integer scaling from float
    # Analyze headers cannot do float-integer scaling '''
    hdr = AnalyzeHeader()
    yield assert_true, hdr.default_x_flip
    shape = (1,2,3)
    hdr.set_data_shape(shape)
    hdr.set_data_dtype(np.float32)
    data = np.ones(shape, dtype=np.float64)
    S = StringIO()
    # Writing to float datatype doesn't need scaling
    write_scaled_data(hdr, data, S)
    rdata = read_data(hdr, S)
    yield assert_true, np.allclose(data, rdata)
    # Writing to integer datatype does, and raises an error
    hdr.set_data_dtype(np.int32)
    yield (assert_raises, HeaderTypeError, write_scaled_data,
           hdr, data, StringIO())
    # unless we aren't scaling, in which case we convert the floats to
    # integers and write
    write_data(hdr, data, S)
    rdata = read_data(hdr, S)
    yield assert_true, np.allclose(data, rdata)
    # This won't work for floats that aren't close to integers
    data_p5 = data + 0.5
    write_data(hdr, data_p5, S)
    rdata = read_data(hdr, S)
    yield assert_false, np.allclose(data_p5, rdata)
Ejemplo n.º 2
0
def test_best_affine():
    hdr = AnalyzeHeader()
    hdr.set_data_shape((3,5,7))
    hdr.set_zooms((4,5,6))
    yield assert_array_equal, hdr.get_base_affine(), hdr.get_best_affine()