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

Add cruise gCO2 calculator #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The following modes of transportation have carbon models to calculate a passenge
* 🚌 [carbon_bus.py](https://github.com/J0ANMM/carbon-calculator/blob/master/carbon_bus.py)
* 🚗 [carbon_car.py](https://github.com/J0ANMM/carbon-calculator/blob/master/carbon_car.py)
* 🚢 [carbon_ferry.py](https://github.com/J0ANMM/carbon-calculator/blob/master/carbon_ferry.py)
* 🛳️ [carbon_cruise.py](https://github.com/J0ANMM/carbon-calculator/blob/master/carbon_cruise.py)


## Coding or debugging
Expand Down
59 changes: 59 additions & 0 deletions carbon_cruise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"carbon_cruise.py calculates the emissions of passengers travelling on a cruise"

try:
from carbon import Carbon
except ImportError:
from results.carbon_calculator_git.carbon import Carbon #complete path inside Django project needed to make it work in Django Framework


class CarbonCruise(Carbon):
"""Class to calculate CO2 emmissions in cruises."""

def __init__(self):
self.avg_speed_kmh = 40 #based on the information on this page: https://www.cruisemapper.com/wiki/762-cruise-ship-cruising-speed


def calculate_co2(self, dist_km, trip_type):
"""Calculate the CO2 eq emission of a ride by cruise."""

pax_qty = 1 #possibility to expand to more than one person per trip for future calculations. Additional emissions due to vehicle would be divided by number of travellers

cruise_co2_dict = self.cruise_co2_dict_from_json()
g_co2_foot_pax = cruise_co2_dict['footPax']
g_co2_km = g_co2_foot_pax * pax_qty

gr_co2_person = int(dist_km * g_co2_km)

if trip_type == "round-trip":
gr_co2_person = gr_co2_person*2

return int(gr_co2_person)


def calculate_co2_from_duration(self, duration_in_days, trip_type):
"""Calculate the CO2 eq emission of a ride by cruise, given a duration as input."""

dist_km = self.estimate_distance_from_duration(duration_in_days)
gr_co2_person = self.calculate_co2(dist_km, trip_type)

return int(gr_co2_person)


def cruise_co2_dict_from_json(self):
"""Return a dictionary with the data for cruises from a given source."""

relative_path = '/sources/cruise_emissions.json'
cruise_emissions_dict = self.dict_from_json(relative_path)

co2_dict = cruise_emissions_dict["gCO2"]["cruise"]

return co2_dict


def estimate_distance_from_duration(self, duration_in_days):
"""Given duration as input, estimate distance covered."""

avg_speed_kmh = self.avg_speed_kmh
dist_km = int(duration_in_days * avg_speed_kmh * 24)

return dist_km
4 changes: 2 additions & 2 deletions carbon_ferry.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def ferry_co2_dict_from_json(self):
return co2_dict


def estimate_distance_from_duration(self, duration_in_minutes):
def estimate_distance_from_duration(self, duration_in_days):
"""Given duration as input, estimate distance covered."""

avg_speed_kmh = self.avg_speed_kmh
dist_km = int(duration_in_minutes * avg_speed_kmh/60)
dist_km = int(duration_in_days * avg_speed_kmh/60)

return dist_km
14 changes: 14 additions & 0 deletions sources/cruise_emissions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"comment": "Grams of CO2 / pkm (passenger kilometer) for cruises",
"year": 2018,
"sources": {
"formula": "https://www.nyteknik.se/tekniknyheter/article6940738.ece/BINARY/Rapport%20om%20koldioxidutsl%C3%A4pp%20fr%C3%A5n%20kryssningsfartyg.pdf",
"averagePax": "https://www.cruisemapper.com/wiki/761-cruise-ship-passenger-capacity-ratings"
},
"gCO2": {
"cruise": {
"footPax": 207,
"comments": "assuming the average PAX is 3000 (based on the source), using the formula 2112 * (3000^-0.29)"
}
}
}
19 changes: 19 additions & 0 deletions tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from carbon_bus import CarbonBus
from carbon_car import CarbonCar
from carbon_ferry import CarbonFerry
from carbon_cruise import CarbonCruise


class CarbonCalculatorTester(object):
Expand Down Expand Up @@ -36,6 +37,23 @@ def compare_flight_ferry(self):
print()


def compare_cruise_ferry(self):
""""""

dist_km = 400
trip_type = "round-trip"

co2_cruise = CarbonCruise().calculate_co2(dist_km, trip_type)

vehicle_ferry = "without-vehicle"
co2_ferry = CarbonFerry().calculate_co2(dist_km, vehicle_ferry, trip_type)

print("---- Travel CRUISE vs FERRY", dist_km, " km ", trip_type, "passenger ----")
print("Carbon footprint by cruise: ", co2_cruise, "gCO2")
print("Carbon footprint by ferry ", vehicle_ferry, ": ", co2_ferry, "gCO2")
print()


def compare_flight_train(self):
""""""

Expand Down Expand Up @@ -126,6 +144,7 @@ def compare_cars(self):
cct = CarbonCalculatorTester()

cct.compare_flight_ferry()
cct.compare_cruise_ferry()
cct.compare_flight_train()
cct.compare_trains()
cct.compare_train_bus_car()
Expand Down