edges 1.0.1__py3-none-any.whl → 1.0.3__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.

Potentially problematic release.


This version of edges might be problematic. Click here for more details.

Files changed (66) hide show
  1. edges/__init__.py +9 -2
  2. edges/data/AWARE 2.0_Country_all_yearly.json +8 -1
  3. edges/data/AWARE 2.0_Country_irri_yearly.json +8 -1
  4. edges/data/AWARE 2.0_Country_non_irri_yearly.json +8 -1
  5. edges/data/AWARE 2.0_Country_unspecified_yearly.json +8 -1
  6. edges/data/GeoPolRisk_paired_2024.json +7 -0
  7. edges/data/ImpactWorld+ 2.1_Freshwater acidification_damage.json +8 -1
  8. edges/data/ImpactWorld+ 2.1_Freshwater acidification_midpoint.json +8 -1
  9. edges/data/ImpactWorld+ 2.1_Freshwater ecotoxicity, long term_damage.json +8 -1
  10. edges/data/ImpactWorld+ 2.1_Freshwater ecotoxicity, short term_damage.json +8 -1
  11. edges/data/ImpactWorld+ 2.1_Freshwater ecotoxicity_midpoint.json +8 -1
  12. edges/data/ImpactWorld+ 2.1_Freshwater eutrophication_damage.json +8 -1
  13. edges/data/ImpactWorld+ 2.1_Freshwater eutrophication_midpoint.json +8 -1
  14. edges/data/ImpactWorld+ 2.1_Land occupation, biodiversity_damage.json +8 -1
  15. edges/data/ImpactWorld+ 2.1_Land occupation, biodiversity_midpoint.json +8 -1
  16. edges/data/ImpactWorld+ 2.1_Land transformation, biodiversity_damage.json +8 -1
  17. edges/data/ImpactWorld+ 2.1_Land transformation, biodiversity_midpoint.json +8 -1
  18. edges/data/ImpactWorld+ 2.1_Marine ecotoxicity, long term_damage.json +8 -1
  19. edges/data/ImpactWorld+ 2.1_Marine ecotoxicity, short term_damage.json +8 -1
  20. edges/data/ImpactWorld+ 2.1_Marine eutrophication_damage.json +8 -1
  21. edges/data/ImpactWorld+ 2.1_Marine eutrophication_midpoint.json +8 -1
  22. edges/data/ImpactWorld+ 2.1_Particulate matter formation_damage.json +8 -1
  23. edges/data/ImpactWorld+ 2.1_Particulate matter formation_midpoint.json +8 -1
  24. edges/data/ImpactWorld+ 2.1_Photochemical ozone formation, ecosystem quality_damage.json +8 -1
  25. edges/data/ImpactWorld+ 2.1_Photochemical ozone formation, human health_damage.json +8 -1
  26. edges/data/ImpactWorld+ 2.1_Photochemical ozone formation_midpoint.json +8 -1
  27. edges/data/ImpactWorld+ 2.1_Terrestrial acidification_damage.json +8 -1
  28. edges/data/ImpactWorld+ 2.1_Terrestrial acidification_midpoint.json +8 -1
  29. edges/data/ImpactWorld+ 2.1_Terrestrial ecotoxicity, long term_damage.json +8 -1
  30. edges/data/ImpactWorld+ 2.1_Terrestrial ecotoxicity, short term_damage.json +8 -1
  31. edges/data/ImpactWorld+ 2.1_Thermally polluted water_damage.json +8 -1
  32. edges/data/ImpactWorld+ 2.1_Water availability, freshwater ecosystem_damage.json +8 -1
  33. edges/data/ImpactWorld+ 2.1_Water availability, human health_damage.json +8 -1
  34. edges/data/ImpactWorld+ 2.1_Water availability, terrestrial ecosystem_damage.json +8 -1
  35. edges/data/ImpactWorld+ 2.1_Water scarcity_midpoint.json +8 -1
  36. edges/data/LCC 1.0_2023.json +8 -1
  37. edges/data/RELICS_copper_primary.json +44 -0
  38. edges/data/RELICS_copper_secondary.json +42 -0
  39. edges/data/SCP_1.0.json +4 -1
  40. edges/edgelcia.py +2113 -816
  41. edges/flow_matching.py +344 -130
  42. edges/georesolver.py +61 -2
  43. edges/supply_chain.py +2052 -0
  44. edges/uncertainty.py +37 -8
  45. {edges-1.0.1.dist-info → edges-1.0.3.dist-info}/METADATA +5 -2
  46. edges-1.0.3.dist-info/RECORD +57 -0
  47. edges/data/GeoPolRisk_elementary flows_2024.json +0 -877
  48. edges/data/ImpactWorld+ 2.1_Freshwater ecotoxicity, long term_midpoint.json +0 -5
  49. edges/data/ImpactWorld+ 2.1_Freshwater ecotoxicity, short term_midpoint.json +0 -5
  50. edges/data/ImpactWorld+ 2.1_Freshwater ecotoxicity_damage.json +0 -0
  51. edges/data/ImpactWorld+ 2.1_Marine ecotoxicity, long term_midpoint.json +0 -5
  52. edges/data/ImpactWorld+ 2.1_Marine ecotoxicity, short term_midpoint.json +0 -5
  53. edges/data/ImpactWorld+ 2.1_Photochemical ozone formation, ecosystem quality_midpoint.json +0 -5
  54. edges/data/ImpactWorld+ 2.1_Photochemical ozone formation, human health_midpoint.json +0 -5
  55. edges/data/ImpactWorld+ 2.1_Photochemical ozone formation_damage.json +0 -5
  56. edges/data/ImpactWorld+ 2.1_Terrestrial ecotoxicity, long term_midpoint.json +0 -5
  57. edges/data/ImpactWorld+ 2.1_Terrestrial ecotoxicity, short term_midpoint.json +0 -5
  58. edges/data/ImpactWorld+ 2.1_Thermally polluted water_midpoint.json +0 -5
  59. edges/data/ImpactWorld+ 2.1_Water availability, freshwater ecosystem_midpoint.json +0 -5
  60. edges/data/ImpactWorld+ 2.1_Water availability, human health_midpoint.json +0 -5
  61. edges/data/ImpactWorld+ 2.1_Water availability, terrestrial ecosystem_midpoint.json +0 -5
  62. edges/data/ImpactWorld+ 2.1_Water scarcity_damage.json +0 -5
  63. edges/data/RELICS_copper.json +0 -22
  64. edges-1.0.1.dist-info/RECORD +0 -71
  65. {edges-1.0.1.dist-info → edges-1.0.3.dist-info}/WHEEL +0 -0
  66. {edges-1.0.1.dist-info → edges-1.0.3.dist-info}/top_level.txt +0 -0
