Blame view

flaskr/legacy/db_scaling_laws.py 3.4 KB
3835f60e   Goutte   Add the python fu...
1
2
3
import numpy as np


3f132a5a   Antoine Goutenoir   Mark spaghetti co...
4
5
6
# Legacy code, for inspiration.  Not actually used.


3835f60e   Goutte   Add the python fu...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def correct_gcd_from_icao(d):
    if d <= 550.:
        return d + 50.
    elif 550. < d < 5500.:
        return d + 100.
    elif d >= 5500.:
        return d + 125.


def db_def_seat_class_coeff_from_defra(category="economy"):
    seat_coeff_defra = [0.073195, 0.11711, 0.21226, 0.29276]
    seat_category = ["economy", "premium ", "business ", "first"]
    assert category in seat_category

    if category.lower() == "economy":
        return 1.
    elif category.lower() == "premium":
        return seat_coeff_defra[1] / seat_coeff_defra[0]
    elif category.lower() == "business":
        return seat_coeff_defra[2] / seat_coeff_defra[0]
    elif category.lower() == "first":
        return seat_coeff_defra[3] / seat_coeff_defra[0]


def db_direct_emission(method, dist_min, x):
    if x < dist_min:
        return 0.

    # x is the GCD I calculate
    if method == "ICAO":
        if x < 1000.:
            return 23.339 + 0.10108 * x
d8b16588   Goutte   Comply with PEP.
39
        elif 1000. <= x < 4000.:
3835f60e   Goutte   Add the python fu...
40
            return 70.851 + 0.050821 * x
d8b16588   Goutte   Comply with PEP.
41
        elif x > 4000.:
3835f60e   Goutte   Add the python fu...
42
43
44
45
46
            return 121.08 + 0.035461 * x

    if method == "DEFRA":
        if x < 500.:
            return x * 0.13483
d8b16588   Goutte   Comply with PEP.
47
        elif 500. <= x < 3700.:
3835f60e   Goutte   Add the python fu...
48
            return x * 0.08233
d8b16588   Goutte   Comply with PEP.
49
        elif x >= 3700.:
3835f60e   Goutte   Add the python fu...
50
51
52
53
54
55
            return x * 0.5 * (0.0792 + 0.073195)

    if method == "ATMOSFAIR":
        x += 50.
        if x < 1000.:
            return 25.922 + 0.079107 * x
d8b16588   Goutte   Comply with PEP.
56
        elif 1000. <= x < 4000.:
3835f60e   Goutte   Add the python fu...
57
            return 35.041 + 0.066183 * x
d8b16588   Goutte   Comply with PEP.
58
        elif x > 4000.:
3835f60e   Goutte   Add the python fu...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
            return (-80.835) + 0.095998 * x

    if method == "ADEME":

        d_corr = correct_gcd_from_icao(x)

        # This is from table 21

        if x < 1000.:
            coeff_emission = [117., 187, 141, 223.]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 1000. <= x < 2000.:
            coeff_emission = [95, 254, 123, 117, 161]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 2000. <= x < 3000.:
            coeff_emission = [91, 101, 109]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 3000. <= x < 4000.:
            coeff_emission = [99, 99, 105]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 4000. <= x < 5000.:
            coeff_emission = [90, 126, 153]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 5000. <= x < 6000.:
            coeff_emission = [88, 98, 150]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 6000. <= x < 7000.:
            coeff_emission = [82, 100]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 7000. <= x < 8000.:
            coeff_emission = [87, 91]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 8000. <= x < 9000.:
            coeff_emission = [87, 95]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 9000. <= x < 10000.:
            coeff_emission = [73, 83]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif 10000. <= x < 11000.:
            coeff_emission = [95]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))
        elif x >= 11000.:
            coeff_emission = [94]
            return np.mean(np.multiply(coeff_emission, d_corr / 1000.))