コード例 #1
0
ファイル: main.py プロジェクト: csm-adapt/pifmod
def main ():
    global args
    # read PIF
    if args.ifile is not None:
        with open(args.ifile) as ifs:
            pifdata = pif.load(ifs)
    else:
        pifdata = pif.load(sys.stdin)
    # perform requested action
    if args.action == 'property':
        rval = str(property(pifdata))
    elif args.action == 'uid':
        rval = str(uid(pifdata))
    elif args.action == 'sagittariidae':
        if not isinstance(pifdata, list):
            pifdata = [pifdata]
        add_link = sagittariidae.link_factory(
			projectID='nq3X4-concept-inconel718',
			host='http://sagittariidae.adapt.mines.edu')
        for p in pifdata:
            add_link(p)
        return json.dumps(pifdata)
    else:
        msg = '{} is not a recognized action.'.format(args.action)
        raise ValueError(msg)
    # write PIF
    if args.ofile is not None:
        if authorize_overwrite(args.ofile):
            with open(args.ofile, 'w') as ofs:
                ofs.write(rval)
    else:
        sys.stdout.write(rval)
コード例 #2
0
ファイル: test_pifmod.py プロジェクト: csm-adapt/pifmod
	def test_property_add_Ifile(self):
		rval, out, err = execute('pifmod -i data/pif.json -o data/test.pif ' \
			'property foo=bar')
		with open('data/out.pif') as ifs:
			expected = pif.load(ifs)
		with open('data/test.pif') as ifs:
			received = pif.load(ifs)
		assert rval == 0
		assert empty(out)
		assert empty(err)
		assert compare_dictionaries(expected.as_dictionary(),
									received.as_dictionary()), \
			'\n'.join(strdiff(pif.dumps(expected), pif.dumps(received)))
コード例 #3
0
ファイル: test_pifmod.py プロジェクト: csm-adapt/pifmod
	def test_property_add_volume_Ifile(self):
		# with tags...
		rval, out, err = execute('pifmod -i data/pif.json -o data/test.pif ' \
			'property data/pore-distribution.json volume')
		with open('data/out_volume.pif') as ifs:
			expected = pif.load(ifs)
		with open('data/test.pif') as ifs:
			received = pif.load(ifs)
		assert rval == 0
		assert empty(out)
		assert empty(err)
		assert compare_dictionaries(expected.as_dictionary(),
									received.as_dictionary()), \
			'{}'.format(strdiff(pif.dumps(expected), pif.dumps(received)))
コード例 #4
0
ファイル: test_pifmod.py プロジェクト: csm-adapt/pifmod
	def test_property_add_tags_Ifile(self):
		# with tags...
		rval, out, err = execute('pifmod -i data/pif.json -o data/test.pif ' \
			'property --tag="Hello World" foo=bar')
		with open('data/out_tags.pif') as ifs:
			expected = pif.load(ifs)
		with open('data/test.pif') as ifs:
			received = pif.load(ifs)
		assert rval == 0
		assert empty(out)
		assert empty(err)
		assert compare_dictionaries(expected.as_dictionary(),
									received.as_dictionary()), \
			'{}'.format(strdiff(pif.dumps(expected), pif.dumps(received)))
コード例 #5
0
ファイル: test_pifmod.py プロジェクト: csm-adapt/pifmod
	def test_property_add_contacts_Ifile(self):
		# with contacts...
		rval, out, err = execute('pifmod -i data/pif.json -o data/test.pif ' \
			'property --contact="Branden Kappes,[email protected]" ' \
			'foo=bar')
		with open('data/out_contact.pif') as ifs:
			expected = pif.load(ifs)
		with open('data/test.pif') as ifs:
			received = pif.load(ifs)
		assert rval == 0
		assert empty(out)
		assert empty(err)
		assert compare_dictionaries(expected.as_dictionary(),
									received.as_dictionary()), \
			'{}'.format(strdiff(pif.dumps(expected), pif.dumps(received)))
コード例 #6
0
ファイル: test_pifmod.py プロジェクト: csm-adapt/pifmod
	def test_linkages_sagittariidae(self):
		# try:
		with open('data/package.json') as ifs:
			pifdata = pif.load(ifs)
		add_link = sagittariidae.link_factory(
			projectID='nq3X4-concept-inconel718',
			host='http://sagittariidae.adapt.mines.edu')
		for p in pifdata:
			add_link(p)
		with open('delme.json', 'w') as ofs:
			pif.dump(pifdata, ofs)
コード例 #7
0
def test_auto_dft():
    """Test that auto-format works"""
    argv = "tests/dft/B.hR12".split()
    args = get_cli().parse_args(args=argv)
    main(args)

    # Make sure both files are processed
    assert exists(
        "tests/dft/B.hR12/pif.json"), "Expected to find output pif for B.hR12"
    assert not exists("tests/dft/B.hR105/pif.json"
                      ), "Did not expect to find output pif for B.hR105"
    # Check basic parsing
    with open("tests/dft/B.hR12/pif.json", "r") as f:
        bhr12 = pif.load(f)[0]
    assert bhr12.chemical_formula == "B12"