edges/georesolver.py CHANGED
@@ -1,4 +1,5 @@
1
1
  # edges/georesolver.py
2
+ from __future__ import annotations
2
3
 
3
4
  from functools import lru_cache
4
5
  import logging
@@ -9,8 +10,35 @@ logger = logging.getLogger(__name__)
9
10
  logger.addHandler(logging.NullHandler())
10
11
 
11
12
 
13
+ for name in ("country_converter", "country_converter.country_converter"):
14
+ l = logging.getLogger(name)
15
+ # remove existing handlers
16
+ while l.handlers:
17
+ h = l.handlers.pop()
18
+ try:
19
+ h.close()
20
+ except:
21
+ pass
22
+ l.propagate = False # don’t bubble to root
23
+ l.setLevel(logging.ERROR) # drop WARNINGs
24
+ logging.lastResort = None
25
+
26
+
12
27
  class GeoResolver:
28
+ """
29
+ Resolve geographic containment/coverage using constructive_geometries + project weights.
30
+
31
+ :param weights: Mapping of (supplier_loc, consumer_loc) tuples to numeric weights.
32
+ :return: GeoResolver instance.
33
+ """
34
+
13
35
  def __init__(self, weights: dict):
36
+ """
37
+ Initialize the resolver and normalize internal weight keys.
38
+
39
+ :param weights: Mapping of (supplier_loc, consumer_loc) -> weight value.
40
+ :return: None
41
+ """
14
42
  self.weights = {get_str(k): v for k, v in weights.items()}
15
43
  self.weights_key = ",".join(sorted(self.weights.keys()))
16
44
  self.logger = logging.getLogger(f"{__name__}.{self.__class__.__name__}")
@@ -27,7 +55,13 @@ class GeoResolver:
27
55
  exceptions: tuple | None = None,
28
56
  ) -> list[str]:
29
57
  """
30
- Find the locations containing or contained by a given location.
58
+ Find locations that contain (or are contained by) a given location, filtered by availability.
59
+
60
+ :param location: Base location code to resolve from.
61
+ :param weights_available: Iterable of allowed region codes to consider.
62
+ :param containing: If True, return regions that contain the base location; else contained regions.
63
+ :param exceptions: Optional tuple of region codes to exclude.
64
+ :return: List of matching region codes, filtered and ordered as discovered.
31
65
  """
32
66
  results = []
33
67
 
@@ -63,12 +97,21 @@ class GeoResolver:
63
97
  except KeyError:
64
98
  self.logger.info("Region %s: no geometry found.", location)
65
99
 
66
- return results
100
+ # Deduplicate and enforce deterministic ordering
101
+ return sorted(set(results))
67
102
 
68
103
  @lru_cache(maxsize=2048)
69
104
  def _cached_lookup(
70
105
  self, location: str, containing: bool, exceptions: tuple | None = None
71
106
  ) -> list:
107
+ """
108
+ Cached backend for resolving candidate locations.
109
+
110
+ :param location: Base location code.
111
+ :param containing: If True, resolve containing regions; else contained regions.
112
+ :param exceptions: Optional tuple of region codes to exclude.
113
+ :return: List of candidate region codes.
114
+ """
72
115
  return self.find_locations(
73
116
  location=location,
74
117
  weights_available=tuple(self.weights.keys()),
@@ -79,6 +122,14 @@ class GeoResolver:
79
122
  def resolve(
80
123
  self, location: str, containing=True, exceptions: list[str] | None = None
81
124
  ) -> list:
125
+ """
126
+ Resolve candidate regions for a given location with caching.
127
+
128
+ :param location: Base location code.
129
+ :param containing: If True, resolve containing regions; else contained regions.
130
+ :param exceptions: Optional list of region codes to exclude.
131
+ :return: List of candidate region codes.
132
+ """
82
133
  return self._cached_lookup(
83
134
  location=get_str(location),
84
135
  containing=containing,
@@ -91,6 +142,14 @@ class GeoResolver:
91
142
  containing=True,
92
143
  exceptions_map: dict[str, list[str]] | None = None,
93
144
  ) -> dict[str, list[str]]:
145
+ """
146
+ Resolve candidate regions for multiple locations at once.
147
+
148
+ :param locations: List of base location codes.
149
+ :param containing: If True, resolve containing regions; else contained regions.
150
+ :param exceptions_map: Optional mapping of location -> list of regions to exclude.
151
+ :return: Dict mapping each input location to its list of candidate region codes.
152
+ """
94
153
  return {
95
154
  loc: self.resolve(
96
155
  loc, containing, exceptions_map.get(loc) if exceptions_map else None