ssb-sgis 0.1.5__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,24 +36,6 @@ class Points:
36
36
  for temp_idx, idx in zip(self.gdf.temp_idx, self.gdf.index, strict=True)
37
37
  }
38
38
 
39
- def _get_n_missing(
40
- self,
41
- results: GeoDataFrame | DataFrame,
42
- col: str,
43
- ) -> None:
44
- """
45
- Get number of missing values for each point after a network analysis.
46
-
47
- Args:
48
- results: (Geo)DataFrame resulting from od_cost_matrix, get_route,
49
- get_k_routes, get_route_frequencies or service_area.
50
- col: id column of the results. Either 'origin' or 'destination'.
51
- """
52
- self.gdf["missing"] = self.gdf["temp_idx"].map(
53
- results.groupby(col).count().iloc[:, 0]
54
- - results.dropna().groupby(col).count().iloc[:, 0]
55
- )
56
-
57
39
  @staticmethod
58
40
  def _convert_distance_to_weight(distances, rules):
59
41
  """Meters to minutes based on 'weight_to_nodes_' attribute of the rules."""
@@ -11,7 +11,7 @@ from .network import Network
11
11
 
12
12
 
13
13
  class DirectedNetwork(Network):
14
- """Subclass of Network with methods for making the network directed.
14
+ """Class for preparing line data for directed network analysis.
15
15
 
16
16
  Can be used as the 'network' parameter in the NetworkAnalysis class for directed
17
17
  network analysis.
@@ -19,7 +19,7 @@ class DirectedNetwork(Network):
19
19
  The DirectedNetwork class differs from the Network base class in two ways:
20
20
  1) using a DirectedNetwork in the NetworkAnalysis class means the network graph
21
21
  will be directed, meaning you can only travel in one direction on each line.
22
- 2) the class offers methods for making the network directed, mainly the
22
+ 2) the class holds methods for making the network directed, mainly the
23
23
  'make_directed_network' method, which reverses lines going the wrong direction
24
24
  and duplicates and flips lines going both directions. It also creates a 'minute'
25
25
  column.
@@ -105,7 +105,7 @@ class Network:
105
105
 
106
106
  >>> len(nw.gdf)
107
107
  85638
108
- >>> nw = nw.close_network_holes(max_distance=1.5, fillna=0)
108
+ >>> nw = nw.close_network_holes(max_distance=1.5, max_angle=90, fillna=0)
109
109
  >>> len(nw.gdf)
110
110
  86929
111
111
 
@@ -612,6 +612,21 @@ class Network:
612
612
 
613
613
  return True
614
614
 
615
+ def get_edges(self) -> list[tuple[str, str]]:
616
+ return [
617
+ (str(source), str(target))
618
+ for source, target in zip(
619
+ self.gdf["source"], self.gdf["target"], strict=True
620
+ )
621
+ ]
622
+
623
+ @staticmethod
624
+ def _create_edge_ids(
625
+ edges: list[tuple[str, str]], weights: list[float]
626
+ ) -> list[str]:
627
+ """Edge identifiers represented with source and target ids and the weight."""
628
+ return [f"{s}_{t}_{w}" for (s, t), w in zip(edges, weights, strict=True)]
629
+
615
630
  def _update_nodes_if(self):
616
631
  if not self._nodes_are_up_to_date():
617
632
  self._make_node_ids()
@@ -653,27 +668,3 @@ class Network:
653
668
 
654
669
  def __len__(self):
655
670
  return len(self.gdf)
656
-
657
-
658
- # TODO: put these a better place:
659
-
660
-
661
- def _edge_ids(
662
- gdf: GeoDataFrame | list[tuple[int, int]], weight: str | list[float]
663
- ) -> list[str]:
664
- """Quite messy way to deal with different input types."""
665
- if isinstance(gdf, GeoDataFrame):
666
- return _edge_id_template(
667
- zip(gdf["source"], gdf["target"], strict=True),
668
- weight_arr=gdf[weight],
669
- )
670
- if isinstance(gdf, list):
671
- return _edge_id_template(gdf, weight_arr=weight)
672
-
673
-
674
- def _edge_id_template(*source_target_arrs, weight_arr):
675
- """Edge identifiers represented with source and target ids and the weight."""
676
- return [
677
- f"{s}_{t}_{w}"
678
- for (s, t), w in zip(*source_target_arrs, weight_arr, strict=True)
679
- ]