コード例 #8
0
def test_recursive_dft():
    """Test that recursive application of the DFT ingester works"""
    argv = "tests/dft dft -r".split()
    args = get_cli().parse_args(args=argv)
    main(args)

    # Make sure both files are processed
    assert exists(
        "tests/dft/B.hR12/pif.json"), "Expected to find output pif for B.hR12"
    assert exists("tests/dft/B.hR105/pif.json"
                  ), "Expected to find output pif for B.hR105"

    # Check basic parsing
    with open("tests/dft/B.hR12/pif.json", "r") as f:
        bhr12 = pif.load(f)
    assert bhr12.chemical_formula == "B12"
コード例 #9
0
def test_recursive_dft():
    """Test that recursive application of the DFT ingester works"""
    argv = "tests/dft -f dft -m tests/dft/metadata.json -r".split()
    args = get_cli().parse_args(args=argv)
    main(args)

    # Make sure both files are processed
    assert exists(
        "tests/dft/B.hR12/pif.json"), "Expected to find output pif for B.hR12"
    assert exists("tests/dft/B.hR105/pif.json"
                  ), "Expected to find output pif for B.hR105"

    # Check basic parsing
    with open("tests/dft/B.hR12/pif.json", "r") as f:
        bhr12 = pif.load(f)[0]
    assert bhr12.chemical_formula == "B12"
    assert len(bhr12.contacts) == 2

    emails = set(["*****@*****.**", "*****@*****.**"])
    assert set(x.email for x in bhr12.contacts) == emails
コード例 #10
0
def test_csv_generator():
    """Test that generator-returning ingesters work"""
    argv = "tests/csv/template_example.csv".split()
    args = get_cli().parse_args(args=argv)
    main(args)

    # Make sure both files are processed
    expected_name = "tests/csv/template_example.csv_pif.json"
    assert exists(expected_name), "Expected to find output pif for template_example"

    # Check basic parsing
    with open(expected_name, "r") as f:
        csv_pif = pif.load(f)

    assert csv_pif[0].names[0] == 'P20 Tool steel'
    assert csv_pif[0].sub_systems[0].names[0] == 'Martensite'
    assert csv_pif[0].sub_systems[0].quantity.ideal_mass_percent.value == '80'
    assert csv_pif[0].contacts[0].name == 'Jo Hill'
    assert csv_pif[0].contacts[0].email == '*****@*****.**'
    assert csv_pif[0].contacts[2].name == 'Mary'
    assert csv_pif[0].contacts[2].url == 'http://jo'
コード例 #11
0
def test_dft_csv_merge():
    """Test that merge works works"""
    argv = "tests/merge/1000000.cif -f merge".split()
    args = get_cli().parse_args(args=argv)
    main(args)

    # Make sure there is an output
    assert exists("tests/merge/1000000.cif_pif.json"
                  ), "Expected to find output pif for 1000000.cif"

    # Check that one property from each ingester is included
    with open("tests/merge/1000000.cif_pif.json", "r") as f:
        merged = pif.load(f)[0]
    # This is from the calphad tdb ingester
    assert next(
        (x for x in merged.properties if x.name == "Thermodynamic database"),
        None) != None
    # This is from the CIF ingester
    space_group = next(
        (x for x in merged.properties if x.name == "Space group symbol"), None)
    assert (space_group.scalars[0].value == "P2_1/c")
コード例 #12
0
from pypif import pif
from pypif.obj import *
import csv
import json

# Open the json file that contains the pifs
json_file = open("pifs.json")

# Load json with pif
pifs = pif.load(json_file)
# Find all the CSV headers
headers = []
for p in pifs:
    props = p.properties
    names = []
    for i in props:
        names.append(i.name)
    if len(names) > len(headers):
        headers = names

# Possible attributes associated with a pif:
pif_common_objs = []
header = []

# CSV outfile
csv_out = "pifs.csv"
with open(csv_out, 'w', newline='') as outfile:
    csvwriter = csv.writer(outfile)
    csvwriter.writerow(headers)

    # Loop through each pif
コード例 #13
0
def stress_dataframe():
    with open(STRESS) as ifs:
        pifobj = pif.load(ifs)
    return pif_to_dataframe(pifobj)
コード例 #14
0
def strain_dataframe():
    with open(STRAIN) as ifs:
        pifobj = pif.load(ifs)
    return pif_to_dataframe(pifobj)
コード例 #15
0
def test_key_error_case():
    with open("./pypif_sdk/readview/tests/csv_pif.pif") as f:
        test_case = load(f)
    rv = ReadView(test_case)
    assert len(rv.keys()) > 0
コード例 #16
0
def sspif():
    # stress-strain PIF
    with open('{}/data/astm-mark10-aramis.json'.format(HERE)) as ifs:
        rval = pif.load(ifs)
    return rval