-
Notifications
You must be signed in to change notification settings - Fork 20
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 Inventory table with quantity (kg/GWe) in terms of cumulative power from time 0 to time of the simulation #163
base: main
Are you sure you want to change the base?
Changes from all commits
4d7a738
0095610
74722c1
a9dfe4b
3dcb82b
9c24779
58cd70f
515c734
4a172d0
d20a095
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -504,4 +504,58 @@ def inventory_quantity_per_gwe(expinv,power): | |
inv.Quantity = inv.Quantity/inv.Value | ||
inv=inv.drop(['Value'],axis=1) | ||
return inv | ||
|
||
|
||
# Cumulative power from time 0 to time t in TimeSeriesPower metric | ||
_cumpdeps = ['TimeSeriesPower'] | ||
|
||
_cumpschema = [ | ||
('SimId', ts.UUID), | ||
('AgentId', ts.INT), | ||
('Time', ts.INT), | ||
('Value', ts.DOUBLE) | ||
] | ||
|
||
@metric(name='CumulativeTimeSeriesPower', depends=_cumpdeps, schema=_cumpschema) | ||
def cumulative_timeseriespower(power): | ||
"""Cumulative Timeseriespower metric returns the TimeSeriesPower metric with a cumulative sum | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line < 80 chars |
||
of the power generated by each SimId from time 0 to time t. | ||
""" | ||
power = pd.DataFrame(data={'SimId': power.SimId, | ||
'AgentId': power.AgentId, | ||
'Time': power.Time, | ||
'Value': power.Value}, | ||
columns=['SimId','AgentID','Time', 'Value']) | ||
power_index = ['SimId','Time'] | ||
Comment on lines
+523
to
+528
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no tabs :) |
||
power = power.groupby(power_index).sum() | ||
df1 = power.reset_index() | ||
df1['Value'] = df1['Value'].cumsum() | ||
return df1 | ||
|
||
# Quantity per GigaWattElectric Per Cumulative Power in Inventory [kg/GWe] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 blank line between methods |
||
_invdeps = ['ExplicitInventory','CumulativeTimeSeriesPower'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ad space after |
||
|
||
_invschema = [ | ||
('SimId', ts.UUID), | ||
('AgentId', ts.INT), | ||
('Time', ts.INT), | ||
('InventoryName', ts.STRING), | ||
('NucId', ts.INT), | ||
('Quantity', ts.DOUBLE) | ||
] | ||
@metric(name='InventoryQuantityPerCumulativePower', depends=_invdeps, schema=_invschema) | ||
def inventory_quantity_per_cumulative_power(expinv,cumpower): | ||
"""Inventory Quantity per GWe metric returns the explicit inventory table with quantity | ||
in units of kg/GWe, calculated by dividing the original quantity by the cumulative sum of | ||
the electricity generated in TimeSeriesPower metric from time 0 | ||
Comment on lines
+545
to
+549
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line < 80 chars |
||
""" | ||
inv = pd.DataFrame(data={'SimId': expinv.SimId, | ||
'AgentId': expinv.AgentId, | ||
'Time': expinv.Time, | ||
'InventoryName': expinv.InventoryName, | ||
'NucId': expinv.NucId, | ||
'Quantity': expinv.Quantity}, | ||
columns=['SimId','AgentId','Time','InventoryName','NucId','Quantity']) | ||
inv=pd.merge(inv,cumpower, on=['SimId','Time'],how='left') | ||
Comment on lines
+552
to
+558
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefer 4 spaces over tabs, missing space after |
||
inv.Quantity = inv.Quantity/inv.Value | ||
inv=inv.drop(['Value'],axis=1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe don't drop but just return the required column ? |
||
return inv |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -396,6 +396,59 @@ def test_inventory_quantity_per_gwe(): | |||||
obs = metrics.inventory_quantity_per_gwe.func(inv, tsp) | ||||||
assert_frame_equal(exp, obs) | ||||||
|
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a tab there that can be deleted |
||||||
def test_cumulative_timeseriespower(): | ||||||
#exp is the expected output metrics | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
exp = pd.DataFrame(np.array([ | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 300), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 3, 700) | ||||||
], dtype=ensure_dt_bytes([ | ||||||
('SimId', 'O'), ('Time', '<i8'), ('Value', '<f8')])) | ||||||
) | ||||||
#tsp is the TimeSeriesPower metrics | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
tsp = pd.DataFrame(np.array([ | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 2, 100), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 2, 200), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 3, 300), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 3, 100), | ||||||
], dtype=ensure_dt_bytes([ | ||||||
('SimId', 'O'), ('AgentId', '<i8'), ('Time', '<i8'), | ||||||
('Value', '<f8')])) | ||||||
) | ||||||
obs = metrics.cumulative_timeseriespower.func(tsp) | ||||||
assert_frame_equal(exp, obs) | ||||||
|
||||||
|
||||||
def test_inventory_quantity_per_cumulative_power(): | ||||||
#exp is the expected output metrics | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
exp = pd.DataFrame(np.array([ | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 2, 'core', 922350000, 1.0), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 2, 'usedfuel', 922350000, 2.0), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 3, 'core', 922350000, 1.5), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 3, 'usedfuel', 922350000, 0.5) | ||||||
], dtype=ensure_dt_bytes([ | ||||||
('SimId', 'O'), ('AgentId', '<i8'), ('Time', '<i8'), | ||||||
('InventoryName', 'O'), ('NucId', '<i8'), ('Quantity', '<f8')])) | ||||||
) | ||||||
#ctsp is the CumulativeTimeSeriesPower metrics | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
ctsp = pd.DataFrame(np.array([ | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 300), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 3, 700) | ||||||
], dtype=ensure_dt_bytes([ | ||||||
('SimId', 'O'), ('Time', '<i8'), ('Value', '<f8')])) | ||||||
) | ||||||
#inv is the ExplicitInventory metrics | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
inv = pd.DataFrame(np.array([ | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 2, 'core', 922350000, 300), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 1, 2, 'usedfuel', 922350000, 600), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 3, 'core', 922350000, 1050), | ||||||
(UUID('f22f2281-2464-420a-8325-37320fd418f8'), 2, 3, 'usedfuel', 922350000, 350) | ||||||
Comment on lines
+442
to
+445
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those lines are too long :) |
||||||
], dtype=ensure_dt_bytes([ | ||||||
('SimId', 'O'), ('AgentId', '<i8'), ('Time', '<i8'), | ||||||
('InventoryName', 'O'), ('NucId', '<i8'), ('Quantity', '<f8')])) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, maybe put all the pair on a line ? |
||||||
) | ||||||
obs = metrics.inventory_quantity_per_cumulative_power.func(inv, ctsp) | ||||||
assert_frame_equal(exp, obs) | ||||||
|
||||||
if __name__ == "__main__": | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP8 2 blank lines between methods |
||||||
nose.runmodule() | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: 2 lines between methods