Exemplo n.º 1
0
 def export_io(self):
     io_table_write_step = int(cfg.cfgfile.get('output_detail','io_table_write_step'))
     io_table_years = sorted([min(cfg.supply_years)] + range(max(cfg.supply_years), min(cfg.supply_years), -io_table_write_step))
     df_list = []
     for year in io_table_years:
         sector_df_list = []
         keys = self.supply.demand_sectors
         name = ['sector']
         for sector in self.supply.demand_sectors:
             sector_df_list.append(self.supply.io_dict[year][sector])
         year_df = pd.concat(sector_df_list, keys=keys,names=name)
         year_df = pd.concat([year_df]*len(keys),keys=keys,names=name,axis=1)
         df_list.append(year_df)
     keys = io_table_years
     name = ['year']
     df = pd.concat(df_list,keys=keys,names=name)
     for row_sector in self.supply.demand_sectors:
         for col_sector in self.supply.demand_sectors:
             if row_sector != col_sector:
                 df.loc[util.level_specific_indexer(df,'sector',row_sector),util.level_specific_indexer(df,'sector',col_sector,axis=1)] = 0
     self.supply.outputs.io = df
     result_df = self.supply.outputs.return_cleaned_output('io')
     keys = [self.scenario.name.upper(), cfg.timestamp]
     names = ['SCENARIO','TIMESTAMP']
     for key, name in zip(keys,names):
         result_df = pd.concat([result_df], keys=[key],names=[name])
     Output.write(result_df, 's_io.csv', os.path.join(cfg.workingdir, 'supply_outputs'))
Exemplo n.º 2
0
    def export_result_to_csv(self, result_name):
        if result_name=='combined_outputs':
            res_obj = self.outputs
        elif result_name=='demand_outputs':
            res_obj = self.demand.outputs
        elif result_name=='supply_outputs':
            res_obj = self.supply.outputs
        else:
            raise ValueError('result_name not recognized')

        for attribute in dir(res_obj):
            if not isinstance(getattr(res_obj, attribute), pd.DataFrame):
                continue

            result_df = getattr(res_obj, 'return_cleaned_output')(attribute)
            keys = [self.scenario.name.upper(), cfg.timestamp]
            names = ['SCENARIO','TIMESTAMP']
            for key, name in zip(keys, names):
                result_df = pd.concat([result_df], keys=[key], names=[name])

            if attribute in ('hourly_dispatch_results', 'electricity_reconciliation', 'hourly_marginal_cost', 'hourly_production_cost'):
                # Special case for hourly dispatch results where we want to write them outside of supply_outputs
                Output.write(result_df, attribute + '.csv', os.path.join(cfg.workingdir, 'dispatch_outputs'))
            else:
                Output.write(result_df, attribute+'.csv', os.path.join(cfg.workingdir, result_name))
Exemplo n.º 3
0
 def export_io(self):
     io_table_write_step = int(cfg.cfgfile.get('output_detail','io_table_write_step'))
     io_table_years = sorted([min(cfg.supply_years)] + range(max(cfg.supply_years), min(cfg.supply_years), -io_table_write_step))
     df_list = []
     for year in io_table_years:
         sector_df_list = []
         keys = self.supply.demand_sectors
         name = ['sector']
         for sector in self.supply.demand_sectors:
             sector_df_list.append(self.supply.io_dict[year][sector])
         year_df = pd.concat(sector_df_list, keys=keys,names=name)
         year_df = pd.concat([year_df]*len(keys),keys=keys,names=name,axis=1)
         df_list.append(year_df)
     keys = io_table_years
     name = ['year']
     df = pd.concat(df_list,keys=keys,names=name)
     for row_sector in self.supply.demand_sectors:
         for col_sector in self.supply.demand_sectors:
             if row_sector != col_sector:
                 df.loc[util.level_specific_indexer(df,'sector',row_sector),util.level_specific_indexer(df,'sector',col_sector,axis=1)] = 0
     self.supply.outputs.io = df
     result_df = self.supply.outputs.return_cleaned_output('io')
     keys = [self.scenario.name.upper(), cfg.timestamp]
     names = ['SCENARIO','TIMESTAMP']
     for key, name in zip(keys,names):
         result_df = pd.concat([result_df], keys=[key],names=[name])
     Output.write(result_df, 's_io.csv', os.path.join(cfg.workingdir, 'supply_outputs'))
