qubed/docs/fiab.md
2025-03-04 19:02:55 +01:00

2.8 KiB

jupytext
jupytext
text_representation
extension format_name format_version jupytext_version
.md myst 0.13 1.16.4

Fiab

Model Selection

This is a demo of using qubed to select from a set of forecast models that each produce a set of output variables.

First let's construct some models represented as qubes:

from qubed import Qube
model_1 = Qube.from_datacube({
        "levtype": "pl",
        "param" : ["q", "t", "u", "v", "w", "z"],
        "level" : [100, 200, 300, 400, 50, 850, 500, 150, 600, 250, 700, 925, 1000],
    }) | Qube.from_datacube({
        "levtype": "sfc",
        "param" : ["10u", "10v", "2d", "2t", "cp", "msl", "skt", "sp", "tcw", "tp"],
})

model_1 = "model=1" / ("frequency=6h" / model_1)
model_1

This is the most complete model. Now let's do one with fewer variables and levels:

model_2 = Qube.from_datacube({
        "levtype": "pl",
        "param" : ["q", "t"],
        "level" : [100, 200, 300, 400, 50, 850, 500, 150, 600, 250, 700, 925, 1000],
    }) | Qube.from_datacube({
        "levtype": "sfc",
        "param" : ["2t", "cp", "msl"],
})
model_2 = "model=2" / ("frequency=continuous" / model_2)
model_3 = Qube.from_datacube({
        "levtype": "pl",
        "param" : ["q", "t"],
        "level" : [100, 200, 300, 400, 50, 850, 500, 150, 600, 250, 700, 925, 1000],
    }) | Qube.from_datacube({
        "levtype": "sfc",
        "param" : ["2t", "cp", "msl"],
})
model_3 = "model=3" / ("frequency=6h" / model_3)
model_3

Model 4 uses and experimental wildcard flag to indicate that it can produce any parameter.

model_4 = Qube.from_datacube({
        "levtype": "pl",
        "param" : "*", # Special value that matches with everything
        "level" : [100, 200, 300, 400, 50, 850, 500, 150, 600, 250, 700, 925, 1000],
    })
model_4 = "model=4" / ("frequency=6h" / model_4)
model_4

Now we can combine the three models into a single qube:

all_models = model_1 | model_2 | model_3 | model_4
all_models

Now we can perform queries over the models. We can get all models that produce 2m temperature:

all_models.select({
    "param" : "2t",
})

Filter on both parameter and frequency:

all_models.select({
    "param" : "2t",
    "frequency": "continuous",
})

Find all models that have some overlap with this set of parameters:

all_models.select({
    "param" : ["q", "t", "u", "v"],
})

Choosing a set of models based on the requested parameter set

all_models.select({
    "param" : ["q", "t", "u", "v"],
    "frequency": "6h",
})