Exemple #1
0
def test_integer_regions():
    """Regions are sometimes integer, and then they will
    typically be returned as integers from the yaml parsing"""
    mapper = fipmapper.FipMapper(mapdata={"fipnum2region": {1: 1, 2: 2}})
    assert mapper.fip2region(1) == [1]
    assert mapper.fip2region(2) == [2]
    assert mapper.region2fip(1) == [1]
    assert mapper.region2fip(2) == [2]
Exemple #2
0
def test_fipmapper_zones():
    mapper = fipmapper.FipMapper(
        mapdata={"fipnum2zone": {
            1: "Upper",
            2: "Middle",
            3: "Middle"
        }})
    assert mapper.fip2zone(1) == ["Upper"]
    assert mapper.fip2zone(2) == ["Middle"]
    assert mapper.fip2zone(3) == ["Middle"]
    assert mapper.zone2fip("Upper") == [1]
    assert mapper.zone2fip("Middle") == [2, 3]
Exemple #3
0
def test_fipmapper():
    mapper = fipmapper.FipMapper(
        mapdata={"fipnum2region": {
            1: "West-Brent",
            2: "East-Sognefjord"
        }})
    assert mapper.fip2region(1) == ["West-Brent"]
    assert mapper.fip2region(2) == ["East-Sognefjord"]
    assert mapper._fips2regions([1, 2]) == [["West-Brent"],
                                            ["East-Sognefjord"]]
    assert mapper.region2fip("West-Brent") == [1]
    assert mapper._regions2fips(["West-Brent"]) == [[1]]
    assert mapper._regions2fips(["West-Brent", "East-Sognefjord"]) == [[1],
                                                                       [2]]
    def __init__(self, volumes_table: pd.DataFrame, fipfile: Path = None):

        self.volume_sources: Dict[str, List[str]] = {
            "static": [],
            "dynamic": [],
            "unknown": [],
        }
        self.disjoint_set_df = (fipmapper.FipMapper(
            yamlfile=fipfile).disjoint_sets() if fipfile else None)
        self.dframe = self.validate_and_combine_sources(volumes_table)
        self.drop_rows_with_totals_from_selectors()
        self.volume_type = self.set_volumetric_type()

        if self.volume_type == "mixed":
            self.drop_total_columns()
Exemple #5
0
def test_fipmapper_regzone2fip():
    mapper = fipmapper.FipMapper(
        mapdata={
            "fipnum2zone": {
                1: "Upper",
                2: "Middle",
                3: "Upper",
                4: "Middle"
            },
            "fipnum2region": {
                1: "West-Brent",
                2: "West-Brent",
                3: "East-Sognefjord",
                4: "East-Sognefjord",
            },
        })
    assert mapper.regzone2fip("West-Brent", "Upper") == [1]
    assert mapper.regzone2fip("West-Brent", "Middle") == [2]
    assert mapper.regzone2fip("East-Sognefjord", "Upper") == [3]
    assert mapper.regzone2fip("East-Sognefjord", "Middle") == [4]
Exemple #6
0
def test_mixed_datatypes():
    """Mixed ints/strs in regions and zones"""
    mapper = fipmapper.FipMapper(mapdata={
        "fipnum2region": {
            1: 1,
            2: "B"
        },
        "fipnum2zone": {
            1: 1,
            2: "L"
        }
    })
    assert mapper.fip2region(1) == [1]
    assert mapper.fip2region(2) == ["B"]
    assert mapper.region2fip(1) == [1]
    assert mapper.region2fip("B") == [2]

    assert mapper.fip2zone(1) == [1]
    assert mapper.fip2zone(2) == ["L"]
    assert mapper.zone2fip(1) == [1]
    assert mapper.zone2fip("L") == [2]
