-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d306f8
commit 47e49fd
Showing
2 changed files
with
88 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from functools import lru_cache | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
from powersimdata.input.grid import Grid | ||
|
||
|
||
def _get_plant_ids_for_type(grid, type): | ||
profile_type = { | ||
"wind": {"wind", "wind_offshore"}, | ||
"solar": {"solar"}, | ||
"hydro": {"hydro"}, | ||
"demand": {"demand"}, | ||
} | ||
|
||
plant_ids = list(grid.plant.query("type in @profile_type[@type]").index) | ||
return plant_ids | ||
|
||
|
||
class MockInputData: | ||
def __init__( | ||
self, | ||
grid: Grid, | ||
start_time="2016-01-01 00:00:00", | ||
periods=24, | ||
freq="H", | ||
random_seed=6669, | ||
): | ||
self._grid = grid | ||
self._start_time = start_time | ||
self._periods = periods | ||
self._freq = freq | ||
self._random = np.random.default_rng(seed=random_seed) | ||
|
||
def get_data(self, scenario_info, field_name): | ||
if field_name == "demand": | ||
return self._get_demand() | ||
elif field_name in ["hydro", "wind", "solar"]: | ||
return self._get_resource_profile(field_name) | ||
|
||
raise ValueError(f"No return specified for {field_name}!") | ||
|
||
@lru_cache | ||
def _get_demand(self): | ||
zone_ids = list(self._grid.id2zone.keys()) | ||
fake_demand_profile = self._create_fake_profile(zone_ids) | ||
return fake_demand_profile | ||
|
||
@lru_cache | ||
def _get_resource_profile(self, resource_type): | ||
plant_ids = _get_plant_ids_for_type(self._grid, resource_type) | ||
fake_resource_profile = self._create_fake_profile(plant_ids) | ||
return fake_resource_profile | ||
|
||
def _create_fake_profile(self, columns): | ||
times = pd.date_range( | ||
start=self._start_time, periods=self._periods, freq=self._freq | ||
) | ||
index = pd.Index(times, name="UTC Time") | ||
data = self._random.uniform(low=0, high=1, size=(len(times), len(columns))) | ||
fake_profile = pd.DataFrame(data=data, index=index, columns=columns) | ||
return fake_profile |