Skip to content

Commit

Permalink
Split if table is summary
Browse files Browse the repository at this point in the history
  • Loading branch information
equinor-ruaj committed Jan 23, 2025
1 parent 4df1662 commit 6eb02e4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 52 deletions.
5 changes: 3 additions & 2 deletions src/fmu/sumo/sim2sumo/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def generate_table_meta(datafile, obj, tagname, config):

def convert_table_2_sumo_file(datafile, obj, tagname, config):
"""Convert table to Sumo File ready for shipping to sumo
If the table has more than 500 columns and a table index is defined
If the table is a summary table and has a defined table_index
we also return the table in chunks of 500 columns with
_sumo.hidden set to True
Expand All @@ -137,8 +137,9 @@ def convert_table_2_sumo_file(datafile, obj, tagname, config):
chunk_size = 500
columns = metadata["data"]["spec"]["columns"]
table_index = metadata["data"]["table_index"]
tagname = metadata["data"]["tagname"]

if len(columns) > chunk_size and table_index:
if table_index and tagname == "summary":
cols = [c for c in columns if c not in table_index]
chunks = batched(cols, chunk_size - len(table_index))
for idx, chunk in enumerate(chunks):
Expand Down
80 changes: 40 additions & 40 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def check_sumo(case_uuid, tag_prefix, correct, class_type, sumo):
results = sumo.get(path, query).json()

returned = results["hits"]["total"]["value"]
assert returned == check_nr, (
f"Supposed to upload {check_nr}, but actual were {returned}"
)
assert (
returned == check_nr
), f"Supposed to upload {check_nr}, but actual were {returned}"

sumo.delete(
path,
Expand All @@ -72,12 +72,12 @@ def check_expected_exports(expected_exports, shared_grid, prefix):
nr_parameter = len(parameters)
nr_meta = len(meta)
assert nr_parameter == nr_meta
assert nr_parameter == expected_exports, (
f"exported {nr_parameter} params, should be {expected_exports}"
)
assert nr_meta == expected_exports, (
f"exported {nr_meta} metadata objects, should be {expected_exports}"
)
assert (
nr_parameter == expected_exports
), f"exported {nr_parameter} params, should be {expected_exports}"
assert (
nr_meta == expected_exports
), f"exported {nr_meta} metadata objects, should be {expected_exports}"


@pytest.mark.parametrize(
Expand All @@ -89,9 +89,9 @@ def check_expected_exports(expected_exports, shared_grid, prefix):
)
def test_non_standard_filter_options(submod, options, expected):
returned_options = filter_options(submod, options)
assert len(returned_options) > 0, (
f"No options left for {submod}, should be {expected}"
)
assert (
len(returned_options) > 0
), f"No options left for {submod}, should be {expected}"


@pytest.mark.parametrize(
Expand Down Expand Up @@ -137,13 +137,13 @@ def test_create_config_dict(config, nrdatafiles, nrsubmodules, tmp_path):
copytree(REEK_REAL1, real1)
os.chdir(real1)
inputs = create_config_dict(sim2sumo_config)
assert len(inputs) == nrdatafiles, (
f"{inputs.keys()} expected to have len {nrdatafiles} datafiles"
)
assert (
len(inputs) == nrdatafiles
), f"{inputs.keys()} expected to have len {nrdatafiles} datafiles"
for submod, subdict in inputs.items():
assert len(subdict) == nrsubmodules, (
f"{subdict} for {submod} expected to have {nrsubmodules} submodules"
)
assert (
len(subdict) == nrsubmodules
), f"{subdict} for {submod} expected to have {nrsubmodules} submodules"


def test_Dispatcher(case_uuid, token, scratch_files, monkeypatch):
Expand Down Expand Up @@ -180,9 +180,9 @@ def test_convert_xtgeo_to_sumo_file(
sleep(SLEEP_TIME)
obj = get_sumo_object(sumo, case_uuid, "FIPNUM", "EIGHTCELLS")
prop = gridproperty_from_file(obj)
assert isinstance(prop, GridProperty), (
f"obj should be xtgeo.GridProperty but is {type(prop)}"
)
assert isinstance(
prop, GridProperty
), f"obj should be xtgeo.GridProperty but is {type(prop)}"
assert allclose(prop.values, eightfipnum.values)
assert allequal(prop.values, eightfipnum.values)

Expand All @@ -201,9 +201,9 @@ def test_convert_table_2_sumo_file(
sleep(SLEEP_TIME)
obj = get_sumo_object(sumo, case_uuid, "EIGHTCELLS", "rft")
table = pq.read_table(obj)
assert isinstance(table, pa.Table), (
f"obj should be pa.Table but is {type(table)}"
)
assert isinstance(
table, pa.Table
), f"obj should be pa.Table but is {type(table)}"
assert table == reekrft
check_sumo(case_uuid, "rft", 1, "table", sumo)

Expand Down Expand Up @@ -282,7 +282,7 @@ def test_upload_tables_from_simulation_run(
monkeypatch.chdir(scratch_files[0])

disp = Dispatcher(scratch_files[1], "dev")
expected_results = 2
expected_results = 3
tables.upload_tables_from_simulation_run(
REEK_DATA_FILE,
{"summary": {"arrow": True}, "rft": {"arrow": True}},
Expand Down Expand Up @@ -314,17 +314,17 @@ def test_submodules_dict():
assert isinstance(submods, dict)
for submod_name, submod_dict in submods.items():
assert isinstance(submod_name, str)
assert "/" not in submod_name, (
f"Left part of folder path for {submod_name}"
)
assert (
"/" not in submod_name
), f"Left part of folder path for {submod_name}"
assert isinstance(submod_dict, dict), f"{submod_name} has no subdict"
assert "options" in submod_dict, (
f"{submod_name} does not have any options"
)
assert (
"options" in submod_dict
), f"{submod_name} does not have any options"

assert isinstance(submod_dict["options"], tuple), (
f"options for {submod_name} not tuple"
)
assert isinstance(
submod_dict["options"], tuple
), f"options for {submod_name} not tuple"


@pytest.mark.parametrize(
Expand All @@ -345,9 +345,9 @@ def test_get_table(submod):
f" but returned {type(frame)}"
)
if submod == "summary":
assert frame.schema.field("FOPT").metadata is not None, (
"Metdata not carried across for summary"
)
assert (
frame.schema.field("FOPT").metadata is not None
), "Metdata not carried across for summary"


def test_convert_to_arrow():
Expand All @@ -369,9 +369,9 @@ def test_find_datafiles_reek(real, nrdfiles):
os.chdir(real)
datafiles = find_datafiles(None)
expected_tools = ["eclipse", "opm", "ix", "pflotran"]
assert len(datafiles) == nrdfiles, (
f"Expected {nrdfiles} datafiles but found {len(datafiles)}"
)
assert (
len(datafiles) == nrdfiles
), f"Expected {nrdfiles} datafiles but found {len(datafiles)}"
for found_path in datafiles:
parent = found_path.parent.parent.name
assert parent in expected_tools, f"|{parent}| not in {expected_tools}"
Expand Down
20 changes: 10 additions & 10 deletions tests/test_with_ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def write_ert_config_and_run(runpath):
error_content = Path(runpath / "ERROR").read_text(encoding=encoding)
except FileNotFoundError:
error_content = ""
assert not error_content, (
f"ERROR file found with content:\n{error_content}"
)
assert Path(runpath / "OK").is_file(), (
f"running {ert_full_config_path}, No OK file"
)
assert (
not error_content
), f"ERROR file found with content:\n{error_content}"
assert Path(
runpath / "OK"
).is_file(), f"running {ert_full_config_path}, No OK file"


def test_sim2sumo_with_ert(
Expand All @@ -54,7 +54,7 @@ def test_sim2sumo_with_ert(
real0 = ert_run_scratch_files[0]
# ! This changes files in the current directory and deletes parameters.txt
write_ert_config_and_run(real0)
expected_exports = 88
expected_exports = 90
path = f"/objects('{ert_run_case_uuid}')/search"
results = sumo.post(
path,
Expand All @@ -80,6 +80,6 @@ def test_sim2sumo_with_ert(
).json()

returned = results["hits"]["total"]["value"]
assert returned == expected_exports, (
f"Supposed to upload {expected_exports}, but actual were {returned}"
)
assert (
returned == expected_exports
), f"Supposed to upload {expected_exports}, but actual were {returned}"

0 comments on commit 6eb02e4

Please sign in to comment.