コード例 #1
0
ファイル: pyGams_new.py プロジェクト: olorinthewhite/Propens
	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)
コード例 #2
0
ファイル: pyGams_new.py プロジェクト: olorinthewhite/Propens
class modelData(object):

	#def __init__(self,fileMain,fileRen,fileDem,params,scenario):
	def __init__(self,fileMain,params,scenario):
			
		self.dbco = ws.add_database()
		self.dbprocess = ws.add_database()
		self.dbtransport = ws.add_database()
		self.dbstorage = ws.add_database()
		self.dbdsm = ws.add_database()
		self.dbsites = ws.add_database()
		self.dbtime = ws.add_database()
		self.dbflags = ws.add_database()
		self.dbPTDF = ws.add_database()
		self.dbDCDF = ws.add_database()
		self.dbPSDF = ws.add_database()
		
		print "added database"
		
	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)
			#Check the column labels
    		expected_column_labels = ['Site', 'Process', 'inst-cap', 'cap-lo', 'cap-up', 'max-grad',
			'min-fraction', 'inv-cost', 'fix-cost', 'var-cost', 'wacc', 'y',
			'area-per-cap', 'act-up', 'on-off', 'start-cost', 'reserve-cost', 'ru',
			'rd', 'rumax', 'rdmax', 'cotwo', 'detail', 'lambda', 'heatmax',
			'maxdeltaT', 'heatupcost', 'su', 'sd', 'hotstart', 'pdt', 'pot',
			'prepow', 'pretemp', 'preheat', 'prestate', 'precaponline', 'year']
    		Validation.CheckColumnNames(expected_column_labels, pro ,'Process')

            #adds the required new columns to the Process dataframe
			new_columns=['CoIn','CoOut','eff','eff_min','cotwo']
			for column in new_columns:
				pro[column]=np.nan
				pro[column]=pro[column].fillna('n')
            #adds the correct values to the new dataframe, considering the fact that
			# in this new dataframe, process can appear multiple times, while in the 
			# previous data structure this didn't happen. Processes appeared just
			# one time each.
			for proc in new_com.index:
				for title in new_columns:
					n_appar=len(pro[title][proc])
					if n_appar==1:
						pro.at[proc, title]=new_com[title][proc]
					else:
						serie_ind=[proc]*n_appar
						serie_cont=[new_com[title][proc]]*n_appar
						serie=pd.Series(serie_cont, index=serie_ind)
						pro.at[proc, title]=serie
			pro.reset_index(inplace=True)
			pro.set_index(['Site','Process','CoIn','CoOut'], inplace=True)

			return pro