def to_dataframe(self):
        """Export grid data to dataframes for statistical analysis.

        The export to dataframe is similar to db tables exported by `export_mv_grid_new`.

        Returns
        -------
        :pandas:`pandas.DataFrame<dataframe>`
            Pandas Data Frame
            
        See Also
        --------
        ding0.core.NetworkDing0.export_mv_grid_new :
        
        """

        node_cols = ['node_id', 'grid_id', 'v_nom', 'geom', 'v_res0', 'v_res1',
                     'peak_load', 'generation_capacity', 'type']
        edges_cols = ['branch_id', 'grid_id', 'type_name', 'type_kind',
                      'type_v_nom', 'type_s_nom', 'length', 'geom', 's_res0',
                      's_res1']

        nodes_df = pd.DataFrame(columns=node_cols)
        edges_df = pd.DataFrame(columns=edges_cols)

        srid = str(int(self.config['geo']['srid']))

        for grid_district in self.mv_grid_districts():

            # get nodes from grid's graph and create datasets
            for node in grid_district.mv_grid.graph_nodes_sorted():
                node_name = '_'.join(['MV',
                                      str(grid_district.mv_grid.id_db),
                                      repr(node)])
                geom = from_shape(Point(node.geo_data), srid=srid)
                if isinstance(node, LVStationDing0):
                    peak_load = node.peak_load
                    generation_capacity = node.peak_generation
                    if hasattr(node, 'voltage_res'):
                        type = 'LV Station'
                    else:
                        type = 'LV station (aggregated)'
                elif isinstance(node, GeneratorDing0):
                    peak_load = 0
                    generation_capacity = node.capacity
                    type = node.type
                elif isinstance(node, MVCableDistributorDing0):
                    peak_load = 0
                    generation_capacity = 0
                    type = 'Cable distributor'
                elif isinstance(node, LVLoadAreaCentreDing0):
                    peak_load = 0
                    generation_capacity = 0
                    type = 'Load area center of aggregated load area'
                elif isinstance(node, CircuitBreakerDing0):
                    peak_load = 0
                    generation_capacity = 0
                    type = 'Switch Disconnector'
                    #round coordinates of circuit breaker
                    geosjson = mapping(node.geo_data)
                    decimal_places = 4 #with 4, its around 10m error N-S or E-W
                    geosjson['coordinates'] = np.round(np.array(geosjson['coordinates']), decimal_places)
                    geom = from_shape(Point(shape(geosjson)), srid=srid)
                else:
                    peak_load = 0
                    generation_capacity = 0
                    type = 'Unknown'

                # add res voltages from nodes which were part of PF only
                if hasattr(node, 'voltage_res'):
                    v_res0 = node.voltage_res[0]
                    v_res1 = node.voltage_res[1]
                else:
                    v_res0 = v_res1 = 0

                nodes_df = nodes_df.append(pd.Series(
                    {'node_id': node_name,
                     'grid_id': grid_district.mv_grid.id_db,
                     'v_nom': grid_district.mv_grid.v_level,
                     'geom': geom,
                     'peak_load': peak_load,
                     'generation_capacity': generation_capacity,
                     'v_res0': v_res0,
                     'v_res1': v_res1,
                     'type': type,
                     'rings': len(grid_district.mv_grid._rings)
                    }), ignore_index=True)

            # get branches (lines) from grid's graph and create datasets
            for branch in grid_district.mv_grid.graph_edges():
                if hasattr(branch['branch'], 's_res'):
                    branch_name = '_'.join(['MV',
                                            str(
                                                grid_district.mv_grid.id_db),
                                            'lin',
                                            str(branch[
                                                    'branch'].id_db)])

                    edges_df = edges_df.append(pd.Series(
                        {'branch_id': branch_name,
                        'grid_id': grid_district.mv_grid.id_db,
                        'type_name': branch['branch'].type['name'],
                        'type_kind': branch['branch'].kind,
                        'type_v_nom': branch['branch'].type['U_n'],
                        'type_s_nom': 3 ** 0.5 * branch['branch'].type[
                            'I_max_th'] * branch['branch'].type['U_n'],
                        'length': branch['branch'].length / 1e3,
                        'geom': from_shape(
                            LineString([branch['adj_nodes'][0].geo_data,
                                        branch['adj_nodes'][
                                            1].geo_data]),
                            srid=srid),
                        's_res0': branch['branch'].s_res[0],
                        's_res1': branch['branch'].s_res[1]}), ignore_index=True)

        return nodes_df, edges_df
