Пример #1
0
	def readfromxls(self,fileMain,params,scenario):	
	#def readfromxls(self,fileMain,fileRen,fileDem,params,scenario):	
		
		global m
		# Create DataFrame from Excel file
		xls = pd.ExcelFile(fileMain)
		m.commodities = Validation.ValidateCommoditySheet(xls.parse('Commodity', convert_float=False))

		def proc_read(xls_file):
			"""
            reads process sheet from the input file, loading the appropriate evrys values.
    
			Args:
				- xls: main excel sheet
			
			Returns:
                evrys-compatible pandas DataFrame with process data
			
			Note:
			    supports just single input, and single output plus CO2.
				If fed with MIMO data, last value will be the considered one 
			"""
			import pandas as pd
			import numpy as np
			import math
			from datetime import datetime

            #imports Process-Commodity sheet, which contains the informations needed
			# for the creation of the evrys-compatible dataframe
			com = xls_file.parse('Process-Commodity', convert_float=False)
			expected_column_labels_2 = ['Process', 'Commodity', 'Direction', 'ratio', 'ratio-min']
    		Validation.CheckColumnNames(expected_column_labels_2, com, "Process-Commodity")
            #adds required evrys columns
			new_com_columns=['CoIn','CoOut','ratio_in','ratio_out','ratio_co2','ratio_in_min','ratio_out_min','eff','eff_min','cotwo']
			new_com = pd.DataFrame(columns=new_com_columns)
			new_com_rows=set(com['Process'])
            #adds string value to create dummy entries in the dataframe, which will be later 
			# changed for the appropriate values
			for i in range(len(new_com_columns)):
				this_column = new_com.columns[i]
				new_com[this_column] = ['n']*len(new_com_rows)
			new_com['Process']=new_com_rows
			new_com.set_index('Process', inplace=True)
            #adds the values which are already available from the excel sheet,
			# taking into consideration the direction of the process
			for i in range(len(com)):
				comprocess=com['Process'][i]
				if com['Direction'][i]=='In':
					new_com.at[comprocess,'CoIn']=com['Commodity'][i]
					#com.at[i,'CoOut']='Elec'
					new_com.at[comprocess,'ratio_in']=com['ratio'][i]
					new_com.at[comprocess,'ratio_in_min']=com['ratio-min'][i]
				elif com['Direction'][i]=='Out' and com['Commodity'][i]!='CO2':
					#com.at[i,'CoIn']='Elec'
					new_com.at[comprocess,'CoOut']=com['Commodity'][i]
					new_com.at[comprocess,'ratio_out']=com['ratio'][i]
					new_com.at[comprocess,'ratio_out_min']=com['ratio-min'][i]
				elif com['Direction'][i]=='Out' and com['Commodity'][i]=='CO2':
					new_com.at[comprocess, 'ratio_co2']=com['ratio'][i]
				else:
					print 'ValueError'
            #calculates the values which are needed for evrys from the values previously
			# loaded
			for row in list(new_com.index):
				new_com.at[row, 'eff']=new_com['ratio_out'][row]/new_com['ratio_in'][row]
				if new_com['ratio_co2'][row]=='n':
					new_com.at[row,'cotwo']=0
				else:
					new_com.at[row,'cotwo']=new_com['ratio_co2'][row]/new_com['ratio_in'][row]
				in_bool=math.isnan(new_com['ratio_in_min'][row])
				out_bool=math.isnan(new_com['ratio_out_min'][row])
				if in_bool==False and out_bool==False:
					new_com.at[row, 'eff_min']=new_com['ratio_out_min'][row]/new_com['ratio_in_min'][row]
				elif in_bool==True and out_bool==False:
					new_com.at[row, 'eff_min']=new_com['ratio_out_min'][row]/new_com['ratio_in'][row]
				elif in_bool==False and out_bool==True:
					new_com.at[row, 'eff_min']=new_com['ratio_out'][row]/new_com['ratio_in_min'][row]
				else:
					new_com.at[row, 'eff_min']=new_com['ratio_out'][row]/new_com['ratio_in'][row]
			new_com.drop(['ratio_in','ratio_out','ratio_in_min','ratio_out_min','ratio_co2'], axis=1, inplace=True)
			#loads the Process sheet, which is the one with the required evrys structure
			pro = xls_file.parse('Process', convert_float=False)