Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • ece7ce6
  • /
  • source
  • /
  • data_collection_tools.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:d6bf0b9108898ba440e6aaac4c016780cab85a40
directory badge
swh:1:dir:fa5362aac1bafdd90967fcc63c7c01b393027131

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
data_collection_tools.py
"""
Date: March 26, 2024
Purpose: Collect input data for truck simulation and lifecycle cost and emissions assessment
Note: Code adapted by Danika MacDonell from a colab notebook written by Kariana Moreno Sader
"""

import pandas as pd
import truck_model_tools
import truck_model_tools_diesel

# Function to read in non-battery parameters for the truck model
def read_parameters(truck_params='default', economy_params='default', vmt_params='default', truck_type='EV'):
    truck_params_str = f'data/{truck_params}_truck_params.csv'
    economy_params_str = f'data/{economy_params}_economy_params.csv'
    vmt_params_str = f'data/{vmt_params}_vmt.csv'
    if truck_type == 'EV':
        parameters = truck_model_tools.read_parameters(truck_params_str, economy_params_str, 'data/constants.csv', 'data/default_vmt.csv')
    else:
        parameters = truck_model_tools_diesel.read_parameters(truck_params_str, economy_params_str, 'data/constants.csv', 'data/default_vmt.csv')
    return parameters

# Function to read in battery parameters for the truck model
def read_battery_params(battery_params='default', chemistry='NMC'):
    battery_params_str = f'data/default_battery_params.csv'
    df_battery_data = pd.read_csv(battery_params_str, index_col=0)
    
    battery_params_dict = {
        'Energy density (kWh/ton)': df_battery_data['Value'].loc[f'{chemistry} battery energy density'],
        'Roundtrip efficiency': df_battery_data['Value'].loc[f'{chemistry} roundtrip efficiency'],
        'Manufacturing emissions (CO2/kWh)': df_battery_data['Value'].loc[f'{chemistry} manufacturing emissions'],
        'Replacements': df_battery_data['Value'].loc[f'{chemistry} replacements']
        }
    
    return battery_params_dict
    
def read_truck_cost_data(truck = 'class_8_daycab', truck_type = 'EV', chemistry='NMC'):
    df_truck_cost = pd.read_csv(f'data/{truck}_cost_data.csv', index_col=0)
    
    truck_cost_data_dict = {}
    
    if truck_type == 'EV':
        truck_cost_data_dict['Capital Costs'] = {
            'glider ($)': float(df_truck_cost['Value'].loc['Glider']),
            'motor and inverter ($/kW)': float(df_truck_cost['Value'].loc['Motor and inverter']),
            'DC-DC converter ($/kW)': float(df_truck_cost['Value'].loc['DC-DC converter'])
            }
        truck_cost_data_dict['Battery Unit Cost ($/kWh)'] = float(df_truck_cost['Value'].loc[f'{chemistry} battery'])
    elif truck_type == 'diesel' or truck_type == 'Diesel':
        truck_cost_data_dict['Capital Costs'] = {
            'glider ($)': float(df_truck_cost['Value'].loc['Glider']),
            'aftertreatment ($)': float(df_truck_cost['Value'].loc['Aftertreatment']),
            'engine ($/kW)': float(df_truck_cost['Value'].loc['Engine']),
            'transmission ($)': float(df_truck_cost['Value'].loc['Transmission']),
            'fuel tank ($)': float(df_truck_cost['Value'].loc['Fuel tank']),
            'WHR system ($)': float(df_truck_cost['Value'].loc['WHR system']),
            }
    else:
        print(f'Error: No info for truck type {truck_type}')
    
    truck_cost_data_dict['Operating Costs'] = {
        'maintenance & repair ($/mi)': float(df_truck_cost['Value'].loc['Maintenance and repair']),
        'labor ($/mi)': float(df_truck_cost['Value'].loc['Labor']),
        'insurance ($/mi-$)': float(df_truck_cost['Value'].loc['Insurance']),
        'tolls ($/mi)': float(df_truck_cost['Value'].loc['Tolls']),
        'permits and licenses ($/mi)': float(df_truck_cost['Value'].loc['Permits and licenses'])
        }
    
    return truck_cost_data_dict
    
    
# Basic code to test the functions defined above
#print(read_truck_cost_data(truck_type='diesel'))
    

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API