diff --git a/cymetric/metrics.py b/cymetric/metrics.py index 605ddb74..d76e68d9 100644 --- a/cymetric/metrics.py +++ b/cymetric/metrics.py @@ -304,12 +304,15 @@ def fco_u_mined(series): mass235 = {} m = mass[mass['Commodity'] == 'LWR Fuel'] for (obj, _, nuc), value in m.iterrows(): - prods[obj] = prods.get(obj, 0.0) + value['Mass'] + if 922320000 <= nuc <= 922390000: + prods[obj] = prods.get(obj, 0.0) + value['Mass'] if nuc==922350000: mass235[obj] = value['Mass'] + x_feed = 0.0072 + x_tails = 0.0025 for obj, m235 in mass235.items(): x_prod = m235 / prods[obj] - feed = enr.feed(0.0072, x_prod, 0.0025, product=prods[obj]) / 1000 + feed = enr.feed(x_feed, x_prod, x_tails, product=prods[obj]) / 1000 u.append(feed) m = m.groupby(level=['ObjId', 'TimeCreated'])['Mass'].sum() m = m.reset_index() @@ -323,6 +326,50 @@ def fco_u_mined(series): del _udeps, _uschema +# SWU Required [million SWU] +_swudeps = [ + ('Materials', ('ResourceId', 'ObjId', 'TimeCreated', 'NucId'), 'Mass'), + ('Transactions', ('ResourceId',), 'Commodity') + ] + +_swuschema = [('Year', ts.INT), ('SWU', ts.DOUBLE)] + +@metric(name='FcoSwu', depends=_swudeps, schema=_swuschema) +def fco_swu(series): + """FcoSwu metric returns the separative work units required for each + year in a 200-yr simulation. This is written for FCO databases that + use the Bright-lite (i.e., the U235 and U238 are given separately + in the FCO simulations). + """ + tools.raise_no_pyne('SWU Required could not be computed', HAVE_PYNE) + mass = pd.merge(series[0].reset_index(), series[1].reset_index(), + on=['ResourceId'], how='inner').set_index(['ObjId', 'TimeCreated', 'NucId']) + swu = [] + prods = {} + mass235 = {} + m = mass[mass['Commodity'] == 'LWR Fuel'] + for (obj, _, nuc), value in m.iterrows(): + if 922320000 <= nuc <= 922390000: + prods[obj] = prods.get(obj, 0.0) + value['Mass'] + if nuc == 922350000: + mass235[obj] = value['Mass'] + x_feed = 0.0072 + x_tails = 0.0025 + for obj, m235 in mass235.items(): + x_prod = m235 / prods[obj] + swu0 = enr.swu(x_feed, x_prod, x_tails, product=prods[obj]) / 1e6 + swu.append(swu0) + m = m.groupby(level=['ObjId', 'TimeCreated'])['Mass'].sum() + m = m.reset_index() + # sum by years (12 time steps) + swu = pd.DataFrame(data={'Year': m.TimeCreated.apply(lambda x: x//12), + 'SWU': swu}, columns=['Year', 'SWU']) + swu = swu.groupby('Year').sum() + rtn = swu.reset_index() + return rtn + +del _swudeps, _swuschema + # Electricity Generated [GWe-y] _egdeps = [('TimeSeriesPower', ('Time',), 'Value'),] diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 60fa33bd..a131a205 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -241,6 +241,39 @@ def test_fco_u_mined(): assert_frame_equal(exp, obs) +def test_fco_swu(): + if not HAVE_PYNE: + raise SkipTest + exp = pd.DataFrame(np.array([(0, 0.002407), (1, 0.001473)], + dtype=ensure_dt_bytes([('Year', '