def to_dataframe ( self ) : node_cols = [ 'node_id' , 'grid_id' , 'v_nom' , 'geom' , 'v_res0' , 'v_res1' , 'peak_load' , 'generation_capacity' , 'type' ] edges_cols = [ 'branch_id' , 'grid_id' , 'type_name' , 'type_kind' , 'type_v_nom' , 'type_s_nom' , 'length' , 'geom' , 's_res0' , 's_res1' ] nodes_df = pd . DataFrame ( columns = node_cols ) edges_df = pd . DataFrame ( columns = edges_cols ) srid = str ( int ( self . config [ 'geo' ] [ 'srid' ] ) ) for grid_district in self . mv_grid_districts ( ) : for node in grid_district . mv_grid . graph_nodes_sorted ( ) : node_name = '_' . join ( [ 'MV' , str ( grid_district . mv_grid . id_db ) , repr ( node ) ] ) geom = from_shape ( Point ( node . geo_data ) , srid = srid ) if isinstance ( node , LVStationDing0 ) : peak_load = node . peak_load generation_capacity = node . peak_generation if hasattr ( node , 'voltage_res' ) : type = 'LV Station' else : type = 'LV station (aggregated)' elif isinstance ( node , GeneratorDing0 ) : peak_load = 0 generation_capacity = node . capacity type = node . type elif isinstance ( node , MVCableDistributorDing0 ) : peak_load = 0 generation_capacity = 0 type = 'Cable distributor' elif isinstance ( node , LVLoadAreaCentreDing0 ) : peak_load = 0 generation_capacity = 0 type = 'Load area center of aggregated load area' elif isinstance ( node , CircuitBreakerDing0 ) : peak_load = 0 generation_capacity = 0 type = 'Switch Disconnector' geosjson = mapping ( node . geo_data ) decimal_places = 4 geosjson [ 'coordinates' ] = np . round ( np . array ( geosjson [ 'coordinates' ] ) , decimal_places ) geom = from_shape ( Point ( shape ( geosjson ) ) , srid = srid ) else : peak_load = 0 generation_capacity = 0 type = 'Unknown' if hasattr ( node , 'voltage_res' ) : v_res0 = node . voltage_res [ 0 ] v_res1 = node . voltage_res [ 1 ] else : v_res0 = v_res1 = 0 nodes_df = nodes_df . append ( pd . Series ( { 'node_id' : node_name , 'grid_id' : grid_district . mv_grid . id_db , 'v_nom' : grid_district . mv_grid . v_level , 'geom' : geom , 'peak_load' : peak_load , 'generation_capacity' : generation_capacity , 'v_res0' : v_res0 , 'v_res1' : v_res1 , 'type' : type , 'rings' : len ( grid_district . mv_grid . _rings ) } ) , ignore_index = True ) for branch in grid_district . mv_grid . graph_edges ( ) : if hasattr ( branch [ 'branch' ] , 's_res' ) : branch_name = '_' . join ( [ 'MV' , str ( grid_district . mv_grid . id_db ) , 'lin' , str ( branch [ 'branch' ] . id_db ) ] ) edges_df = edges_df . append ( pd . Series ( { 'branch_id' : branch_name , 'grid_id' : grid_district . mv_grid . id_db , 'type_name' : branch [ 'branch' ] . type [ 'name' ] , 'type_kind' : branch [ 'branch' ] . kind , 'type_v_nom' : branch [ 'branch' ] . type [ 'U_n' ] , 'type_s_nom' : 3 ** 0.5 * branch [ 'branch' ] . type [ 'I_max_th' ] * branch [ 'branch' ] . type [ 'U_n' ] , 'length' : branch [ 'branch' ] . length / 1e3 , 'geom' : from_shape ( LineString ( [ branch [ 'adj_nodes' ] [ 0 ] . geo_data , branch [ 'adj_nodes' ] [ 1 ] . geo_data ] ) , srid = srid ) , 's_res0' : branch [ 'branch' ] . s_res [ 0 ] , 's_res1' : branch [ 'branch' ] . s_res [ 1 ] } ) , ignore_index = True ) return nodes_df , edges_df
Export grid data to dataframes for statistical analysis.

        The export to dataframe is similar to db tables exported by `export_mv_grid_new`.

        Returns
        -------
        :pandas:`pandas.DataFrame<dataframe>`
            Pandas Data Frame
            
        See Also
        --------
        ding0.core.NetworkDing0.export_mv_grid_new :