def __add_symbol_to_gdx(self, symbol_name, df): data_type, num_dims = self.__infer_data_type(symbol_name, df) logger.info("Inferred data type of {} to be {}.".format( symbol_name, data_type.name)) self.__gdx.append(GdxSymbol(symbol_name, data_type, dims=num_dims)) self.__gdx[symbol_name].dataframe = df return
def __add_symbol_to_gdx(self, symbol_name, df): if self.data_types is not None: data_type = self.data_types[symbol_name] else: data_type = self.__infer_data_type(symbol_name, df) logger.info("Inferred data type of {} to be {}.".format( symbol_name, data_type.name)) self.__gdx.append(GdxSymbol(symbol_name, data_type)) self.__gdx[symbol_name].dataframe = df return
def setup(self, gendists=None, precision=0): gendists_df, desired_capacity_df = super().setup(gendists=gendists, precision=precision) from gdxpds.gdx import GdxFile, GdxSymbol, GamsDataType with GdxFile() as ingdx: # Sets ingdx.append(GdxSymbol('n', GamsDataType.Set, dims=['n'])) df = pds.DataFrame(self.request.nodes['node_id']) df['Value'] = True ingdx[-1].dataframe = df ingdx.append(GdxSymbol('g', GamsDataType.Set, dims=['g'])) df = pds.DataFrame([[g, True] for g in self.request.gentypes], columns=['g', 'Value']) ingdx[-1].dataframe = df ingdx.append(GdxSymbol('g_indep', GamsDataType.Set, dims=['g'])) df = pds.DataFrame([[g, True] for g in self.request.gentypes if g in self.request.RESOURCE_INDEPENDENT], columns=['g', 'Value']) ingdx[-1].dataframe = df ingdx.append(GdxSymbol('g_dep', GamsDataType.Set, dims=['g'])) df = pds.DataFrame([[g, True] for g in self.request.gentypes if g not in self.request.RESOURCE_INDEPENDENT], columns=['g', 'Value']) ingdx[-1].dataframe = df # Parameters ingdx.append( GdxSymbol('desired_capacity', GamsDataType.Parameter, dims=['g'])) ingdx[-1].dataframe = desired_capacity_df ingdx.append( GdxSymbol('current_capacity', GamsDataType.Parameter, dims=['n', 'g'])) # pivot with sum on capacity in case there are multiple units of type g at node n df = pds.pivot_table(self.request.generators, values='capacity (MW)', index=['node_id', 'generator type'], aggfunc=np.sum) df = df.reset_index() df.columns = ['n', 'g', 'Value'] ingdx[-1].dataframe = df ingdx.append( GdxSymbol('g_dist', GamsDataType.Parameter, dims=['g', 'gg'])) ingdx[-1].dataframe = gendists_df ingdx.append( GdxSymbol('current_indep_capacity', GamsDataType.Parameter, dims=['n'])) df = pds.pivot_table(self.request.generators[ self.request.generators['generator type'].isin( self.request.RESOURCE_INDEPENDENT)], values='capacity (MW)', index=['node_id'], aggfunc=np.sum) df = df.reset_index() df.columns = ['n', 'Value'] ingdx[-1].dataframe = df ingdx.append( GdxSymbol('maximum_capacity', GamsDataType.Parameter, dims=['n', 'g_dep'])) data = [] for g in self.request.gentypes: if g in self.request.RESOURCE_INDEPENDENT: continue if g in self.request.nodes: tmp = pds.DataFrame(self.request.nodes['node_id']) tmp['g_dep'] = g tmp['Value'] = self.request.nodes[g] data.append(tmp) df = pds.concat(data) df.columns = ['n', 'g_dep', 'Value'] ingdx[-1].dataframe = df ingdx.write(os.path.join(self.outdir, 'in.gdx'))