コード例 #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 プロジェクト: awantae/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.)
コード例 #3
0
ファイル: test_ovf.py プロジェクト: anyint/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
コード例 #4
0
ファイル: test_ovf.py プロジェクト: awantae/oommf-python
def test_example_docstring_write_ovff10(tmpdir, field1):
    from ovf import OVFFile, OVF10
    fl = field1
    ovf = OVFFile()
    ovf.new(fl, version=OVF10, data_type="binary8")
    path = os.path.join(str(tmpdir), "newfile.ovf")
    ovf.write(path)
    ovf.write("tmp_test_ovf1.ovf")
    assert os.path.exists(path)
    filecontent = open(path, encoding='ISO-8859-1').read()
    assert filecontent.startswith("""# OOMMF: rectangular mesh v1.0
# Segment count: 1
# Begin: Segment
# Begin: Header
# Title: Title
# meshtype: rectangular
# meshunit: 1.0""")
コード例 #5
0
ファイル: test_ovf.py プロジェクト: awantae/oommf-python
def test_example_docstring_write_ovff20(tmpdir, field1):
    from ovf import OVFFile, OVF20
    fl = field1
    # Save it to file, with OVF2 format
    ovf = OVFFile()
    ovf.new(fl, version=OVF20, data_type="binary8")
    path = os.path.join(str(tmpdir), "newfile.ovf")
    ovf.write(path)
    assert os.path.exists(path)
    filecontent = open(path, encoding='ISO-8859-1').read()
    assert filecontent.startswith("""# OOMMF OVF 2.0
# Segment count: 1
# Begin: Segment
# Begin: Header
# Title: Title""")
    # for reading test
    ovf.write("tmp_test_ovf2.ovf")