switch_model/tools/graph/main.py
def gen_type(self, df: pd.DataFrame, map_name='default', gen_tech_col='gen_tech',
                 energy_source_col='gen_energy_source', drop_previous_col=True,
                 others=None):
        """
        Returns a dataframe that contains a column 'gen_type'.

        By default 'gen_type' is the aggregation of 'gen_tech' + 'gen_energy_source'
        however this can be overidden in graph_tech_types.csv
        """
        # If there's no mapping, we simply make the mapping the sum of both columns
        # Read the tech_colors and tech_types csv files.
        try:
            cols = ["map_name", "gen_type", "gen_tech", "energy_source", "scenario_index"]
            tech_types = self.tools.get_dataframe("graph_tech_types.csv", from_inputs=True, drop_scenario_info=False)[cols]
        except FileNotFoundError:
            df['gen_type'] = df[gen_tech_col] + "_" + df[energy_source_col]
            return df
        tech_types = tech_types[tech_types['map_name'] == map_name].drop('map_name', axis=1)
        # If we got many scenarios "scenario_name" will exist in tech_types and in that case
        # we want to merge by scenario
        left_on = [gen_tech_col, energy_source_col]
        right_on = ["gen_tech", "energy_source"]
        if "scenario_index" in df:
            left_on.append("scenario_index")
            right_on.append("scenario_index")
        else:
            tech_types = tech_types.drop(columns=["scenario_index"]).drop_duplicates()
        df = df.merge(
            tech_types,
            left_on=left_on,
            right_on=right_on,
            validate="many_to_one",
            how="left")
        df["gen_type"] = df["gen_type"].fillna("Other")  # Fill with Other so the colors still work
        if drop_previous_col:
            df = df.drop([gen_tech_col, energy_source_col], axis=1)
        if others is not None:
            df["gen_type"] = df["gen_type"].replace(others, "Other")
        return df

        Returns a dataframe that contains a column 'gen_type'.

        By default 'gen_type' is the aggregation of 'gen_tech' + 'gen_energy_source'
        however this can be overidden in graph_tech_types.csv
        
Returns a dataframe that contains a column 'gen_type'.
Returns a dataframe that contains a column ' gen_type ' .
def gen_type(self, df: pd.DataFrame, map_name='default', gen_tech_col='gen_tech',
                 energy_source_col='gen_energy_source', drop_previous_col=True,
                 others=None):
        try:
            cols = ["map_name", "gen_type", "gen_tech", "energy_source", "scenario_index"]
            tech_types = self.tools.get_dataframe("graph_tech_types.csv", from_inputs=True, drop_scenario_info=False)[cols]
        except FileNotFoundError:
            df['gen_type'] = df[gen_tech_col] + "_" + df[energy_source_col]
            return df
        tech_types = tech_types[tech_types['map_name'] == map_name].drop('map_name', axis=1)
        left_on = [gen_tech_col, energy_source_col]
        right_on = ["gen_tech", "energy_source"]
        if "scenario_index" in df:
            left_on.append("scenario_index")
            right_on.append("scenario_index")
        else:
            tech_types = tech_types.drop(columns=["scenario_index"]).drop_duplicates()
        df = df.merge(
            tech_types,
            left_on=left_on,
            right_on=right_on,
            validate="many_to_one",
            how="left")
        df["gen_type"] = df["gen_type"].fillna("Other")  
        if drop_previous_col:
            df = df.drop([gen_tech_col, energy_source_col], axis=1)
        if others is not None:
            df["gen_type"] = df["gen_type"].replace(others, "Other")
        return df
def gen_type ( self , df : pd . DataFrame , map_name = 'default' , gen_tech_col = 'gen_tech' , energy_source_col = 'gen_energy_source' , drop_previous_col = True , others = None ) : try : cols = [ "map_name" , "gen_type" , "gen_tech" , "energy_source" , "scenario_index" ] tech_types = self . tools . get_dataframe ( "graph_tech_types.csv" , from_inputs = True , drop_scenario_info = False ) [ cols ] except FileNotFoundError : df [ 'gen_type' ] = df [ gen_tech_col ] + "_" + df [ energy_source_col ] return df tech_types = tech_types [ tech_types [ 'map_name' ] == map_name ] . drop ( 'map_name' , axis = 1 ) left_on = [ gen_tech_col , energy_source_col ] right_on = [ "gen_tech" , "energy_source" ] if "scenario_index" in df : left_on . append ( "scenario_index" ) right_on . append ( "scenario_index" ) else : tech_types = tech_types . drop ( columns = [ "scenario_index" ] ) . drop_duplicates ( ) df = df . merge ( tech_types , left_on = left_on , right_on = right_on , validate = "many_to_one" , how = "left" ) df [ "gen_type" ] = df [ "gen_type" ] . fillna ( "Other" ) if drop_previous_col : df = df . drop ( [ gen_tech_col , energy_source_col ] , axis = 1 ) if others is not None : df [ "gen_type" ] = df [ "gen_type" ] . replace ( others , "Other" ) return df
Returns a dataframe that contains a column 'gen_type'.
Returns a dataframe that contains a column ' gen_type ' .
"""
        Returns a dataframe that contains a column 'gen_type'.

        By default 'gen_type' is the aggregation of 'gen_tech' + 'gen_energy_source'
        however this can be overidden in graph_tech_types.csv
        """ # If there's no mapping, we simply make the mapping the sum of both columns # Read the tech_colors and tech_types csv files. # If we got many scenarios "scenario_name" will exist in tech_types and in that case # we want to merge by scenario # Fill with Other so the colors still work
self
df
pd.DataFrame
map_name
gen_tech_col
energy_source_col
drop_previous_col
others