# spaghetti.extract_component

spaghetti.extract_component(net, component_id, weightings=None)

  Extract a single component from a network object.

  Parameters:
    net `spaghetti.Network`

      Full network object.

    component_id `python:int`

      The ID of the desired network component.

    weightings{`python:dict`, bool}

      See the `weightings` keyword argument in `spaghetti.Network`.

  Returns:
    cnet `spaghetti.Network`

      The pruned network containing the component specified in `component_id`.

  Notes

  Point patterns are not reassigned when extracting a component. Therefore, component extraction should be performed prior to snapping any point sets onto the network. Also, if the `spaghetti.Network` object has `distance_matrix` or `network_trees` attributes, they are deleted and must be computed again on the single component.

  Examples

  Instantiate a network object.

      >>> from libpysal import examples
      >>> import spaghetti
      >>> snow_net = examples.get_path("Soho_Network.shp")
      >>> ntw = spaghetti.Network(
      ...     in_data=snow_net,
      ...     extractgraph=False,
      ...     weights_kws=dict(silence_warnings=True)
      ... )

  The network is not fully connected.

      >>> ntw.network_fully_connected
      False

  Examine the number of network components.

      >>> ntw.network_n_components
      45

  Extract the longest component.

      >>> longest = spaghetti.extract_component(ntw, ntw.network_longest_component)
      >>> longest.network_n_components
      1
      >>> longest.network_component_lengths
      {np.int32(0): 13508.169276875526}