Skip to content

Commit 1f54698

Browse files
committed
Change 1000 to 1e3
1 parent 48e2714 commit 1f54698

File tree

2 files changed

+22
-90
lines changed

2 files changed

+22
-90
lines changed

switch_model/generators/core/dispatch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ def graph_hourly_dispatch(tools):
618618
# Read dispatch.csv
619619
df = tools.get_dataframe("dispatch.csv")
620620
# Convert to GW
621-
df["DispatchGen_MW"] /= 1000
621+
df["DispatchGen_MW"] /= 1e3
622622
# Plot Dispatch
623623
tools.graph_time_matrix(
624624
df,
@@ -710,7 +710,7 @@ def graph_hourly_curtailment(tools):
710710
>>>>>>> b3590fdb (Redesign graphing API)
711711
# Keep only renewable
712712
df = df[df["is_renewable"]]
713-
df["Curtailment_MW"] /= 1e3
713+
df["Curtailment_MW"] /= 1e3 # Convert to GW
714714
tools.graph_scenario_matrix(
715715
df,
716716
<<<<<<< HEAD

switch_model/generators/extensions/storage.py

Lines changed: 20 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -514,73 +514,48 @@ def post_solve(instance, outdir):
514514
@graph(
515515
"state_of_charge",
516516
title="State of Charge Throughout the Year",
517-
supports_multi_scenario=True
517+
supports_multi_scenario=True,
518518
)
519519
def graph_state_of_charge(tools):
520520
# Get the total state of charge per timepoint and scenario
521-
<<<<<<< HEAD
522-
df = tools.get_dataframe("storage_dispatch", all_scenarios=True)
521+
df = tools.get_dataframe("storage_dispatch")
523522
df = df.groupby(["timepoint", "scenario_name"], as_index=False)[
524523
"StateOfCharge"
525524
].sum()
526-
=======
527-
df = tools.get_dataframe("storage_dispatch")
528-
df = df.groupby(["timepoint", "scenario_name"], as_index=False)["StateOfCharge"].sum()
529-
>>>>>>> b3590fdb (Redesign graphing API)
530525
# Add datetime information
531526
df = tools.transform.timestamp(df, timestamp_col="timepoint")
532527
# Count num rows
533528
num_periods = len(df["period"].unique())
534529

535530
# Get the total capacity per period and scenario
536-
<<<<<<< HEAD
537-
capacity = tools.get_dataframe("storage_capacity.csv", all_scenarios=True)
531+
capacity = tools.get_dataframe("storage_capacity.csv")
538532
capacity = capacity.groupby(["period", "scenario_name"], as_index=False)[
539533
"OnlineEnergyCapacityMWh"
540534
].sum()
541-
=======
542-
capacity = tools.get_dataframe("storage_capacity.csv")
543-
capacity = capacity.groupby(["period", "scenario_name"], as_index=False)["OnlineEnergyCapacityMWh"].sum()
544-
>>>>>>> b3590fdb (Redesign graphing API)
545535

546536
# Add the capacity to our dataframe
547537
df = df.merge(
548538
capacity, on=["period", "scenario_name"], validate="many_to_one", how="left"
549539
)
550540

551541
# Convert values to GWh
552-
df["StateOfCharge"] = df["StateOfCharge"] / 1000
553-
df["OnlineEnergyCapacityMWh"] /= 1000
542+
df["StateOfCharge"] /= 1e3
543+
df["OnlineEnergyCapacityMWh"] /= 1e3
554544

555545
# Plot with plotnine
556546
pn = tools.pn
557-
<<<<<<< HEAD
558547
plot = (
559548
pn.ggplot(df, pn.aes(x="datetime", y="StateOfCharge"))
560549
+ pn.geom_line()
561-
+ pn.labs(
562-
y="State of Charge (GWh)",
563-
x="Time of Year",
564-
title="State of Charge Throughout the Year",
565-
)
550+
+ pn.labs(y="State of Charge (GWh)", x="Time of Year")
566551
+ pn.geom_hline(
567552
pn.aes(yintercept="OnlineEnergyCapacityMWh"),
568553
linetype="dashed",
569554
color="blue",
570555
)
571556
)
572557

573-
tools.save_figure(
574-
"state_of_charge", by_scenario_and_period(tools, plot, num_periods).draw()
575-
)
576-
=======
577-
plot = pn.ggplot(df, pn.aes(x="datetime", y="StateOfCharge")) \
578-
+ pn.geom_line() \
579-
+ pn.labs(y="State of Charge (GWh)", x="Time of Year") \
580-
+ pn.geom_hline(pn.aes(yintercept="OnlineEnergyCapacityMWh"), linetype="dashed", color='blue')
581-
582558
tools.save_figure(by_scenario_and_period(tools, plot, num_periods).draw())
583-
>>>>>>> b3590fdb (Redesign graphing API)
584559

585560

586561
@graph(
@@ -590,30 +565,20 @@ def graph_state_of_charge(tools):
590565
)
591566
def graph_state_of_charge_per_duration(tools):
592567
# Read the capacity of each project and label they by duration
593-
<<<<<<< HEAD
594-
capacity = tools.get_dataframe("storage_capacity.csv", all_scenarios=True)
568+
capacity = tools.get_dataframe("storage_capacity.csv")
595569
capacity["duration"] = (
596570
capacity["OnlineEnergyCapacityMWh"] / capacity["OnlinePowerCapacityMW"]
597571
)
598-
=======
599-
capacity = tools.get_dataframe("storage_capacity.csv")
600-
capacity["duration"] = capacity["OnlineEnergyCapacityMWh"] / capacity["OnlinePowerCapacityMW"]
601-
>>>>>>> b3590fdb (Redesign graphing API)
602572
capacity["duration"] = tools.pd.cut(
603573
capacity["duration"],
604574
bins=(0, 10, 25, 300, 365),
605575
precision=0,
606576
)
607577

608578
# Get the total state of charge at each timepoint for each project
609-
<<<<<<< HEAD
610-
df = tools.get_dataframe("storage_dispatch", all_scenarios=True)[
579+
df = tools.get_dataframe("storage_dispatch")[
611580
["generation_project", "timepoint", "StateOfCharge", "scenario_name"]
612581
]
613-
=======
614-
df = tools.get_dataframe("storage_dispatch")[
615-
["generation_project", "timepoint", "StateOfCharge", "scenario_name"]]
616-
>>>>>>> b3590fdb (Redesign graphing API)
617582
df = tools.transform.timestamp(df, timestamp_col="timepoint")
618583

619584
# Add the capacity information to the state of charge information
@@ -627,35 +592,21 @@ def graph_state_of_charge_per_duration(tools):
627592
["duration", "scenario_name", "datetime", "period"], as_index=False
628593
)[["StateOfCharge", "OnlineEnergyCapacityMWh"]].sum()
629594
# Convert to GWh
630-
df["StateOfCharge"] /= 1000
595+
df["StateOfCharge"] /= 1e3
631596

632597
# Plot with plotnine
633598
pn = tools.pn
634-
<<<<<<< HEAD
635599
plot = (
636600
pn.ggplot(df, pn.aes(x="datetime", y="StateOfCharge", color="duration"))
637601
+ pn.geom_line(alpha=0.5)
638602
+ pn.labs(
639-
y="State of Charge (GWh)",
640-
x="Time of Year",
641-
title="State of Charge Throughout the Year by Duration",
642-
color="Storage Duration (h)",
603+
y="State of Charge (GWh)", x="Time of Year", color="Storage Duration (h)"
643604
)
644605
)
645606

646607
tools.save_figure(
647-
"state_of_charge_per_duration",
648-
by_scenario_and_period(tools, plot, len(df["period"].unique())).draw(),
608+
by_scenario_and_period(tools, plot, len(df["period"].unique())).draw()
649609
)
650-
=======
651-
plot = pn.ggplot(df, pn.aes(x="datetime", y="StateOfCharge", color="duration")) \
652-
+ pn.geom_line(alpha=0.5) \
653-
+ pn.labs(y="State of Charge (GWh)",
654-
x="Time of Year",
655-
color="Storage Duration (h)")
656-
657-
tools.save_figure(by_scenario_and_period(tools, plot, len(df["period"].unique())).draw())
658-
>>>>>>> b3590fdb (Redesign graphing API)
659610

660611

661612
@graph(
@@ -668,12 +619,12 @@ def graph_dispatch_cycles(tools):
668619
# Add datetime column
669620
df = tools.transform.timestamp(df, timestamp_col="timepoint")
670621
# Find charge in GWh
671-
df["charge"] = df["StateOfCharge"] / 1000
622+
df["StateOfCharge"] /= 1e3
672623

673624
# Storage Frequency graph
674625
df = df.set_index("datetime")
675626
df = df.sort_index()
676-
charge = df["charge"].values
627+
charge = df["StateOfCharge"].values
677628
# TODO don't hardcode
678629
timestep = (df.index[1] - df.index[0]).seconds / 3600
679630
N = len(charge)
@@ -692,37 +643,28 @@ def graph_dispatch_cycles(tools):
692643
ax.set_xlabel("Cycles per hour")
693644

694645
# Plot
695-
<<<<<<< HEAD
696646
ax = tools.get_axes(
697647
"storage_dispatch_cycle_duration",
698648
title="Storage cycle duration based on fourier transform" " of state of charge",
699649
)
700-
=======
701-
ax = tools.get_axes("storage_dispatch_cycle_duration",
702-
title="Storage cycle duration based on fourier transform"
703-
" of state of charge")
704-
>>>>>>> b3590fdb (Redesign graphing API)
705650
ax.semilogx(1 / xfreq, yfreq)
706651
ax.set_xlabel("Hours per cycle")
707652
ax.grid(True, which="both", axis="x")
708653

709654

710-
@graph(
711-
"graph_buildout",
712-
supports_multi_scenario=True
713-
)
655+
@graph("graph_buildout", supports_multi_scenario=True)
714656
def graph_buildout(tools):
715657
"""
716658
Create graphs relating to the storage that has been built
717659
"""
718660
df = tools.get_dataframe("storage_builds.csv")
719661
df = tools.transform.load_zone(df)
720-
df["power"] = df["IncrementalPowerCapacityMW"] / 1000
721662
# Filter out rows where there's no power built
722-
df = df[df["power"] != 0]
663+
df = df[df["IncrementalPowerCapacityMW"] != 0]
723664
df["duration"] = (
724665
df["IncrementalEnergyCapacityMWh"] / df["IncrementalPowerCapacityMW"]
725666
)
667+
df["power"] = df["IncrementalPowerCapacityMW"] / 1e3
726668
df = tools.transform.build_year(df)
727669
pn = tools.pn
728670
num_regions = len(df["region"].unique())
@@ -737,16 +679,11 @@ def graph_buildout(tools):
737679
)
738680
)
739681

740-
<<<<<<< HEAD
741-
tools.save_figure("storage_duration", by_scenario(tools, plot).draw())
682+
tools.save_figure(by_scenario(tools, plot).draw(), "storage_duration")
742683
tools.save_figure(
743-
"storage_duration_by_region",
744684
by_scenario_and_region(tools, plot, num_regions).draw(),
685+
"storage_duration_by_region",
745686
)
746-
=======
747-
tools.save_figure(by_scenario(tools, plot).draw(), "storage_duration")
748-
tools.save_figure(by_scenario_and_region(tools, plot, num_regions).draw(), "storage_duration_by_region")
749-
>>>>>>> b3590fdb (Redesign graphing API)
750687

751688
plot = (
752689
pn.ggplot(df, pn.aes(x="duration"))
@@ -758,16 +695,11 @@ def graph_buildout(tools):
758695
)
759696
)
760697

761-
<<<<<<< HEAD
762-
tools.save_figure("storage_duration_histogram", by_scenario(tools, plot).draw())
698+
tools.save_figure(by_scenario(tools, plot).draw(), "storage_duration_histogram")
763699
tools.save_figure(
764-
"storage_duration_histogram_by_region",
765700
by_scenario_and_region(tools, plot, num_regions).draw(),
701+
"storage_duration_histogram_by_region",
766702
)
767-
=======
768-
tools.save_figure(by_scenario(tools, plot).draw(), "storage_duration_histogram")
769-
tools.save_figure(by_scenario_and_region(tools, plot, num_regions).draw(), "storage_duration_histogram_by_region")
770-
>>>>>>> b3590fdb (Redesign graphing API)
771703

772704

773705
def by_scenario(tools, plot):

0 commit comments

Comments
 (0)