Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes on generic_metric and mode_specific_metrics in relation to Mo… #91

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
34eae86
Changes on generic_metric and mode_specific_metrics in relation to Mo…
iantei Sep 7, 2023
176655a
Address Review comments.
iantei Sep 11, 2023
f04e596
Update generate_plots.py & scaffolding.py
iantei Sep 12, 2023
3182a0b
Fix merge conflict.
iantei Sep 12, 2023
43d974b
Fix scaffolding, updated mode_specific_metrics.ipynb.
iantei Sep 12, 2023
7343606
Revert version changes to 3.7.12.
iantei Sep 12, 2023
080f4f4
Update initialization of dynamic_labels from { } to json object refer…
iantei Sep 12, 2023
7d8b2d6
Default initialize dynamic_labels to { }.
iantei Sep 14, 2023
1b037c2
Merge with main. Resolve merge conflict.
iantei Sep 14, 2023
fea6365
Add an environment variable in Docker Compose to pass dynamic config.
iantei Sep 17, 2023
b04096b
Chang in docker-compose for STUDY_CONFIG to dev-emulator-study. Rever…
iantei Sep 18, 2023
5a70ecb
Change back docker-compose.dev.yml: STUDY_CONFIG to stage-program.
iantei Sep 19, 2023
6e80c7f
Replace Mode_confirm with Replaced_mode for barplot_mode() in mode_sp…
iantei Sep 22, 2023
30c1dd4
1. Remove extraneous whitespace from generate_plots.py. 2. Revert ref…
iantei Sep 25, 2023
86f8133
Remove extraneous whitespace from line 96 in generate_plots.py
iantei Sep 25, 2023
845dd47
Introduce defaultdic for dic_translations with Other in analogy to di…
iantei Sep 26, 2023
40519ec
Merge branch 'main' into ananta_support_customLabel_from_dynamic_config
iantei Sep 27, 2023
af9d3fc
Handle initialization of mode_count_interest. Introduce try-except bl…
iantei Sep 28, 2023
a868e4c
Move quality_text code into the if block in the above cell.
iantei Sep 28, 2023
54e213b
Update log messages for dynamic_labels_url and label_options unavaila…
iantei Sep 29, 2023
81407fc
Update scaffolding to introduce compute_CO2_impact_kg() computation w…
iantei Oct 5, 2023
d4fb9bc
1. Change the plots.py X-axis to showcase CO2 Impact in kg. 2. In sca…
iantei Oct 5, 2023
42990a2
Move the compute_CO2_impact_kg() call to scaffolding, such that energ…
iantei Oct 5, 2023
2dd360f
Changes to understand difference between default mapping and dynamic …
iantei Oct 6, 2023
0aeb70c
Update scaffolding to create different dictionary mappings for MODE, …
iantei Oct 7, 2023
aae0d2a
Update Trip_purpose to To Work instead of Work whenever dynamic label…
iantei Oct 7, 2023
f2f0a45
Update scaffolding.py CO2_footprint_lb() to utilize the distance whil…
iantei Oct 9, 2023
fecec39
Update changes for generic_timeseries. 1. Inside scaffolding.py intro…
iantei Oct 10, 2023
5cf84bc
Create new metrics_study and metrics_program options html files witho…
iantei Oct 12, 2023
5a8c9d6
Update index.html to use different metrics_ options html when dynamic…
iantei Oct 12, 2023
8fefdea
Remove redundant check for dynamic_labels_urls. Update the message to…
iantei Oct 12, 2023
a2c1910
Remove print statements used to evaluate the difference in energy cal…
iantei Oct 12, 2023
a42b308
Update the mode mapping in accordance to MODE for Daily Mode Share in…
iantei Oct 13, 2023
6f13c03
Refactor the code to load the config and corresponding metrics.html p…
iantei Oct 19, 2023
32864c6
Reinstate the comment for energy_calculations.ipynb. Removed extranne…
iantei Oct 19, 2023
b3a92a1
Update data.label_options to dynamic_labels to make it coherent acros…
iantei Oct 19, 2023
1628f5a
Created a new function inside scaffolding.py, mapping_labels(dynamic_…
iantei Oct 19, 2023
f3edc61
Moving the mapping_labels() call inside the conditional check for eac…
iantei Oct 19, 2023
e7c17a1
Update the purpose mapping for Work to select from scaffolding.mappin…
iantei Oct 19, 2023
c114d38
Update the Timeseries of emissions per miles TO Timeseries of emissio…
iantei Oct 24, 2023
b26207d
Update plots.py CO2_impact to take x and y Labels from the notebook. …
iantei Oct 27, 2023
14a3666
Update generic_timeseries to show the CO2 emissions in Imperial syste…
iantei Oct 27, 2023
4c177d7
Added print statements to understand the difference in CO2 emissions …
iantei Oct 27, 2023
a8f3697
Renamed 1. compute_CO2_impact_kg to compute_CO2_impact_dynamic 2. com…
iantei Oct 27, 2023
e7f804e
Removed the unnecessary file unde frontend/Dockerfile.dev.
iantei Oct 27, 2023
23e5773
Showing Timeseries of emissions per mile for default mapping.
iantei Oct 27, 2023
6c469a5
Remove extranneous whitespaces from energy_calculations and generic_t…
iantei Oct 27, 2023
a18c549
Remove whitespace from generic_timeseries.ipynb
iantei Oct 27, 2023
88b899b
Fixing the scaffolding calculation for computation of conversion to k…
iantei Oct 30, 2023
9134465
Add new function in scaffolding.py to print the computation of CO2 em…
iantei Oct 30, 2023
5229d7e
Added is_debug_mode flag, which by default is set to False. When it i…
iantei Oct 30, 2023
efbd31f
Removed energy_impact computation for Dynamic config case.
iantei Oct 31, 2023
3c8823e
Update distace_miles column in the selected_columns in scaffolding.py…
iantei Oct 31, 2023
adb5258
Setting the default is_debug_mode flag to False. This will disable ca…
iantei Oct 31, 2023
b858b53
Removed redundant if/else case for different label_type inside mappin…
iantei Nov 2, 2023
3ee1bbb
Energy_calculations.ipynb added justification for computation of tota…
iantei Nov 2, 2023
5cbce25
Refactor both energy_calculations and generic_timeseries notebook to …
iantei Nov 7, 2023
dd64513
Stored the returned expanded_ct from compute_CO2_footprint_dynamic().
iantei Nov 7, 2023
a72ac99
Fixed try-catch block to handle case where emissions is not defined. …
iantei Nov 7, 2023
ae3117a
Fixed issue with default mapping - calling the right function. Update…
iantei Nov 7, 2023
8832e79
Remove conversion_kilometer_to_mile and vice versa in scaffolding.py …
iantei Nov 13, 2023
78e4777
Removed f{'distance_unit'} with distance_unit for compute_daily_metri…
iantei Nov 13, 2023
932af13
Update sense keyword in the phrase for dropdown menu for Trip miles b…
iantei Nov 21, 2023
a23ad9f
Updated the comment to explain this is specically used to test with e…
iantei Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 22 additions & 146 deletions viz_scripts/energy_calculations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"study_type = \"program\"\n",
"mode_of_interest = \"e-bike\"\n",
"include_test_users = False\n",
"is_debug_mode = False\n",
"dynamic_labels = {}"
]
},
Expand Down Expand Up @@ -237,172 +238,47 @@
" CO2_impact(x,y,color,plot_title, xLabel,yLabel,file_name)\n",
" alt_text = store_alt_text_bar(pd.DataFrame(x.values,y), file_name, plot_title)\n",
" \n",
" filtered_taxi_data = data_eb[data_eb['Replaced_mode'] == \"Taxi/Uber/Lyft\"]\n",
" filtered_bus_data = data_eb[data_eb['Replaced_mode'] == \"Bus\"]\n",
" filtered_notravel_data = data_eb[data_eb['Replaced_mode'] == \"No travel\"]\n",
" filtered_freeshuttle_data = data_eb[data_eb['Replaced_mode'] == \"Free Shuttle\"]\n",
" filtered_walk_data = data_eb[data_eb['Replaced_mode'] == \"Walk\"]\n",
" filtered_GasCarShared_data = data_eb[data_eb['Replaced_mode'] == \"Gas Car Shared Ride\"]\n",
"\n",
" selected_columns = ['distance', 'Replaced_mode_kg_CO2', 'Mode_confirm_kg_CO2', \"replaced_mode\", \"mode_confirm\"]\n",
"\n",
" print(\"With Dynamic config mapping:\")\n",
" print(\"\\n\")\n",
"\n",
" print(\"Walk Data:\")\n",
" print(str(filtered_walk_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
"\n",
" print(\"No Travel Data:\")\n",
" print(str(filtered_notravel_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
"\n",
" print(\"Gas Car Shared Data:\")\n",
" print(str(filtered_GasCarShared_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
"\n",
" print(\"Free Shuttle Data:\")\n",
" print(str(filtered_freeshuttle_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
"\n",
" print(\"Bus Data:\")\n",
" print(str(filtered_bus_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
" \n",
" print(\"Taxi/Uber/Lyft Data:\")\n",
" print(str(filtered_taxi_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
" \n",
" print(\"Total Kg CO2 Emissions\")\n",
" print(ebco2['total_kg_CO2_emissions'])\n",
" if (is_debug_mode == True):\n",
" ebco2_lb=data_eb.groupby('Replaced_mode').agg({'CO2_Impact(lb)': ['sum', 'mean']},)\n",
" ebco2_lb.columns = ['total_lb_CO2_emissions', 'average_lb_CO2_emission']\n",
shankari marked this conversation as resolved.
Show resolved Hide resolved
" ebco2_lb = ebco2_lb.reset_index()\n",
" ebco2_lb = ebco2_lb.sort_values(by=['total_lb_CO2_emissions'], ascending=False)\n",
" \n",
" scaffolding.print_CO2_emission_calculations(data_eb, ebco2_lb, ebco2, dynamic_labels)\n",
" \n",
" except:\n",
" generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n",
" alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)\n",
"# case: when label_options is absent from the config file\n",
"# else: \n",
"# plot_title_no_quality=f\"Sketch of Total pounds of CO2 Emissions of {mode_of_interest} trips\"\n",
"# file_name =f'sketch_CO2impact_{mode_of_interest}%s' % file_suffix\n",
"\n",
"# try:\n",
"# ebco2=data_eb.groupby('Replaced_mode').agg({'CO2_Impact(lb)': ['sum', 'mean']},)\n",
shankari marked this conversation as resolved.
Show resolved Hide resolved
"# ebco2.columns = ['total_lb_CO2_emissions', 'average_lb_CO2_emission']\n",
"# ebco2 = ebco2.reset_index()\n",
"# ebco2 = ebco2.sort_values(by=['total_lb_CO2_emissions'], ascending=False)\n",
"# ebco2['boolean'] = ebco2['total_lb_CO2_emissions'] > 0\n",
"# net_CO2_emissions = round(sum(ebco2['total_lb_CO2_emissions']), 2)\n",
"\n",
"# x = ebco2['total_lb_CO2_emissions']\n",
"# y = ebco2['Replaced_mode']\n",
"# xLabel = 'CO2 Emissions (lb)'\n",
"# yLabel = 'Replaced Mode'\n",
"# color = ebco2['boolean']\n",
"\n",
"# plot_title= plot_title_no_quality+f\"\\n Contribution by replaced mode towards a total of {net_CO2_emissions}(lb CO2 Emissions )\\n\"+quality_text\n",
"# CO2_impact(x,y,color,plot_title,xLabel,yLabel,file_name)\n",
"# alt_text = store_alt_text_bar(pd.DataFrame(x.values,y), file_name, plot_title)\n",
"\n",
"# filtered_taxi_data = data_eb[data_eb['Replaced_mode'] == \"Taxi/Uber/Lyft\"]\n",
"# filtered_bus_data = data_eb[data_eb['Replaced_mode'] == \"Bus\"]\n",
"# filtered_notravel_data = data_eb[data_eb['Replaced_mode'] == \"No Travel\"]\n",
"# filtered_freeshuttle_data = data_eb[data_eb['Replaced_mode'] == \"Free Shuttle\"]\n",
"# filtered_walk_data = data_eb[data_eb['Replaced_mode'] == \"Walk\"]\n",
"# filtered_GasCarShared_data = data_eb[data_eb['Replaced_mode'] == \"Gas Car, with others\"]\n",
"\n",
"# selected_columns = ['distance', 'Replaced_mode_kg_CO2', 'Mode_confirm_kg_CO2', \"replaced_mode\", \"mode_confirm\"]\n",
"\n",
"# print(\"With Default mapping:\")\n",
"# print(\"\\n\")\n",
"\n",
"# print(\"Walk Data:\")\n",
"# print(str(filtered_walk_data[selected_columns].head()))\n",
"# print(\"\\n\")\n",
"\n",
"# print(\"No Travel Data:\")\n",
"# print(str(filtered_notravel_data[selected_columns].head()))\n",
"# print(\"\\n\")\n",
"\n",
"# print(\"Gas Car Shared Data:\")\n",
"# print(str(filtered_GasCarShared_data[selected_columns].head()))\n",
"# print(\"\\n\")\n",
"\n",
"# print(\"Free Shuttle Data:\")\n",
"# print(str(filtered_freeshuttle_data[selected_columns].head()))\n",
"# print(\"\\n\")\n",
"\n",
"# print(\"Bus Data:\")\n",
"# print(str(filtered_bus_data[selected_columns].head()))\n",
"# print(\"\\n\")\n",
" \n",
"# print(\"Taxi/Uber/Lyft Data:\")\n",
"# print(str(filtered_taxi_data[selected_columns].head()))\n",
"# print(\"\\n\")\n",
" \n",
"# print(\"Total lbs CO2 Emissions\")\n",
"# print(ebco2['total_lb_CO2_emissions'])\n",
"# except:\n",
"# generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n",
"# alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)\n",
"else: \n",
shankari marked this conversation as resolved.
Show resolved Hide resolved
" plot_title_no_quality=f\"Sketch of Total pounds of CO2 Emissions of {mode_of_interest} trips\"\n",
" file_name =f'sketch_CO2impact_{mode_of_interest}%s' % file_suffix\n",
"\n",
" try:\n",
" ebco2=data_eb.groupby('Replaced_mode').agg({'CO2_Impact(kg)': ['sum', 'mean']},)\n",
" ebco2.columns = ['total_kg_CO2_emissions', 'average_kg_CO2_emission']\n",
" ebco2=data_eb.groupby('Replaced_mode').agg({'CO2_Impact(lb)': ['sum', 'mean']},)\n",
" ebco2.columns = ['total_lb_CO2_emissions', 'average_lb_CO2_emission']\n",
" ebco2 = ebco2.reset_index()\n",
" ebco2 = ebco2.sort_values(by=['total_kg_CO2_emissions'], ascending=False)\n",
" ebco2['boolean'] = ebco2['total_kg_CO2_emissions'] > 0\n",
" net_CO2_emissions = round(sum(ebco2['total_kg_CO2_emissions']), 2)\n",
" ebco2 = ebco2.sort_values(by=['total_lb_CO2_emissions'], ascending=False)\n",
" ebco2['boolean'] = ebco2['total_lb_CO2_emissions'] > 0\n",
" net_CO2_emissions = round(sum(ebco2['total_lb_CO2_emissions']), 2)\n",
"\n",
" x = ebco2['total_kg_CO2_emissions']\n",
" x = ebco2['total_lb_CO2_emissions']\n",
" y = ebco2['Replaced_mode']\n",
" xLabel = 'CO2 Emissions (kg)'\n",
" xLabel = 'CO2 Emissions (lb)'\n",
" yLabel = 'Replaced Mode'\n",
" color = ebco2['boolean']\n",
"\n",
" plot_title= plot_title_no_quality+f\"\\n Contribution by replaced mode towards a total of {net_CO2_emissions}(lb CO2 Emissions )\\n\"+quality_text\n",
" CO2_impact(x,y,color,plot_title,xLabel,yLabel,file_name)\n",
" alt_text = store_alt_text_bar(pd.DataFrame(x.values,y), file_name, plot_title)\n",
"\n",
" filtered_taxi_data = data_eb[data_eb['Replaced_mode'] == \"Taxi/Uber/Lyft\"]\n",
" filtered_bus_data = data_eb[data_eb['Replaced_mode'] == \"Bus\"]\n",
" filtered_notravel_data = data_eb[data_eb['Replaced_mode'] == \"No Travel\"]\n",
" filtered_freeshuttle_data = data_eb[data_eb['Replaced_mode'] == \"Free Shuttle\"]\n",
" filtered_walk_data = data_eb[data_eb['Replaced_mode'] == \"Walk\"]\n",
" filtered_GasCarShared_data = data_eb[data_eb['Replaced_mode'] == \"Gas Car, with others\"]\n",
"\n",
" selected_columns = ['distance_miles', 'Replaced_mode_kg_CO2', 'Mode_confirm_kg_CO2', \"replaced_mode\", \"mode_confirm\"]\n",
"\n",
" print(\"With Default mapping:\")\n",
" print(\"\\n\")\n",
"\n",
" print(\"Walk Data:\")\n",
" print(str(filtered_walk_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
"\n",
" print(\"No Travel Data:\")\n",
" print(str(filtered_notravel_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
"\n",
" print(\"Gas Car Shared Data:\")\n",
" print(str(filtered_GasCarShared_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
"\n",
" print(\"Free Shuttle Data:\")\n",
" print(str(filtered_freeshuttle_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
"\n",
" print(\"Bus Data:\")\n",
" print(str(filtered_bus_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
" \n",
" print(\"Taxi/Uber/Lyft Data:\")\n",
" print(str(filtered_taxi_data[selected_columns].head()))\n",
" print(\"\\n\")\n",
" \n",
" print(\"Total Kg CO2 Emissions\")\n",
" print(ebco2['total_kg_CO2_emissions'])\n",
" if (is_debug_mode == True):\n",
shankari marked this conversation as resolved.
Show resolved Hide resolved
" ebco2_kg=data_eb.groupby('Replaced_mode').agg({'CO2_Impact(kg)': ['sum', 'mean']},)\n",
" ebco2_kg.columns = ['total_kg_CO2_emissions', 'average_kg_CO2_emission']\n",
" ebco2_kg = ebco2_kg.reset_index()\n",
" ebco2_kg = ebco2_kg.sort_values(by=['total_kg_CO2_emissions'], ascending=False)\n",
" \n",
" scaffolding.print_CO2_emission_calculations(data_eb, ebco2, ebco2_kg, dynamic_labels)\n",
" except:\n",
" generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n",
" alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)"
Expand Down
34 changes: 15 additions & 19 deletions viz_scripts/generic_timeseries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@
" emissions['Mode_confirm_kg_CO2'] = emissions['Mode_confirm_kg_CO2'].fillna(0)\n",
" emissions['distance'] = emissions['Mode_confirm_kg_CO2'].fillna(0)\n",
"\n",
" # Sum daily energy for each user\n",
shankari marked this conversation as resolved.
Show resolved Hide resolved
" energy = data.groupby(['user_id','date_time'], as_index=False)[['Mode_confirm_EI(kWH)', 'distance']].sum()\n",
" energy['Mode_confirm_EI(kWH)'] = energy['Mode_confirm_EI(kWH)'].fillna(0)\n",
" energy['distance'] = energy['Mode_confirm_EI(kWH)'].fillna(0)\n",
"\n",
" # Add 7-day rolling avg smoothing to better see trends\n",
" mode_counts['trip_count_smooth'] = mode_counts.groupby(['user_id','Mode_confirm'])['trip_count'].apply(lambda x: x.rolling(7,1).mean())\n",
" mode_distance['distance_smooth'] = mode_distance.groupby(['user_id','Mode_confirm'])['distance'].apply(lambda x: x.rolling(7,1).mean())\n",
Expand Down Expand Up @@ -274,22 +269,23 @@
"metadata": {},
"outputs": [],
"source": [
"plot_title_no_quality = 'Net Daily Energy (All Users, excluding air)'\n",
"file_name = \"ts_energy_user%s\"%file_suffix\n",
"if (len(dynamic_labels) == 0):\n",
" plot_title_no_quality = 'Net Daily Energy (All Users, excluding air)'\n",
" file_name = \"ts_energy_user%s\"%file_suffix\n",
"\n",
"try:\n",
" # Energy per week across all users (net impact)\n",
" plot_data = energy.groupby(['date_time'], as_index=False)['Mode_confirm_EI(kWH)'].agg(['sum'])\n",
" plot_data = plot_data.merge(active_users, on='date_time')\n",
" plot_data['sum'] = plot_data['sum'] / plot_data['active_users']\n",
" try:\n",
" # Energy per week across all users (net impact)\n",
" plot_data = energy.groupby(['date_time'], as_index=False)['Mode_confirm_EI(kWH)'].agg(['sum'])\n",
" plot_data = plot_data.merge(active_users, on='date_time')\n",
" plot_data['sum'] = plot_data['sum'] / plot_data['active_users']\n",
"\n",
" plot_title= plot_title_no_quality+\"\\n\"+quality_text\n",
" ylab = 'Energy (kWH/day/user)'\n",
" timeseries_plot(plot_data['date_time'], plot_data['sum'], plot_title, ylab, file_name)\n",
" alt_text = store_alt_text_timeseries(plot_data, file_name, plot_title)\n",
"except:\n",
" generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n",
" alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)"
" plot_title= plot_title_no_quality+\"\\n\"+quality_text\n",
" ylab = 'Energy (kWH/day/user)'\n",
" timeseries_plot(plot_data['date_time'], plot_data['sum'], plot_title, ylab, file_name)\n",
" alt_text = store_alt_text_timeseries(plot_data, file_name, plot_title)\n",
" except:\n",
" generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n",
" alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)"
]
},
{
Expand Down
52 changes: 51 additions & 1 deletion viz_scripts/scaffolding.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ def energy_intensity(trip_df,mode_intensity_df,col):
mode_intensity_df = dataframe with energy/cost/time factors
col = the column for which we want to map the intensity
"""

shankari marked this conversation as resolved.
Show resolved Hide resolved
mode_intensity_df = mode_intensity_df.copy()
mode_intensity_df[col] = mode_intensity_df['mode']
dic_ei_factor = dict(zip(mode_intensity_df[col],mode_intensity_df['energy_intensity_factor']))
Expand Down Expand Up @@ -426,3 +425,54 @@ def compute_CO2_impact_dynamic(expanded_ct, dynamic_labels):
expanded_ct['CO2_Impact(kg)'] = round ((expanded_ct['Replaced_mode_kg_CO2'] - expanded_ct['Mode_confirm_kg_CO2']), 3)
expanded_ct['CO2_Impact(lb)'] = round ((expanded_ct['Replaced_mode_lb_CO2'] - expanded_ct['Mode_confirm_lb_CO2']), 3)
return expanded_ct

def print_CO2_emission_calculations(data_eb, ebco2_lb, ebco2_kg, dynamic_labels):

filtered_taxi_data = data_eb[data_eb['Replaced_mode'] == "Taxi/Uber/Lyft"]
filtered_bus_data = data_eb[data_eb['Replaced_mode'] == "Bus"]
filtered_freeshuttle_data = data_eb[data_eb['Replaced_mode'] == "Free Shuttle"]
filtered_walk_data = data_eb[data_eb['Replaced_mode'] == "Walk"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not going to require any changes here since this is only invoked in debug cases, but note that dynamic configs are not guaranteed to have the same labels, or even the same modes. Note that the Lao labels, for example that I asked you to test against, do not have the translation "Gas Car Shared Ride".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some notes here about the particular dynamic config that this works with. Because we have at least two production (non-example) dynamic configs now (Laos and CA e-bike) and the second is even in English. So people might be confused while debugging and not know why this doesn't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment by mentioning the print statements for debugging mode are specifically designed in consideration with https://github.com/e-mission/nrel-openpath-deploy-configs/blob/main/configs/dev-emulator-program.nrel-op.json.


# Handling different cases of Replaced mode translations
if len(dynamic_labels) > 0:
filtered_GasCarShared_data = data_eb[data_eb['Replaced_mode'] == "Gas Car Shared Ride"]
filtered_notravel_data = data_eb[data_eb['Replaced_mode'] == "No travel"]
print("With Dynamic Config:")
print("\n")
else:
filtered_GasCarShared_data = data_eb[data_eb['Replaced_mode'] == "Gas Car, with others"]
filtered_notravel_data = data_eb[data_eb['Replaced_mode'] == "No Travel"]
print("With Default mapping:")
print("\n")

selected_columns = ['distance','distance_miles', 'Replaced_mode_kg_CO2', 'Replaced_mode_lb_CO2', 'Mode_confirm_kg_CO2','Mode_confirm_lb_CO2', "replaced_mode", "mode_confirm"]

print("Walk Data:")
print(str(filtered_walk_data[selected_columns].head()))
print("\n")

print("No Travel Data:")
print(str(filtered_notravel_data[selected_columns].head()))
print("\n")

print("Gas Car Shared Data:")
print(str(filtered_GasCarShared_data[selected_columns].head()))
print("\n")

print("Free Shuttle Data:")
print(str(filtered_freeshuttle_data[selected_columns].head()))
print("\n")

print("Bus Data:")
print(str(filtered_bus_data[selected_columns].head()))
print("\n")

print("Taxi/Uber/Lyft Data:")
print(str(filtered_taxi_data[selected_columns].head()))
print("\n")

combined_df = pd.concat([ebco2_lb['total_lb_CO2_emissions'], ebco2_kg['total_kg_CO2_emissions']], axis=1)
combined_df.columns = ['Total CO2 Emissions (lb)', 'Total CO2 Emissions (kg)']

print("CO2 Emissions:")
print(combined_df)