apply_AK.py 2.29 KB
Newer Older
Antoine Berchet's avatar
Antoine Berchet committed
1
2
3
import numpy as np


4
def apply_ak(sim_ak, dpavgs, aks, nbformula, qa0, chosenlevel, drycols):
5
6
    """Apply the corresponding AK values"""
    if nbformula == 1:
Antoine Berchet's avatar
Antoine Berchet committed
7
        y0 = (sim_ak * dpavgs * aks).sum(axis=0) / (dpavgs * aks).sum(axis=0)
8

Robin Plauchu's avatar
Robin Plauchu committed
9
    # OMI-QA4ECV & TROPOMI-S5P [NO2]
10
    elif nbformula == 2:
11
        y0 = (sim_ak * aks).sum(axis=0)
Antoine Berchet's avatar
Antoine Berchet committed
12

13
    # MOPITT
14
    elif nbformula == 3:
15
16
17
        # Check that qa0 is well defined
        if ~np.all(~np.isnan(qa0[chosenlevel])) or np.all(np.isnan(qa0)):
            raise Exception("WARNING! Can't apply formula #3 with NaNs in qa0")
18
19
        prof = aks * (np.log10(sim_ak) - np.log10(qa0) )
        prof[ ~np.isfinite(prof) ] = np.nan
20
        y0 = np.log10(qa0[chosenlevel]) \
21
             + np.nansum(prof, axis=0)
22
        y0 = np.power(10, y0)
Robin Plauchu's avatar
Robin Plauchu committed
23
24
25
26
27

    # TROPOMI-S5P [CO]
    elif nbformula == 4:
        y0 = (sim_ak * aks * 10e-4).sum(axis=0)

28
29
30
31
    # TROPOMI-S5P CH4
    elif nbformula == 5:
       y0 = ( qa0.sum(axis=0) + (aks * ( sim_ak * drycols - qa0 )).sum(axis = 0) ) / drycols.sum(axis = 0)

32
    else:
33
        raise Exception("Don't know formula: {}".format(nbformula))
Antoine Berchet's avatar
Antoine Berchet committed
34

Antoine Berchet's avatar
Antoine Berchet committed
35
36
37
    return y0


Antoine Berchet's avatar
Antoine Berchet committed
38
def apply_ak_tl(
39
    sim_ak_tl, dpavgs, aks, nbformula, qa0, chosenlevel, sim_ak
Antoine Berchet's avatar
Antoine Berchet committed
40
):
Robin Plauchu's avatar
Robin Plauchu committed
41
    if nbformula == 1 or nbformula == 2 or nbformula == 4:
42
        y0 = apply_ak(sim_ak_tl, dpavgs, aks, nbformula, qa0, chosenlevel)
Antoine Berchet's avatar
Antoine Berchet committed
43

44
    elif nbformula == 3:
45
        tmp = sim_ak_tl / (sim_ak * np.log(10))
46
47
        y0 = apply_ak(sim_ak, dpavgs, aks, nbformula, qa0, chosenlevel)
        y0 = y0 * np.log(10) * np.nansum(aks * tmp, axis=0)
Antoine Berchet's avatar
Antoine Berchet committed
48

49
50
    else:
        raise Exception("Don't know formula")
Antoine Berchet's avatar
Antoine Berchet committed
51

Antoine Berchet's avatar
Antoine Berchet committed
52
53
54
    return y0


55
def apply_ak_ad(sim_ak, dpavgs, aks, nbformula, qa0, chosenlevel, obs_incr):
56
    if nbformula == 1:
Antoine Berchet's avatar
Antoine Berchet committed
57
58
        obs_incr = (
            dpavgs
59
60
61
            * aks
            / (dpavgs * aks).sum(axis=0)
            * obs_incr
Antoine Berchet's avatar
Antoine Berchet committed
62
63
        )

64
    elif nbformula == 2:
65
        obs_incr = aks * obs_incr
Antoine Berchet's avatar
Antoine Berchet committed
66

67
    elif nbformula == 3:
68
        y0 = apply_ak(sim_ak, dpavgs, aks, nbformula, qa0, chosenlevel)
69
70
        y0 *= np.log(10) * obs_incr
        y0 = aks * y0
71
72
73
        prof = sim_ak * np.log(10)
        prof[ prof == 0 ] = np.nan
        obs_incr = y0 / prof
Antoine Berchet's avatar
Antoine Berchet committed
74

Robin Plauchu's avatar
Robin Plauchu committed
75
76
77
    elif nbformula == 4:
        obs_incr = aks * obs_incr * 10e-4

78
    else:
79
        raise Exception("Don't know formula: {}".format(nbformula))
Antoine Berchet's avatar
Antoine Berchet committed
80

Antoine Berchet's avatar
Antoine Berchet committed
81
    return obs_incr