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
  • /
  • evaluate_payload_vs_mileage_diesel.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:d5d81af3c0398dfd88bcaed9377bcd858c75ea31
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 ...
evaluate_payload_vs_mileage_diesel.py
"""
Date: May 2, 2024
Purpose: Evaluate linear coefficients to calculate mpg as a function of payload for each drivecycle
"""

import data_collection_tools
import truck_model_tools_diesel
import pandas as pd

KG_PER_KILOTON = 1e6

###################################### Select drivecycles to consider #####################################
drivecycles = {
    'pepsi_1': [2, 9, 13, 15, 33],
    'pepsi_2': [7, 10, 14, 22, 25, 31],
    'pepsi_3': [8, 10, 13, 16, 21, 24, 28, 32, 33]
}
###########################################################################################################

def main():
    parameters = data_collection_tools.read_parameters(truck_params='diesel_daycab', vmt_params = 'daycab_vmt_vius_2021', truck_type = 'diesel')

    evaluated_linear_params_df = pd.DataFrame(columns=['Linear Slope (gal/mile/kiloton)', 'Y Intercept (gal/mile)'])
    for truck_name in drivecycles:
        for drivecycle in drivecycles[truck_name]:
            df_drivecycle = truck_model_tools_diesel.extract_drivecycle_data(f'data/{truck_name}_drive_cycle_{drivecycle}.csv')
            slope_gpm, y_intercept_payload_gpm, miles_per_gallon_ave_payload = truck_model_tools_diesel.truck_model(parameters).get_power_requirement(df_drivecycle)
            
            result = {
                'Linear Slope (gal/mile/kiloton)': [slope_gpm * KG_PER_KILOTON],
                'Y Intercept (gal/mile)': [y_intercept_payload_gpm]
            }
            
        
            # Assuming results are in the format expected, create a DataFrame
            evaluated_linear_params_df = pd.concat([evaluated_linear_params_df, pd.DataFrame(result)])

    # Save the evaluated linear parameters as a csv file
    filename = f'tables/linear_mpg_params_diesel_daycab.csv'

    evaluated_linear_params_df.to_csv(filename, index=False)
    
    
if __name__ == '__main__':
    main()

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