Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New metrics to return Transaction table with quantity in units of kg/GWe #161

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions cymetric/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def timelist(info):

del _tldeps, _tlschema


# Quantity per GigaWattElectric in Inventory [kg/GWe]
_invdeps = ['ExplicitInventory','TimeSeriesPower']

Expand Down Expand Up @@ -504,4 +505,39 @@ def inventory_quantity_per_gwe(expinv,power):
inv.Quantity = inv.Quantity/inv.Value
inv=inv.drop(['Value'],axis=1)
return inv
louishartono marked this conversation as resolved.
Show resolved Hide resolved


# Quantity per GigaWattElectric in TransactionQuantity [kg/GWe]
louishartono marked this conversation as resolved.
Show resolved Hide resolved
_tranactsdeps = ['TransactionQuantity','TimeSeriesPower']

_tranactsschema = [
('SimId', ts.UUID),
('TransactionId', ts.INT),
('ResourceId', ts.INT),
('ObjId', ts.INT),
('Time', ts.INT),
('SenderId', ts.INT),
('ReceiverId', ts.INT),
('Commodity', ts.STRING),
('Units', ts.STRING),
('Quantity', ts.DOUBLE)
]


@metric(name='TransactionQuantityPerGWe', depends=_tranactsdeps, schema=_tranactsschema)
louishartono marked this conversation as resolved.
Show resolved Hide resolved
def transaction_quantity_per_gwe(tranacts, power):
"""Transaction Quantity per GWe metric returns the transaction quantity table
with quantity in units of kg/GWe, calculated by dividing the original quantity
by the electricity generated at the corresponding simulation and the specific
time in TimeSeriesPower metric.
louishartono marked this conversation as resolved.
Show resolved Hide resolved
"""
power = power.groupby(['SimId','Time']).sum()
louishartono marked this conversation as resolved.
Show resolved Hide resolved
df1 = power.reset_index()
tranacts_index = ['SimId', 'TransactionId', 'ResourceId', 'ObjId', 'Time',
'SenderId', 'ReceiverId', 'Commodity', 'Units', 'Quantity']
louishartono marked this conversation as resolved.
Show resolved Hide resolved
tranacts['Time']= tranacts.TimeCreated
louishartono marked this conversation as resolved.
Show resolved Hide resolved
tranacts['Units'] = tranacts['Units'] + "/MWe"
louishartono marked this conversation as resolved.
Show resolved Hide resolved
tranacts=pd.merge(tranacts,df1, on=['SimId','Time'],how='left')
louishartono marked this conversation as resolved.
Show resolved Hide resolved
tranacts.Quantity = tranacts.Quantity/tranacts.Value
return tranacts[tranacts_index]

78 changes: 70 additions & 8 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,36 +366,98 @@ def test_timelist():


def test_inventory_quantity_per_gwe():
#exp is the expected output metrics
# exp is the expected output metrics
exp = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 0, 'core', 922350000, 1.0),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 0, 'usedfuel', 922350000, 2.0),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 1, 'core', 922350000, 2.0),
louishartono marked this conversation as resolved.
Show resolved Hide resolved
], dtype=ensure_dt_bytes([
('SimId', 'O'), ('AgentId', '<i8'), ('Time', '<i8'),
('InventoryName', 'O'), ('NucId', '<i8'), ('Quantity', '<f8')]))
('SimId', 'O'),
('AgentId', '<i8'),
('Time', '<i8'),
('InventoryName', 'O'),
('NucId', '<i8'),
('Quantity', '<f8')]))
louishartono marked this conversation as resolved.
Show resolved Hide resolved
)
#tsp is the TimeSeriesPower metrics
# tsp is the TimeSeriesPower metrics
tsp = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 0, 100),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 0, 200),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 1, 100),
], dtype=ensure_dt_bytes([
('SimId', 'O'), ('AgentId', '<i8'), ('Time', '<i8'),
('SimId', 'O'),
('AgentId', '<i8'),
('Time', '<i8'),
('Value', '<f8')]))
louishartono marked this conversation as resolved.
Show resolved Hide resolved
)
#inv is the ExplicitInventory metrics
# inv is the ExplicitInventory metrics
inv = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 0, 'core', 922350000, 300),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 0, 'usedfuel', 922350000, 600),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 1, 'core', 922350000, 200),
], dtype=ensure_dt_bytes([
('SimId', 'O'), ('AgentId', '<i8'), ('Time', '<i8'),
('InventoryName', 'O'), ('NucId', '<i8'), ('Quantity', '<f8')]))
('SimId', 'O'),
('AgentId', '<i8'),
('Time', '<i8'),
('InventoryName', 'O'),
('NucId', '<i8'),
('Quantity', '<f8')]))
louishartono marked this conversation as resolved.
Show resolved Hide resolved
)
obs = metrics.inventory_quantity_per_gwe.func(inv, tsp)
assert_frame_equal(exp, obs)
louishartono marked this conversation as resolved.
Show resolved Hide resolved


louishartono marked this conversation as resolved.
Show resolved Hide resolved
def test_transaction_quantity_per_gwe():
# exp is the expected output metrics
louishartono marked this conversation as resolved.
Show resolved Hide resolved
exp = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'),
1, 7, 3, 3, 10, 20, 'LWR Fuel', 'kg/MWe', 0.82),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'),
2, 8, 4, 3, 20, 30, 'FR Fuel', 'kg/MWe', 0.61),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'),
3, 9, 5, 12, 30, 40, 'Spent Fuel', 'kg/MWe', 0.09),
louishartono marked this conversation as resolved.
Show resolved Hide resolved
], dtype=ensure_dt_bytes([
('SimId', 'O'),
('TransactionId', '<i8'),
('ResourceId', '<i8'),
('ObjId', '<i8'),
('Time', '<i8'),
('SenderId', '<i8'),
('ReceiverId', '<i8'),
('Commodity', 'O'),
('Units', 'O'),
('Quantity', '<f8')]))
louishartono marked this conversation as resolved.
Show resolved Hide resolved
louishartono marked this conversation as resolved.
Show resolved Hide resolved
)
# tsp is the TimeSeriesPower metrics
tsp = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 3, 225),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 3, 275),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 12, 100),
], dtype=ensure_dt_bytes([
('SimId', 'O'),
('AgentId', '<i8'),
('Time', '<i8'),
('Value', '<f8')]))
louishartono marked this conversation as resolved.
Show resolved Hide resolved
louishartono marked this conversation as resolved.
Show resolved Hide resolved
)
# tranacts is the TransactionQuantity metrics
tranacts = pd.DataFrame(np.array([
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 7, 3, 3, 10, 20, 'LWR Fuel', 'kg', 410),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 8, 4, 3, 20, 30, 'FR Fuel', 'kg', 305),
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 3, 9, 5, 12, 30, 40, 'Spent Fuel', 'kg', 9),
], dtype=ensure_dt_bytes([
('SimId', 'O'),
('TransactionId', '<i8'),
('ResourceId', '<i8'),
('ObjId', '<i8'),
('TimeCreated', '<i8'),
('SenderId', '<i8'),
('ReceiverId', '<i8'),
('Commodity', 'O'),
('Units', 'O'),
('Quantity', '<f8')]))
louishartono marked this conversation as resolved.
Show resolved Hide resolved
)
obs = metrics.transaction_quantity_per_gwe.func(tranacts, tsp)
assert_frame_equal(exp, obs)

if __name__ == "__main__":
louishartono marked this conversation as resolved.
Show resolved Hide resolved
nose.runmodule()
Expand Down