Skip to content

Commit

Permalink
add experimental mass flow diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
pjamesjoyce committed Oct 13, 2017
1 parent 63d1b7b commit 280cb50
Show file tree
Hide file tree
Showing 11 changed files with 652 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lcopt/analysis.py
@@ -1,5 +1,6 @@
from lcopt.bw2_export import Bw2Exporter
from lcopt.utils import DEFAULT_DB_NAME, FORWAST_DB_NAME
from lcopt.mass_balance import recurse_mass
import brightway2 as bw2
from bw2analyzer.tagged import recurse_tagged_database, aggregate_tagged_graph
from copy import deepcopy
Expand Down Expand Up @@ -248,7 +249,8 @@ def run_analyses(self, demand_item, demand_item_code, amount=1, methods=[('IPCC
'foreground_results': foreground_result,
'graph': recursed_graph,
'dropped_graph': dropped_graph,
'original_graph': str(type_graph[0])
'original_graph': str(type_graph[0]),
'mass_flow': recurse_mass(type_graph[0])
}

ps_results.append(result_set)
Expand Down
4 changes: 4 additions & 0 deletions lcopt/interact.py
Expand Up @@ -1003,6 +1003,10 @@ def locations_as_json():

return json.dumps(filtered_locations)

@app.route('/mass_flow')
def mass_flow():
return render_template('mass_flow.html')

return app

def run(self): # pragma: no cover
Expand Down
48 changes: 48 additions & 0 deletions lcopt/mass_balance.py
@@ -0,0 +1,48 @@
def recurse_mass(d):

to_return = {}
#cum_impact = 0

for k, v in d.items():
if k == 'amount' and d['tag'] == 'biosphere':
#print (k, -v)
to_return[k] = -v

elif k == 'technosphere':
#print('technosphere')
for e in v:
#print (e['activity'])
#cum_impact += e['impact']
#if 'cum_impact' in e.keys():
# cum_impact += e['cum_impact']

if k in to_return.keys():
to_return[k].append(recurse_mass(e))
else:
to_return[k] = [recurse_mass(e)]

elif k in['biosphere', 'impact']:
pass

elif k == 'activity':
#print (k,v)
#activity_list = v.split('(')
activity = v['name'] # activity_list[0].strip()
unit = v['unit'] # activity_list[1].split(',')[0]
#print(activity, unit)
to_return['activity'] = str(activity)
to_return['unit'] = unit
if unit in ['kg', 'g']:
to_return['is_mass'] = True
else:
to_return['is_mass'] = False

#elif k == 'impact':
# print('impact of {} = {}'.format(d['activity'], v))

else:
to_return[k] = v
#print('cum_impact of {} = {}'.format(d['activity'], cum_impact))
#to_return['cum_impact'] = cum_impact

return to_return
38 changes: 38 additions & 0 deletions lcopt/static/css/mass_flow.css
@@ -0,0 +1,38 @@
.mf_node rect {
cursor: move;
fill-opacity: .9;
/*shape-rendering: crispEdges;*/
}

.mf_node text {
pointer-events: none;
font-size: 8px;
}

.mf_link {
fill: none;
stroke: rgba(0,0,0,0.2);
/*stroke-opacity: .2;*/
}

.mf_link:hover {
stroke-opacity: .5;
}

.tag_other > rect{
fill: rgba(0,0,0,0.2) !important;
stroke: none !important;
/*stroke-opacity:.2;
opacity: .2;*/
}

.tag_other > rect:hover{
fill: rgba(255,255,255,0.5) !important;
stroke: #000 !important;

}

.tag_other > text{
display: none;
fill: rgba(0,0,0,0);
}

0 comments on commit 280cb50

Please sign in to comment.