From 3835f60ea663f8960f274b14e6f01aa0bf0d5cf6 Mon Sep 17 00:00:00 2001 From: Goutte Date: Wed, 16 Oct 2019 13:37:42 +0200 Subject: [PATCH] Add the python functions from Dr. Barret, after some PEP conformance cleanup. --- flaskr/db_scaling_laws.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 100 insertions(+), 0 deletions(-) create mode 100644 flaskr/db_scaling_laws.py diff --git a/flaskr/db_scaling_laws.py b/flaskr/db_scaling_laws.py new file mode 100644 index 0000000..2d1efc4 --- /dev/null +++ b/flaskr/db_scaling_laws.py @@ -0,0 +1,99 @@ +import numpy as np + + +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 + if 1000. <= x < 4000.: + return 70.851 + 0.050821 * x + if x > 4000.: + return 121.08 + 0.035461 * x + + if method == "DEFRA": + if x < 500.: + return x * 0.13483 + if 500. <= x < 3700.: + return x * 0.08233 + if x >= 3700.: + return x * 0.5 * (0.0792 + 0.073195) + + if method == "ATMOSFAIR": + x += 50. + if x < 1000.: + return 25.922 + 0.079107 * x + if 1000. <= x < 4000.: + return 35.041 + 0.066183 * x + if x > 4000.: + 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.)) diff --git a/requirements.txt b/requirements.txt index fd513f7..17c9a95 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ cssmin==0.2.0 jsmin==2.2.1 pyyaml==5.1.2 Markdown==3.1.1 +numpy==1.16.5 # Testing -- libgit2 0.21.2