antelope-interface 0.2.3.2__tar.gz → 0.2.4__tar.gz

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.
Files changed (44) hide show
  1. antelope_interface-0.2.4/PKG-INFO +59 -0
  2. antelope_interface-0.2.4/README.md +39 -0
  3. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/pyproject.toml +2 -2
  4. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/setup.py +7 -31
  5. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/__init__.py +16 -16
  6. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/flows/flow.py +5 -1
  7. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/flows/flow_interface.py +6 -3
  8. antelope_interface-0.2.4/src/antelope/interfaces/__init__.py +3 -0
  9. antelope_interface-0.2.4/src/antelope/interfaces/abstract_query.py +61 -0
  10. antelope_interface-0.2.3.2/src/antelope/interfaces/abstract_query.py → antelope_interface-0.2.4/src/antelope/interfaces/ibasic.py +42 -67
  11. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/interfaces/iconfigure.py +2 -1
  12. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/interfaces/iexchange.py +14 -20
  13. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/interfaces/iforeground.py +1 -1
  14. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/interfaces/iquantity.py +1 -0
  15. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/models/__init__.py +52 -15
  16. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/refs/base.py +2 -2
  17. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/refs/process_ref.py +6 -1
  18. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/refs/quantity_ref.py +12 -4
  19. antelope_interface-0.2.4/src/antelope_interface.egg-info/PKG-INFO +59 -0
  20. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope_interface.egg-info/SOURCES.txt +1 -0
  21. antelope_interface-0.2.4/src/antelope_interface.egg-info/requires.txt +2 -0
  22. antelope_interface-0.2.3.2/PKG-INFO +0 -40
  23. antelope_interface-0.2.3.2/README.md +0 -18
  24. antelope_interface-0.2.3.2/src/antelope/interfaces/__init__.py +0 -2
  25. antelope_interface-0.2.3.2/src/antelope_interface.egg-info/PKG-INFO +0 -40
  26. antelope_interface-0.2.3.2/src/antelope_interface.egg-info/requires.txt +0 -2
  27. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/LICENSE +0 -0
  28. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/MANIFEST.in +0 -0
  29. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/setup.cfg +0 -0
  30. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/exchanges_from_spreadsheet.py +0 -0
  31. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/flows/__init__.py +0 -0
  32. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/flows/openlca_locales.json +0 -0
  33. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/interfaces/ibackground.py +0 -0
  34. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/interfaces/iindex.py +0 -0
  35. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/models/auth.py +0 -0
  36. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/refs/__init__.py +0 -0
  37. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/refs/catalog_ref.py +0 -0
  38. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/refs/exchange_ref.py +0 -0
  39. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/refs/flow_ref.py +0 -0
  40. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/refs/tests/__init__.py +0 -0
  41. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/refs/tests/test_flows.py +0 -0
  42. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope/xdb_tokens.py +0 -0
  43. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope_interface.egg-info/dependency_links.txt +0 -0
  44. {antelope_interface-0.2.3.2 → antelope_interface-0.2.4}/src/antelope_interface.egg-info/top_level.txt +0 -0
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.1
2
+ Name: antelope_interface
3
+ Version: 0.2.4
4
+ Summary: A common interface for accessing LCA data
5
+ Author-email: Brandon Kuczenski <bkuczenski@ucsb.edu>
6
+ License: BSD-3-Clause
7
+ Keywords: one,two
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: Natural Language :: English
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering
15
+ Requires-Python: >=3.6
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: synonym_dict>=0.2.4
19
+ Requires-Dist: pydantic>=2.5.0
20
+
21
+ # antelope
22
+ Standard Interface and reference framework for LCA
23
+
24
+ The `antelope` package is an interface specification for accessing LCA data resources.
25
+ The goal of the Antelope project is to reduce the complexity of LCA along three central
26
+ fronts:
27
+
28
+ 1. Reduce complexity of *modeling* by providing a simple, recursive data structure (the
29
+ fragment) that can effectively describe complex, dynamic LCA models;
30
+ 2. Reduce complexity of *software* by liberating users from costly and cumbersome desktop
31
+ LCA software applications and relocating reference data to the cloud, without compromising
32
+ computational sophistication;
33
+ 3. Reduce complexity of *communication* by providing online tools for describing and sharing
34
+ LCA models that conceal or omit confidential and proprietary information.
35
+
36
+
37
+ ## Principles
38
+
39
+ The Antelope framework is *distributed by design*, intended to allow data owners to independently
40
+ create and manage their own intellectual property, allowing access by others while regulating
41
+ what can be seen and concealed.
42
+
43
+ Antelope provides a *hosting platform* for working online and sharing information within a
44
+ trust network. User-owned data is managed by owners, while reference data is curated by
45
+ the user community.
46
+
47
+ Antelope uses *separation of concerns* to help organize different computational facets of
48
+ the LCA problem into separate services.
49
+
50
+ ## Documentation
51
+
52
+ Coming to github.io
53
+
54
+ ### See Also
55
+
56
+ * [vault.lc](https://vault.lc/) Home to the Antelope authentication service
57
+ * [antelope_core](https://github.com/AntelopeLCA/core) The reference implementation including local data source management.
58
+ * [antelope_background](https://github.com/AntelopeLCA/background) Used for partial ordering of databases and construction and inversion of matrices
59
+ * [antelope_foreground](https://github.com/AntelopeLCA/foreground) Used for building foreground models
@@ -0,0 +1,39 @@
1
+ # antelope
2
+ Standard Interface and reference framework for LCA
3
+
4
+ The `antelope` package is an interface specification for accessing LCA data resources.
5
+ The goal of the Antelope project is to reduce the complexity of LCA along three central
6
+ fronts:
7
+
8
+ 1. Reduce complexity of *modeling* by providing a simple, recursive data structure (the
9
+ fragment) that can effectively describe complex, dynamic LCA models;
10
+ 2. Reduce complexity of *software* by liberating users from costly and cumbersome desktop
11
+ LCA software applications and relocating reference data to the cloud, without compromising
12
+ computational sophistication;
13
+ 3. Reduce complexity of *communication* by providing online tools for describing and sharing
14
+ LCA models that conceal or omit confidential and proprietary information.
15
+
16
+
17
+ ## Principles
18
+
19
+ The Antelope framework is *distributed by design*, intended to allow data owners to independently
20
+ create and manage their own intellectual property, allowing access by others while regulating
21
+ what can be seen and concealed.
22
+
23
+ Antelope provides a *hosting platform* for working online and sharing information within a
24
+ trust network. User-owned data is managed by owners, while reference data is curated by
25
+ the user community.
26
+
27
+ Antelope uses *separation of concerns* to help organize different computational facets of
28
+ the LCA problem into separate services.
29
+
30
+ ## Documentation
31
+
32
+ Coming to github.io
33
+
34
+ ### See Also
35
+
36
+ * [vault.lc](https://vault.lc/) Home to the Antelope authentication service
37
+ * [antelope_core](https://github.com/AntelopeLCA/core) The reference implementation including local data source management.
38
+ * [antelope_background](https://github.com/AntelopeLCA/background) Used for partial ordering of databases and construction and inversion of matrices
39
+ * [antelope_foreground](https://github.com/AntelopeLCA/foreground) Used for building foreground models
@@ -21,8 +21,8 @@ classifiers = [
21
21
  "Programming Language :: Python :: 3",
22
22
  "Topic :: Scientific/Engineering"
23
23
  ]
24
- dependencies = ["synonym_dict", "pydantic"]
25
- version = "0.2.3.2"
24
+ dependencies = ["synonym_dict >= 0.2.4", "pydantic >= 2.5.0"]
25
+ version = "0.2.4"
26
26
 
27
27
  [tool.setuptools.packages.find]
28
28
  where = ["src"]
@@ -1,14 +1,15 @@
1
- from setuptools import setup, find_packages
1
+ from setuptools import setup
2
2
 
3
- ANTELOPE_VERSION = '0.2.3.2'
3
+ setup()
4
4
 
5
- requires = [
6
- "synonym_dict>=0.2.4",
7
- "pydantic>=2.5.0"
8
- ]
9
5
 
10
6
  """
11
7
  Version History:
8
+ 0.2.4 2024/04/17 - split out BasicInterface from AbstractQuery.
9
+ abandon setup.py except for this changelog.
10
+ Redesign ExteriorFlow to have maybe a little bit more logic
11
+ First pass at API documentation
12
+
12
13
  0.2.3.2 2024/03/26 move to src layout
13
14
 
14
15
  0.2.3.1 2024/03/22 LciaDetail objects now return DirectedFlow instead of FlowSpec (as exchange proxy)
@@ -55,28 +56,3 @@ Version History:
55
56
 
56
57
  0.1.0 2020/07/31 - Initial release - JIE paper
57
58
  """
58
-
59
- setup(
60
- name="antelope_interface",
61
- version=ANTELOPE_VERSION,
62
- author="Brandon Kuczenski",
63
- author_email="bkuczenski@ucsb.edu",
64
- license="BSD 3-Clause",
65
- install_requires=requires,
66
- url="https://github.com/AntelopeLCA/antelope",
67
- summary="An interface specification for accessing LCA data",
68
- long_description_content_type='text/markdown',
69
- long_description=open('README.md').read(),
70
- include_package_data=True,
71
- classifiers=[
72
- "Development Status :: 4 - Beta",
73
- "Intended Audience :: Science/Research",
74
- "License :: OSI Approved :: BSD License",
75
- "Natural Language :: English",
76
- "Operating System :: OS Independent",
77
- "Programming Language :: Python :: 3",
78
- "Topic :: Scientific/Engineering"
79
- ],
80
- python_requires='>=3.6',
81
- packages=find_packages('src')
82
- )
@@ -5,8 +5,9 @@ The abstract classes in this sub-package define what information is made availab
5
5
  resource of some kind. The interfaces must be instantiated in order to be used. In the core package
6
6
  """
7
7
 
8
- from .interfaces.abstract_query import PrivateArchive, EntityNotFound, NoAccessToEntity
8
+ from .interfaces import ANTELOPE_INTERFACES
9
9
 
10
+ from .interfaces.ibasic import BasicInterface, EntityNotFound, NoAccessToEntity
10
11
  from .interfaces.iconfigure import ConfigureInterface
11
12
  from .interfaces.iexchange import ExchangeInterface, ExchangeRequired
12
13
  from .interfaces.iindex import IndexInterface, IndexRequired, directions, comp_dir, num_dir, check_direction, valid_sense, comp_sense
@@ -28,8 +29,6 @@ import re
28
29
 
29
30
  from os.path import splitext
30
31
 
31
- from collections import namedtuple
32
-
33
32
 
34
33
  class ValuesAccessRequired(Exception):
35
34
  """
@@ -50,14 +49,14 @@ Query classes
50
49
  '''
51
50
 
52
51
 
53
- class BasicQuery(IndexInterface, ExchangeInterface, QuantityInterface):
52
+ class BasicQuery(BasicInterface, IndexInterface, ExchangeInterface, QuantityInterface):
54
53
  """
55
- A basic query depends on an archive-- which is not yet well-defined, but which has the following API:
56
- archive.make_interface(interface): returns an implementation of the designated interface
57
- archive.ref: returns the archive's semantic reference
58
- archive.source: returns the physical source for the archive's content
54
+ A basic query depends on an archive-- which has the following API:
55
+
56
+ - archive.make_interface(interface): returns an implementation of the designated interface
57
+ - archive.ref: returns the archive's semantic reference
58
+ - archive.source: returns the physical source (or URI) for the archive's content
59
59
 
60
- Note that an alternative abstract query implementation could be imagined
61
60
  """
62
61
  def __init__(self, archive, debug=False):
63
62
  self._archive = archive
@@ -153,9 +152,10 @@ def q_node_activity(fg):
153
152
 
154
153
  def enum(iterable, filt=None, invert=True):
155
154
  """
156
- Enumerate an iterable for interactive use. return it as a list. Optional negative filter supplied as regex
155
+ Enumerate an iterable for interactive use. return it as a list. Optional negative filter supplied as regex.
156
+
157
157
  :param iterable:
158
- :param filt:
158
+ :param filt: regex to filter out entries from return and enumeration.
159
159
  :param invert: [True] sense of filter. note default is negative i.e. to screen *out* matches
160
160
  (the thinking is that the input is already positive-filtered)
161
161
  :return:
@@ -173,10 +173,10 @@ def enum(iterable, filt=None, invert=True):
173
173
  ret.append(v)
174
174
  return ret
175
175
 
176
+
176
177
  """
177
- In most LCA software, including the current operational version of lca-tools, a 'flow' is a composite entity
178
- that is made up of a 'flowable' (substance, product, intervention, or service) and a 'context', which is
179
- synonymous with an environmental compartment.
178
+ In most LCA software, a 'flow' is a composite entity that is made up of a 'flowable' (substance, product,
179
+ intervention, or service) and a 'context', which is synonymous with an environmental compartment.
180
180
 
181
181
  The US EPA review of elementary flows recommended managing the names of flowables and contexts separately, and that
182
182
  is the approach that is done here.
@@ -196,9 +196,9 @@ CONTEXT_STATUS_ = 'new' # 'compat': context = flow['Compartment']; 'new': conte
196
196
 
197
197
  # Exterior exchanges- with contexts outside the db. Direction is given with respect to the Interior (e.g. "Output" "to air")
198
198
  # LciaResults should negate values when an exchange direction and a context are not complementary (i.e. "Input" "to air")
199
- ExteriorFlow = namedtuple('ExteriorFlow', ('origin', 'flow', 'direction', 'termination'))
199
+ # ExteriorFlow = namedtuple('ExteriorFlow', ('origin', 'flow', 'direction', 'termination'))
200
200
 
201
- EntitySpec = namedtuple('EntitySpec', ('link', 'ref', 'name', 'group'))
201
+ # EntitySpec = namedtuple('EntitySpec', ('link', 'ref', 'name', 'group'))
202
202
 
203
203
  # packages that contain 'providers'
204
204
  antelope_herd = [
@@ -5,6 +5,8 @@ import os
5
5
  import re
6
6
  import json
7
7
 
8
+ from abc import ABC
9
+
8
10
  from synonym_dict import SynonymSet
9
11
  from synonym_dict.flowables.cas_number import CasNumber, InvalidCasNumber
10
12
 
@@ -36,14 +38,16 @@ with open(os.path.join(os.path.dirname(__file__), 'openlca_locales.json')) as fp
36
38
  olca_locales = json.load(fp)
37
39
 
38
40
 
39
- class Flow(FlowInterface):
41
+ class Flow(FlowInterface, ABC):
40
42
  """
41
43
  A partly-abstract class that implements the flow specification but not the entity specification.
42
44
 
43
45
  Included in this specification is a *detection of biogenic CO2 by regex*
44
46
  Each flow has a quell_co2 property which is True if:
47
+
45
48
  - the flow is a synonym for CO2 and
46
49
  - the flow's name matches the biogenic regex: '(biotic|biogenic|non-fossil|in air)' (case insensitive)
50
+
47
51
  There are 3 ways for a flow to be identified as a synonym for CO2:
48
52
  1. pass is_co2=True at instantiation
49
53
  2. set flow.is_co2 = True
@@ -1,3 +1,6 @@
1
+ from abc import ABC
2
+
3
+
1
4
  class BaseEntity(object):
2
5
  """
3
6
  The very most basic characteristics of entities and entity refs
@@ -81,7 +84,7 @@ class NullEntity(BaseEntity):
81
84
  return NotImplemented
82
85
 
83
86
 
84
- class FlowInterface(BaseEntity):
87
+ class FlowInterface(BaseEntity, ABC):
85
88
  """
86
89
  An abstract class that establishes common functionality for OBSERVATIONS OF FLOWS. A Flow consists of:
87
90
  - a reference quantity with a fixed unit
@@ -138,8 +141,8 @@ class FlowInterface(BaseEntity):
138
141
 
139
142
  def lookup_cf(self, quantity, context, locale, refresh=False, **kwargs):
140
143
  """
141
- Look for cached characterizations, and retrieve if none is found
142
- :param quantity:
144
+ Look for cached characterizations, and retrieve one from the provided quantity if none is found.
145
+ :param quantity: a QuantityRef
143
146
  :param context:
144
147
  :param locale:
145
148
  :param refresh: [False] if True, discard cached CF
@@ -0,0 +1,3 @@
1
+ from .abstract_query import ANTELOPE_INTERFACES
2
+ from .ibasic import EntityNotFound, NoAccessToEntity
3
+ from .iindex import check_direction, InvalidDirection, InvalidSense
@@ -0,0 +1,61 @@
1
+ """
2
+ Root-level catalog interface
3
+ """
4
+
5
+
6
+ #: The interfaces that exist in the Antelope framework
7
+ ANTELOPE_INTERFACES = ('basic', 'exchange', 'index', 'quantity', 'background', 'configure', 'foreground')
8
+
9
+
10
+ class PrivateArchive(Exception):
11
+ """
12
+ :meta exclude:
13
+ """
14
+ pass
15
+
16
+
17
+ class AbstractQuery(object):
18
+ """ Not-quite-abstract base class for executing queries
19
+
20
+ Query implementation must provide:
21
+ - origin (property)
22
+ - _iface (generator: itype)
23
+ - _tm (property) a TermManager
24
+ """
25
+ _validated = None
26
+
27
+ '''
28
+ Overridde these methods
29
+ '''
30
+ @property
31
+ def origin(self):
32
+ return NotImplemented
33
+
34
+ def make_ref(self, entity):
35
+ raise NotImplementedError
36
+
37
+ def _perform_query(self, itype, attrname, exc, *args, **kwargs):
38
+ """
39
+ The workhorse of the abstract query. The implementation uses this to perform whatever query is requested.
40
+
41
+ :param itype: type of query being performed (which interface is being invoked). Must be in ANTELOPE_INTERFACES
42
+ :param attrname: query name
43
+ :param exc: "fallback exception": ignore it if an implementation raises it; then raise it if no implementation
44
+ succeeds
45
+ :param args: to pass to the query
46
+ :param kwargs: to pass to the query or subclass
47
+ :return:
48
+ """
49
+ raise NotImplementedError
50
+
51
+ def _grounded_query(self, origin):
52
+ """
53
+ Pseudo-abstract method used to construct entity references from a query that is anchored to a metaresource.
54
+ must be overriden by user-facing subclasses if resources beyond self are required to answer
55
+ the queries (e.g. a catalog).
56
+ Can be overridden.
57
+
58
+ :param origin:
59
+ :return:
60
+ """
61
+ return self
@@ -1,17 +1,25 @@
1
- """
2
- Root-level catalog interface
3
- """
1
+ from .abstract_query import AbstractQuery
4
2
 
5
3
 
6
- class ValidationError(Exception):
4
+ class BasicRequired(Exception):
5
+ """
6
+ Default exception to indicate that the requested method cannot be invoked without an implementation of the
7
+ basic interface (and none could be found).
8
+ """
7
9
  pass
8
10
 
9
11
 
10
- class PrivateArchive(Exception):
12
+ class ValidationError(Exception):
13
+ """
14
+ :meta private:
15
+ """
11
16
  pass
12
17
 
13
18
 
14
19
  class EntityNotFound(Exception):
20
+ """
21
+ An exception of generic usefulness.
22
+ """
15
23
  pass
16
24
 
17
25
 
@@ -22,56 +30,15 @@ class NoAccessToEntity(Exception):
22
30
  pass
23
31
 
24
32
 
25
- class AbstractQuery(object):
33
+ class BasicInterface(AbstractQuery):
26
34
  """
27
- Not-quite-abstract base class for executing queries
35
+ BasicInterface core methods.
28
36
 
29
- Query implementation must provide:
30
- - origin (property)
31
- - _iface (generator: itype)
32
- - _tm (property) a TermManager
33
- """
34
- _validated = None
35
-
36
- '''
37
- Overridde these methods
38
- '''
39
- @property
40
- def origin(self):
41
- return NotImplemented
37
+ These are methods for retrieving objects and accessing documentary information about them. The basic interface
38
+ should provide access to the most authoritative source of information about a data resource.
42
39
 
43
- def make_ref(self, entity):
44
- raise NotImplementedError
45
-
46
- def _perform_query(self, itype, attrname, exc, *args, **kwargs):
47
- """
48
-
49
- :param itype: type of query being performed (which interface is being invoked)
50
- :param attrname: query name
51
- :param exc: "fallback exception": ignore it if an implementation raises it; then raise it if no implementation
52
- succeeds
53
- :param args: to pass to the query
54
- :param kwargs: to pass to the query or subclass
55
- :return:
56
- """
57
- raise NotImplementedError
58
-
59
- '''
60
- Internal workings
61
- '''
62
- '''
63
- Can be overridden
64
- '''
65
- def _grounded_query(self, origin):
66
- """
67
- Pseudo-abstract method used to construct entity references from a query that is anchored to a metaresource.
68
- must be overriden by user-facing subclasses if resources beyond self are required to answer
69
- the queries (e.g. a catalog).
70
- :param origin:
71
- :return:
72
- """
73
- return self
74
40
 
41
+ """
75
42
  """
76
43
  Basic "Documentary" interface implementation
77
44
  From JIE submitted:
@@ -86,6 +53,13 @@ class AbstractQuery(object):
86
53
  """
87
54
 
88
55
  def validate(self):
56
+ """
57
+ This method should return `True` whenever the implementation is attached to a valid data source that is
58
+ capable of answering questions. The existence of a basic implementation is necessary and sufficient for a
59
+ query to be valid.
60
+
61
+ :return: bool
62
+ """
89
63
  if self._validated is None:
90
64
  try:
91
65
  self._perform_query('basic', 'validate', ValidationError)
@@ -115,17 +89,12 @@ class AbstractQuery(object):
115
89
 
116
90
  def get_item(self, external_ref, item):
117
91
  """
118
- access an entity's dictionary items
119
- :param external_ref:
120
- :param item:
92
+ access an entity's properties. This requires de-referencing the query to the true entity. This method
93
+ is used to access essentially all documentary information about an object.
94
+ :param external_ref: the entity's identifier
95
+ :param item: the desired property
121
96
  :return:
122
97
  """
123
- '''
124
- if hasattr(external_ref, 'external_ref'): # debounce
125
- err_str = external_ref.external_ref
126
- else:
127
- err_str = external_ref
128
- '''
129
98
  return self._perform_query('basic', 'get_item', EntityNotFound,
130
99
  external_ref, item)
131
100
 
@@ -148,19 +117,24 @@ class AbstractQuery(object):
148
117
 
149
118
  def is_lcia_engine(self, **kwargs):
150
119
  """
151
- A key question in the quantity interface is the way terms are managed. There are two main footings:
152
- - the terms specified by the source are authentic / canonical and should be reproduced
153
- - terms from different data sources refer to the same concept.
120
+ A key question in the quantity interface is the way terms are managed.
154
121
  An archive's Term Manager determines how input terms are interpreted and how characterizations are looked up.
122
+ There are two main footings:
123
+
124
+ - the terms specified by the source are authentic / canonical and should be reproduced
125
+ - terms from different data sources refer to the same concept, and the *concept* should be returned.
126
+
127
+ A *provincial* term manager considers the local archive (to which it is attached) to be the source of all
128
+ truth. It will return flowables and contexts exactly as they are defined in the native data source. In
129
+ this case, `is_lcia_engine()` returns `False`.
155
130
 
156
131
  if the term manager is an LciaEngine, it uses a standard set of contexts and flowables, and provides routes
157
132
  to add new synonyms for flowables/contexts and to report new flowables or contexts. Ultimately the objective
158
- is to manage characterization + knowledge of intermediate flows.
159
-
160
- This routine reports whether an origin implements the LciaEngine [protocol?] for dealing with flows.
133
+ is to manage characterization + knowledge of both elementary and intermediate flows.
134
+ In this case, `is_lcia_engine()` returns `True`.
161
135
 
162
136
  :param kwargs:
163
- :return: True/False - could also provide more structured information as needed.
137
+ :return: bool
164
138
  """
165
139
 
166
140
  try:
@@ -168,3 +142,4 @@ class AbstractQuery(object):
168
142
  except TypeError:
169
143
  return False
170
144
 
145
+
@@ -81,7 +81,8 @@ class ConfigureInterface(AbstractQuery):
81
81
  def characterize_flow(self, flow_ref, quantity_ref, value, location='GLO', **kwargs):
82
82
  """
83
83
  Add a characterization to the given flow in the given quantity, with respect to the flow's native reference
84
- quantity. Optional location field.
84
+ quantity. Optional location field.
85
+
85
86
  :param flow_ref:
86
87
  :param quantity_ref:
87
88
  :param value:
@@ -13,19 +13,10 @@ EXCHANGE_VALUES_REQUIRED = {'ev', 'exchange_values', 'inventory', 'exchange_rela
13
13
 
14
14
  class ExchangeInterface(AbstractQuery):
15
15
  """
16
- InventoryInterface core methods: individual processes, quantitative data.
17
-
18
- Need to do some thinking here-- the list of methods is very short. In particular there is no way to do any of
19
- the following:
20
- * retrieve reference exchanges
21
- * retrieve cutoff exchanges or only terminated exchanges
22
- * retrieve only intermediate or only elementary exchanges [[ pending context refactor :(:( ]]
23
- = this is frankly not possible to do, even after the context refactor, because there is no bulletproof way to
24
- determine whether a termination is a context or a process or some non-elementary compartment, until you
25
- introduce the Lcia Engine with its reference set of contexts, UNLESS you include the reference elementary set
26
- in ALL context managers. Which is feasible- since it's a short list- but still, not done as yet.
27
- There's also no access to information from the original source that is not part of the data model, e.g. uncertainty
28
- information, arbitrary XML queries, etc.
16
+ The Exchange Interface implements the Exchange Relation:
17
+ - given a process, a reference flow, and a query flow, report the quantity of the query flow that is exchanged
18
+ with respect to a unit of the reference flow.
19
+
29
20
  """
30
21
  def exchanges(self, process, **kwargs):
31
22
  """
@@ -39,6 +30,7 @@ class ExchangeInterface(AbstractQuery):
39
30
  def ev(self, process, flow, direction=None, termination=None, ref_flow=None, **kwargs):
40
31
  """
41
32
  Return a float. Symmetric to quantity.cf
33
+
42
34
  :param process:
43
35
  :param flow:
44
36
  :param direction: [None] if none, if flows exist with both directions, raise an error
@@ -57,7 +49,8 @@ class ExchangeInterface(AbstractQuery):
57
49
  2022-12-27: is this really deprecated? it's used in computing reference_value and I don't see any other way...
58
50
  perhaps we should add reference_value() to the API but for now let's keep this around
59
51
 
60
- Return a list of exchanges with values matching the specification
52
+ Return a list of exchanges with values matching the specification.
53
+
61
54
  :param process:
62
55
  :param flow:
63
56
  :param direction: [None] if none,
@@ -77,17 +70,18 @@ class ExchangeInterface(AbstractQuery):
77
70
 
78
71
  If a reference flow is supplied, expected behavior depends on a number of factors.
79
72
  - If the supplied reference flow is part of the process's reference entity, the inventory should return all
80
- non-reference exchanges, appropriately allocated to the specified flow, and normalized to a unit of the
81
- specified flow.
73
+ non-reference exchanges, appropriately allocated to the specified flow, and normalized to a unit of the
74
+ specified flow.
82
75
  - If the supplied reference flow is not part of the reference entity, NO allocation should be performed.
83
- Instead, the inventory should return ALL exchanges except for the specified flow, un-allocated, normalized to
84
- a unit of the specified flow. This query is only valid if the specified flow is a cut-off (i.e. un-terminated)
85
- exchange (i.e. it could be treated as a "silent reference" or effective co-product)
76
+ Instead, the inventory should return ALL exchanges except for the specified flow, un-allocated, normalized to
77
+ a unit of the specified flow. This query is only valid if the specified flow is a cut-off (i.e. un-terminated)
78
+ exchange (i.e. it could be treated as a "silent reference" or effective co-product)
86
79
  - If the supplied reference flow is a non-reference, non-cutoff flow (i.e. it is a terminated exchange), then
87
- the appropriate behavior is undefined. The default implementation raises an ExchangeError.
80
+ the appropriate behavior is undefined. The default implementation raises an ExchangeError.
88
81
 
89
82
  Note: if this is called on a fragment, the signature is the same but the 'ref_flow' argument is ignored and
90
83
  the alternative 'scenario' kwarg is accepted
84
+
91
85
  :param process:
92
86
  :param ref_flow: used only for processes
93
87
  :param scenario: used only for fragments (antelope_foreground)
@@ -80,7 +80,7 @@ class ForegroundInterface(AbstractQuery):
80
80
 
81
81
  :param flow: a flow entity/ref, or an external_ref known to the foreground
82
82
  :param direction:
83
- :param kwargs: uuid=None, parent=None, comment=None, value=None, balance=False; **kwargs passed to LcFragment
83
+ :param kwargs: uuid=None, parent=None, comment=None, value=None, balance=False; kwargs passed to LcFragment
84
84
  :return: the fragment? or a fragment ref? <== should only be used in the event of a non-local foreground
85
85
  """
86
86
  return self._perform_query(_interface, 'new_fragment', ForegroundRequired,
@@ -178,6 +178,7 @@ class QuantityInterface(AbstractQuery):
178
178
  (hence the basic interface)
179
179
  - either the quantity ref must be known locally or resolvable to a do_lcia operation by the catalog
180
180
  - there is also the implied need for sys_lcia which is a POST operation that uses sys_lci
181
+
181
182
  It needs to be rewritten.
182
183
 
183
184
  :param process:
@@ -72,7 +72,15 @@ class Entity(EntityRef):
72
72
  return self.entity_id
73
73
 
74
74
  @classmethod
75
- def from_entity(cls, entity, **kwargs):
75
+ def from_search(cls, entity):
76
+ ent = cls(origin=entity.origin, entity_id=entity.external_ref, entity_type=entity.entity_type,
77
+ properties=dict())
78
+ for k in entity.signature_fields():
79
+ ent.properties[k] = entity[k]
80
+ return ent
81
+
82
+ @classmethod
83
+ def from_entity(cls, entity):
76
84
  ent = cls(origin=entity.origin, entity_id=entity.external_ref, entity_type=entity.entity_type,
77
85
  properties=dict())
78
86
  # ent.properties.update(kwargs) # I don't know why this was here but I don't think I want it
@@ -162,6 +170,7 @@ class FlowEntity(Entity):
162
170
 
163
171
  obj.properties['name'] = entity.name
164
172
  obj.properties[entity.reference_field] = entity.reference_entity.external_ref
173
+ obj.properties['unit'] = entity.unit
165
174
  obj.properties['Synonyms'] = []
166
175
 
167
176
  for key, val in kwargs.items():
@@ -245,20 +254,6 @@ class FlowSpec(ResponseModel):
245
254
  context=cx, locale=loc)
246
255
 
247
256
 
248
- class ExteriorFlow(ResponseModel):
249
- """
250
- Do we really need both an ExteriorFlow model and a FlowSpec model? this one has direction, and origin+flow;
251
- that one has flowable+ref entity, and locale (but we added locale)
252
-
253
- This is currently unused, but that's because we haven't implemented the {origin}/exterior route yet
254
- """
255
- origin: str
256
- flow: str
257
- direction: str # antelope_interface specifies the direction as w/r/t/ context, as in "Input" "to air". This SEEMS WRONG.
258
- context: List[str]
259
- locale: Optional[str] = 'GLO' # ???
260
-
261
-
262
257
  class DirectedFlow(ResponseModel):
263
258
  flow: FlowSpec
264
259
  direction: str
@@ -284,6 +279,38 @@ class DirectedFlow(ResponseModel):
284
279
  return cls(flow=FlowSpec.from_exchange(obj), direction=obj.direction)
285
280
 
286
281
 
282
+ class ExteriorFlow(DirectedFlow):
283
+ """
284
+ An ExteriorFlow is essentially a row in the LCI Environment `B` matrix. It consists of a directed flow,
285
+ enhanced with a context. Now I know a flow already has a context, but (a) context is not required for a flow and
286
+ (b) flows can be terminated to contexts other than their 'default'
287
+ """
288
+ context: List[str]
289
+
290
+ @classmethod
291
+ def from_background(cls, flow, direction, context):
292
+ if hasattr(context, 'entity_type'):
293
+ if context.entity_type == 'context':
294
+ cx = context.as_list()
295
+ else:
296
+ raise TypeError('supplied Context %s (type %s)' % (context, context.entity_type))
297
+ elif context is None:
298
+ cx = []
299
+ else:
300
+ cx = list(context)
301
+ return cls(flow=FlowSpec.from_flow(flow), direction=direction, context=cx)
302
+
303
+ @classmethod
304
+ def from_exchange(cls, obj):
305
+ if obj.type == 'context':
306
+ context = obj.termination.as_list()
307
+ elif obj.type == 'cutoff':
308
+ context = []
309
+ else:
310
+ raise TypeError('exchange is not exterior (type %s)' % obj.type)
311
+ return cls(flow=FlowSpec.from_exchange(obj), direction=obj.direction, context=context)
312
+
313
+
287
314
  class Exchange(ResponseModel):
288
315
  """
289
316
  Do we need to add locale??
@@ -313,6 +340,15 @@ class ReferenceExchange(Exchange):
313
340
  is_reference: bool = True
314
341
  termination: None
315
342
 
343
+ @classmethod
344
+ def from_exchange(cls, x):
345
+ if x.termination is not None:
346
+ cx = list(x.termination)
347
+ else:
348
+ cx = None
349
+ return cls(origin=x.process.origin, process=x.process.external_ref, flow=FlowEntity.from_flow(x.flow),
350
+ direction=x.direction, termination=None, context=cx, type=x.type, comment=x.comment, str=str(x))
351
+
316
352
 
317
353
  class ReferenceValue(ReferenceExchange):
318
354
  value: float
@@ -583,6 +619,7 @@ class DisaggregatedLciaScore(AggregatedLciaScore):
583
619
  details: List[LciaDetail] = []
584
620
 
585
621
  '''
622
+ :meta exclude:
586
623
  @classmethod
587
624
  def from_component(cls, obj, c):
588
625
  if hasattr(c.entity, 'name'):
@@ -33,7 +33,7 @@ The CatalogRef can instantiate a grounded reference if supplied with a query obj
33
33
  from synonym_dict import LowerDict
34
34
 
35
35
  from ..flows import BaseEntity
36
- from ..interfaces.abstract_query import NoAccessToEntity, EntityNotFound
36
+ from ..interfaces import NoAccessToEntity, EntityNotFound
37
37
 
38
38
  import re
39
39
 
@@ -390,8 +390,8 @@ class EntityRef(BaseRef):
390
390
  -- which causes recursion error if the query actually gets the entity_ref
391
391
  --- attempted solution with NoAccessToEntity exception in BasicImplementation
392
392
  - fine. So when do we raise a key error?
393
+
393
394
  :param item:
394
- :param force_query:
395
395
  :return:
396
396
  """
397
397
  if item == self._ref_field:
@@ -1,4 +1,4 @@
1
- from .base import EntityRef
1
+ from .base import EntityRef, _MissingItem
2
2
  from .exchange_ref import ExchangeRef
3
3
  from itertools import chain
4
4
 
@@ -21,6 +21,11 @@ class ProcessRef(EntityRef):
21
21
  _etype = 'process'
22
22
  _ref_field = 'referenceExchange'
23
23
 
24
+ def signature_fields(self):
25
+ for k in ('Name', 'Comment', 'SpatialScope', 'TemporalScope'):
26
+ if self._d[k] is not _MissingItem:
27
+ yield k
28
+
24
29
  @property
25
30
  def _addl(self):
26
31
  return self.get('SpatialScope', default='')
@@ -201,30 +201,38 @@ class QuantityRef(EntityRef):
201
201
  """
202
202
  Enter a characterization factor for the current object (query quantity) w.r.t. the specified reference quantity.
203
203
  The characterization value should report the amount of the query quantity (quantity being characterized) that
204
- equals a unit of the reference quantity (used to measure the flow). The following is correct,
205
- for mass in kg and volume in m3:
204
+ equals a unit of the reference quantity (used to measure the flow). The following is correct,
205
+ for mass in kg and volume in m3:
206
+
206
207
  >>> mass.characterize('water', 'volume', 1000.0)
207
- "I {characterize} the [mass] of [water] in a unit [volume] to be 1000.0". The thing being measured is mass.
208
+ "I {characterize} the [mass] of [water] in a unit [volume] to be 1000.0".
209
+
210
+ The thing being measured is mass.
208
211
  The flow's reference quantity is volume. a unit reference quantity of water is characterized as 1000.0 kg.
209
212
 
210
213
  The following is NOT correct, but it may SEEM more semantically natural:
214
+
211
215
  >>> mass.characterize('water', 'volume', 0.001)
212
216
  "I {characterize} the unit [mass] of [water] to have a [volume] of 0.001"
217
+
213
218
  The unit of the flow is measured in terms of the query quantity. But we don't yet know the size of a unit
214
219
  of the query quantity because that is what is in fact being characterized.
215
220
 
216
221
  To see this borne out, imagine using characterize() in its most natural way, for LCIA:
222
+
217
223
  >>> gwp.characterize('methane', 'mass', 25)
218
224
  "I characterize the GWP of methane in a unit mass to be 25" <<--- CORRECT
219
225
  {I characterize the unit GWP of methane to have a mass of 0.04} <<--- plainly wrong
220
226
 
221
- REALLY, the MOST natural way to characterize is as follows (see FlowRef.characterize()):
227
+ REALLY, the MOST natural way to characterize is to use `FlowRef.characterize()`:
228
+
222
229
  >>> m = q.get('methane')
223
230
  >>> m.unit
224
231
  'kg'
225
232
  >>> m.characterize(gwp, 25, context='to air')
226
233
 
227
234
  generations may determine whether this was a terrible mistake.
235
+
228
236
  :param flowable:
229
237
  :param ref_quantity:
230
238
  :param value:
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.1
2
+ Name: antelope_interface
3
+ Version: 0.2.4
4
+ Summary: A common interface for accessing LCA data
5
+ Author-email: Brandon Kuczenski <bkuczenski@ucsb.edu>
6
+ License: BSD-3-Clause
7
+ Keywords: one,two
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: Natural Language :: English
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering
15
+ Requires-Python: >=3.6
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: synonym_dict>=0.2.4
19
+ Requires-Dist: pydantic>=2.5.0
20
+
21
+ # antelope
22
+ Standard Interface and reference framework for LCA
23
+
24
+ The `antelope` package is an interface specification for accessing LCA data resources.
25
+ The goal of the Antelope project is to reduce the complexity of LCA along three central
26
+ fronts:
27
+
28
+ 1. Reduce complexity of *modeling* by providing a simple, recursive data structure (the
29
+ fragment) that can effectively describe complex, dynamic LCA models;
30
+ 2. Reduce complexity of *software* by liberating users from costly and cumbersome desktop
31
+ LCA software applications and relocating reference data to the cloud, without compromising
32
+ computational sophistication;
33
+ 3. Reduce complexity of *communication* by providing online tools for describing and sharing
34
+ LCA models that conceal or omit confidential and proprietary information.
35
+
36
+
37
+ ## Principles
38
+
39
+ The Antelope framework is *distributed by design*, intended to allow data owners to independently
40
+ create and manage their own intellectual property, allowing access by others while regulating
41
+ what can be seen and concealed.
42
+
43
+ Antelope provides a *hosting platform* for working online and sharing information within a
44
+ trust network. User-owned data is managed by owners, while reference data is curated by
45
+ the user community.
46
+
47
+ Antelope uses *separation of concerns* to help organize different computational facets of
48
+ the LCA problem into separate services.
49
+
50
+ ## Documentation
51
+
52
+ Coming to github.io
53
+
54
+ ### See Also
55
+
56
+ * [vault.lc](https://vault.lc/) Home to the Antelope authentication service
57
+ * [antelope_core](https://github.com/AntelopeLCA/core) The reference implementation including local data source management.
58
+ * [antelope_background](https://github.com/AntelopeLCA/background) Used for partial ordering of databases and construction and inversion of matrices
59
+ * [antelope_foreground](https://github.com/AntelopeLCA/foreground) Used for building foreground models
@@ -13,6 +13,7 @@ src/antelope/flows/openlca_locales.json
13
13
  src/antelope/interfaces/__init__.py
14
14
  src/antelope/interfaces/abstract_query.py
15
15
  src/antelope/interfaces/ibackground.py
16
+ src/antelope/interfaces/ibasic.py
16
17
  src/antelope/interfaces/iconfigure.py
17
18
  src/antelope/interfaces/iexchange.py
18
19
  src/antelope/interfaces/iforeground.py
@@ -0,0 +1,2 @@
1
+ synonym_dict>=0.2.4
2
+ pydantic>=2.5.0
@@ -1,40 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: antelope_interface
3
- Version: 0.2.3.2
4
- Summary: A common interface for accessing LCA data
5
- Home-page: https://github.com/AntelopeLCA/antelope
6
- Author: Brandon Kuczenski
7
- Author-email: Brandon Kuczenski <bkuczenski@ucsb.edu>
8
- License: BSD-3-Clause
9
- Keywords: one,two
10
- Classifier: Development Status :: 4 - Beta
11
- Classifier: Intended Audience :: Science/Research
12
- Classifier: License :: OSI Approved :: BSD License
13
- Classifier: Natural Language :: English
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: Topic :: Scientific/Engineering
17
- Requires-Python: >=3.6
18
- Description-Content-Type: text/markdown
19
- License-File: LICENSE
20
- Requires-Dist: synonym_dict
21
- Requires-Dist: pydantic
22
-
23
- # antelope
24
- Standard Interface and reference framework for LCA
25
-
26
- The `antelope` package is an interface specification for accessing LCA data resources, as described in [JIE submitted]. It should be subclassed by implementations that wish to expose data using this uniform interface. A reference implementation, including a stand-alone LCA computing tool, exists...
27
-
28
- ## Documentation
29
-
30
- See the following articles:
31
-
32
- * [Antelope Design Principles](principles.md) for documentation of this repository.
33
- * [Entity Specification](entities.md) and nomenclature.
34
- * [Return Types](types.md) which are *references* to entities.
35
-
36
- ### See Also
37
-
38
- * [antelope_core](https://github.com/AntelopeLCA/core) The reference implementation including local data source management.
39
- * [antelope_background](https://github.com/AntelopeLCA/background) Used for partial ordering of databases and construction and inversion of matrices
40
- * [antelope_foreground](https://github.com/AntelopeLCA/foreground) Used for building foreground models
@@ -1,18 +0,0 @@
1
- # antelope
2
- Standard Interface and reference framework for LCA
3
-
4
- The `antelope` package is an interface specification for accessing LCA data resources, as described in [JIE submitted]. It should be subclassed by implementations that wish to expose data using this uniform interface. A reference implementation, including a stand-alone LCA computing tool, exists...
5
-
6
- ## Documentation
7
-
8
- See the following articles:
9
-
10
- * [Antelope Design Principles](principles.md) for documentation of this repository.
11
- * [Entity Specification](entities.md) and nomenclature.
12
- * [Return Types](types.md) which are *references* to entities.
13
-
14
- ### See Also
15
-
16
- * [antelope_core](https://github.com/AntelopeLCA/core) The reference implementation including local data source management.
17
- * [antelope_background](https://github.com/AntelopeLCA/background) Used for partial ordering of databases and construction and inversion of matrices
18
- * [antelope_foreground](https://github.com/AntelopeLCA/foreground) Used for building foreground models
@@ -1,2 +0,0 @@
1
- from .abstract_query import EntityNotFound
2
- from .iindex import check_direction, InvalidDirection, InvalidSense
@@ -1,40 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: antelope_interface
3
- Version: 0.2.3.2
4
- Summary: A common interface for accessing LCA data
5
- Home-page: https://github.com/AntelopeLCA/antelope
6
- Author: Brandon Kuczenski
7
- Author-email: Brandon Kuczenski <bkuczenski@ucsb.edu>
8
- License: BSD-3-Clause
9
- Keywords: one,two
10
- Classifier: Development Status :: 4 - Beta
11
- Classifier: Intended Audience :: Science/Research
12
- Classifier: License :: OSI Approved :: BSD License
13
- Classifier: Natural Language :: English
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: Topic :: Scientific/Engineering
17
- Requires-Python: >=3.6
18
- Description-Content-Type: text/markdown
19
- License-File: LICENSE
20
- Requires-Dist: synonym_dict
21
- Requires-Dist: pydantic
22
-
23
- # antelope
24
- Standard Interface and reference framework for LCA
25
-
26
- The `antelope` package is an interface specification for accessing LCA data resources, as described in [JIE submitted]. It should be subclassed by implementations that wish to expose data using this uniform interface. A reference implementation, including a stand-alone LCA computing tool, exists...
27
-
28
- ## Documentation
29
-
30
- See the following articles:
31
-
32
- * [Antelope Design Principles](principles.md) for documentation of this repository.
33
- * [Entity Specification](entities.md) and nomenclature.
34
- * [Return Types](types.md) which are *references* to entities.
35
-
36
- ### See Also
37
-
38
- * [antelope_core](https://github.com/AntelopeLCA/core) The reference implementation including local data source management.
39
- * [antelope_background](https://github.com/AntelopeLCA/background) Used for partial ordering of databases and construction and inversion of matrices
40
- * [antelope_foreground](https://github.com/AntelopeLCA/foreground) Used for building foreground models
@@ -1,2 +0,0 @@
1
- synonym_dict
2
- pydantic