prereise.gather.demanddata.transportation_electrification package¶
Subpackages¶
- prereise.gather.demanddata.transportation_electrification.data package
- prereise.gather.demanddata.transportation_electrification.tests package
- Submodules
- prereise.gather.demanddata.transportation_electrification.tests.test_dwelling module
- prereise.gather.demanddata.transportation_electrification.tests.test_generate_BEV_vehicle_profiles module
- prereise.gather.demanddata.transportation_electrification.tests.test_immediate module
- prereise.gather.demanddata.transportation_electrification.tests.test_immediate_charging_integration module
- prereise.gather.demanddata.transportation_electrification.tests.test_smart_charging_integration module
- Module contents
Submodules¶
prereise.gather.demanddata.transportation_electrification.charging_optimization module¶
- prereise.gather.demanddata.transportation_electrification.charging_optimization.calculate_optimization(charging_consumption, rates, elimit, seg, total_trips, kwh, charging_efficiency)[source]¶
Calculates the minimized charging cost during a specific dwelling activity
- Parameters:
charging_consumption (list) – the charging consumption for each trip
rates (list) – rates to be used for the cost function
elimit (list) – energy limits during the time span of available charging
seg (list) – the amount of the segments in the dwelling activity
total_trips (int) – total number of trips for the current vehicle
kwh (float) – kwhmi * veh_range, amount of energy needed to charge vehicle.
charging_efficiency (float) – from grid to battery efficiency.
- Returns:
(dict) – contains the necessary inputs for the linprog optimization
- prereise.gather.demanddata.transportation_electrification.charging_optimization.get_constraints(constraints_df, kwhmi, power, trip_strategy, location_strategy, location_allowed, charging_efficiency)[source]¶
Determine the consumption and charging constraints for each trip (hour segment)
- Parameters:
constraints_df (pandas.DataFrame) – trip data of vehicles for optimization constraints
kwhmi (int) – fuel efficiency, should vary based on vehicle type and model_year.
power (float) – charger power, EVSE kW.
trip_strategy (int) – a toggle that determines if should charge on any trip or only after last trip (1-anytrip number, 2-last trip)
location_strategy (int) – where the vehicle can charge-1, 2, 3, 4, 5, or 6; 1-home only, 2-home and work related, 3-anywhere if possibile, 4-home and school only, 5-home and work and school, 6-only work
location_allowed (dict) – starting locations allowed in the dataset
charging_efficiency (float) – from grid to battery efficiency.
- Returns:
(pandas.DataFrame) – a DataFrame adding the calculated constraints to an individual vehicle’s data
prereise.gather.demanddata.transportation_electrification.const module¶
prereise.gather.demanddata.transportation_electrification.data_helper module¶
- prereise.gather.demanddata.transportation_electrification.data_helper.generate_daily_weighting(year, area_type='urban')[source]¶
Generate daily weighting factors based on vehicle-miles-travelled distributions.
- Parameters:
year (int/str) – year to generate weighting factors for.
area_type (str) – Either ‘urban’ or ‘rural’.
- Returns:
(pandas.Series) – index is the day of the year, values are the fraction of the year’s vehicle miles travelled are estimated to occur in that day.
- Raises:
ValueError – if
area_type
is neither ‘urban’ nor ‘rural’.
- prereise.gather.demanddata.transportation_electrification.data_helper.get_data_day(data: DataFrame)[source]¶
Get weekday/weekend designation value from data.
- Parameters:
data (pandas.DataFrame) – the data to get day of week from.
- Returns:
(numpy.array) – indicates weekend or weekday for every day.
- prereise.gather.demanddata.transportation_electrification.data_helper.get_input_day(model_year_dti: DatetimeIndex)[source]¶
Determine whether each day of the model year is a weekend (1) or weekday (2)
- Parameters:
model_year_dti (pandas.DatetimeIndex) – a DatetimeIndex encompassing the model year.
- Returns:
(numpy.ndarray) – array of 1s and 2s indicating weekend/weekday designations for the model year.
- prereise.gather.demanddata.transportation_electrification.data_helper.get_kwhmi(model_year, veh_type, veh_range)[source]¶
Get the fuel efficiency value based on the model year and vehicle type.
- Parameters:
model_year (int) – year that is being modelled/projected to, 2017, 2030, 2040, 2050.
veh_type (str) – determine which category (MDV, HDV, or Transit) to produce a fuel efficiency value for.
veh_range (int) – 100, 200, or 300, represents how far vehicle can travel on single charge.
- Returns:
(float) – fuel efficiency value from the Fuel_efficiencies.csv
- Raises:
ValueError – if
veh_range
is not 100, 200, or 300 and ifveh_type
is not ‘LDT’, ‘LDV’, ‘MDV’, ‘HDV’, or ‘Transit
- prereise.gather.demanddata.transportation_electrification.data_helper.get_model_year_dti(model_year: int)[source]¶
Creates a DatetimeIndex based on the input year of the model.
- Parameters:
model_year (int) – the input year of the model
- Returns:
(pandas.DatetimeIndex model_year_dti) – a DatetimeIndex encompassing the model year.
- prereise.gather.demanddata.transportation_electrification.data_helper.get_total_daily_vmt(data: DataFrame, input_day, veh_type)[source]¶
Calculates the total VMT and total vehicles for for each day of the model year, based on if the day is a weekend (1) or weekday (2).
- Parameters:
data (pandas.DataFrame) – the data returned from
load_data()
.input_day (numpy.ndarray) – day of the week for each day in the year derived from
get_input_day()
.veh_type (pandas.Series) – vehicle class (LDV, LDT, MDV, HDV)
- Raises:
ValueError – Vehicle class is not specified
- Returns:
(np.array) – an array where each element is the daily VMT and total vehicles for that day.
- prereise.gather.demanddata.transportation_electrification.data_helper.load_data(census_region: int, filepath: str = 'nhts_census_updated.mat')[source]¶
Load the data at nhts_census.mat.
- Parameters:
census_region (int) – the census region to load data from.
filepath (str) – the path to the matfile.
- Raises:
ValueError – if the census division is not between 1 and 9, inclusive.
- Returns:
(pandas.DataFrame) – the data loaded from nths_census.mat, with column names added.
- prereise.gather.demanddata.transportation_electrification.data_helper.load_hdv_data(veh_type, filepath)[source]¶
Load the data at fdata_v10st.mat.
- Parameters:
veh_type (str) – vehicle type (“hhdv: and “mhdv”) category for trips
filepath (str) – the path to the matfile.
- Returns:
(pandas.DataFrame) – the data loaded from fdata_v10st.mat, with column names added.
- prereise.gather.demanddata.transportation_electrification.data_helper.load_rural_scaling_factor(model_year, veh_type, veh_range, state, filepath='regional_scaling_factors_RA_')[source]¶
Load the scaling factor for rural areas based on model year and vehicle type for the inputted state.
- Parameters:
model_year (int) – year that is being modelled/projected to, 2017, 2030, 2040, 2050.
veh_type (str) – determine which category (MDV, HDV, or Transit) to produce a fuel efficiency value for.
veh_range (int) – 100, 200, or 300, represents how far vehicle can travel on single charge.
state (str) – the US state the inputted urbanized area is in.
filepath (str) – the path to the csv.
- Returns:
(int/float) – scaling factor value from the regional_scaling_factors_RA_{model_year}.csv
- Raises:
ValueError – if
veh_range
is not 100, 200, or 300 and ifveh_type
is not ‘LDT’, ‘LDV’, ‘MDV’, ‘HDV’, or ‘Transit
- prereise.gather.demanddata.transportation_electrification.data_helper.load_urbanized_scaling_factor(model_year, veh_type, veh_range, urbanized_area, state, filepath='regional_scaling_factors_UA_')[source]¶
Load the scaling factor for urbanized areas based on model year and vehicle type for the inputted urbanized area and state.
- Parameters:
model_year (int) – year that is being modelled/projected to, 2017, 2030, 2040, 2050.
veh_type (str) – determine which category (MDV, HDV, or Transit) to produce a fuel efficiency value for.
veh_range (int) – 100, 200, or 300, represents how far vehicle can travel on single charge.
urbanized_area (str) – name of urbanized area or city.
state (str) – the US state the inputted urbanized area is in.
filepath (str) – the path to the csv.
- Returns:
(int/float) – scaling factor value from the regional_scaling_factors_UA_{model_year}.csv
- Raises:
ValueError – if
veh_range
is not 100, 200, or 300 and ifveh_type
is not ‘LDT’, ‘LDV’, ‘MDV’, ‘HDV’, or ‘Transit
- prereise.gather.demanddata.transportation_electrification.data_helper.remove_ldt(data: DataFrame)[source]¶
Remove light duty trucks (vehicle types 4-6) from data loaded from nths_census.mat. Keep light duty vehicles (vehicle types 1-3).
- Parameters:
data (pandas.DataFrame) – the data returned from
load_data()
.- Returns:
(pandas.DataFrame) – the data loaded from
load_data()
with all rows involving LDT removed.
- prereise.gather.demanddata.transportation_electrification.data_helper.remove_ldv(data: DataFrame)[source]¶
Remove light duty vehicles (vehicle types 1-3) from data loaded from nths_census.mat. Keep light duty trucks (vehicle types 4-6).
- Parameters:
data (pandas.DataFrame) – the data returned from
load_data()
.- Returns:
(pandas.DataFrame) – the data loaded from
load_data()
with all rows involving LDT removed.
- prereise.gather.demanddata.transportation_electrification.data_helper.update_if_weekend(data: DataFrame)[source]¶
Updates the “If Weekend” values depending on the “Day of Week” value. Fridays and Sundays overlap into the weekend or weekday due to the vehicle time window, 6AM - 5:59AM.
- Parameters:
data (pandas.DataFrame) – the data returned from
remove_ldt()
orremove_ldv()
.- Returns:
(pandas.DataFrame) – the data loaded from
remove_ldt()
orremove_ldv()
with updated “If Weekend” values.
prereise.gather.demanddata.transportation_electrification.data_process module¶
- prereise.gather.demanddata.transportation_electrification.data_process.calculate_dwell_time(data: DataFrame)[source]¶
Calculates the dwell time, how long a vehicle has been charging. For the last trip, dwell time is calculated based on the last trip’s end time and the start time of the first trip. This calculation handles when start times begin past 12AM.
- Parameters:
data (pandas.DataFrame) – the data to calculate the dwell time from
- Returns:
(pandas.Series) – list of dwell times
- prereise.gather.demanddata.transportation_electrification.data_process.data_filtering(raw_nhts, census_division)[source]¶
Filter raw NHTS data to be used in mileage.py
- Parameters:
raw_nhts (pandas.DataFrame) – raw NHTS dataframe
census_division (int) – any of the 9 census regions defined by the US census bureau
- Returns:
(pandas.DataFrame) – filtered and sorted trip data
prereise.gather.demanddata.transportation_electrification.dwelling module¶
- prereise.gather.demanddata.transportation_electrification.dwelling.get_energy_limit(power, segment, dwelling_start_time, dwelling_length, charging_efficiency)[source]¶
Determines the energy limit for the entire dwelling period. Takes into consideration if charging does not start or end directly on the hour.
- Parameters:
power (int) – charger power, EVSE kW.
segment (int) – the amount of the rates segments the dwelling activity possess.
dwelling_start_time (float) – dwelling start time.
dwelling_length (float) – length of dwell time.
charging_efficiency (float) – grid to battery efficiency.
- Returns:
(list) – list of energy limits during the time span of available charging
- prereise.gather.demanddata.transportation_electrification.dwelling.get_rates(cost, dwelling_start_time, dwelling_length)[source]¶
Determine the rates that will be used for the cost function.
- Parameters:
cost (numpy.array) – cost function
dwelling_start_time (float) – dwelling start time.
dwelling_length (float) – length of dwell time.
- Returns:
(numpy.array) – rates for the corresponding dwelling period
- prereise.gather.demanddata.transportation_electrification.dwelling.get_segment(dwelling_start_time, dwelling_length)[source]¶
Get dwelling activity segment.
- Parameters:
dwelling_start_time (float) – dwelling start time.
dwelling_length (float) – length of dwell time.
- Returns:
(int) – the amount of the rates (cost function) segments the dwelling activity possess.
prereise.gather.demanddata.transportation_electrification.generate_BEV_vehicle_profiles module¶
- prereise.gather.demanddata.transportation_electrification.generate_BEV_vehicle_profiles.generate_bev_vehicle_profiles(vehicle_trip_data_filepath, charging_strategy, veh_type, veh_range, projection_year, state, external_signal=None, power=6.6, location_strategy=2, trip_strategy=1)[source]¶
Generate Battery Electric Vehicle (BEV) profiles
- Parameters:
vehicle_trip_data_filepath (str) – filepath of collected trip data from external sources representing driving patterns
charging_strategy (str) – establishes whether charging happens immediately (“immediate”) or optimize based on external signals, i.e. smart charging (“smart”)
veh_type (str) – vehicle category: LDV: light duty vehicle, LDT: light duty truck, MDV: medium duty vehicle, HDV: heavy duty vehicle
veh_range (int) – 100, 200, or 300, represents how far vehicle can travel on single charge in miles.
projection_year (int) – year that is being modelled/projected to, 2017, 2030, 2040, 2050.
state (str) – US state abbreviation
external_signal (numpy.ndarray (optional)) – initial load demand (MW for each hour)
power (int) – (optional) charger power, EVSE kW; default value: 6.6 kW;
location_strategy (int) – (optional) where the vehicle can charge-1, 2, 3, 4, or 5; 1-home only, 2-home and work related, 3-anywhere if possibile, 4-home and school only, 5-home and work and school. default value: 2
trip_strategy (int) – (optional) determine to charge after any trip (1) or only after the last trip (2); default value: 1
- Returns:
(pandas.DataFrame) – yearly charging profiles for all urban areas and the rural area in each state (MW for each hour)
prereise.gather.demanddata.transportation_electrification.generate_scaling_factors module¶
prereise.gather.demanddata.transportation_electrification.immediate module¶
- prereise.gather.demanddata.transportation_electrification.immediate.adjust_bev(hourly_profile, adjustment_values, model_year, veh_type, veh_range, bev_vmt, charging_efficiency)[source]¶
Adjusts the charging profiles by applying weighting factors based on seasonal/monthly values
- Parameters:
hourly_profile (numpy.ndarray) – normalized charging profiles
adjustment_values (pandas.DataFrame) – weighting factors for each day of the year loaded from month_info_nhts.mat.
model_year (int) – year that is being modelled/projected to, 2017, 2030, 2040, 2050.
veh_type (str) – determine which category (MDV or HDV) to produce charging profiles for
veh_range (int) – 100, 200, or 300, represents how far vehicle can travel on single charge.
bev_vmt (int/float) – BEV VMT value / scaling factor loaded from Regional_scaling_factors.csv
charging_efficiency (float) – from grid to battery efficiency.
- Returns:
(numpy.ndarray) – final adjusted charging profiles.
- prereise.gather.demanddata.transportation_electrification.immediate.apply_annual_scaling(hourly_profile, bev_vmt, charging_efficiency, kwhmi)[source]¶
Adjusts the charging profiles by applying weighting factors based on seasonal/monthly values
- Parameters:
hourly_profile (numpy.ndarray) – hourly charging profile
bev_vmt (int/float) – BEV VMT value / scaling factor loaded from Regional_scaling_factors.csv
charging_efficiency (float) – from grid to battery efficiency.
kwhmi (int) – fuel efficiency, should vary based on vehicle type and model_year.
- Returns:
(numpy.ndarray) – adjusted charging profile
- prereise.gather.demanddata.transportation_electrification.immediate.apply_daily_adjustments(hourly_profile, adjustment_values, num_days_per_year=365, num_segments_per_day=24)[source]¶
Adjusts the charging profiles by applying weighting factors based on annual vehicle miles traveled (VMT) for battery electric vehicles in a specific geographic region
- Parameters:
hourly_profile (numpy.ndarray) – normalized charging profiles
adjustment_values (pandas.DataFrame) – weighting factors for each day of the year loaded from month_info_nhts.mat.
num_days_per_year (int) – optional year parameter to facilite easier testing
num_segments_per_day (int) – optional specification of hours per day
- Returns:
(numpy.ndarray) – adjusted charging profile
- prereise.gather.demanddata.transportation_electrification.immediate.calculate_charging(trips, charging_power, battery_capacity, kwhmi, charging_efficiency)[source]¶
Parse travel patterns to estimate charging and state-of-charge after each trip.
- Parameters:
trips (pandas.DataFrame) – trip data.
charging_power (int/float) – charging power (kW).
battery_capacity (int/float) – battery capacity (kWh).
kwhmi (int/float) – vehicle electricity consumption (kWh/ mile).
charging_efficiency (int/float) – from grid to battery efficiency.
- prereise.gather.demanddata.transportation_electrification.immediate.immediate_charging(census_region, model_year, veh_range, power, location_strategy, veh_type, filepath, trip_strategy=1, input_day=None)[source]¶
Immediate charging function
- Parameters:
census_region (int) – any of the 9 census regions defined by US census bureau.
model_year (int) – year that is being modelled/projected to, 2017, 2030, 2040, 2050.
veh_range (int) – 100, 200, or 300, represents how far vehicle can travel on single charge.
power (int) – charger power, EVSE kW.
location_strategy (int) – where the vehicle can charge-1, 2, 3, 4, or 5; 1-home only, 2-home and work related, 3-anywhere if possibile, 4-home and school only, 5-home and work and school.
veh_type (str) – determine which category (LDV or LDT) to produce charging profiles for
filepath (str) – the path to the nhts mat file.
trip_strategy (int) – determine to charge after any trip (1) or only after the last trip (2)
- Returns:
(numpy.ndarray) – charging profiles.
- prereise.gather.demanddata.transportation_electrification.immediate.resample_daily_charging(trips, charging_power)[source]¶
Translate start and end times and power to a 72-hour output array.
- Parameters:
trips (pandas.DataFrame) – trip data with trip-end and charge-time columns.
charging_power (int/float) – charging power (kW).
- Returns:
(numpy.array) – hourly total charging power for the 72-hour span.
prereise.gather.demanddata.transportation_electrification.immediate_charging_HDV module¶
- prereise.gather.demanddata.transportation_electrification.immediate_charging_HDV.calculate_charging(trips, charging_power, battery_capacity, kwhmi, charging_efficiency)[source]¶
Parse travel patterns to estimate charging and state-of-charge after each trip.
- Parameters:
trips (pandas.DataFrame) – trip data.
charging_power (int/float) – charging power (kW).
battery_capacity (int/float) – battery capacity (kWh).
kwhmi (int/float) – vehicle electricity consumption (kWh/ mile).
- Returns:
(pandas.DataFrame) – the updated data with the charging and SOC values for all vehicles.
- prereise.gather.demanddata.transportation_electrification.immediate_charging_HDV.calculate_charging_helper(group, battery_capacity, kwhmi, charging_power, charging_efficiency)[source]¶
Calculates the charging and state-of-charge after each trip.
- Parameters:
group (pandas.DataFrame) – group of trips from one vehicle.
battery_capacity (int/float) – battery capacity (kWh).
kwhmi (int/float) – vehicle electricity consumption (kWh/ mile).
charging_power (int/float) – charging power (kW).
charging_efficiency (float) – from grid to battery efficiency.
- Returns:
(pandas.DataFrame) – the updated data with the charging and SOC values for one group of trips.
- prereise.gather.demanddata.transportation_electrification.immediate_charging_HDV.immediate_hdv_charging(model_year, veh_range, power, location_strategy, veh_type, filepath, trip_strategy=1)[source]¶
Immediate charging function
- Parameters:
model_year (int) – year that is being modelled/projected to, 2017, 2030, 2040, 2050.
veh_range (int) – 100, 200, or 300, represents how far vehicle can travel on single charge.
power (int) – charger power, EVSE kW.
location_strategy (int) – where the vehicle can charge - 1 or 3; 1-base only, 3-anywhere if possibile.
veh_type (str) – determine which category (MDV or HDV) to produce charging profiles for
filepath (str) – the path to the HDV data file.
trip_strategy (int) – determine to charge after any trip (1) or only after the last trip (2)
- Returns:
(numpy.ndarray) – charging profiles.
- prereise.gather.demanddata.transportation_electrification.immediate_charging_HDV.resample_daily_charging(trips, charging_power)[source]¶
Translate start and end times and power to a 72-hour output array.
- Parameters:
trips (pandas.DataFrame) – trip data with trip-end and charge-time columns.
charging_power (int/float) – charging power (kW).
- Returns:
(numpy.array) – hourly total charging power for the 72-hour span.
prereise.gather.demanddata.transportation_electrification.smart_charging module¶
- prereise.gather.demanddata.transportation_electrification.smart_charging.hdv_use_all_data_rows(x, y)[source]¶
Helper function to select weekday/weekend data rows
- Parameters:
x (int) – data weekday/weekend value
y (int) – model year weekday/weekend value
- Returns:
(bool) – always returns true to use all data rows
- prereise.gather.demanddata.transportation_electrification.smart_charging.ldv_weekday_weekend_check(x, y)[source]¶
Helper function to select weekday/weekend data rows
- Parameters:
x (int) – data weekday/weekend value
y (int) – model year weekday/weekend value
- Returns:
(bool) – if data row matches whether the current day is a weekday/weekend
- prereise.gather.demanddata.transportation_electrification.smart_charging.smart_charging(model_year, veh_range, power, location_strategy, veh_type, filepath, external_signal, bev_vmt, census_region=None, daily_values=None, kwhmi=None, trip_strategy=1, input_day=None, debug_printout=False)[source]¶
Smart charging function
- Parameters:
model_year (int) – year that is being modelled/projected to, 2017, 2030, 2040, 2050.
veh_range (int) – 100, 200, or 300, represents how far vehicle can travel on single charge.
power (int) – charger power, EVSE kW.
location_strategy (int) – where the vehicle can charge-1, 2, 3, 4, or 5; 1-home only, 2-home and work related, 3-anywhere if possibile, 4-home and school only, 5-home and work and school.
veh_type (str) – determine which category (LDV or LDT) to produce charging profiles for
filepath (str) – the path to the nhts mat file.
external_signal (np.array) – the initial load demand
bev_vmt (float) – BEV VMT value / scaling factor loaded from regional_scaling_factors.csv
census_region (int) – any of the 9 census regions defined by US census bureau.
daily_values (pandas.Series) – daily weight factors returned from
generate_daily_weighting()
.kwhmi (int) – fuel efficiency, should vary based on vehicle type and model_year.
trip_strategy (int) – determine to charge after any trip (1) or only after the last trip (2)
input_day (numpy.ndarray) – daily list which specifies 1 if the day is a weekend, and 2 if the day is a weekday
debug_printout (bool) – specify if additional model parameters will be printed
- Returns:
(numpy.ndarray) – charging profiles.