Skip to content

Commit

Permalink
expand base modes to include "met" and "footprint"
Browse files Browse the repository at this point in the history
Up to now, we've had base modes only for the purpose of having a designated color and icon for any rich modes that get defined.
All of the MET and carbon footprint info was defined for each and every rich mode (in the label-options JSON)

Now, base modes will have a base "met" and "footprint".
The mets are copied over from what was in e-mission-phone (reformatted to Python).
Rich modes previously had a 'kgCo2PerKm' value. As part of the effort to de-couple energy calculations from carbon calculations (e-mission/e-mission-docs#954), this is replaced by a 'footprint' field, which has energy intensities broken down by fuel type. For transit, we describe the mapping to mode(s) in the NTD.
Rich modes can still override "footprint" or "met", or any of these properties.

It will no longer be necessary to include "met_equivalent" in rich modes. If "met" is not present, it will be implied as being the met of the base mode.

Now our "base modes" and "rich modes" line up better and we can describe it as an inheritance pattern.
  • Loading branch information
JGreenlee committed Jul 22, 2024
1 parent 299f2ab commit 5409121
Showing 1 changed file with 200 additions and 23 deletions.
223 changes: 200 additions & 23 deletions src/emcommon/diary/base_mode_colors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from emcommon.metrics.footprint_calculations import mpge_to_wh_per_km

mode_colors = {
"pink": '#c32e85', # oklch(56% 0.2 350) # e-car
"red": '#c21725', # oklch(52% 0.2 25) # car
Expand All @@ -10,34 +12,209 @@
"taupe": '#7d585a', # oklch(50% 0.05 15) # ferry, trolleybus, user-defined modes
}

NON_ACTIVE_METS = {
"ALL": {"range": [0, float('inf')]},
}
WALKING_METS = {
"VERY_SLOW": {"range": [0, 2.0], "mets": 2.0},
"SLOW": {"range": [2.0, 2.5], "mets": 2.8},
"MODERATE_0": {"range": [2.5, 2.8], "mets": 3.0},
"MODERATE_1": {"range": [2.8, 3.2], "mets": 3.5},
"FAST": {"range": [3.2, 3.5], "mets": 4.3},
"VERY_FAST_0": {"range": [3.5, 4.0], "mets": 5.0},
"VERY_FAST_1": {"range": [4.0, 4.5], "mets": 6.0},
"VERY_VERY_FAST": {"range": [4.5, 5], "mets": 7.0},
"SUPER_FAST": {"range": [5, 6], "mets": 8.3},
"RUNNING": {"range": [6, float('inf')], "mets": 9.8},
}
BIKING_METS = {
"VERY_VERY_SLOW": {"range": [0, 5.5], "mets": 3.5},
"VERY_SLOW": {"range": [5.5, 10], "mets": 5.8},
"SLOW": {"range": [10, 12], "mets": 6.8},
"MODERATE": {"range": [12, 14], "mets": 8.0},
"FAST": {"range": [14, 16], "mets": 10.0},
"VERT_FAST": {"range": [16, 19], "mets": 12.0},
"RACING": {"range": [20, float('inf')], "mets": 15.8},
}
E_BIKING_METS = {
"ALL": {"range": [0, float('inf')], "mets": 4.9}
}

# "average" values for various modes of transportation
# TODO get these from GREET or somewhere trustworthy
GAS_CAR_MPG = 24
ECAR_MPGE = 100
PHEV_UF = 0.4 # UF = utility factor
PHEV_GAS_MPG = 40
PHEV_ELEC_MPGE = 100
E_BIKE_WH_PER_KM = 13.67
E_SCOOTER_WH_PER_KM = 16.78
MOPED_AVG_MPG = 100
TAXI_WH_PER_KM = 941.5
AIR_WH_PER_KM = 999

AIR_FOOTPRINT = { "gasoline": { "wh_per_km": AIR_WH_PER_KM } }
CAR_FOOTPRINT = { "gasoline": { "wh_per_km": mpge_to_wh_per_km(GAS_CAR_MPG) } }
E_CAR_FOOTPRINT = { "electric": { "wh_per_km": mpge_to_wh_per_km(ECAR_MPGE) } }
PHEV_CAR_FOOTPRINT = {
"electric": {
"wh_per_km": mpge_to_wh_per_km(PHEV_ELEC_MPGE),
"weight": PHEV_UF
},
"gasoline": {
"wh_per_km": mpge_to_wh_per_km(PHEV_GAS_MPG),
"weight": 1 - PHEV_UF
},
}
E_BIKE_FOOTPRINT = {"electric": {"wh_per_km": E_BIKE_WH_PER_KM }}
E_SCOOTER_FOOTPRINT = { "electric": { "wh_per_km": E_SCOOTER_WH_PER_KM } }
MOPED_FOOTPRINT = { "gasoline": { "wh_per_km": mpge_to_wh_per_km(MOPED_AVG_MPG) } }
TAXI_FOOTPRINT = { "gasoline": { "wh_per_km": TAXI_WH_PER_KM } }

BASE_MODES = {
# BEGIN MotionTypes
"IN_VEHICLE": { "name": 'IN_VEHICLE', "icon": 'speedometer', "color": mode_colors["red"] },
"BICYCLING": { "name": 'BICYCLING', "icon": 'bike', "color": mode_colors["green"] },
"ON_FOOT": { "name": 'ON_FOOT', "icon": 'walk', "color": mode_colors["blue"] },
"UNKNOWN": { "name": 'UNKNOWN', "icon": 'help', "color": mode_colors["grey"] },
"WALKING": { "name": 'WALKING', "icon": 'walk', "color": mode_colors["blue"] },
"AIR_OR_HSR": { "name": 'AIR_OR_HSR', "icon": 'airplane', "color": mode_colors["orange"] },
"IN_VEHICLE": {
"icon": 'speedometer',
"color": mode_colors['red'],
"met": NON_ACTIVE_METS,
# footprint not known; left undefined. later filled in by an average of:
# CAR, BUS, LIGHT_RAIL, TRAIN, TRAM, SUBWAY
},
"BICYCLING": {
"icon": 'bike',
"color": mode_colors['green'],
"met": BIKING_METS,
"footprint": {},
},
"ON_FOOT": {
"icon": 'walk',
"color": mode_colors['blue'],
"met": WALKING_METS,
"footprint": {},
},
"UNKNOWN": {
"icon": 'help',
"color": mode_colors['grey'],
# met and footprint not known; left undefined
},
"WALKING": {
"icon": 'walk',
"color": mode_colors['blue'],
"met": WALKING_METS,
"footprint": {},
},
"AIR_OR_HSR": {
"icon": 'airplane',
"color": mode_colors['orange'],
"met": NON_ACTIVE_METS,
"footprint": AIR_FOOTPRINT,
},
# END MotionTypes
"CAR": { "name": 'CAR', "icon": 'car', "color": mode_colors["red"] },
"E_CAR": { "name": 'E_CAR', "icon": 'car-electric', "color": mode_colors["pink"] },
"E_BIKE": { "name": 'E_BIKE', "icon": 'bicycle-electric', "color": mode_colors["green"] },
"E_SCOOTER": { "name": 'E_SCOOTER', "icon": 'scooter-electric', "color": mode_colors["periwinkle"] },
"MOPED": { "name": 'MOPED', "icon": 'moped', "color": mode_colors["green"] },
"TAXI": { "name": 'TAXI', "icon": 'taxi', "color": mode_colors["red"] },
"BUS": { "name": 'BUS', "icon": 'bus-side', "color": mode_colors["magenta"] },
"AIR": { "name": 'AIR', "icon": 'airplane', "color": mode_colors["orange"] },
"LIGHT_RAIL": { "name": 'LIGHT_RAIL', "icon": 'train-car-passenger', "color": mode_colors["periwinkle"] },
"TRAIN": { "name": 'TRAIN', "icon": 'train-car-passenger', "color": mode_colors["periwinkle"] },
"TRAM": { "name": 'TRAM', "icon": 'fas fa-tram', "color": mode_colors["periwinkle"] },
"SUBWAY": { "name": 'SUBWAY', "icon": 'subway-variant', "color": mode_colors["periwinkle"] },
"FERRY": { "name": 'FERRY', "icon": 'ferry', "color": mode_colors["taupe"] },
"TROLLEYBUS": { "name": 'TROLLEYBUS', "icon": 'bus-side', "color": mode_colors["taupe"] },
"UNPROCESSED": { "name": 'UNPROCESSED', "icon": 'help', "color": mode_colors["grey"] },
"OTHER": { "name": 'OTHER', "icon": 'pencil-circle', "color": mode_colors["taupe"] },
"CAR": {
"icon": 'car',
"color": mode_colors['red'],
"met": NON_ACTIVE_METS,
"footprint": CAR_FOOTPRINT,
},
"E_CAR": {
"icon": 'car-electric',
"color": mode_colors['pink'],
"met": NON_ACTIVE_METS,
"footprint": E_CAR_FOOTPRINT,
},
"PHEV_CAR": {
"icon": 'car-electric',
"color": mode_colors['pink'],
"met": NON_ACTIVE_METS,
"footprint": PHEV_CAR_FOOTPRINT,
},
"E_BIKE": {
"icon": 'bicycle-electric',
"color": mode_colors['green'],
"met": E_BIKING_METS,
"footprint": E_BIKE_FOOTPRINT,
},
"E_SCOOTER": {
"icon": 'scooter-electric',
"color": mode_colors['periwinkle'],
"met": NON_ACTIVE_METS,
"footprint": E_SCOOTER_FOOTPRINT,
},
"MOPED": {
"icon": 'moped',
"color": mode_colors['green'],
"met": NON_ACTIVE_METS,
"footprint": MOPED_FOOTPRINT,
},
"TAXI": {
"icon": 'taxi',
"color": mode_colors['red'],
"met": NON_ACTIVE_METS,
"footprint": TAXI_FOOTPRINT,
},
"BUS": {
"icon": 'bus-side',
"color": mode_colors['magenta'],
"met": NON_ACTIVE_METS,
"footprint": { "transit": ["MB", "RB", "CB"] }, # fixed-route bus, bus rapid transit, commuter bus
},
"AIR": {
"icon": 'airplane',
"color": mode_colors['orange'],
"met": NON_ACTIVE_METS,
"footprint": AIR_FOOTPRINT,
},
"LIGHT_RAIL": {
"icon": 'train-car-passenger',
"color": mode_colors['periwinkle'],
"met": NON_ACTIVE_METS,
"footprint": { "transit": ["LR"] } # light rail
},
"TRAIN": {
"icon": 'train-car-passenger',
"color": mode_colors['periwinkle'],
"met": NON_ACTIVE_METS,
"footprint": { "transit": ["HR", "YR"] } # heavy rail, hybrid rail
},
"TRAM": {
"icon": 'tram',
"color": mode_colors['periwinkle'],
"met": NON_ACTIVE_METS,
"footprint": { "transit": ["SR"] } # streetcar
},
"SUBWAY": {
"icon": 'subway-variant',
"color": mode_colors['periwinkle'],
"met": NON_ACTIVE_METS,
"footprint": { "transit": ["HR"] } # heavy rail
},
"FERRY": {
"icon": 'ferry',
"color": mode_colors['taupe'],
"met": NON_ACTIVE_METS,
"footprint": { "transit": ["FB"] } # ferry boat
},
"TROLLEYBUS": {
"icon": 'bus-side',
"color": mode_colors['taupe'],
"met": NON_ACTIVE_METS,
"footprint": { "transit": ["TB", "SR"] } # trolleybus, streetcar
},
"UNPROCESSED": {
"icon": 'help',
"color": mode_colors['grey'],
# met not known; left undefined
# footprint not known; left undefined
},
"OTHER": {
"icon": 'pencil-circle',
"color": mode_colors['taupe'],
# met not known; left undefined
# footprint not known; left undefined
},
};

def get_base_mode_by_key(motionName):
key = ('' + motionName).upper()
pop = key.split('.').pop() # if "MotionTypes.WALKING", then just take "WALKING"
return BASE_MODES.get(pop, BASE_MODES["UNKNOWN"])
return BASE_MODES.get(pop, BASE_MODES["UNKNOWN"])

0 comments on commit 5409121

Please sign in to comment.