Skip to content

Commit

Permalink
Merge branch 'master' into new-counterfactual-scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
vor115384876 committed Mar 9, 2021
2 parents a0a0987 + 7a9d803 commit 50ae31d
Show file tree
Hide file tree
Showing 234 changed files with 26 additions and 8,916 deletions.
71 changes: 0 additions & 71 deletions average_dist_vintage_engine_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,18 @@
# print(annual_passenger_kilometers)
annual_pkm = list(map(int, annual_passenger_kilometers))
print(annual_pkm)

# engine_cc_cat = 1
# while engine_cc_cat < 15:

# annual_pkm_enginecat = annual_pkm[engine_cc_cat::15]
# print(annual_pkm_enginecat)
# annual_pkm_by_category = sum(annual_pkm_enginecat)
# engine_cc_cat += 1
# #print(annual_pkm_by_category)

PATH = constants.path
fuel_type = constants.f_type
year = base_year
readfile = f'{PATH}/{fuel_type}/average_distance_engine_cc/scenario_0_distance_travelled.csv'
# with open(readfile, newline='', encoding='utf-8-sig') as f:
# data = [row for row in csv.reader(f)]

# # gets average distance for engine cc data[year_row][enginecc_catgory]
# #enginecc_category_starts at 1, because year data is stored in 0

# average_distance_for_engine_cc = data[0][year - 2000]
# #need to get list of cars of year and of engine cc specified in average_distance_for_engine_cc
# #opening a file of all the years
num_car_year = 0
for year in range(2001,2018):
readfile = f'{PATH}/{fuel_type}/{year}.csv'
with open(readfile, newline='', encoding='utf-8-sig') as ff:
data = [row for row in csv.reader(ff)]
#print(data)

readfile = f'{PATH}/{fuel_type}/average_distance_engine_cc/scenario_0_distance_travelled.csv'
with open(readfile, newline='', encoding='utf-8-sig') as f:
Expand All @@ -95,63 +78,9 @@
average_distance_for_engine_cc = enginecc[(year- 2000)][enginecol]

average_distance_list.append(int(average_distance_for_engine_cc))

#print(average_distance_list)
#print(average_distance_list[0])
#print(average_distance_list[0])


#print(average_distance_for_engine_cc)
engineccpklist = []
for listyear in average_distance_list:
for engine_cc_mileage_average in average_distance_list:
engineccpkitem = engine_cc_mileage_average*total_engine_cc_stock_for_year
engineccpklist.append(engineccpkitem)


#this list prints a list of the average distances
#print(average_distance_list)
#print(engineccpklist)
#print(total_engine_cc_stock_for_year)





# gets average distance for engine cc data[year_row][enginecc_catgory]
#enginecc_category_starts at 1, because year data is stored in 0


#need to get list of cars of year and of engine cc specified in average_distance_for_engine_cc
#opening a file of all the years

#print(average_distance_for_engine_cc)
#print(total_engine_cc_stock_for_year)

#print(total_engine_cc_stock_for_year)




#average_pkm_for_given_engine_cc_and_year = [stock*average_distance_for_engine_cc for stock in
#info = item[1]
#print(average_distance_for_engine_cc)

# readfile = f'{PATH}/{fuel_type}/average_distance_engine_cc/scenario_0_distance_travelled.csv'
# with open(readfile, newline='', encoding='utf-8-sig') as f:



# #print(sample_model._year, annual_pkm)
# dist_dict.append({"year": sample_model._year, "passenger_kilometers": annual_pkm})
# #print(total_passenger_kilometers)
# csv_file = f'distance_cc_vintage/{f_type}/{sample_model._year}.csv'
# csv_columns = ["year","passenger_kilometers"]
# with open(csv_file, 'w', newline='') as csvfile:
# for col in csv.reader(csvfile):
# total += int(col[1])
# print(total)
# writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
# writer.writeheader()
# for year in dist_dict:
# writer.writerow(year)
21 changes: 3 additions & 18 deletions breakout_avg_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,17 @@

# Getting pkm per cat for every year
dist_for_yr = list(map(int,dist_travelled.get_constant(year=sample_model._year)))
#print(dist_for_yr)
cars_per_cat = sample_model.get_cat_counts()
#print(cars_per_cat)
pkm_cat = list_prod(dist_for_yr,cars_per_cat)
#print(pkm_cat)

# getting the share of a car age for that cat
car_share_weightings = [[car_count/cat_count for car_count, cat_count in zip(cars_per_age,cars_per_cat)] for cars_per_age in sample_model.get_counts()]
#car_share_weightings = [[car_count/1 for car_count, cat_count in zip(cars_per_age,cars_per_cat)] for cars_per_age in sample_model.get_counts()]
#print(car_share_weightings)
#print(car_share_weightings)

# multiply the two weightings together
overall_weightings = [[float(ar)*car_share for ar,car_share in zip(ar_row, cs_row)] for ar_row,cs_row in zip(age_rates,car_share_weightings)]
#print(overall_weightings)

# multiply the total pkm on top of each weighting to get the final avg dist
total_dist_breakout_by_car = [[o_w*pkm for o_w,pkm in zip(weight_row,pkm_cat)] for weight_row in overall_weightings]
#print(total_dist_breakout_by_car)
#breakpoint()

