# Dense optical flow models¶

Here we will briefly describe and implement the models from the Dense group of the rainymotion library:

Dense model

DenseRotation model

The Dense group models’ implementation can be summarized as follows:

Calculate a continuous displacement field using a global DIS optical flow algorithm (Kroeger et al., 2016) based on the radar images at t-1 and t;

Use a constant-vector or a semi-Lagrangian scheme (Fig. 1) to advect each pixel according obtained displacement (velocity) field, in one single step for each lead time t+n;

Use the intensity of each displaced pixel at its new location at time t+n in order to interpolate the intensity at each grid point of the original (native) radar grid (Liu et al., 2015; Zahraei et al., 2012) (Fig. 2).

References: Kroeger, T., Timofte, R., Dai, D., & Van Gool, L. (2016, October). Fast optical flow using dense inverse search. In European Conference on Computer Vision (pp. 471-488). Springer, Cham.

Fig. 1. Advection

Fig. 2. Scheme of Dense group models

## The Dense model¶

The Dense model usage example:

```
# import the model from the rainymotion library
from rainymotion.models import Dense
# initialize the model
model = Dense()
# upload data to the model instance
model.input_data = np.load("/path/to/data")
# run the model with default parameters
nowcast = model.run()
```

## The DenseRotation model¶

The DenseRotation model usage example:

```
# import the model from the rainymotion library
from rainymotion.models import DenseRotation
# initialize the model
model = DenseRotation()
# upload data to the model instance
model.input_data = np.load("/path/to/data")
# run the model with default parameters
nowcast = model.run()
```