def calculate_defult_TiO2(): ''' Do a single vintage calculation default market share rate = 0.3 ''' # read data now TiO2_data = np.loadtxt('../data/TiO2_production_real.csv', delimiter=',') TiO2_to_paints = 0.3 # what portion of SiO2 are used in coating, paints and pigment market TiO2_data[:, 1] = TiO2_data[:, 1] * TiO2_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') ''' deal with dictionary here ''' # set up the model TiO2_market = vintage_model.vintage_market(TiO2_data, market_data_dict, weibull=True) test = TiO2_market.calculate_market_vintage() '''Change 26/12/2016 by Yuwei''' table_of_test = np.zeros((35, 21)) row_num_in_table = 0 for index in range( len(test)): #find each category e.g. Household & Furniture index_in_test = test[test.keys()[index]] #create a table of test for num in range(len(index_in_test)): #num is each phase list_in_index = index_in_test[index_in_test.keys()[num]] #print(list_in_index) # save number in each phase e.g. manufacturing, in use #print(row_num_in_table) for val in range(len(list_in_index)): #val is year #print(val) table_of_test[row_num_in_table, val] = list_in_index[val] row_num_in_table += 1 #print(table_of_test) #print np.sum(test['Household & Furniture']['In Use'] + test['Household & Furniture']['End of Life']) #raw_input() table_of_sum = np.zeros([1, 21]) '''sum up the total release for each year ''' for i in range(21): #print(i) '''only sum up manufacturing release, in use and end of life (row: 5n,5n+1,5n+2) ''' sum = 0 for row in range(7): sum += table_of_test[5 * row, i] + table_of_test[ 5 * row + 1, i] + table_of_test[5 * row + 2, i] table_of_sum[0, i] = sum #print(table_of_sum) return table_of_sum # df = FeO2_market.to_dataframe(test) # FeO2_market.plot_market_vintage() # df.to_csv('../results/dynamic_results/FeOx_vintage_results_1215.csv') # df.to_csv('../results/static_results/FeOx_vintage_results_static_1215.csv') ''' done'''
def do_release_market(): Fe_data = np.loadtxt('./data/Fe_production_real.csv',delimiter=',') market_data_dict = csv_to_dict('./data/coating_market_fake.csv') SiO2_to_coating = 0.1 Fe_data[:,1] = Fe_data[:,1] * SiO2_to_coating Fe_market = vintage_model.vintage_market(Fe_data,market_data_dict) test = Fe_market.calculate_market_vintage() print Fe_market.tot_releases_year() Fe_market.plot_market_vintage('In Use')
def do_release_market(): TiO2_data = np.loadtxt('./data/SiO2_production_real.csv',delimiter=',') market_data_dict = csv_to_dict('./data/coating_market_fake.csv') TiO2_to_coating = 0.3 TiO2_data[:,1] = TiO2_data[:,1] * TiO2_to_coating TiO2_market = vintage_model.vintage_market(TiO2_data,market_data_dict) test = TiO2_market.calculate_market_vintage() print TiO2_market.tot_releases_year() TiO2_market.plot_market_vintage()
def do_release_market(): SiO2_data = np.loadtxt('./data/SiO2_production_real.csv', delimiter=',') market_data_dict = csv_to_dict('./data/coating_market_fake.csv') SiO2_to_coating = 0.1 SiO2_data[:, 1] = SiO2_data[:, 1] * SiO2_to_coating SiO2_market = vintage_model.vintage_market(SiO2_data, market_data_dict) test = SiO2_market.calculate_market_vintage() print SiO2_market.tot_releases_year() SiO2_market.plot_market_vintage('')
def calculate_defult_TiO2(): ''' Do a single vintage calculation default market share rate = 0.3 ''' # read data now TiO2_data = np.loadtxt('../data/TiO2_production_real.csv',delimiter=',') TiO2_to_paints = 0.3 # what portion of SiO2 are used in coating, paints and pigment market TiO2_data[:,1] = TiO2_data[:,1] * TiO2_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') ''' deal with dictionary here ''' # set up the model TiO2_market = vintage_model.vintage_market(TiO2_data,market_data_dict, weibull=True) test = TiO2_market.calculate_market_vintage() '''Change 26/12/2016 by Yuwei''' table_of_test = np.zeros((35,21)) row_num_in_table = 0 for index in range(len(test)): #find each category e.g. Household & Furniture index_in_test = test[test.keys()[index]] #create a table of test for num in range(len(index_in_test)): #num is each phase list_in_index = index_in_test[index_in_test.keys()[num]] #print(list_in_index) # save number in each phase e.g. manufacturing, in use #print(row_num_in_table) for val in range(len(list_in_index)): #val is year #print(val) table_of_test[row_num_in_table,val] = list_in_index[val] row_num_in_table += 1 #print(table_of_test) #print np.sum(test['Household & Furniture']['In Use'] + test['Household & Furniture']['End of Life']) #raw_input() table_of_sum = np.zeros([1,21]) '''sum up the total release for each year ''' for i in range(21): #print(i) '''only sum up manufacturing release, in use and end of life (row: 5n,5n+1,5n+2) ''' sum = 0 for row in range(7): sum += table_of_test[5*row,i]+table_of_test[5*row+1,i]+table_of_test[5*row+2,i] table_of_sum[0,i] = sum #print(table_of_sum) return table_of_sum # df = FeO2_market.to_dataframe(test) # FeO2_market.plot_market_vintage() # df.to_csv('../results/dynamic_results/FeOx_vintage_results_1215.csv') # df.to_csv('../results/static_results/FeOx_vintage_results_static_1215.csv') ''' done'''
def monte_carlo_analysis(self, round = 100): results = [] for i in range(round): print 'Working on round', i this_market_dict = self._shake_lifetime() this_market_vintage = vintage_model.vintage_market(self.prod_year_data,this_market_dict) this_vintage_results = this_market_vintage.calculate_market_vintage() this_vintage_tot_release = this_market_vintage.tot_releases_year() results.append(this_vintage_tot_release) return results
def monte_carlo_analysis(self, round=100): results = [] for i in range(round): print 'Working on round', i this_market_dict = self._shake_lifetime() this_market_vintage = vintage_model.vintage_market( self.prod_year_data, this_market_dict) this_vintage_results = this_market_vintage.calculate_market_vintage( ) this_vintage_tot_release = this_market_vintage.tot_releases_year() results.append(this_vintage_tot_release) return results
def get_results_for_one_vintage(year): ''' calculate the results for one vintage year ''' # read data now SiO2_data = np.loadtxt('../data/SiO2_production_real.csv',delimiter=',') SiO2_to_paints = 0.1 # what portion of SiO2 are used in coating, paints and pigment market SiO2_data[:,1] = SiO2_data[:,1] * SiO2_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') SiO2_market = vintage_model.vintage_market(SiO2_data,market_data_dict, weibull=True) this_year_vintage = SiO2_market.calculate_for_one_vintage(year=2016) df = SiO2_market.to_dataframe(this_year_vintage) df.to_csv('../results/dynamic_results/year_vintage/SiO2_vintage_2016.csv')
def calculate_defult_Fe(): ''' Do a single vintage calculation default in use Rate = 0.33 ''' # read data now Fe_data = np.loadtxt('../data/Fe_production_real.csv',delimiter=',') Fe_to_paints = 0.33 # what portion of SiO2 are used in coating, paints and pigment market Fe_data[:,1] = Fe_data[:,1] * Fe_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') FeO2_market = vintage_model.vintage_market(Fe_data,market_data_dict, weibull=True) test = FeO2_market.calculate_market_vintage() df = FeO2_market.to_dataframe(test) FeO2_market.plot_market_vintage() df.to_csv('../results/dynamic_results/FeOx_vintage_results_1215.csv')
def calculate_defult_SiO2(): ''' Do a single vintage calculation default market share = 0.1 ''' # read data now SiO2_data = np.loadtxt('../data/SiO2_production_real.csv',delimiter=',') SiO2_to_paints = 0.1 # what portion of SiO2 are used in coating, paints and pigment market SiO2_data[:,1] = SiO2_data[:,1] * SiO2_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') SiO2_market = vintage_model.vintage_market(SiO2_data,market_data_dict, weibull=True) test = SiO2_market.calculate_market_vintage() df = SiO2_market.to_dataframe(test) SiO2_market.plot_market_vintage() df.to_csv('../results/dynamic_results/SiO2_vintage_results_0226.csv')
def calculate_defult_Fe(): ''' Do a single vintage calculation default in use Rate = 0.33 ''' # read data now Fe_data = np.loadtxt('../data/Fe_production_real.csv', delimiter=',') Fe_to_paints = 0.33 # what portion of SiO2 are used in coating, paints and pigment market Fe_data[:, 1] = Fe_data[:, 1] * Fe_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') FeO2_market = vintage_model.vintage_market(Fe_data, market_data_dict, weibull=True) test = FeO2_market.calculate_market_vintage() df = FeO2_market.to_dataframe(test) FeO2_market.plot_market_vintage() df.to_csv('../results/dynamic_results/FeOx_vintage_results_0226.csv')
def get_results_for_one_vintage(year): ''' calculate the results for one vintage year ''' # read data now TiO2_data = np.loadtxt('../data/TiO2_production_real.csv', delimiter=',') TiO2_to_paints = 0.3 # what portion of SiO2 are used in coating, paints and pigment market TiO2_data[:, 1] = TiO2_data[:, 1] * TiO2_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') TiO2_market = vintage_model.vintage_market(TiO2_data, market_data_dict, weibull=True) this_year_vintage = TiO2_market.calculate_for_one_vintage(year=2016) df = TiO2_market.to_dataframe(this_year_vintage) df.to_csv('../results/dynamic_results/year_vintage/TiO2_vintage_2016.csv')
def calculate_defult_SiO2(): ''' Do a single vintage calculation default market share = 0.1 ''' # read data now SiO2_data = np.loadtxt('../data/SiO2_production_real.csv', delimiter=',') SiO2_to_paints = 0.1 # what portion of SiO2 are used in coating, paints and pigment market SiO2_data[:, 1] = SiO2_data[:, 1] * SiO2_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') SiO2_market = vintage_model.vintage_market(SiO2_data, market_data_dict, weibull=True) test = SiO2_market.calculate_market_vintage() df = SiO2_market.to_dataframe(test) SiO2_market.plot_market_vintage() df.to_csv('../results/dynamic_results/SiO2_vintage_results_0226.csv')
def calculate_defult_TiO2(): ''' Do a single vintage calculation default market share rate = 0.3 ''' # read data now TiO2_data = np.loadtxt('../data/TiO2_production_real.csv',delimiter=',') TiO2_to_paints = 0.3 # what portion of SiO2 are used in coating, paints and pigment market TiO2_data[:,1] = TiO2_data[:,1] * TiO2_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') ''' deal with dictionary here ''' # set up the model TiO2_market = vintage_model.vintage_market(TiO2_data,market_data_dict, weibull=True) test = TiO2_market.calculate_market_vintage() # save the results to data frame and plot the market figure df = TiO2_market.to_dataframe(test) df.to_csv('../results/dynamic_results/TiO2_vintage_results_1215.csv') # df.to_csv('../results/static_results/TiO2_vintage_results_static_1215.csv') TiO2_market.plot_market_vintage()
def calculate_defult_TiO2(): ''' Do a single vintage calculation default market share rate = 0.3 ''' # read data now TiO2_data = np.loadtxt('./data/TiO2_production_real.csv',delimiter=',') TiO2_to_paints = 0.3 # what portion of SiO2 are used in coating, paints and pigment market TiO2_data[:,1] = TiO2_data[:,1] * TiO2_to_paints market_data_dict = csv_to_dict('./data/coating_market_fake.csv') ''' deal with dictionary here ''' # set up the model TiO2_market = vintage_model.vintage_market(TiO2_data,market_data_dict) test = TiO2_market.calculate_market_vintage() print np.sum(test['Household & Furniture']['In Use'] + test['Household & Furniture']['End of Life']) # save the results to data frame and plot the market figure df = TiO2_market.to_dataframe(test) df.to_csv('./results/TiO2_vintage_results.csv') TiO2_market.plot_market_vintage()
def calculate_defult_TiO2(): ''' Do a single vintage calculation default market share rate = 0.3 ''' # read data now TiO2_data = np.loadtxt('../data/TiO2_production_real.csv', delimiter=',') TiO2_to_paints = 0.3 # what portion of SiO2 are used in coating, paints and pigment market TiO2_data[:, 1] = TiO2_data[:, 1] * TiO2_to_paints market_data_dict = csv_to_dict('../data/coating_market_fake.csv') ''' deal with dictionary here ''' # set up the model TiO2_market = vintage_model.vintage_market(TiO2_data, market_data_dict, weibull=True) test = TiO2_market.calculate_market_vintage() # save the results to data frame and plot the market figure df = TiO2_market.to_dataframe(test) # df.to_csv('../results/dynamic_results/TiO2_vintage_results_0226.csv') # df.to_csv('../results/static_results/TiO2_vintage_results_static_1215.csv') TiO2_market.plot_market_vintage()
explode = (0, 0.1, 0, 0, 0, 0, 0) # only explode the second one colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral'] for each_key, each_val in vintage_results.iteritems(): this_tot_rel_year = each_val['In Use'][40] + each_val['End of Life'][40] size.append(this_tot_rel_year) plt.pie(size, explode=explode, labels=labels, autopct='%1.1f%%', colors=colors, shadow=True) plt.show() if __name__ == '__main__': ''' Read production data and multiply it with the market share data to coating and paints market''' tiO2_production_data = np.loadtxt('./data/TiO2_production_real.csv', delimiter=',') tiO2_to_coating = 0.3 # what portion of SiO2 are used in coating, paints and pigment market tiO2_production_data[:, 1] = tiO2_production_data[:, 1] * tiO2_to_coating ''' Set up and calcuate vintage''' tiO2_market_data = './data/coating_market_fake.csv' tiO2 = vintage_model.vintage_market(tiO2_production_data, tiO2_market_data) tiO2_vintage_results_market = tiO2.calculate_market_vintage() total_release = tiO2.tot_releases_year() ax = plt.subplot(111) ax.plot(tiO2_production_data[30::, 0], total_release[30::]) plt.show()
''' plot a pie chart show the release break down (by market) for the specific year ''' labels = vintage_results.keys() size = [] explode = (0,0.1,0,0,0,0,0) # only explode the second one colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral'] for each_key, each_val in vintage_results.iteritems(): this_tot_rel_year = each_val['In Use'][40] + each_val['End of Life'][40] size.append(this_tot_rel_year) plt.pie(size,explode=explode,labels=labels,autopct='%1.1f%%',colors=colors,shadow=True) plt.show() if __name__ == '__main__': ''' Read production data and multiply it with the market share data to coating and paints market''' tiO2_production_data = np.loadtxt('./data/TiO2_production_real.csv',delimiter=',') tiO2_to_coating = 0.3 # what portion of SiO2 are used in coating, paints and pigment market tiO2_production_data[:,1] = tiO2_production_data[:,1] * tiO2_to_coating ''' Set up and calcuate vintage''' tiO2_market_data = './data/coating_market_fake.csv' tiO2 = vintage_model.vintage_market(tiO2_production_data,tiO2_market_data) tiO2_vintage_results_market = tiO2.calculate_market_vintage() total_release = tiO2.tot_releases_year() ax = plt.subplot(111) ax.plot(tiO2_production_data[30::,0],total_release[30::]) plt.show()