hainegroup / oceanspy

A Python package to facilitate ocean model data analysis and visualization.
https://oceanspy.readthedocs.io
MIT License
98 stars 32 forks source link

Include new forcing variables in mates list (llc_rearrange) for transforming topology #322

Closed Mikejmnez closed 1 year ago

Mikejmnez commented 1 year ago

Transforming (rotating+transposing) llc-data, requires to know the mate variable when transforming data variables associaed with a vector field. For example, in a rotated facet, the local U-variable is actually -V since the local I-index (or X in oceanspy) is parallel to latitude, and increasing i (or 'X') yields a lower (southern) latitude.

The way oceanspy works with this, is through a function name mates (line 619 in llc_rearrange.py), which iterates through all variables of a dataset and associates its mate as long as said variable is defined in a list of mated-vars vars_mates. The function in hand is:

def mates(ds):
    vars_mates = [
        "ADVx_SLT",
        "ADVy_SLT",
        "ADVx_TH",
        "ADVy_TH",
        "DFxE_TH",
        "DFyE_TH",
        "DFxE_SLT",
        "DFyE_SLT",
        "maskW",
        "maskS",
        "TAUX",
        "TAUY",
        "U",
        "V",
        "UVELMASS",
        "VVELMASS",
        "dxC",
        "dyC",
        "dxG",
        "dyG",
        "HFacW",
        "HFacS",
        "rAw",
        "rAs",
        "CS",
        "SN",
    ]
    for k in range(int(len(vars_mates) / 2)):
        nk = 2 * k
        if vars_mates[nk] in ds.variables:
            ds[vars_mates[nk]].attrs["mate"] = vars_mates[nk + 1]
            ds[vars_mates[nk + 1]].attrs["mate"] = vars_mates[nk]
    return ds

Not the most elegant way to do this, but the easiest I could think of. This has worked so far with LLC4320 since these are all the data variables and grid variables that we had available.

However, there is a pair of forcing variables (from the newly available forcing variables) that need to be included in the list above, so that these can be properly transformed when necessary. These are:

['SIuice', 'SIvice']

In addition, the list above has TAUX and TAUY, but their default name is oceTAUX and oceTAUY (that is also how they appear when reading theEGshelfIIseas2km_ASR_full dataset -- see Kogur.ipynb) .

Before, those variables weren't available so it never caused an issue. This is a super quick fix.

Mikejmnez commented 1 year ago

closed by PR #325