Skip to content

Commit

Permalink
invoke format
Browse files Browse the repository at this point in the history
  • Loading branch information
keurfonluu committed Jun 12, 2022
1 parent e6bb2d8 commit 00b4ca7
Show file tree
Hide file tree
Showing 30 changed files with 66 additions and 215 deletions.
2 changes: 1 addition & 1 deletion test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def random_label(label_length):
n = label_length - 3
fmt = "{{:0{}d}}".format(n)

return random_string(3) + fmt.format(np.random.randint(10**n))
return random_string(3) + fmt.format(np.random.randint(10 ** n))


def allclose_dict(a, b, atol=1.0e-8):
Expand Down
43 changes: 10 additions & 33 deletions test/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
)

write_read_tough = lambda x: write_read(
x,
writer_kws={"file_format": "tough"},
reader_kws={"file_format": "tough"},
x, writer_kws={"file_format": "tough"}, reader_kws={"file_format": "tough"},
)

write_read_json = lambda x: write_read(
x,
writer_kws={"file_format": "json"},
reader_kws={"file_format": "json"},
x, writer_kws={"file_format": "json"}, reader_kws={"file_format": "json"},
)


Expand Down Expand Up @@ -244,8 +240,7 @@ def test_ncgas(write_read):


@pytest.mark.parametrize(
"write_read, isothermal",
[(write_read_tough, True), (write_read_tough, False)],
"write_read, isothermal", [(write_read_tough, True), (write_read_tough, False)],
)
def test_multi(write_read, isothermal):
import random
Expand Down Expand Up @@ -409,9 +404,7 @@ def test_indom(write_read, num_pvars, num_items):
num_items = num_items if num_items else np.random.randint(10) + 1
parameters_ref = {
"rocks": {
helpers.random_string(5): {
"initial_condition": np.random.rand(num_pvars),
}
helpers.random_string(5): {"initial_condition": np.random.rand(num_pvars),}
for _ in range(num_items)
},
}
Expand Down Expand Up @@ -785,18 +778,9 @@ def test_meshm_xyz():
"n_increment": np.random.randint(100) + 1,
"sizes": np.random.rand(),
},
{
"type": "ny",
"sizes": np.random.rand(np.random.randint(100) + 1),
},
{
"type": "nz",
"sizes": np.random.rand(np.random.randint(100) + 1),
},
{
"type": "nx",
"sizes": np.random.rand(np.random.randint(100) + 1),
},
{"type": "ny", "sizes": np.random.rand(np.random.randint(100) + 1),},
{"type": "nz", "sizes": np.random.rand(np.random.randint(100) + 1),},
{"type": "nx", "sizes": np.random.rand(np.random.randint(100) + 1),},
],
"angle": np.random.rand(),
}
Expand Down Expand Up @@ -830,10 +814,7 @@ def test_meshm_rz2d(layer):
"meshmaker": {
"type": "rz2dl" if layer else "rz2d",
"parameters": [
{
"type": "radii",
"radii": np.random.rand(np.random.randint(100) + 1),
},
{"type": "radii", "radii": np.random.rand(np.random.randint(100) + 1),},
{
"type": "equid",
"n_increment": np.random.randint(100) + 1,
Expand Down Expand Up @@ -875,9 +856,7 @@ def test_tmvoc():
"eos": "tmvoc",
"n_component": 1,
"n_phase": 1,
"default": {
"phase_composition": np.random.randint(10),
},
"default": {"phase_composition": np.random.randint(10),},
"rocks": {
helpers.random_string(5): {
"initial_condition": np.random.rand(4),
Expand All @@ -894,9 +873,7 @@ def test_tmvoc():
},
}
parameters = write_read(
parameters_ref,
writer_kws={"eos": "tmvoc"},
reader_kws={"eos": "tmvoc"},
parameters_ref, writer_kws={"eos": "tmvoc"}, reader_kws={"eos": "tmvoc"},
)

helpers.allclose_dict(parameters_ref["default"], parameters["default"])
Expand Down
23 changes: 5 additions & 18 deletions test/test_mesh_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@

output_ref = {
"element": {
0: {
"PRES": 9641264.130638,
"TEMP": 149.62999493,
},
-1: {
"PRES": 635804.12294844,
"TEMP": 142.89449866,
},
0: {"PRES": 9641264.130638, "TEMP": 149.62999493,},
-1: {"PRES": 635804.12294844, "TEMP": 142.89449866,},
},
"connection": {
0: {
"HEAT": -1.64908253e-07,
"FLOW": -2.85760551e-13,
},
-1: {
"HEAT": -5.54750914e-08,
"FLOW": -4.68234504e-14,
},
0: {"HEAT": -1.64908253e-07, "FLOW": -2.85760551e-13,},
-1: {"HEAT": -5.54750914e-08, "FLOW": -4.68234504e-14,},
},
}

Expand Down Expand Up @@ -227,8 +215,7 @@ def test_near():

@pytest.mark.skipif(sys.version_info < (3, 6), reason="Order of keys in dictionary")
@pytest.mark.parametrize(
"num_pvars, eos",
[(4, None), (6, None), (4, "tmvoc")],
"num_pvars, eos", [(4, None), (6, None), (4, "tmvoc")],
)
def test_write_tough(num_pvars, eos):
this_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down
4 changes: 1 addition & 3 deletions test/test_meshio.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def test_meshio(mesh_ref, file_format, binary):
writer_kws["binary"] = binary

mesh = write_read(
mesh=mesh_ref,
writer_kws=writer_kws,
reader_kws={"file_format": file_format},
mesh=mesh_ref, writer_kws=writer_kws, reader_kws={"file_format": file_format},
)
if file_format == "flac3d":
mesh_ref.cell_data.pop("c", None)
Expand Down
7 changes: 2 additions & 5 deletions test/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def test_output_eleme(filename, filename_ref):


@pytest.mark.parametrize(
"filename",
["OUTPUT_CONNE.csv", "OUTPUT.out", "OUTPUT_6.out"],
"filename", ["OUTPUT_CONNE.csv", "OUTPUT.out", "OUTPUT_6.out"],
)
def test_output_conne(filename):
this_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -147,9 +146,7 @@ def test_output_conne(filename):
)
def test_output(output_ref, file_format):
output = write_read(
output=output_ref,
writer_kws={"file_format": file_format},
reader_kws={},
output=output_ref, writer_kws={"file_format": file_format}, reader_kws={},
)

output_ref = output_ref if isinstance(output_ref, list) else [output_ref]
Expand Down
15 changes: 3 additions & 12 deletions test/test_react.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,7 @@ def write_read(x):
parameters_ref = {
"title": helpers.random_string(80),
"primary_species": [
{
"name": helpers.random_string(20),
"transport": np.random.randint(2),
}
{"name": helpers.random_string(20), "transport": np.random.randint(2),}
for _ in range(np.random.randint(5) + 1)
],
"aqueous_kinetics": [
Expand Down Expand Up @@ -513,10 +510,7 @@ def write_read(x):
},
],
"gaseous_species": [
{
"name": helpers.random_string(20),
"fugacity": np.random.randint(2),
}
{"name": helpers.random_string(20), "fugacity": np.random.randint(2),}
for _ in range(np.random.randint(5) + 1)
],
"surface_complexes": [
Expand Down Expand Up @@ -673,10 +667,7 @@ def write_read(x):
pp = "partial_pressure" if key == "initial_gases" else "mole_fraction"
parameters_ref["zones"][key] = [
[
{
"name": helpers.random_string(20),
pp: np.random.rand(),
}
{"name": helpers.random_string(20), pp: np.random.rand(),}
for _ in range(np.random.randint(5) + 1)
]
for _ in range(np.random.randint(5) + 1)
Expand Down
4 changes: 1 addition & 3 deletions toughio/_cli/_co2tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def _get_parser():

# Output path
parser.add_argument(
"path",
type=str,
help="directory path",
"path", type=str, help="directory path",
)

return parser
29 changes: 7 additions & 22 deletions toughio/_cli/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def export(argv=None):
print("{} ...".format(msg), end="")
sys.stdout.flush()
points, axis = _get_points(
output if args.file_format != "xdmf" else output[0],
args.ignore_elements,
output if args.file_format != "xdmf" else output[0], args.ignore_elements,
)
ndim = len(axis)
print(" Done!")
Expand Down Expand Up @@ -131,7 +130,7 @@ def export(argv=None):

if args.ignore_elements:
data = data[mask]

mesh.add_cell_data(label, data[idx])

voxelized = True
Expand All @@ -149,7 +148,7 @@ def export(argv=None):
for label, data in output.data.items():
if label in {"X", "Y", "Z"}:
continue

if args.ignore_elements:
data = data[mask]

Expand Down Expand Up @@ -233,36 +232,22 @@ def _get_parser():

# Input file
parser.add_argument(
"infile",
type=str,
help="TOUGH output file",
"infile", type=str, help="TOUGH output file",
)

# Mesh file
parser.add_argument(
"--mesh",
"-m",
type=str,
default=None,
help="pickled toughio.Mesh",
"--mesh", "-m", type=str, default=None, help="pickled toughio.Mesh",
)

# Time step
parser.add_argument(
"--time-step",
"-t",
type=int,
default=None,
help="time step to export",
"--time-step", "-t", type=int, default=None, help="time step to export",
)

# Output file
parser.add_argument(
"--output-file",
"-o",
type=str,
default=None,
help="exported file",
"--output-file", "-o", type=str, default=None, help="exported file",
)

# File format
Expand Down
8 changes: 2 additions & 6 deletions toughio/_cli/_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,12 @@ def _get_parser():

# Input file
parser.add_argument(
"infile",
type=str,
help="TOUGH output file",
"infile", type=str, help="TOUGH output file",
)

# Mesh file
parser.add_argument(
"mesh",
type=str,
help="TOUGH MESH file (can be INFILE)",
"mesh", type=str, help="TOUGH MESH file (can be INFILE)",
)

# Output file
Expand Down
4 changes: 1 addition & 3 deletions toughio/_cli/_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def _get_parser():

# Input file
parser.add_argument(
"infile",
type=str,
help="TOUGH input file",
"infile", type=str, help="TOUGH input file",
)

# Output file
Expand Down
14 changes: 3 additions & 11 deletions toughio/_cli/_save2incon.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,17 @@ def _get_parser():

# Input file
parser.add_argument(
"infile",
type=str,
help="SAVE file to convert",
"infile", type=str, help="SAVE file to convert",
)

# Output file
parser.add_argument(
"outfile",
type=str,
help="converted INCON file",
"outfile", type=str, help="converted INCON file",
)

# Reset
parser.add_argument(
"--reset",
"-r",
default=False,
action="store_true",
help="reset all counters",
"--reset", "-r", default=False, action="store_true", help="reset all counters",
)

return parser
22 changes: 4 additions & 18 deletions toughio/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
2: "10d,10.3e,10.3e,10.3e,10.3e,10.3e,10.3e,10.3e",
3: "5d,5s,10.3e,10.3e,10.3e,10.3e,10.3e,10.3e,10.3e",
},
"CHEMP": {
1: "5d",
2: "20s",
3: ",".join(5 * ["10.3e"]),
},
"CHEMP": {1: "5d", 2: "20s", 3: ",".join(5 * ["10.3e"]),},
"NCGAS": {1: "5d", 2: "10s"},
"MULTI": ",".join(5 * ["5d"]),
"SELEC": {1: ",".join(16 * ["5d"]), 2: ",".join(8 * ["10.3e"])},
Expand Down Expand Up @@ -89,23 +85,13 @@
},
"MESHM": {
1: "5s",
"XYZ": {
1: "10.3e",
2: "5s,5d,10.4e",
3: ",".join(8 * ["10.4e"]),
},
"XYZ": {1: "10.3e", 2: "5s,5d,10.4e", 3: ",".join(8 * ["10.4e"]),},
"RZ2D": {
1: "5s",
"RADII": {
1: "5d",
2: ",".join(8 * ["10.3e"]),
},
"RADII": {1: "5d", 2: ",".join(8 * ["10.3e"]),},
"EQUID": "5d,5s,10.4e",
"LOGAR": "5d,5s,10.4e,10.4e",
"LAYER": {
1: "5d",
2: ",".join(8 * ["10.4e"]),
},
"LAYER": {1: "5d", 2: ",".join(8 * ["10.4e"]),},
},
},
"REACT": "25S",
Expand Down
Loading

0 comments on commit 00b4ca7

Please sign in to comment.