Skip to content

Commit

Permalink
Version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi authored and romainsacchi committed Jan 23, 2024
1 parent f1d8c8a commit 699b3c0
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 59 deletions.
23 changes: 22 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@ include *.yaml
include *.rst
include *.ini
include *.csv
include *.npz
include carculator_utils/data/*.csv
include carculator_utils/data/*.json
include carculator_utils/data/*.yaml
include carculator_utils/data/*.yml
include carculator_utils/data/driving_cycles/*.csv
include carculator_utils/data/driving_cycles/*.yaml
include carculator_utils/data/efficiency/*.yaml
include carculator_utils/data/electricity/*.csv
include carculator_utils/data/electricity/*.yaml
include carculator_utils/data/emission_factors/*.yaml
include carculator_utils/data/emission_factors/bus/*.csv
include carculator_utils/data/emission_factors/car/*.csv
include carculator_utils/data/emission_factors/truck/*.csv
include carculator_utils/data/emission_factors/two-wheeler/*.csv
include carculator_utils/data/export/*.csv
include carculator_utils/data/export/*.yaml
include carculator_utils/data/export/*.json
include carculator_utils/data/fuel/*.csv
include carculator_utils/data/fuel/*.yaml
include carculator_utils/data/gradient/*.csv
include carculator_utils/data/IAM/*.csv
include carculator_utils/data/IAM/*.npz
include carculator_utils/data/lci/*.xlsx
include carculator_utils/data/lcia/*.csv
include carculator_utils/data/lcia/*.yaml
include LICENSE
2 changes: 1 addition & 1 deletion carculator_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ExportInventory",
"VehicleInputParameters",
)
__version__ = (1, 2, 0, "dev0")
__version__ = (1, 2, 0, "dev1")

from pathlib import Path

Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions carculator_utils/driving_cycles.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
driving_cycles.py loads a driving cycle based on
driving_cycles.py loads a driving_cycles based on
the name specific by the user.
The driving cycle returned is a numpy
The driving_cycles returned is a numpy
array with speed levels (in km/h) for each
second of driving.
"""
Expand All @@ -15,7 +15,7 @@

from . import DATA_DIR

FILEPATH_DC_SPECS = DATA_DIR / "driving cycle" / "dc_specs.yaml"
FILEPATH_DC_SPECS = DATA_DIR / "driving_cycles" / "dc_specs.yaml"


def detect_vehicle_type(vehicle_sizes: List[str]) -> str:
Expand All @@ -35,9 +35,9 @@ def detect_vehicle_type(vehicle_sizes: List[str]) -> str:


def get_driving_cycle_specs() -> dict:
"""Get driving cycle specifications.
"""Get driving_cycles specifications.
:returns: A dictionary with driving cycle specifications.
:returns: A dictionary with driving_cycles specifications.
:rtype: dict
"""
Expand All @@ -51,7 +51,7 @@ def get_dc_column_number(
) -> List[int]:
"""
Loads YAML file that contains the column number.
Return the column number given a vehicle type and driving cycle name.
Return the column number given a vehicle type and driving_cycles name.
"""

dc_specs = get_driving_cycle_specs()
Expand Down Expand Up @@ -94,18 +94,18 @@ def get_data(
return dc

except KeyError as err:
print(err, "The specified driving cycle could not be found.")
print(err, "The specified driving_cycles could not be found.")
raise


def get_standard_driving_cycle_and_gradient(
vehicle_type: str, vehicle_sizes: List[str], name: str
) -> Tuple[np.ndarray, np.ndarray]:
"""Get driving cycle and gradient data as a Pandas `Series`.
"""Get driving_cycles and gradient data as a Pandas `Series`.
Driving cycles are given as km/h per second up to 3200 seconds.
:param name: The name of the driving cycle.
:param name: The name of the driving_cycles.
e.g., WLTC (Worldwide harmonized Light vehicles Test Cycles)
:type name: str
Expand All @@ -115,12 +115,12 @@ def get_standard_driving_cycle_and_gradient(
"""

filepath_dc = DATA_DIR / "driving cycle" / f"{vehicle_type}.csv"
filepath_dc = DATA_DIR / "driving_cycles" / f"{vehicle_type}.csv"
filepath_gradient = DATA_DIR / "gradient" / f"{vehicle_type}.csv"

# definition of columns to select in the CSV file
# each column corresponds to a size class
# since the driving cycle is simulated for each size class
# since the driving_cycles is simulated for each size class
return (
get_data(filepath_dc, vehicle_type, vehicle_sizes, name),
get_data(filepath_gradient, vehicle_type, vehicle_sizes, name),
Expand Down
14 changes: 7 additions & 7 deletions carculator_utils/energy_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __(obj: Union[np.ndarray, xr.DataArray]) -> Union[np.ndarray, xr.DataArray]:


def get_default_driving_cycle_name(vehicle_type) -> str:
"""Get the default driving cycle name"""
"""Get the default driving_cycles name"""
return list(get_driving_cycle_specs()["columns"][vehicle_type].keys())[0]


Expand Down Expand Up @@ -121,9 +121,9 @@ def convert_to_xr(data):
class EnergyConsumptionModel:
"""
Calculate energy consumption of a vehicle for a
given driving cycle and vehicle parameters.
given driving_cycles and vehicle parameters.
Based on a selected driving cycle, this class calculates
Based on a selected driving_cycles, this class calculates
the acceleration needed and provides
two methods:
Expand All @@ -140,7 +140,7 @@ class EnergyConsumptionModel:
:type rho_air: float
:param gradient: Road gradient per second of driving, in degrees.
None by default. Should be passed as an array of length equal
to the length of the driving cycle.
to the length of the driving_cycles.
:type gradient: numpy.ndarray
:ivar rho_air: Mass per unit volume of air. Value of 1.204 at 23C (test temperature for WLTC).
Expand Down Expand Up @@ -196,7 +196,7 @@ def __init__(

assert len(self.cycle) == len(
self.gradient
), "The length of the driving cycle and the gradient must be the same."
), "The length of the driving_cycles and the gradient must be the same."

# Unit conversion km/h to m/s
self.velocity = np.where(np.isnan(self.cycle), 0, (self.cycle * 1000) / 3600)
Expand Down Expand Up @@ -295,7 +295,7 @@ def calculate_hvac_energy(

def find_last_driving_second(self) -> ndarray:
"""
Find the last second of the driving cycle that is not zero.
Find the last second of the driving_cycles that is not zero.
"""

# find last index where velocity is greater than 0
Expand Down Expand Up @@ -617,7 +617,7 @@ def motive_energy_per_km(

auxiliary_energy = np.where(self.velocity > 0, auxiliary_energy, 0)

# if first dimension is 1, resize it to the length of the driving cycle
# if first dimension is 1, resize it to the length of the driving_cycles
if auxiliary_energy.shape[0] == 1:
auxiliary_energy = np.resize(
auxiliary_energy, (self.velocity.shape[0], *auxiliary_energy.shape[1:])
Expand Down
14 changes: 7 additions & 7 deletions carculator_utils/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def get_simapro_technosphere() -> Dict[Tuple[str, str], str]:

def rename_mapping(filename: str) -> Dict[str, str]:
"""
Load the file rename_powertrains.yml and return a dictionary
Load the file rename_powertrains.yaml and return a dictionary
"""
with open(DATA_DIR / "export" / filename, encoding="utf-8") as f:
rename_map = yaml.safe_load(f)
Expand All @@ -192,8 +192,8 @@ def __init__(
self.array: xr.DataArray = array
self.indices: Dict[int, Tuple[str, str, str, str]] = indices
self.vm = vehicle_model
self.rename_pwt = rename_mapping("rename_powertrains.yml")
self.rename_parameters = rename_mapping("rename_parameters.yml")
self.rename_pwt = rename_mapping("rename_powertrains.yaml")
self.rename_parameters = rename_mapping("rename_parameters.yaml")
self.rename_vehicles()
self.rev_rename_pwt = {v: k for k, v in self.rename_pwt.items()}
self.db_name: str = db_name
Expand Down Expand Up @@ -463,15 +463,15 @@ def format_data_for_lci_for_simapro(
self, data: List[Dict], ei_version: str
) -> List[List]:
# not all biosphere flows exist in simapro
# load list from `simapro_blacklist.yml`
# load list from `simapro_blacklist.yaml`
with open(
DATA_DIR / "export" / "simapro_blacklist.yml", "r", encoding="utf-8"
DATA_DIR / "export" / "simapro_blacklist.yaml", "r", encoding="utf-8"
) as f:
blacklist = yaml.safe_load(f)

# load fields list from `simapro_fields.yml`
# load fields list from `simapro_fields.yaml`
with open(
DATA_DIR / "export" / "simapro_fields.yml", "r", encoding="utf-8"
DATA_DIR / "export" / "simapro_fields.yaml", "r", encoding="utf-8"
) as f:
fields = yaml.safe_load(f)

Expand Down
14 changes: 7 additions & 7 deletions carculator_utils/hot_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from . import DATA_DIR

FILEPATH_DC_SPECS = DATA_DIR / "driving cycle" / "dc_specs.yaml"
FILEPATH_DC_SPECS = DATA_DIR / "driving_cycles" / "dc_specs.yaml"

MAP_PWT = {
"Human": "BEV",
Expand Down Expand Up @@ -194,7 +194,7 @@ def get_hot_emissions(
:param powertrain_type: "diesel", "petrol" or "CNG"
:param euro_class: integer, corresponding to the EURO pollution class
:param energy_consumption: tank-to-wheel energy consumption for each second of the driving cycle
:param energy_consumption: tank-to-wheel energy consumption for each second of the driving_cycles
:param yearly_km: annual mileage, to calculate cold start emissions
:return: Pollutants emission per km driven, per air compartment.
"""
Expand Down Expand Up @@ -227,7 +227,7 @@ def get_hot_emissions(

distance = self.velocity.sum(dim="second") / 3600

# Emissions for each second of the driving cycle equal:
# Emissions for each second of the driving_cycles equal:
# a * energy consumption
# with a being a coefficient given by fitting HBEFA 4.1 data
# the fitting of emissions function of energy consumption
Expand Down Expand Up @@ -313,7 +313,7 @@ def get_hot_emissions(

# Cold start and soak emissions are defined per start and stop
# Therefore, we need to normalize per km
# And add cold start emissions to the first second of the driving cycle
# And add cold start emissions to the first second of the driving_cycles

yearly_km = yearly_km.transpose("value", "year", "powertrain", "size")

Expand All @@ -327,7 +327,7 @@ def get_hot_emissions(
* non_exhaust.sel(type="cold start").values
)

# And add soak emissions to the last second of the driving cycle
# And add soak emissions to the last second of the driving_cycles
emissions.loc[
dict(
second=emissions.second.values[-1],
Expand All @@ -340,7 +340,7 @@ def get_hot_emissions(

# Diurnal emissions are defined in g/day
# And need to be evenly distributed
# throughout the driving cycle
# throughout the driving_cycles

daily_km_to_year = distance / (yearly_km / 365)

Expand All @@ -351,7 +351,7 @@ def get_hot_emissions(
)

# Running losses are in g/km (no conversion needed)
# And need to be evenly distributed throughout the driving cycle
# And need to be evenly distributed throughout the driving_cycles

emissions.loc[dict(component=non_exhaust.component.values)] += (
_(distance)
Expand Down
4 changes: 2 additions & 2 deletions carculator_utils/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ def get_split_indices(self):
:return: list of indices
:rtype: list
"""
# read `impact_source_categories.yml` file
# read `impact_source_categories.yaml` file
with open(
DATA_DIR / "lcia" / "impact_source_categories.yml", "r", encoding="utf-8"
DATA_DIR / "lcia" / "impact_source_categories.yaml", "r", encoding="utf-8"
) as stream:
source_cats = yaml.safe_load(stream)

Expand Down
20 changes: 10 additions & 10 deletions carculator_utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class VehicleModel:
all the vehicles parameters.
:ivar array: multi-dimensional numpy-like array that contains parameters' value(s)
:ivar cycle: name of a driving cycle, or custom driving cycle
:ivar gradient: series of gradients, for each second of the driving cycle
:ivar cycle: name of a driving_cycles, or custom driving_cycles
:ivar gradient: series of gradients, for each second of the driving_cycles
:ivar energy_storage: dictionary with selection of battery chemistry for each powertrain
"""
Expand Down Expand Up @@ -68,8 +68,8 @@ def __init__(
"""
:param array: multi-dimensional numpy-like array that contains parameters' value(s)
:param country: country code
:param cycle: name of a driving cycle, or custom driving cycle
:param gradient: series of gradients, for each second of the driving cycle
:param cycle: name of a driving_cycles, or custom driving_cycles
:param gradient: series of gradients, for each second of the driving_cycles
:param energy_storage: dictionary with selection of battery chemistry, capacity and origin for each powertrain-size-year combination
:param electric_utility_factor: fraction of electricity that is generated from renewable sources
:param drop_hybrids: boolean, if True, hybrid vehicles are dropped from the inventory
Expand Down Expand Up @@ -1329,10 +1329,10 @@ def set_ttw_efficiency(self) -> None:

def set_hot_emissions(self) -> None:
"""
Calculate hot pollutant emissions based on ``driving cycle``.
The driving cycle is passed to the :class:`HotEmissionsModel` class
Calculate hot pollutant emissions based on ``driving_cycles``.
The driving_cycles is passed to the :class:`HotEmissionsModel` class
and :meth:`get_emissions_per_powertrain`
return emissions per substance per second of driving cycle.
return emissions per substance per second of driving_cycles.
Those are summed up and divided by
the distance driven, to obtain emissions, in kg per km.
:return: Does not return anything. Modifies ``self.array`` in place.
Expand Down Expand Up @@ -1442,11 +1442,11 @@ def set_particulates_emission(self) -> None:

def set_noise_emissions(self) -> None:
"""
Calculate noise emissions based on ``driving cycle``.
The driving cycle is passed to the :class:`NoiseEmissionsModel` class
Calculate noise emissions based on ``driving_cycles``.
The driving_cycles is passed to the :class:`NoiseEmissionsModel` class
and :meth:`get_sound_power_per_compartment`
returns emissions per compartment type ("rural", "non-urban" and "urban")
per second of driving cycle.
per second of driving_cycles.
Noise emissions are not differentiated by size classes at the moment,
but only by powertrain "type"
Expand Down
Loading

0 comments on commit 699b3c0

Please sign in to comment.