#print(car_share_weightings)


avg_dist_per_car = [[fadb*car_share for fadb, car_share in zip(cs_row,fadb_row)] for fadb_row,cs_row in zip(final_avg_dist_breakout,car_share_weightings)]
#avg_dist_per_car_ans = [[avg_dist_per_car*car_coun for avg_dist_per_car, car_coun in zip(avg_dist_per_car,cars_per_cat)]]

avg_dist_per_car = [[fadb*car_share for fadb, car_share in zip(cs_row,fadb_row)] for fadb_row,cs_row in zip(final_avg_dist_breakout,car_share_weightings)]

print(avg_dist_per_car)
#print(final_avg_dist_breakout)
print(avg_dist_per_car)
18 changes: 0 additions & 18 deletions calc_band_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,16 @@
total_passenger_kilometers = [[float(numcar)*1*float(dt) for numcar,cpk,dt in zip(numcars,cpks, dist_for_yr_cat)] for numcars, cpks, dist_for_yr_cat in zip(sample_model._data, yr_consumption_per_km, dist_for_yr)]
total_consumption_unweighted_list = [[float(numcar)*1*float(cpk) for numcar,cpk,dt in zip(numcars,cpks, dist_for_yr_cat)] for numcars, cpks, dist_for_yr_cat in zip(sample_model._data, yr_consumption_per_km, dist_for_yr)]

#print(total_passenger_kilometers)
#totalvehicles = [float(numcars) for numcars in zip(sample_model._data)]
#sumtotalvehicles = sum(sum(totalvehicles))
annual_grams = sum(sum(total_consumption_grams,[]))
total_travel = sum(sum(total_passenger_kilometers,[]))
total_consumption_unweighted = sum(sum(total_consumption_unweighted_list,[]))
#totalnumcars = get_counts(self)
numlist = BaseModel.get_counts(self=sample_model)
numcars = sum(sum(numlist,[]))
emissions_intensity = annual_grams/(numcars)

emissions_intensity_per_km = annual_grams/(total_travel)

emissions_intensity_per_km_unweighted = total_consumption_unweighted/(numcars)



print(f'{f_type} Emissions for year: {sample_model._year} = {annual_grams} grams_CO2- number of cars :{numcars}')
# em_dict.append({"year": str(sample_model._year), "grams_CO2" : {annual_grams})
em_dict.append({"year": str(sample_model._year), "grams_CO2" : annual_grams, "number_cars":numcars, "g_per_car_average": emissions_intensity, "g_per_km_per_car_weighted": emissions_intensity_per_km, "g_per_km_per_car_unweighted":emissions_intensity_per_km_unweighted })

# this code outputs the year emissions to a csv
Expand All @@ -73,12 +64,3 @@
writer.writeheader()
for year in em_dict:
writer.writerow(year)

# total_consumption_grams = []
# # this for loop will run through a 14 length row 17 team times (per age)
# for numcars_per_age, cpks_per_age in zip(sample_model._data, yr_consumption_per_km):
# row_per_age = []
# # this for loop will run through every category on a row
# for numcars_per_age_cat, cpks_per_age_cat, dist_for_yr_per_cat in zip(numcars_per_age,cpks_per_age, dist_for_yr):
# row_per_age.append(float(cpks_per_age_cat)*float(cpks_per_age_cat)*float(dist_for_yr_per_cat))
# total_consumption_grams.append(row_per_age)
1 change: 0 additions & 1 deletion calc_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
bio_fuel_dict = {2001: 0, 2002:0, 2003: 0, 2004:0, 2005:0, 2006:0, 2007:0, 2008:0, 2009:0, 2010:0.027, 2011: 0.038, 2012: 0.03, 2013: 0.038, 2014: 0.044, 2015: 0.044, 2016: 0.036, 2017: 0.054, 2018: 0.05}

print(bio_fuel_dict)
#dist_travelled = ConstantBaseModel(generate_constants(fuel_type=f_type,constant_type=constants.d_travelled))
#need to figure out a way to chance how the distances are stored
new_rd_factor = [row[1:] for row in rd_factor]
new_eff_band = [row[1:] for row in eff_band]
Expand Down
18 changes: 0 additions & 18 deletions distance_cc_vintage/diesel/2001.csv

This file was deleted.

18 changes: 0 additions & 18 deletions distance_cc_vintage/diesel/2002.csv

This file was deleted.

18 changes: 0 additions & 18 deletions distance_cc_vintage/diesel/2003.csv

This file was deleted.

18 changes: 0 additions & 18 deletions distance_cc_vintage/diesel/2004.csv

This file was deleted.

18 changes: 0 additions & 18 deletions distance_cc_vintage/diesel/2005.csv

This file was deleted.

18 changes: 0 additions & 18 deletions distance_cc_vintage/diesel/2006.csv

This file was deleted.

18 changes: 0 additions & 18 deletions distance_cc_vintage/diesel/2007.csv

This file was deleted.

Loading

0 comments on commit 50ae31d

Please sign in to comment.