# Retrievals

The full retrieval process looks like this:

## Measurement Vectors

Measurement vectors are transformed versions of the Level 1 data that reduce sensitivity to unwanted atmospheric constituents as well as calibration or measurement errors. These typically take the form of normalizations, either in the spectral or spatial domains and can be thought of as transforms of the level 1 data.

A measurement vector can be composed of multiple components, for example, measurements as several wavelengths. Each of components, or “elements” can have their own transforms. To help compose these measurement vectors and elements the MeasurementVector and MeasurementVectorElement classes can be used in conjunction with a Transformer. These handle the transformation of the radiance, error and weighting functions into the new space.

```
from ali.retrieval.measvec import MeasurementVector, MeasurementVectorElement
from ali.retrieval.measvec.transformer import AltitudeNormalization, LogRadiance
element = MeasurementVectorElement()
element.add_transform(AltitudeNormalization(norm_alts=(35000, 40000))))
element.add_transform(LogRadiance())
meas_vector = MeasurementVector([element])
```

## State Vectors

A state vector is a list of elements that describes the quantities being retrieved. This could be a vertical profile of ozone, the BRDF, a wavelength shift for the instrument, or all of the above simultaneously. Each element of the state is defined by a StateVectorElement that are composed together to create the StateVector.

```
from skretrieval.retrieval.statevector import StateVector
from ali.retrieval.statevector import StateVectorAerosolProfile, StateVectorProfileParticleSize
aerosol_state = StateVectorAerosolProfile(...)
lognormal_radius_state = StateVectorProfileParticleSize(...)
state_vector = StateVector([aerosol_state, lognormal_radius_state])
```

## Retrieval

The retrieval combines the state and measurement vectors

```
from ali.retrieval.aerosol import AerosolRetrieval, ParticleSizeRetrieval
particle_size_ret = ParticleSizeRetrieval(state_vector, meas_vector, retrieval_altitudes=altitudes)
```

## Forward model

The forward model is in charge of simulating level 1 products given an atmosphere

```
from ali.instrument.simulator import ImagingSimulator
forward_model = ImagingSimulator(sensors, geometries, atmosphere, options)
forward_model.integration_time = integration_time
```

## Minimizer

In charge of updating the atmospheric state given a measurement, a forward model, and a target species. Typically the Rodgers optimal estimation method is used.

```
# add the retrieved species to the atmosphere
aerosol_state.add_to_atmosphere(atmosphere)
lognormal_radius_state.add_to_atmosphere(atmosphere)
# do the retrieval
rodgers = Rodgers(max_iter=5, lm_damping=0.01)
particle_size_ret.configure_from_model(forward_model, measurement_l1)
results = rodgers.retrieve(measurement_l1, forward_model, particle_size_ret)
```