Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
0.2. Water releases are good.
  • Loading branch information
cmutel committed Sep 17, 2018
1 parent 0337f68 commit d753f2a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bw2_aware/__init__.py
Expand Up @@ -4,7 +4,7 @@
'AnnualNonagricultural'
)

__version__ = (0, 1)
__version__ = (0, 2)

from .aware import (
AnnualAgricultural,
Expand Down
49 changes: 28 additions & 21 deletions bw2_aware/aware.py
Expand Up @@ -3,22 +3,24 @@
from numbers import Number


SURFACE_WATER = [
('Fresh water (obsolete)', ('water', 'surface water')),
('Water', ('water',)),
('Water', ('water', 'surface water')),
('Water, cooling, unspecified natural origin', ('natural resource', 'in water')),
WATER_RESOURCE = [
('Water, lake', ('natural resource', 'in water')),
('Water, river', ('natural resource', 'in water')),
('Water, turbine use, unspecified natural origin', ('natural resource', 'in water')),
('Water, unspecified natural origin', ('natural resource', 'in water')),
('Water, cooling, unspecified natural origin', ('natural resource', 'in water')),
('Water, unspecified natural origin', ('natural resource', 'in ground')),
('Water, well, in ground', ('natural resource', 'in water')),
]

GROUND_WATER = [
# Ignored on the advice of Stephan Pfister (ETHZ)
# ('Water', ('water', 'ground-, long-term')),

WATER_RELEASE = [
('Fresh water (obsolete)', ('water', 'surface water')),
('Water', ('water',)),
('Water', ('water', 'surface water')),
('Water', ('water', 'ground-')),
('Water', ('water', 'ground-, long-term')),
('Water, unspecified natural origin', ('natural resource', 'in ground')),
('Water, well, in ground', ('natural resource', 'in water')),
]


Expand All @@ -32,17 +34,10 @@ class AWARE(LCIA):
url = "http://www.wulca-waterlca.org/aware.html"
id_column = 'id'

def _water_flows(self, kind='all'):
mapping = {
'all': SURFACE_WATER + GROUND_WATER,
'surface': SURFACE_WATER,
'ground': GROUND_WATER
}
flows = mapping[kind]

def _water_flows(self, water):
for act in self.db:
name, categories = act['name'], tuple(act['categories'])
for x, y in flows:
for x, y in water:
if name == x and categories == y:
yield act.key

Expand All @@ -54,19 +49,22 @@ def setup_geocollections(self):
}

def global_cfs(self):
for key in self._water_flows():
for key in self._water_flows(WATER_RESOURCE):
yield((key, self.global_cf, "GLO"))
for key in self._water_flows(WATER_RELEASE):
yield((key, self.global_cf * -1, "GLO"))

def regional_cfs(self):
water_flows = list(self._water_flows())
positive_water_flows = list(self._water_flows(WATER_RESOURCE))
negative_water_flows = list(self._water_flows(WATER_RELEASE))

for obj in self.global_cfs():
yield obj

with fiona.drivers():
with fiona.open(self.vector_ds) as src:
for feat in src:
for key in water_flows:
for key in positive_water_flows:
if not isinstance(feat['properties'][self.column], Number):
continue
yield (
Expand All @@ -75,6 +73,15 @@ def regional_cfs(self):
(self.geocollection, feat['properties'][self.id_column])
)

for key in negative_water_flows:
if not isinstance(feat['properties'][self.column], Number):
continue
yield (
key,
feat['properties'][self.column] * -1,
(self.geocollection, feat['properties'][self.id_column])
)


class AnnualAgricultural(AWARE):
column = "annual_agriculture"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -16,7 +16,7 @@

setup(
name='bw2_aware',
version="0.1",
version="0.2",
packages=packages,
author="Chris Mutel",
author_email="cmutel@gmail.com",
Expand Down

0 comments on commit d753f2a

Please sign in to comment.