apply_AK.py 3.02 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)
Antoine Berchet's avatar
Antoine Berchet committed
8

Robin Plauchu's avatar
Robin Plauchu committed
9
    # OMI-QA4ECV & TROPOMI-S5P [NO2] et [CO]
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)
Antoine Berchet's avatar
Antoine Berchet committed
23

Robin Plauchu's avatar
Robin Plauchu committed
24
25
26
    # TROPOMI-S5P [CO]
    elif nbformula == 4:
        y0 = (sim_ak * aks * 10e-4).sum(axis=0)
Antoine Berchet's avatar
Antoine Berchet committed
27

Robin Plauchu's avatar
Robin Plauchu committed
28
    # TROPOMI-S5P [CH4]
29
    elif nbformula == 5:
Antoine Berchet's avatar
Antoine Berchet committed
30
31
32
33
        y0 = (qa0.sum(axis=0)
              + (aks * (sim_ak * drycols - qa0)).sum(axis=0)
              ) / drycols.sum(axis=0)

34
35
36
37
38
    # OCO-2
    elif nbformula == 6:
        y0 = (dpavgs*qa0).sum(axis=0) \
            + (dpavgs*aks*(sim_ak - qa0)).sum(axis=0)

39
    else:
40
        raise Exception("Don't know formula: {}".format(nbformula))
Antoine Berchet's avatar
Antoine Berchet committed
41

Antoine Berchet's avatar
Antoine Berchet committed
42
43
44
    return y0


Antoine Berchet's avatar
Antoine Berchet committed
45
def apply_ak_tl(
46
        sim_ak_tl, dpavgs, aks, nbformula, qa0, chosenlevel, sim_ak, drycols
Antoine Berchet's avatar
Antoine Berchet committed
47
):
Robin Plauchu's avatar
Robin Plauchu committed
48
    if nbformula == 1 or nbformula == 2 or nbformula == 4:
49
50
        y0 = apply_ak(sim_ak_tl, dpavgs, aks, nbformula, qa0, chosenlevel,
                      drycols)
Antoine Berchet's avatar
Antoine Berchet committed
51

52
    elif nbformula == 3:
53
        tmp = sim_ak_tl / (sim_ak * np.log(10))
54
        y0 = apply_ak(sim_ak, dpavgs, aks, nbformula, qa0, chosenlevel, drycols)
55
        y0 = y0 * np.log(10) * np.nansum(aks * tmp, axis=0)
Antoine Berchet's avatar
Antoine Berchet committed
56

Robin Plauchu's avatar
Robin Plauchu committed
57
58
59
    # passe dans le premier if normalement
    # elif nbformula == 4:
    #     y0 = (sim_ak_tl * aks * 10e-4).sum(axis=0)
Antoine Berchet's avatar
Antoine Berchet committed
60

Isabelle Pison's avatar
Isabelle Pison committed
61
    elif nbformula == 5:
Antoine Berchet's avatar
Antoine Berchet committed
62
        y0 = (aks * sim_ak_tl * drycols).sum(axis=0) / drycols.sum(axis=0)
Isabelle Pison's avatar
Isabelle Pison committed
63

64
65
66
    elif nbformula == 6:
        y0 = (dpavgs*aks*sim_ak_tl).sum(axis=0)

67
    else:
Antoine Berchet's avatar
Antoine Berchet committed
68
69
        raise Exception("Don't know formula: {}".format(nbformula))

Antoine Berchet's avatar
Antoine Berchet committed
70
71
72
    return y0


73
74
def apply_ak_ad(sim_ak, dpavgs, aks, nbformula, qa0, chosenlevel, obs_incr,
                drycols):
75
    if nbformula == 1:
Antoine Berchet's avatar
Antoine Berchet committed
76
        obs_incr = (
77
78
79
80
                dpavgs
                * aks
                / (dpavgs * aks).sum(axis=0)
                * obs_incr
Antoine Berchet's avatar
Antoine Berchet committed
81
        )
Antoine Berchet's avatar
Antoine Berchet committed
82

83
    elif nbformula == 2:
84
        obs_incr = aks * obs_incr
Antoine Berchet's avatar
Antoine Berchet committed
85

86
    elif nbformula == 3:
87
        y0 = apply_ak(sim_ak, dpavgs, aks, nbformula, qa0, chosenlevel, drycols)
88
89
        y0 *= np.log(10) * obs_incr
        y0 = aks * y0
90
        prof = sim_ak * np.log(10)
91
        prof[prof == 0] = np.nan
92
        obs_incr = y0 / prof
Antoine Berchet's avatar
Antoine Berchet committed
93

Robin Plauchu's avatar
Robin Plauchu committed
94
95
    elif nbformula == 4:
        obs_incr = aks * obs_incr * 10e-4
Antoine Berchet's avatar
Antoine Berchet committed
96

Isabelle Pison's avatar
Isabelle Pison committed
97
    elif nbformula == 5:
Antoine Berchet's avatar
Antoine Berchet committed
98
99
        obs_incr = aks * obs_incr * drycols / drycols.sum(axis=0)

100
101
102
    elif nbformula == 6:
        obs_incr = dpavgs*aks*obs_incr

103
    else:
104
        raise Exception("Don't know formula: {}".format(nbformula))
Antoine Berchet's avatar
Antoine Berchet committed
105

Antoine Berchet's avatar
Antoine Berchet committed
106
    return obs_incr