Commit 8a74d49c01dbf4280dd3df168bb0445890e0dc49

Authored by Antoine Goutenoir
1 parent c20659f0
Exists in master

Add the model using LERP instead of intervals.

Showing 2 changed files with 74 additions and 0 deletions   Show diff stats
content.yml
... ... @@ -62,6 +62,34 @@ models:
62 62 # b is optional and defaults to 0
63 63 # - "0 500 4"
64 64 # - 500 1000 8
  65 + - name: MyClimate
  66 + # Slugged version of the display name above
  67 + # Only lowercase alphanumeric, starting with a letter, using - as liaison
  68 + # In other words, MUST match ^[a-z]([a-z0-9-]*[a-z0-9])?$ eg: icao-with-rfi
  69 + # MUST be unique, two models MUST NOT have the same slug.
  70 + slug: my-climate
  71 + # There MUST exist a python file named like this in `flaskr/laws`
  72 + # And it MUST contain a class named EmissionModel
  73 + # Please keep this lowercased, letters-only (or I will breathe fire)
  74 + file: travel_emission_lerp_fit
  75 + # The configuration that will be fed to the model.
  76 + # May be anything, really. Go bonkers!
  77 + config:
  78 + plane_emission_linear_fit:
  79 + # A coefficient applied to the distance
  80 + connecting_flights_scale: 1.05
  81 + # Radiative Forcing Index
  82 + # Multiplier after scaling
  83 + rfi: 1.9
  84 + # Flat scalar to add before scaling with intervals
  85 + offset_before: 0
  86 + # Flat scalar to multiply before scaling with intervals
  87 + scale_before: 1
  88 + points:
  89 + - [ 300.0, 120.42928309 ]
  90 + - [ 1500.0, 278.88301355 ]
  91 + - [ 2500.0, 438.31863895 ]
  92 + - [ 20000.0, 3335.62849772 ]
65 93  
66 94  
67 95 # The content is Markdown. HTML is also allowed.
... ...
flaskr/laws/travel_emission_lerp_fit.py 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +import numpy as np
  2 +from .travel_emission_linear_fit import EmissionModel as BaseEmissionModel
  3 +from flaskr.content import Struct
  4 +
  5 +
  6 +class EmissionModel(BaseEmissionModel):
  7 +
  8 + def apply_scaling_law(self, distance, config):
  9 +
  10 + assert config.points
  11 + assert len(config.points) > 0
  12 +
  13 + footprint = None
  14 +
  15 + sample_points = sorted(config.points, key=lambda p: float(p[0]))
  16 +
  17 + previous_point = [0, 0]
  18 + for i, sample_point in enumerate(sample_points):
  19 + if distance <= sample_point[0]:
  20 + t = 0
  21 + if sample_point[0] != previous_point[0]:
  22 + t = (distance - previous_point[0]) * 1.0 \
  23 + / \
  24 + (sample_point[0] - previous_point[0])
  25 +
  26 + footprint = previous_point[1] + t * (sample_point[1] - previous_point[1])
  27 + previous_point = sample_point
  28 + break
  29 +
  30 + previous_point = sample_point
  31 +
  32 + if footprint is None:
  33 + if len(config.points) == 1:
  34 + last = sample_points[0]
  35 + penu = [0, 0]
  36 + else:
  37 + last = sample_points[-1]
  38 + penu = sample_points[-2]
  39 +
  40 + t = 0
  41 + if last[0] != penu[0]:
  42 + t = (distance - last[0]) * 1.0 / (last[0] - penu[0])
  43 +
  44 + footprint = last[1] + t * (last[1] - penu[1])
  45 +
  46 + return footprint
... ...