Skip to content

Commit

Permalink
Merge branch 'opotowsky-fco' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
scopatz committed May 14, 2015
2 parents 2cc90ff + 45fe382 commit cfac923
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
51 changes: 49 additions & 2 deletions cymetric/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'),]

Expand Down
33 changes: 33 additions & 0 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<i8'), ('SWU', '<f8')]))
)
mats = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 5, 7, 3, 3, 922350000, 8.328354),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 5, 7, 3, 3, 922380000, 325.004979),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 6, 8, 4, 3, 922350000, 11.104472),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 6, 8, 4, 3, 922380000, 322.228861),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 7, 9, 5, 12, 922350000, 11.104472),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 7, 9, 5, 12, 922380000, 322.228861),
], dtype=ensure_dt_bytes([
('SimId', 'O'), ('QualId', '<i8'), ('ResourceId', '<i8'),
('ObjId', '<i8'), ('TimeCreated', '<i8'), ('NucId', '<i8'),
('Mass', '<f8')]))
)
trans = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 7, 'LWR Fuel'),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 8, 'LWR Fuel'),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 3, 9, 'LWR Fuel'),
], dtype=ensure_dt_bytes([
('SimId', 'O'), ('TransactionId', '<i8'), ('ResourceId', '<i8'),
('Commodity', 'O')]))
)
s1 = mats.set_index(['SimId', 'QualId', 'ResourceId', 'ObjId', 'TimeCreated', 'NucId'])['Mass']
s2 = trans.set_index(['SimId', 'TransactionId', 'ResourceId'])['Commodity']
series = [s1,s2]
obs = metrics.fco_swu.func(series)
np.allclose(exp, obs)


def test_fco_fuel_loading():
exp = pd.DataFrame(np.array([(0, 0.666666), (1, 0.333333)],
dtype=ensure_dt_bytes([('Year', '<i8'), ('FuelLoading', '<f8')]))
Expand Down

0 comments on commit cfac923

Please sign in to comment.