def test_documentation_example(tmp_path, mocker):
    """Test the example that is used in the documentation"""
    # pylint: disable=line-too-long
    os.chdir(tmp_path)
    print(
        f"\nLook in {tmp_path} for input and output to be used in documentation"
    )
    Path("FOO.PRT").write_text(
        """
  REPORT   0     1 JAN 2000
                                                =================================
                                                : FIPNUM  REPORT REGION    1    :
                                                :     PAV =        139.76  BARSA:
                                                :     PORV=     27777509.   RM3 :
                           :--------------- OIL    SM3  ---------------:-- WAT    SM3  -:--------------- GAS    SM3  ---------------:
                           :     LIQUID         VAPOUR         TOTAL   :       TOTAL    :       FREE      DISSOLVED         TOTAL   :
 :-------------------------:-------------------------------------------:----------------:-------------------------------------------:
 :CURRENTLY IN PLACE       :          100.                         100.:           200. :           400.           0.           400.:
 :-------------------------:-------------------------------------------:----------------:-------------------------------------------:

                                                =================================
                                                : FIPNUM  REPORT REGION    2    :
                                                :     PAV =        139.76  BARSA:
                                                :     PORV=     27777509.   RM3 :
                           :--------------- OIL    SM3  ---------------:-- WAT    SM3  -:--------------- GAS    SM3  ---------------:
                           :     LIQUID         VAPOUR         TOTAL   :       TOTAL    :       FREE      DISSOLVED         TOTAL   :
 :-------------------------:-------------------------------------------:----------------:-------------------------------------------:
 :CURRENTLY IN PLACE       :          200.                         200.:           400. :           800.           0.           800.:
 :-------------------------:-------------------------------------------:----------------:-------------------------------------------:
""",  # noqa
        encoding="utf8",
    )
    Path("volumetrics_sim_oil_1.txt").write_text(
        """
   Zone      Region index          Bulk                Pore                Hcpv               Stoiip
Upper  West                             500.0              400.                300.00              50.40
Lower  West                             500.0              400.                300.00              50.40
Upper  East                            1000.0              800.                600.00              100.40
Lower  East                            1000.0              800.                600.00              100.40
""",  # noqa
        encoding="utf8",
    )
    Path("volumetrics_sim_gas_1.txt").write_text(
        """
   Zone      Region index          Bulk                Pore                Hcpv              Giip
Upper  West                             500.0              400.                300.00              200.40
Lower  West                             500.0              400.                300.00              200.40
Upper  East                            1000.0              800.                600.00              404.40
Lower  East                            1000.0              800.                600.00              404.40
""",  # noqa
        encoding="utf8",
    )
    Path("fipmap_config_1.yml").write_text(
        """
region2fipnum:
  West: [1]
  East: [2]
zone2fipnum:
  Upper: [1, 2]
  Lower: [1, 2]""",
        encoding="utf8",
    )
    Path("fipmap_config_2.yml").write_text(
        """
fipnum2region:
  1: West
  2: East
fipnum2zone:
  1:
   - Upper
   - Lower
  2:
   - Upper
   - Lower""",
        encoding="utf8",
    )
    Path("fipmap_config_3.yml").write_text(
        """
FIPNUM:
  groups:
    REGION:
      West: [1]
      East: [2]
    ZONE:
      Upper: [1, 2]
      Lower: [1, 2]""",
        encoding="utf8",
    )
    mocker.patch(
        "sys.argv",
        [
            "rmsecl_volumetrics",
            "FOO.PRT",
            "volumetrics_sim",
            "fipmap_config_1.yml",
            "--sets",
            "sets.yml",
            "--output",
            "volcomp.csv",
        ],
    )
    main()
    print(Path("sets.yml").read_text(encoding="utf8"))
    print(Path("volcomp.csv").read_text(encoding="utf8"))
    print(pd.read_csv("volcomp.csv"))
    sets_fromdisk = yaml.safe_load(Path("sets.yml").read_text(encoding="utf8"))
    assert sets_fromdisk == {
        0: {
            "FIPNUM": [2],
            "REGION": ["East"],
            "ZONE": ["Lower", "Upper"]
        },
        1: {
            "FIPNUM": [1],
            "REGION": ["West"],
            "ZONE": ["Lower", "Upper"]
        },
    }
    mocker.patch(
        "sys.argv",
        [
            "rmsecl_volumetrics",
            "FOO.PRT",
            "volumetrics_sim",
            "fipmap_config_1.yml",
        ],
    )
    main()

    # Run again to get the script output:

    # Test that the three yaml files give the same disjoint sets
    disjoint_sets_1 = fipmapper.FipMapper(
        yamlfile="fipmap_config_1.yml").disjoint_sets()
    disjoint_sets_2 = fipmapper.FipMapper(
        yamlfile="fipmap_config_2.yml").disjoint_sets()
    disjoint_sets_3 = fipmapper.FipMapper(
        yamlfile="fipmap_config_3.yml").disjoint_sets()

    pd.testing.assert_frame_equal(disjoint_sets_1, disjoint_sets_2)
    pd.testing.assert_frame_equal(disjoint_sets_1, disjoint_sets_3)
Exemple #8
0
def test_fipmapper_empty():
    mapper = fipmapper.FipMapper()
    assert mapper.has_region2fip is False
    assert mapper.has_zone2fip is False
    assert mapper.has_fip2region is False
    assert mapper.has_fip2zone is False