Commit 8c2482e372711d5d70591b6c97a243c6c290e90e

Authored by Antoine Goutenoir
1 parent b4e0bfc3
Exists in master

Grunt! Grunt! GRUNT.

/spend 16h
content.yml
... ... @@ -26,32 +26,42 @@ models:
26 26 # There MUST exist a python file named like this in `flaskr/laws`
27 27 # And it MUST contain a class named EmissionModel
28 28 # Please keep this lowercased, letters-only (or I will breathe fire)
29   - file: atmosfair
  29 + file: travel_emission_linear_fit
30 30 # The configuration that will be fed to the model.
31 31 # May be anything, really. Go bonkers!
32 32 config:
33 33 plane_emission_linear_fit:
34 34 # A coefficient applied to the distance
35 35 connecting_flights_scale: 1.05
  36 + # Radiative Forcing Index
  37 + # Multiplier after scaling
  38 + rfi: 1.9
  39 + # Flat scalar to add before scaling with intervals
  40 + offset_before: 50
  41 + # Flat scalar to multiply before scaling with intervals
  42 + scale_before: 1
36 43 # First interval found will apply its scale and offset
37 44 intervals:
38   - # Distances [dmin, dmax[ are in kilometers.
  45 + # Distances [dmin, dmax[ are in kilometers, here.
39 46 - dmin: 0
40   - dmax: 500
  47 + dmax: 1000
41 48 # The scaling law for this interval of distances. Defaults to 1.
42   - scale: 5
  49 + scale: 0.079107
43 50 # Offset is optional and defaults to 0.
44   - offset: 0
45   - - dmin: 500
46   - dmax: 5000
47   - scale: 50
48   - offset: 0
  51 + offset: 25.922
  52 + - dmin: 1000
  53 + dmax: 4000
  54 + scale: 0.066183
  55 + offset: 35.041
  56 + - dmin: 4000
  57 + dmax: 999999999
  58 + scale: 0.095998
  59 + offset: -80.835
49 60 # dmin dmax a b
50 61 # for a fitting of (a*x + b) on the interval [dmin dmax[
51 62 # b is optional and defaults to 0
52 63 # - "0 500 4"
53 64 # - 500 1000 8
54   - offset: 50
55 65  
56 66  
57 67 # The content is Markdown. HTML is also allowed.
... ...
flaskr/laws/atmosfair.py renamed to flaskr/laws/travel_emission_linear_fit.py
... ... @@ -2,7 +2,7 @@ import numpy as np
2 2 from geopy.distance import great_circle
3 3  
4 4  
5   -class EmissionModel():
  5 +class BaseEmissionModel():
6 6 def __init__(self, config): # Constructor
7 7 self.name = config.name
8 8 self.slug = config.slug
... ... @@ -14,6 +14,11 @@ class EmissionModel():
14 14 "%s (%s)" % (self.name, self.slug) + \
15 15 repr(self.config)
16 16  
  17 + # def compute_travel_footprint()
  18 +
  19 +
  20 +class EmissionModel(BaseEmissionModel):
  21 + # @abc
17 22 def compute_travel_footprint(
18 23 self,
19 24 origin_latitude, # degrees
... ... @@ -25,7 +30,7 @@ class EmissionModel():
25 30 footprint = 0.0
26 31  
27 32 #############################################
28   - # FIXME: find closest airport(s) and pick one
  33 + # TODO: find closest airport(s) and pick one
29 34 # We're going to need caching here as well.
30 35 from collections import namedtuple
31 36 origin_airport = namedtuple('Position', [
... ... @@ -75,15 +80,25 @@ class EmissionModel():
75 80 destination_latitude, destination_longitude
76 81 )
77 82  
78   - distance = config.connecting_flights_scale * great_circle_distance
  83 + distance = great_circle_distance
  84 +
  85 + distance = config.connecting_flights_scale * distance
  86 +
  87 + distance = distance * config.scale_before + config.offset_before
79 88  
80 89 footprint = self.apply_scaling_law(
81 90 distance,
82 91 config.intervals
83 92 )
84 93  
  94 + footprint = self.adjust_footprint_for_rfi(footprint, config)
  95 +
85 96 return footprint
86 97  
  98 + def adjust_footprint_for_rfi(self, footprint, config):
  99 + # Todo: grab data from config merged with form input?
  100 + return config.rfi * footprint
  101 +
87 102 def apply_scaling_law(self, distance, intervals):
88 103 footprint = distance
89 104 for interval in intervals:
... ...