def process_optional_input(pop = None, conc = None, port_y = None): global port_name, port_ambient_conc, port_y0, port_c0, port_pop_struc, port_pop, base_conc, port_real_em, ratio if pop is not None: port_pop = pop if conc is not None: port_ambient_conc = conc # call Port class to do calc, if use inputs his own y, then pass y to port class instead of y0 to calc ymin if port_y is None: port = Port(port_name, port_ambient_conc, port_y0, port_c0, port_pop_struc, port_pop, base_conc, port_real_em, ratio) indicator = 0 else: port = Port(port_name, port_ambient_conc, port_y, port_c0, port_pop_struc, port_pop, base_conc, port_real_em, ratio) indicator = 1 name_t = port_name ambient_t = port_ambient_conc y0_t = port_y0 c0_t = port_c0 pop_struc_t = port_pop_struc pop_t = port_pop base_t = base_conc em_t = port_real_em #print impact.key impact = port.get_impact(indicator) # process/aggregate the impact in some way result_disease_age = {} result_disease_time = {} result_disease_zone = {} result_disease_age_yll = {} for key in impact.keys(): if key != 'ARI': impact_all_age = np.empty(age_group) for i in range(age_group): impact_all_age[i] = sum(impact[key][i][4, :]) result_disease_age[key] = np.around(impact_all_age, 2) else: result_disease_age[key] = np.around(np.array([sum(impact[key][0][4, :])]),2) # does not matter if ARI or not for key in impact.keys(): impact_sum_age = sum(impact[key]) result_disease_zone[key] = np.around(impact_sum_age[4, :],2) #print impact_sum_age.key temp = np.empty(time_interval) for i in range(time_interval): temp[i] = sum(impact_sum_age[i, :]) result_disease_time[key] = np.around(temp, 2) #sum_age_t = impact_sum_age #print sum_age_t.key for key in impact.keys(): if key != "ARI": result_disease_age_yll[key] = np.around(np.array(life_exp) * result_disease_age[key], 2) #-- add total col for yll except its ARI result_disease_age_yll[key] = np.append(result_disease_age_yll[key], sum(result_disease_age_yll[key])) #-- add total col for age except its ARI result_disease_age[key] = np.append(result_disease_age[key], sum(result_disease_age[key])) else: result_disease_age_yll[key] = np.around(np.array(life_exp[0]) * result_disease_age[key], 2) #exp_t = life_exp #age_t = result_disease_age_yll["ARI"] #print exp_t.key #--- Add N/A and total in cols for ARI result_disease_age['ARI'] = np.append(result_disease_age['ARI'], np.array([ 0 for i in range(age_group - 1)])) result_disease_age['ARI'] = np.append(result_disease_age['ARI'], result_disease_age['ARI'][0]) result_disease_age_yll['ARI'] = np.append(result_disease_age_yll['ARI'], np.array([ 0 for i in range(age_group - 1)])) result_disease_age_yll['ARI'] = np.append(result_disease_age_yll['ARI'], result_disease_age_yll['ARI'][0]) #-- add total row below each table #result_disease_age['Total'] = np.zeros(age_group + 1) #result_disease_time['Total'] = np.zeros(age_group + 1) #result_disease_age_yll['Total'] = np.zeros(age_group + 1) #result_disease_zone['Total'] = np.zeros(age_group + 1) #for i in range(age_group + 1): # for key in result_disease_age.keys(): # if key!= 'Total' and result_disease_age[key][i] != 'N/A': # result_disease_age['Total'][i] = result_disease_age['Total'][i] + float(result_disease_age[key][i]) #-- get rid of 0-4 value for age time before adding up cols #result_disease_age['LC'][0] = 0 #result_disease_age['CP'][0] = 0 #result_disease_age_yll['LC'][0] = 0 #result_disease_age_yll['CP'][0] = 0 #-- add total row below table add_total(result_disease_age) add_total(result_disease_time, time_interval) add_total(result_disease_age_yll) add_total(result_disease_zone, len(result_disease_zone['ARI'])) return {'age': result_disease_age, 'time': result_disease_time, 'zone': result_disease_zone, 'yll': result_disease_age_yll, 'indicator': indicator}