Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #99

Merged
merged 34 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
841bd41
Simplify debug logging
equinor-ruaj Sep 25, 2024
2ece89b
Merge branch 'main' into refactor-create-config-dict
equinor-ruaj Oct 1, 2024
988745b
Simplify method
equinor-ruaj Oct 1, 2024
06aae31
Move function used only for test fixture
equinor-ruaj Oct 1, 2024
6bfb3f6
Simplify method
equinor-ruaj Oct 1, 2024
1de9b55
Remove unused import
equinor-ruaj Oct 1, 2024
e57d4ac
Remove get_help functionality
equinor-ruaj Oct 1, 2024
ad66e89
Simplify convert_table_2_sumo_file and convert_xtgeo_2_sumo_file
equinor-ruaj Oct 1, 2024
b195741
Remove debug logging
equinor-ruaj Oct 1, 2024
d102818
Remove test of removed function
equinor-ruaj Oct 1, 2024
653b10f
Move asserts to before function returns
equinor-ruaj Oct 1, 2024
a5f346a
Remove code asserts in favour of tests
equinor-ruaj Oct 1, 2024
c6f8932
Remove deprecated argument
equinor-ruaj Oct 1, 2024
5ade0b3
Fix test_get_table to test what it says it does
equinor-ruaj Oct 1, 2024
9f69d0e
Remove unused function
equinor-ruaj Oct 1, 2024
e9b7e69
Organize imports
equinor-ruaj Oct 1, 2024
fd2c303
Run tests sequentially
equinor-ruaj Oct 1, 2024
84af214
Simplify global dict specification
equinor-ruaj Oct 8, 2024
2604770
Reduce debug logging
equinor-ruaj Oct 8, 2024
ac2cd0f
Simplify test constants and remove verbose prints
equinor-ruaj Oct 8, 2024
1860f31
Remove params that were always defaulted
equinor-ruaj Oct 8, 2024
ad3f33e
Remove verbose logging and some refactoring
equinor-ruaj Oct 8, 2024
1c3881e
Move sleep to after the action that makes the sleep necessary
equinor-ruaj Oct 8, 2024
76804d6
Simplify test assert
equinor-ruaj Oct 9, 2024
4487b42
Remove deprecated ssdl block from test config files
equinor-ruaj Oct 9, 2024
48324a2
Fix test warning could not auto detect case path
equinor-ruaj Oct 9, 2024
cac6cb4
Add required info when setting content=property on grid3d metadata
equinor-ruaj Oct 9, 2024
8a77c97
Make printout after test ert run more readable
equinor-ruaj Oct 9, 2024
2e33208
Separate test that runs ert to own file
equinor-ruaj Oct 10, 2024
e3da67e
Simplify
equinor-ruaj Oct 10, 2024
202ee30
Fix typo
equinor-ruaj Oct 10, 2024
67ad292
Simplify function return
equinor-ruaj Oct 10, 2024
cfa2dec
Fix warning message
equinor-ruaj Oct 10, 2024
0db081c
Remove logging
equinor-ruaj Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest]
max-parallel: 1
permissions:
contents: read
id-token: write
Expand Down Expand Up @@ -57,4 +58,4 @@ jobs:
python -c 'import sys; print(sys.platform)'
python -c 'import os; import sys; print(os.path.dirname(sys.executable))'

pytest --log-cli-level WARNING -s --timeout=300
pytest --log-cli-level=WARNING -s --timeout=300
50 changes: 1 addition & 49 deletions src/fmu/sumo/sim2sumo/_special_treatments.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def convert_to_arrow(frame):
logger.debug("!!!!Using convert to arrow!!!")
standard = {"DATE": pa.timestamp("ms")}
if "DATE" in frame.columns:
frame["DATE"] = pd.to_datetime(
frame["DATE"], infer_datetime_format=True
)
frame["DATE"] = pd.to_datetime(frame["DATE"])
equinor-ruaj marked this conversation as resolved.
Show resolved Hide resolved
scheme = []
for column_name in frame.columns:
if pd.api.types.is_string_dtype(frame[column_name]):
Expand Down Expand Up @@ -85,7 +83,6 @@ def find_functions_and_docstring(submod):
if name not in {"deck", "eclfiles"}
),
"arrow_convertor": find_arrow_convertor(import_path),
"doc": func.__doc__,
}

return returns
Expand Down Expand Up @@ -192,30 +189,20 @@ def vfp_to_arrow_dict(datafile, options):
Returns:
tuple: vfp keyword, then dictionary with key: table_name, value: table
"""
logger = logging.getLogger(__file__ + ".vfp_to_arrow_dict")
filepath_no_suffix = Path(datafile).with_suffix("")
resdatafiles = res2df.ResdataFiles(filepath_no_suffix)
vfp_dict = {}
keyword = options.get("keyword", ["VFPPROD", "VFPINJ"])
logger.debug("keyword is %s", keyword)
vfpnumbers = options.get("vfpnumbers", None)
if isinstance(keyword, str):
keywords = [keyword]
else:
keywords = keyword

logger.debug("%s keywords to go through", len(keywords))

for keyword in keywords:
vfp_dict[keyword] = res2df.vfp._vfp.pyarrow_tables(
resdatafiles.get_deck(), keyword=keyword, vfpnumbers_str=vfpnumbers
)

logger.debug(
"Keyword %s, extracted %s vfp tables",
keyword,
len(vfp_dict[keyword]),
)
return vfp_dict


Expand Down Expand Up @@ -264,38 +251,3 @@ def add_md_to_rft(rft_table, md_file_path):
logger.debug("Head of merged table to return:\n %s", rft_table.head())

return rft_table


def give_help(submod, only_general=False):
"""Give descriptions of variables available for submodule

