pyTMD icon indicating copy to clipboard operation
pyTMD copied to clipboard

Refactor to define known models using a JSON database

Open tsutterley opened this issue 1 year ago • 5 comments

Will simplify the io/model.py program and possibly make creating new entries easier. Would be similar to the databases in geopandas/xyzservices or geopandas/geodatasets

tsutterley avatar Sep 04 '24 18:09 tsutterley

Hey @tsutterley, this would be brilliant, and I think would go a long way towards making model setup much more reproducible.

In the background I've been working on implementing something similar, but am super happy to shift to this instead! In case it helps, here's a bit of a JSON/dict catalgoue I've been working on for some of the more niche models/variants:

NONSTANDARD_MODELS = {
    # GOT5.6 (which includes GOT5.5 constituents)
    "GOT5.6": {
        "format": "GOT-netcdf",
        "name": "GOT5.6",
        "model_file": [
            "GOT5.5/ocean_tides/2n2.nc",
            "GOT5.5/ocean_tides/j1.nc",
            "GOT5.5/ocean_tides/k1.nc",
            "GOT5.5/ocean_tides/k2.nc",
            "GOT5.6/ocean_tides/l2.nc",
            "GOT5.6/ocean_tides/m1.nc",
            "GOT5.5/ocean_tides/m2.nc",
            "GOT5.6/ocean_tides/m3.nc",
            "GOT5.5/ocean_tides/m4.nc",
            "GOT5.5/ocean_tides/ms4.nc",
            "GOT5.5/ocean_tides/mu2.nc",
            "GOT5.6/ocean_tides/n2.nc",
            "GOT5.5/ocean_tides/o1.nc",
            "GOT5.5/ocean_tides/oo1.nc",
            "GOT5.5/ocean_tides/p1.nc",
            "GOT5.5/ocean_tides/q1.nc",
            "GOT5.5/ocean_tides/s1.nc",
            "GOT5.5/ocean_tides/s2.nc",
            "GOT5.5/ocean_tides/sig1.nc",
        ],
        "type": "z",
        "variable": "tide_ocean",
        "version": "5.6",
        "scale": 0.01,
        "compressed": False,
        "reference": "https://doi.org/10.1126/sciadv.abd4744",
    },
    # Extrapolated version of GOT5.6 (which includes GOT5.5 constituents)
    "GOT5.6_extrapolated": {
        "format": "GOT-netcdf",
        "name": "GOT5.6_extrapolated",
        "model_file": [
            "GOT5.5/extrapolated/2n2x.nc",
            "GOT5.5/extrapolated/j1x.nc",
            "GOT5.5/extrapolated/k1x.nc",
            "GOT5.5/extrapolated/k2x.nc",
            "GOT5.6/extrapolated/l2x.nc",
            "GOT5.6/extrapolated/m1x.nc",
            "GOT5.5/extrapolated/m2x.nc",
            "GOT5.6/extrapolated/m3x.nc",
            "GOT5.5/extrapolated/m4x.nc",
            "GOT5.5/extrapolated/ms4x.nc",
            "GOT5.5/extrapolated/mu2x.nc",
            "GOT5.6/extrapolated/n2x.nc",
            "GOT5.5/extrapolated/o1x.nc",
            "GOT5.5/extrapolated/oo1x.nc",
            "GOT5.5/extrapolated/p1x.nc",
            "GOT5.5/extrapolated/q1x.nc",
            "GOT5.5/extrapolated/s1x.nc",
            "GOT5.5/extrapolated/s2x.nc",
            "GOT5.5/extrapolated/sig1x.nc",
        ],
        "type": "z",
        "variable": "tide_ocean",
        "version": "5.6",
        "scale": 0.01,
        "compressed": False,
        "reference": "https://doi.org/10.1126/sciadv.abd4744",
    },
    # FES2012
    "FES2012": {
        "format": "FES-netcdf",
        "name": "FES2012",
        "model_file": "fes2012/data/*_FES2012_SLEV.nc",
        "type": "z",
        "version": "FES2012",
        "variable": "tide_ocean",
        "scale": 0.01,
        "compressed": False,
        "reference": "https://www.aviso.altimetry.fr/en/data/products/auxiliary-products/global-tide-fes.html",
    },
    # Extrapolated version of FES2014
    "FES2014_extrapolated": {
        "format": "FES-netcdf",
        "name": "FES2014_extrapolated",
        "model_file": [
            "fes2014/ocean_tide_extrapolated/2n2.nc",
            "fes2014/ocean_tide_extrapolated/eps2.nc",
            "fes2014/ocean_tide_extrapolated/j1.nc",
            "fes2014/ocean_tide_extrapolated/k1.nc",
            "fes2014/ocean_tide_extrapolated/k2.nc",
            "fes2014/ocean_tide_extrapolated/l2.nc",
            "fes2014/ocean_tide_extrapolated/la2.nc",
            "fes2014/ocean_tide_extrapolated/m2.nc",
            "fes2014/ocean_tide_extrapolated/m3.nc",
            "fes2014/ocean_tide_extrapolated/m4.nc",
            "fes2014/ocean_tide_extrapolated/m6.nc",
            "fes2014/ocean_tide_extrapolated/m8.nc",
            "fes2014/ocean_tide_extrapolated/mf.nc",
            "fes2014/ocean_tide_extrapolated/mks2.nc",
            "fes2014/ocean_tide_extrapolated/mm.nc",
            "fes2014/ocean_tide_extrapolated/mn4.nc",
            "fes2014/ocean_tide_extrapolated/ms4.nc",
            "fes2014/ocean_tide_extrapolated/msf.nc",
            "fes2014/ocean_tide_extrapolated/msqm.nc",
            "fes2014/ocean_tide_extrapolated/mtm.nc",
            "fes2014/ocean_tide_extrapolated/mu2.nc",
            "fes2014/ocean_tide_extrapolated/n2.nc",
            "fes2014/ocean_tide_extrapolated/n4.nc",
            "fes2014/ocean_tide_extrapolated/nu2.nc",
            "fes2014/ocean_tide_extrapolated/o1.nc",
            "fes2014/ocean_tide_extrapolated/p1.nc",
            "fes2014/ocean_tide_extrapolated/q1.nc",
            "fes2014/ocean_tide_extrapolated/r2.nc",
            "fes2014/ocean_tide_extrapolated/s1.nc",
            "fes2014/ocean_tide_extrapolated/s2.nc",
            "fes2014/ocean_tide_extrapolated/s4.nc",
            "fes2014/ocean_tide_extrapolated/sa.nc",
            "fes2014/ocean_tide_extrapolated/ssa.nc",
            "fes2014/ocean_tide_extrapolated/t2.nc",
        ],
        "constituents": [
            "2n2",
            "eps2",
            "j1",
            "k1",
            "k2",
            "l2",
            "lambda2",
            "m2",
            "m3",
            "m4",
            "m6",
            "m8",
            "mf",
            "mks2",
            "mm",
            "mn4",
            "ms4",
            "msf",
            "msqm",
            "mtm",
            "mu2",
            "n2",
            "n4",
            "nu2",
            "o1",
            "p1",
            "q1",
            "r2",
            "s1",
            "s2",
            "s4",
            "sa",
            "ssa",
            "t2",
        ],
        "type": "z",
        "version": "FES2014",
        "variable": "tide_ocean",
        "scale": 0.01,
        "compressed": False,
        "reference": "https://www.aviso.altimetry.fr/en/data/products/auxiliary-products/global-tide-fes.html",
    },
    # Extrapolated version of FES2022
    "FES2022_extrapolated": {
        "format": "FES-netcdf",
        "name": "FES2022_extrapolated",
        "model_file": "fes2022b/ocean_tide_extrapolated/*fes2022.nc*",
        "type": "z",
        "version": "FES2022",
        "variable": "tide_ocean",
        "scale": 0.01,
        "compressed": False,
        "reference": "https://doi.org/10.24400/527896/A01-2024.004",
    },
    # NetCDF version of TPXO8
    "TPXO8-atlas-v1": {
        "format": "ATLAS-netcdf",
        "name": "TPXO8-atlas-v1",
        "model_file": "TPXO8_atlas_v1/hf.*_tpxo8_atlas_30c_v1.nc",
        "grid_file": "TPXO8_atlas_v1/grid_tpxo8atlas_30_v1.nc",
        "type": "z",
        "version": "v1",
        "variable": "tide_ocean",
        "scale": 0.001,
        "compressed": False,
        "reference": "https://www.tpxo.net/global/tpxo8-atlas",
    },
}

robbibt avatar Sep 04 '24 23:09 robbibt

I guess one thought is that consistent naming conventions are going to become particularly important here - especially when we might have combinations of e.g. non-NetCDF + NetCDF, extrapolated vs. non-extrapolated etc, load vs. ocean etc.

Extrapolated model definitions in particular are something I'd love to have available in the database (we use them for most of our modelling when they're available) - I've been hacking things on my end by renaming the original files, but it's not a great solution!

(happy to add some extras via PR once you've got the code in a ready state!)

robbibt avatar Sep 05 '24 00:09 robbibt

Oh amazing! Yes that would be fantastic!

tsutterley avatar Sep 05 '24 00:09 tsutterley

Alright. I think I have this in good shape. You can update any of the provider JSON files, and when a PR is made it will merge them all into the database for pyTMD.

tsutterley avatar Sep 05 '24 23:09 tsutterley

@tsutterley Brilliant, works great! I've raised a PR here - please feel free to suggest any changes. I'd also really appreciate you check some of my model file/constituent lists, because I'm not 100% sure I've matched them up correctly. https://github.com/tsutterley/pyTMD/pull/331

robbibt avatar Sep 06 '24 03:09 robbibt