equinor / fmu-dataio

FMU data standard and data export with rich metadata in the FMU context
https://fmu-dataio.readthedocs.io/en/latest/
Apache License 2.0
10 stars 15 forks source link

Faultroom export lacks mapping of juxtapositions to SMDA names #724

Open mferrera opened 3 months ago

mferrera commented 3 months ago

[T]he new faultroom export is lacking mapping of juxtapositions to standardized (SMDA) names.

but I think this should be part of fmu-dataio, probably as part of fmu.dataio.ExportData

The best would be to also include the uuid for the strat unit, but I see that this is currently not included in the global variables stratigraphy. The best solution would be to also include the uuids there and then map everything related to stratigraphy into sumo with both name and uuid. (The reason being obviously that with uuid, you know you get the right one, but the names are not unique as it exist both multiple strat tables in many fields AND various fields have the same strat unit names in the strat tables.

CFG = utils.yaml_load('../../../../../../../../../testdata/global_variables.yml')
stratigraphy_name_mapper = {k: v['name'] for k, v in CFG['stratigraphy'].items()}

def dataio_faultroom():
    edata = dio.ExportData(
        config=CFG, content="fault_properties"
    )
    faultroom_files = Path('../../../../../../../../../testdata/faultroom').glob("*.json")
    for faultroom_file in faultroom_files:
        fdata = dio.readers.read_faultroom_file(faultroom_file)

        # This will change the metadata
        for s in fdata.juxtaposition_fw + fdata.juxtaposition_hw:
            # Trig error if stratigraphy is not in map (thus not in the fmu config)
            assert s in stratigraphy_name_mapper
        fdata.juxtaposition_fw = [stratigraphy_name_mapper.get(s) for s in fdata.juxtaposition_fw]
        fdata.juxtaposition_hw = [stratigraphy_name_mapper.get(s) for s in fdata.juxtaposition_hw]
        output = edata.export(fdata, tagname=faultroom_file.stem)
        print(f"Output is: {output}")

        # Reload and fix json file
        json_file = Path(output)
        faultroom_data = json.loads(json_file.read_text())
        faultroom_data['metadata']['juxtaposition']['fw'] = [stratigraphy_name_mapper.get(x) for x in faultroom_data['metadata']['juxtaposition']['fw']]
        faultroom_data['metadata']['juxtaposition']['hw'] = [stratigraphy_name_mapper.get(x) for x in faultroom_data['metadata']['juxtaposition']['hw']]
        with json_file.open('w') as outfile:
            json.dump(faultroom_data, outfile, indent=4)
mferrera commented 6 days ago

In the Faultroom export we have

https://github.com/equinor/fmu-dataio/blob/1cc79a8a04fa6f774fd118b8678083bec9215374/tests/data/drogon/rms/output/faultroom/ex_faultroom_1.3.1.json#L18-L23

These are the juxtaposition names in the faultroom file that are relevant to RMS. However, they are not aligned with the names in SMDA. The idea is to make these RMS names to the ones in SMDA, and this mapping already exists in the global configuration file:

https://github.com/equinor/fmu-dataio/blob/1a1054e025d9a91f0613bd50bbd021c8946026e1/examples/s/d/nn/xcase/realization-0/iter-0/fmuconfig/output/global_variables.yml#L62-L70

The idea is when exported the faultroom metadata, the SMDA name should be exported in the metadata, not the RMS name.

This requires having access to the global configuration file, so it should be done in the object data provider without modifying the original faultroom export file or its parsed object in Python.

https://github.com/equinor/fmu-dataio/blob/1cc79a8a04fa6f774fd118b8678083bec9215374/src/fmu/dataio/providers/objectdata/_faultroom.py#L69-L76

Then an initial implementation could be placing a helper function either in the data provider class so that it has access to dataio.config

https://github.com/equinor/fmu-dataio/blob/1cc79a8a04fa6f774fd118b8678083bec9215374/src/fmu/dataio/providers/objectdata/_faultroom.py#L24-L26

We can take some inspiration from the existing implementation in the ObjectDataProvider base class:

https://github.com/equinor/fmu-dataio/blob/1cc79a8a04fa6f774fd118b8678083bec9215374/src/fmu/dataio/providers/objectdata/_base.py#L198-L207

In this case we'd only need the name and can ignore some part:

if (
    isinstance(self.dataio.config, GlobalConfiguration)
    and (strat := self.dataio.config.stratigraphy)
    and name in strat
):
    return strat[name].name