コード例 #1
0
ファイル: test_ovf.py プロジェクト: fangohr/nmag-src
def just_test_one(fl, ver, data_type, mesh_type, filename):
    quasi_zero = small_value[data_type]

    print "Testing OVF%s,%s,%s" % (ver[0], data_type, mesh_type)

    print "Writing file to disk"
    f = OVFFile()
    f.new(fl, version=ver, data_type=data_type, mesh_type=mesh_type)
    f.write(filename)

    print "Reading file back"
    g = OVFFile(filename)

    print "Checking consistency"
    g_data = g.content.a_segment.a_data.field
    f_data = f.content.a_segment.a_data.field
    diff = f_data - g_data
    diff_norm = ((diff ** 2).sum()) ** 0.5

    assert diff_norm <= quasi_zero, "Saved and loaded data differ. Difference is %g > %g." % (diff_norm, quasi_zero)

    print "norm(loaded - saved) = %g <= %g" % (diff_norm, quasi_zero)
    print

    import os

    try:
        os.unlink(filename)
    except:
        pass
コード例 #2
0
ファイル: test_ovf.py プロジェクト: fangohr/oommf-python
def test_example_docstring_read_ovf_file_ovf2():
    from ovf import OVFFile, OVF20
    ovf_file = OVFFile("tmp_test_ovf2.ovf")
    assert ovf_file.content.ovf_version == OVF20
    fl = ovf_file.get_field()
    assert fl.field_dim == 3
    assert np.allclose(fl.field_data[0, :, :, 0], 1.)
    assert np.allclose(fl.field_data[1, :, :, 0], 2.)
    assert np.allclose(fl.field_data[2, :, :, 0], 3.)