Exemplo n.º 4
0
    def export_result_to_csv(self, result_name):
        if result_name=='combined_outputs':
            res_obj = self.outputs
        elif result_name=='demand_outputs':
            res_obj = self.demand.outputs
        elif result_name=='supply_outputs':
            res_obj = self.supply.outputs
        else:
            raise ValueError('result_name not recognized')

        for attribute in dir(res_obj):
            if not isinstance(getattr(res_obj, attribute), pd.DataFrame):
                continue

            result_df = getattr(res_obj, 'return_cleaned_output')(attribute)
            keys = [self.scenario.name.upper(), cfg.timestamp]
            names = ['SCENARIO','TIMESTAMP']
            for key, name in zip(keys, names):
                result_df = pd.concat([result_df], keys=[key], names=[name])

            if attribute in ('hourly_dispatch_results', 'electricity_reconciliation', 'hourly_marginal_cost', 'hourly_production_cost'):
                # Special case for hourly dispatch results where we want to write them outside of supply_outputs
                Output.write(result_df, attribute + '.csv', os.path.join(cfg.workingdir, 'dispatch_outputs'))
            else:
                Output.write(result_df, attribute+'.csv', os.path.join(cfg.workingdir, result_name))
Exemplo n.º 5
0
 def export_stacked_io(self):
     df = copy.deepcopy(self.supply.outputs.io)
     df.index.names = [x + '_input'if x!= 'year' else x for x in df.index.names ]
     df = df.stack(level=df.columns.names).to_frame()
     df.columns = ['value']
     self.supply.outputs.stacked_io = df
     result_df = self.supply.outputs.return_cleaned_output('stacked_io')
     keys = [self.scenario.name.upper(), cfg.timestamp]
     names = ['SCENARIO','TIMESTAMP']
     for key, name in zip(keys,names):
         result_df = pd.concat([result_df], keys=[key],names=[name])
     Output.write(result_df, 's_stacked_io.csv', os.path.join(cfg.workingdir, 'supply_outputs'))
Exemplo n.º 6
0
 def export_stacked_io(self):
     df = copy.deepcopy(self.supply.outputs.io)
     df.index.names = [x + '_input'if x!= 'year' else x for x in df.index.names ]
     df = df.stack(level=df.columns.names).to_frame()
     df.columns = ['value']
     self.supply.outputs.stacked_io = df
     result_df = self.supply.outputs.return_cleaned_output('stacked_io')
     keys = [self.scenario.name.upper(), cfg.timestamp]
     names = ['SCENARIO','TIMESTAMP']
     for key, name in zip(keys,names):
         result_df = pd.concat([result_df], keys=[key],names=[name])
     Output.write(result_df, 's_stacked_io.csv', os.path.join(cfg.workingdir, 'supply_outputs'))
Exemplo n.º 7
0
        def clean_and_write(result_df, attribute):
            """

            :param result_df: pandas dataframe
            :param attribute: string
            """
            if cfg.rio_supply_run and self.supply is not None:
                keys = [self.supply.rio_scenario.upper(), cfg.timestamp]
            else:
                keys = [self.scenario.name.upper(), cfg.timestamp]
            names = ['SCENARIO', 'TIMESTAMP']
            for key, name in zip(keys, names):
                result_df = pd.concat([result_df], keys=[key], names=[name])
                result_df = result_df.fillna(0)
            if attribute in (
            'hourly_dispatch_results', 'electricity_reconciliation', 'hourly_marginal_cost', 'hourly_production_cost'):
                # Special case for hourly dispatch results where we want to write them outside of supply_outputs
                Output.write(result_df, attribute + '.csv', os.path.join(cfg.workingdir, 'dispatch_outputs'))
            else:
                Output.write(result_df, attribute + '.csv', os.path.join(cfg.workingdir, result_name))
Exemplo n.º 8
0
    def export_result_to_csv(self, result_name):
        if result_name=='combined_outputs':
            res_obj = self.outputs
        elif result_name=='demand_outputs':
            res_obj = self.demand.outputs
        elif result_name=='supply_outputs':
            res_obj = self.supply.outputs
        else:
            raise ValueError('result_name not recognized')

        for attribute in dir(res_obj):
            if not isinstance(getattr(res_obj, attribute), pd.DataFrame):
                continue

            result_df = getattr(res_obj, 'return_cleaned_output')(attribute)
            keys = [self.scenario.upper(),str(datetime.now().replace(second=0, microsecond=0))]
            names = ['SCENARIO','TIMESTAMP']
            for key, name in zip(keys, names):
                result_df = pd.concat([result_df], keys=[key], names=[name])
            
            Output.write(result_df, attribute+'.csv', os.path.join(cfg.workingdir, result_name))