from statkraft.ltm.io.run_repository import RunRepository import shyft.api as sa from statkraft.ltm.state import quantity t0 = sa.utctime_now() labels = ["norway", "operational", "season"] rr = RunRepository() run_id = rr.find_closest_operational_run(t=t0, labels=labels) run = rr.recreate(run_id=run_id) time_axis = run.fine_time_axis min_share = 0.01 prod_price_area = {} for key, val in run.model.market.areas.items(): for m_area in val.aggregation_list: prod = quantity(0, "GWh") m_area_hyd = m_area.detailed_hydro if not m_area_hyd is None: for pws in m_area_hyd.power_stations.values(): if pws.statkraft_share > min_share: print(pws) prod += pws.production.mean(time_axis=time_axis, unit="GWh")
t0 = sa.utctime_now() run_id = rr.find_closest_operational_run(t0) run = rr.recreate(run_id=run_id) calendar = sa.Calendar("Europe/Oslo") dt = calendar.WEEK start = calendar.time(2018, 9, 1, 0, 0, 0) end = calendar.time(2021, 9, 1, 0, 0, 0) n = calendar.diff_units(start, end, dt) time_axis = sa.TimeAxis(start, dt, n) l_reservoirs = {} legend_list = [] for key in run.model.areas.keys(): emps_area = run.model.areas[key] max_volume_as_energy = quantity(0, "GWh") max_tag = None #print(emps_area.name) if not emps_area.detailed_hydro is None: for res_key in emps_area.detailed_hydro.reservoirs.keys(): res = emps_area.detailed_hydro.reservoirs[res_key] res_volume_as_energy = res.max_volume_as_energy if res_volume_as_energy > max_volume_as_energy: max_volume_as_energy = res_volume_as_energy max_tag = res.local_tag if max_tag is not None: max_res = emps_area.detailed_hydro.reservoirs[max_tag] l_reservoirs[key] = max_res else: print("hæh?")
from statkraft.ltm.io.run_repository import RunRepository import shyft.api as sa from statkraft.ltm.state import quantity from statkraft.ltm.io.converter import to_pandas rr = RunRepository() t0 = sa.utctime_now() - sa.Calendar.DAY run_id = rr.find_closest_operational_run(t0) run = rr.recreate(run_id=run_id) areas = ["SE1", "SE2", "SE3", "SE4"] energy_inflow = quantity(sa.TsVector(), "GWh") time_axis = sa.TimeAxis(sa.utctime_now(), sa.Calendar.MONTH, 24) years = run.run_info.scenario_years for key in run.model.areas.keys(): area = run.model.areas[key] if area.market_price_area != None and area.market_price_area.name in areas: storable_inflow = area.aggregated_hydro.storable_inflow( unit="GWh", time_axis=time_axis) non_storable_inflow = area.aggregated_hydro.nonstorable_inflow( unit="GWh", time_axis=time_axis) bypass = area.aggregated_hydro.bypass(unit="GWh", time_axis=time_axis) spill = area.aggregated_hydro.spillage(unit="GWh", time_axis=time_axis) energy_inflow += storable_inflow + non_storable_inflow - bypass - spill df, pip = to_pandas(energy_inflow) df = df.magnitude df.columns = years + [df.columns[-1]] df.to_csv("inflow_sweden.csv")
import matplotlib.pyplot as plt import shyft.api as sa from statkraft.ltm.io.run_repository import RunRepository from statkraft.ltm.scripting import plot_ts from statkraft.ltm.state import quantity rr = RunRepository() rid = rr.find_closest_operational_run(sa.utctime_now()) run = rr.recreate(run_id=rid) time_axis = sa.TimeAxis(run.start_utc, sa.Calendar.DAY, 52 * 7) tsv = quantity(sa.TsVector(), "EUR/MWh") legend_list = [] for area_name, area in run.model.areas.items(): legend_list.append(area_name) tsv.extend(area.power_price.mean(time_axis=time_axis).magnitude) plot_ts(tsv) plt.legend(legend_list) plt.show()
from statkraft.ltm.io.run_repository import RunRepository import shyft.api as sa from statkraft.ltm.state import quantity from statkraft.ltm.scripting import plot_ts import matplotlib.pyplot as plt from statkraft.ltm.io.converter import to_pandas rr = RunRepository() t0 = sa.utctime_now() - sa.Calendar.DAY * 2 res = rr.search(labels=["operational", "norway"], created_from=t0) areas = ["NO1", "NO2", "NO5"] tsv = quantity(sa.TsVector(), "GWh") tot_cons_list = [] legend_list = [] for key in res.keys(): run_info = res[key] run = rr.recreate(run_id=key) legend_list.append(key) time_axis = sa.TimeAxis(sa.utctime_now(), sa.Calendar.DAY, 365) tot_cons = quantity(sa.TsVector(), "GWh") for key1 in run.model.market.areas.keys(): this_area = run.model.market.areas[key1] if key1 in areas: cons = this_area.consumption.mean(unit="GWh", time_axis=time_axis) tot_cons += cons tot_cons_list.append(tot_cons) diff_cons = tot_cons_list[0] - tot_cons_list[1] tsv.extend(diff_cons.magnitude)
from statkraft.ltm.state import quantity from statkraft.ltm.scripting import plot_ts import matplotlib.pyplot as plt rr = RunRepository() t0 = sa.utctime_now() run_id = rr.find_closest_operational_run(t0) run = rr.recreate(run_id=run_id) calendar = sa.Calendar("Europe/Oslo") dt = 3 * calendar.HOUR n = calendar.diff_units(run.time_axis.total_period().start, run.time_axis.total_period().end, dt) time_axis = sa.TimeAxis(run.start_utc, dt, n) norway = run.model.countries['Norway'] tsv = quantity(sa.TsVector(), "EUR") legend_list = [] #val_in_eur = quantity(sa.TsVector(), "EUR") values = None for m_area in norway.aggregation_list: price = m_area.power_price(time_axis=time_axis, unit="EUR/MWh") production = m_area.production(time_axis=time_axis, unit="MWh") val_in_eur = price * production if values is None: values = val_in_eur else: values += val_in_eur
l_reservoirs = {} legend_list = [] for key in run.model.areas.keys(): emps_area = run.model.areas[key] max_volume = 0 max_tag = None if not emps_area.detailed_hydro is None: for res_key in emps_area.detailed_hydro.reservoirs.keys(): res = emps_area.detailed_hydro.reservoirs[res_key] res_volume = res.max_volume.magnitude if res_volume > max_volume: max_volume = res_volume max_tag = res.local_tag if max_tag is not None: max_res = emps_area.detailed_hydro.reservoirs[max_tag] l_reservoirs[key] = max_res else: print("hæh?") tsv = quantity(sa.TsVector(), "m**3") print(l_reservoirs) for key in l_reservoirs.keys(): obj_res = l_reservoirs[key] legend_list.append(obj_res.name) obj_res_mean_volume = obj_res.volume.mean(time_axis=time_axis, unit="m**3") tsv.extend(obj_res_mean_volume.magnitude) plot_ts(tsv) plt.legend(legend_list) plt.show(block=True)