Example #1
0
def test_tag_preservation():
    """Test that we can preserve tags/comments through interpolation"""
    wo_low = WaterOil(swl=0.1)
    wo_high = WaterOil(swl=0.2)
    wo_low.add_corey_water(nw=2)
    wo_high.add_corey_water(nw=3)
    wo_low.add_corey_oil(now=2)
    wo_high.add_corey_oil(now=3)
    interpolant1 = utils.interpolate_wo(wo_low, wo_high, parameter=0.1, h=0.2)
    assert "Interpolated to 0.1" in interpolant1.tag
    assert sat_table_str_ok(interpolant1.SWOF())

    wo_high.tag = "FOOBAR"
    interpolant2 = utils.interpolate_wo(wo_low, wo_high, parameter=0.1, h=0.2)
    assert "Interpolated to 0.1" in interpolant2.tag
    assert "between" in interpolant2.tag
    assert wo_high.tag in interpolant2.tag
    assert sat_table_str_ok(interpolant2.SWOF())
    # wo_low.tag was empty deliberately here.

    # When wo_log and wo_high has the same tag:
    wo_low.tag = "FOOBAR"
    interpolant3 = utils.interpolate_wo(wo_low, wo_high, parameter=0.1, h=0.2)
    assert "Interpolated to 0.1" in interpolant3.tag
    assert "between" not in interpolant3.tag
    assert wo_high.tag in interpolant3.tag
    assert sat_table_str_ok(interpolant3.SWOF())

    # Explicit tag:
    interpolant4 = utils.interpolate_wo(wo_low,
                                        wo_high,
                                        parameter=0.1,
                                        h=0.2,
                                        tag="Explicit tag")
    assert interpolant4.tag == "Explicit tag"

    # Tag with newline
    interpolant6 = utils.interpolate_wo(wo_low,
                                        wo_high,
                                        parameter=0.1,
                                        h=0.2,
                                        tag="Explicit tag\non two lines")
    assert "Explicit tag" in interpolant6.tag
    print(interpolant6.SWOF())
    assert sat_table_str_ok(interpolant6.SWOF())

    # Empty tag:
    interpolant5 = utils.interpolate_wo(wo_low,
                                        wo_high,
                                        parameter=0.1,
                                        h=0.2,
                                        tag="")
    assert interpolant5.tag == ""

    # Also sample check for GasOil (calls the same code)
    go_low = GasOil()
    go_high = GasOil()
    go_low.add_corey_gas(ng=2)
    go_high.add_corey_gas(ng=3)
    go_low.add_corey_oil(nog=2)
    go_high.add_corey_oil(nog=3)
    interpolant1 = utils.interpolate_go(go_low, go_high, parameter=0.1, h=0.2)
    assert "Interpolated to 0.1" in interpolant1.tag
    assert sat_table_str_ok(interpolant1.SGOF())
Example #2
0
    def create_gas_oil(params=None):
        """Create a GasOil object from a dictionary of parameters.

        Parameterization (Corey/LET) is inferred from presence
        of certain parameters in the dictionary.

        Don't rely on behaviour of you supply both Corey and LET at
        the same time.

        NB: the add_LET_* methods have the names 'l', 'e' and 't'
        in their signatures, which is not precise enough in this
        context, so we require e.g. 'Lg' and 'Log' (which both will be
        translated to 'l')
        """
        if not params:
            params = dict()
        if not isinstance(params, dict):
            raise TypeError("Parameter to create_gas_oil must be a dictionary")

        # For case insensitiveness, all keys are converted to lower case:
        params = {key.lower(): value for (key, value) in params.items()}

        usedparams = set()
        # No requirements to the base objects, defaults are ok.
        gasoil = GasOil(**slicedict(params, GO_INIT))
        usedparams = usedparams.union(set(slicedict(params, GO_INIT).keys()))
        logging.info("Initialized GasOil object from parameters %s",
                     str(list(usedparams)))

        # Gas curve
        params_corey_gas = slicedict(params, GO_COREY_GAS + GO_GAS_ENDPOINTS)
        params_let_gas = slicedict(params, GO_LET_GAS + GO_GAS_ENDPOINTS)
        if set(GO_COREY_GAS).issubset(set(params_corey_gas)):
            gasoil.add_corey_gas(**params_corey_gas)
            usedparams = usedparams.union(set(params_corey_gas.keys()))
            logging.info(
                "Added Corey gas to GasOil object from parameters %s",
                str(params_corey_gas.keys()),
            )
        elif set(GO_LET_GAS).issubset(set(params_let_gas)):
            params_let_gas["l"] = params_let_gas.pop("lg")
            params_let_gas["e"] = params_let_gas.pop("eg")
            params_let_gas["t"] = params_let_gas.pop("tg")
            gasoil.add_LET_gas(**params_let_gas)
            usedparams = usedparams.union(set(params_let_gas.keys()))
            logging.info(
                "Added LET gas to GasOil object from parameters %s",
                str(params_let_gas.keys()),
            )
        else:
            logging.warning(
                "Missing or ambiguous parameters for gas curve in GasOil object"
            )

        # Oil curve:
        params_corey_oil = slicedict(params, GO_COREY_OIL + GO_OIL_ENDPOINTS)
        params_let_oil = slicedict(params, GO_LET_OIL + GO_OIL_ENDPOINTS)
        if set(GO_COREY_OIL).issubset(set(params_corey_oil)):
            gasoil.add_corey_oil(**params_corey_oil)
            logging.info(
                "Added Corey gas to GasOil object from parameters %s",
                str(params_corey_oil.keys()),
            )
        elif set(GO_LET_OIL).issubset(set(params_let_oil)):
            params_let_oil["l"] = params_let_oil.pop("log")
            params_let_oil["e"] = params_let_oil.pop("eog")
            params_let_oil["t"] = params_let_oil.pop("tog")
            gasoil.add_LET_oil(**params_let_oil)
            logging.info(
                "Added LET gas to GasOil object from parameters %s",
                str(params_let_oil.keys()),
            )
        else:
            logging.warning(
                "Missing or ambiguous parameters for oil curve in GasOil object"
            )
        if not gasoil.selfcheck():
            raise ValueError(("Incomplete GasOil object, some parameters "
                              "missing to factory"))

        return gasoil