Args:
submod (str): submodule

Returns:
str: description of submodule input
"""
general_info = """
This utility uses the library ecl2csv, but uploads directly to sumo. Required options are:
A config file in yaml format, where you specifiy the variables to extract. What is required
is a keyword in the config called "sim2simo". under there you have three optional arguments:
* datafile: this can be a string, a list, or it can be absent altogether
* datatypes: this needs to be a list, or non existent
* options: The options are listed below in the original documentation from ecl2csv. The eclfiles
option is replaced with what is under datafile

"""
if submod is None:
only_general = True
if only_general:
text_to_return = general_info
else:
try:
text_to_return = general_info + SUBMOD_DICT[submod]["doc"]
except KeyError:
text_to_return = (
f"subtype {submod} does not exist!!, existing options:\n"
+ "\n".join(SUBMODULES)
)

return text_to_return
61 changes: 7 additions & 54 deletions src/fmu/sumo/sim2sumo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import psutil
import yaml


from fmu.dataio import ExportData
from fmu.sumo.uploader import SumoConnection
from fmu.sumo.uploader._fileonjob import FileOnJob
from fmu.sumo.uploader._upload_files import upload_files
from fmu.sumo.sim2sumo._special_treatments import (
SUBMOD_DICT,
Expand Down Expand Up @@ -49,15 +47,11 @@ def get_case_uuid(file_path, parent_level=4):
Returns:
str: the case uuid
"""
logger = logging.getLogger(__name__ + ".get_case_uuid")
logger.debug("Asked for parent %s for %s", parent_level, file_path)
case_meta_path = (
Path(file_path).parents[parent_level] / "share/metadata/fmu_case.yml"
)
logger.debug("Case meta path: %s", case_meta_path)
case_meta = yaml_load(case_meta_path)
uuid = case_meta["fmu"]["case"]["uuid"]
logger.info("Case uuid: %s", uuid)
return uuid


Expand Down Expand Up @@ -114,11 +108,12 @@ def find_full_path(datafile, paths):
try:
return paths[data_name]
except KeyError:
mess = (
"Datafile %s, with derived name %s, not found in %s,"
" have to skip"
logger.warning(
"Datafile %s, with derived name %s, not found in %s, have to skip",
datafile,
data_name,
paths,
)
logger.warning(mess, datafile, data_name, paths)
return None


Expand All @@ -137,7 +132,7 @@ def find_datafile_paths():
paths[name] = data_path
else:
logger.warning(
"Name %s from file %s allready used", name, data_path
"Name %s from file %s already used", name, data_path
)

return paths
Expand All @@ -161,10 +156,7 @@ def create_config_dict(config, datafile=None, datatype=None):
logger.debug("Input config keys are %s", config.keys())

simconfig = config.get("sim2sumo", {})
if len(simconfig) == 0:
logger.warning("We are starting from scratch")
else:
logger.debug("This is the starting point %s", simconfig)
logger.debug("sim2sumo config %s", simconfig)
grid3d = simconfig.get("grid3d", False)
if isinstance(simconfig, bool):
simconfig = {}
Expand Down Expand Up @@ -403,7 +395,6 @@ def _upload(self):

def finish(self):
"""Cleanup"""
self._logger.info("Final stretch")
self._upload()


Expand Down Expand Up @@ -467,44 +458,6 @@ def generate_meta(config, datafile_path, tagname, obj, content):
return metadata


def convert_2_sumo_file(obj, converter, metacreator, meta_args):
"""Convert object to sumo file

Args:
obj (object): the object
converter (func): function to convert to bytestring
metacreator (func): the function that creates the metadata
meta_args (iterable): arguments for generating metadata

Returns:
SumoFile: file containing obj
"""
logger = logging.getLogger(__name__ + ".convert_2_sumo_file")
logger.debug("Obj type: %s", type(obj))
logger.debug("Convert function %s", converter)
logger.debug("Meta function %s", metacreator)
logger.debug("Arguments for creating metadata %s", meta_args)
if obj is None:
logger.warning("Nothing to do with None object")
return obj
bytestring = converter(obj)
metadata = metacreator(*meta_args)
logger.debug("Metadata created")
assert isinstance(
metadata, dict
), f"meta should be dict, but is {type(metadata)}"
assert isinstance(
bytestring, bytes
), f"bytestring should be bytes, but is {type(bytestring)}"
sumo_file = FileOnJob(bytestring, metadata)
logger.debug("Init of sumo file")
sumo_file.path = metadata["file"]["relative_path"]
sumo_file.metadata_path = ""
sumo_file.size = len(sumo_file.byte_string)
logger.debug("Returning from func")
return sumo_file


def nodisk_upload(files, parent_id, config_path, env="prod", connection=None):
"""Upload files to sumo

Expand Down
Loading