code: def calc_geo_branches_in_polygon(mv_grid, polygon, mode, proj):
      
  
      branches = []
      polygon_shp = transform(proj, polygon)
      for branch in mv_grid.graph_edges():
          nodes = branch['adj_nodes']
          branch_shp = transform(proj, LineString([nodes[0].geo_data, nodes[1].geo_data]))
  
          # check if branches intersect with polygon if mode = 'intersects'
          if mode == 'intersects':
              if polygon_shp.intersects(branch_shp):
                  branches.append(branch)
          # check if polygon contains branches if mode = 'contains'
          elif mode == 'contains':
              if polygon_shp.contains(branch_shp):
                  branches.append(branch)
          # error
          else:
              raise ValueError('Mode is invalid!')
      return branches
docs: Calculate geographical branches in polygon.
  
      For a given `mv_grid` all branches (edges in the graph of the grid) are
      tested if they are in the given `polygon`. You can choose different modes
      and projections for this operation.
  
      Parameters
      ----------
      mv_grid : MVGridDing0
          MV Grid object. Edges contained in `mv_grid.graph_edges()` are taken
          for the test.
      polygon : :shapely:`Shapely Point object<points>`
          Polygon that contains edges.
      mode : str
          Choose between 'intersects' or 'contains'.
      proj : int
          EPSG code to specify projection
  
      Returns
      -------
      :any:`list` of :any:`BranchDing0` objects
          List of branches