Example #3
0
def test_plotting():
    """Test that plotting code pass through (nothing displayed)"""
    gasoil = GasOil(swl=0.1, h=0.1)
    gasoil.add_corey_gas()
    gasoil.add_corey_oil()
    gasoil.plotkrgkrog(mpl_ax=matplotlib.pyplot.subplots()[1])
Example #4
0
def make_gasoil_plot(show=True, krgendanchor="sorg"):
    """Make a plot explaining the inputs to a GasOil object"""
    plt.xkcd()
    _, axes = plt.subplots()
    swl = 0.1
    sgcr = 0.2
    sorg = 0.2
    krgend = 0.7
    krgmax = 0.75
    kroend = 0.85
    gasoil = GasOil(sgcr=sgcr, sorg=sorg, swl=swl, krgendanchor=krgendanchor)
    gasoil2 = GasOil(sgcr=sgcr, sorg=sorg, swl=swl, krgendanchor=None)
    gasoil.add_corey_gas(ng=3, krgend=krgend, krgmax=krgmax)
    gasoil2.add_corey_gas(ng=3, krgend=krgend)
    gasoil.add_corey_oil(nog=3, kroend=kroend)
    gasoil2.add_corey_oil(nog=3, kroend=kroend)
    gasoil2.table.plot(ax=axes,
                       x="sg",
                       y="krg",
                       c="pink",
                       alpha=0.7,
                       label="KRG*",
                       linewidth=2)
    gasoil.table.plot(ax=axes,
                      x="sg",
                      y="krg",
                      c="red",
                      alpha=1,
                      label="KRG",
                      linewidth=2)
    gasoil.table.plot(ax=axes,
                      x="sg",
                      y="krog",
                      c="green",
                      alpha=1,
                      label="KROG",
                      linewidth=2)
    plt.ylim([-0.02, 1])
    plt.xticks([0, 1])
    plt.yticks([0, 1])
    axes.annotate(
        "KROEND",
        xy=(0, kroend),
        arrowprops=dict(arrowstyle="->"),
        xytext=(0.1, kroend - 0.2),
    )
    axes.annotate(
        "KRGEND",
        xy=(1 - sorg - swl, krgend),
        arrowprops=dict(arrowstyle="->"),
        xytext=(1 - sorg - swl + 0.01, krgmax - 0.2),
    )
    # Overwrite with same text at identical spots for
    # two arrows:
    axes.annotate(
        "KRGEND",
        xy=(1 - swl, krgend),
        arrowprops=dict(arrowstyle="->"),
        xytext=(1 - sorg - swl + 0.01, krgmax - 0.2),
    )
    axes.annotate(
        "KRGMAX",
        xy=(1 - swl, krgmax),
        arrowprops=dict(arrowstyle="->"),
        xytext=(1 - swl - 0.2, krgmax + 0.1),
    )
    axes.annotate(
        "SGCR",
        xy=(sgcr, 0),
        arrowprops=dict(arrowstyle="->"),
        xytext=(sgcr - 0.05, 0 + 0.14),
    )
    plt.xlabel("SG", labelpad=-10)
    axes.annotate(
        "",
        xy=(1 - sorg - swl, 0.02),
        xytext=(1 - swl, 0.02),
        arrowprops=dict(arrowstyle="<->"),
    )
    axes.text(1 - sorg - swl + 0.04, 0.04, "SORG")
    axes.annotate("",
                  xy=(1 - swl, 0.02),
                  xytext=(1, 0.02),
                  arrowprops=dict(arrowstyle="<->"))
    axes.text(1 - swl + 0.04, 0.04, "SWL")
    axes.legend(loc="upper center")
    if show:
        plt.show()