def test_int_mean_options(od, varNameList, axesList, storeWeights):
    if axesList == "wrong":
        with pytest.raises(ValueError):
            weighted_mean(
                od,
                varNameList=varNameList,
                axesList=axesList,
                storeWeights=storeWeights,
            )
    else:
        weighted_mean(od,
                      varNameList=varNameList,
                      axesList=axesList,
                      storeWeights=storeWeights)
def test_integral(od, varNameList):
    int_ds = integral(od, varNameList)
    w_mean_ds = weighted_mean(od, varNameList)
    int_name = [var for var in int_ds.data_vars][0]
    var = int_ds[int_name]
    check = (w_mean_ds["w_mean_" + varNameList] *
             w_mean_ds["weight_" + varNameList].sum())
    assert var.values == check.values
def test_shortcuts(od_in):

    # Only use some variables
    list_calc = [
        "Temp",
        "U",
        "V",
        "W",
        "HFacC",
        "HFacW",
        "HFacS",
        "drC",
        "drF",
        "dxC",
        "dyC",
        "dxF",
        "dyF",
        "dxG",
        "dyG",
        "dxV",
        "dyU",
        "rA",
        "rAw",
        "rAs",
        "rAz",
    ]
    od_in = od_in.subsample.cutout(varList=list_calc)

    # Gradient
    ds_out = gradient(od_in)
    od_out = od_in.compute.gradient()
    ds_out_IN_od_out(ds_out, od_out)

    # Divergence
    ds_out = divergence(od_in, iName="U", jName="V", kName="W")
    od_out = od_in.compute.divergence(iName="U", jName="V", kName="W")
    ds_out_IN_od_out(ds_out, od_out)

    # Curl
    ds_out = curl(od_in, iName="U", jName="V", kName="W")
    od_out = od_in.compute.curl(iName="U", jName="V", kName="W")
    ds_out_IN_od_out(ds_out, od_out)

    # Laplacian
    ds_out = laplacian(od_in, "Temp")
    od_out = od_in.compute.laplacian(varNameList="Temp")
    ds_out_IN_od_out(ds_out, od_out)

    # Weighted mean
    ds_out = weighted_mean(od_in)
    od_out = od_in.compute.weighted_mean()
    ds_out_IN_od_out(ds_out, od_out)

    # Integral
    ds_out = integral(od_in)
    od_out = od_in.compute.integral()
    ds_out_IN_od_out(ds_out, od_out)
def test_weighted_mean(od, varNameList):
    w_mean_ds = weighted_mean(od, varNameList)
    var = w_mean_ds["w_mean_" + varNameList].values
    check = od.dataset[varNameList].mean().values
    assert var == check