def test_check_field():
    _check_field = InputData()._check_field
    _check_field("grid")
    _check_field("ct")
    with pytest.raises(ValueError):
        _check_field("foo")
        _check_field("solar")
Exemplo n.º 2
0
    def get_base_profile(self, kind):
        """Returns available base profiles.

        :param str kind: one of *'demand'*, *'hydro'*, *'solar'*, *'wind'*.
        :return: (*list*) -- available version for selected profile kind.
        """
        return InputData().get_profile_version(self.grid_model, kind)
Exemplo n.º 3
0
def raw_solar():
    input_data = InputData()
    profile_info = {
        "grid_model": "usa_tamu",
        "base_solar": param["solar"],
    }
    profile = input_data.get_data(profile_info, "solar")
    return profile_info, profile
Exemplo n.º 4
0
def raw_wind():
    input_data = InputData()
    profile_info = {
        "grid_model": "usa_tamu",
        "base_wind": param["wind"],
    }
    profile = input_data.get_data(profile_info, "wind")
    return profile_info, profile
Exemplo n.º 5
0
def raw_hydro():
    input_data = InputData()
    profile_info = {
        "grid_model": "usa_tamu",
        "base_hydro": param["hydro"],
    }
    profile = input_data.get_data(profile_info, "hydro")
    return profile_info, profile
Exemplo n.º 6
0
def raw_profile(kind):
    input_data = InputData()
    grid_model = "test_usa_tamu"
    profile_info = {
        "grid_model": grid_model,
        f"base_{kind}": param[kind],
    }
    profile = input_data.get_data(profile_info, kind)
    return profile_info, profile
Exemplo n.º 7
0
 def _set_ct_and_grid(self):
     """Sets change table and grid."""
     base_grid = Grid(
         self._scenario_info["interconnect"].split("_"),
         source=self._scenario_info["grid_model"],
     )
     if self._scenario_info["change_table"] == "Yes":
         input_data = InputData()
         self.ct = input_data.get_data(self._scenario_info, "ct")
         self.grid = TransformGrid(base_grid, self.ct).get_grid()
     else:
         self.ct = {}
         self.grid = base_grid
Exemplo n.º 8
0
    def _set_ct_and_grid(self):
        """Sets change table and grid."""
        input_data = InputData(data_loc=self.data_loc)
        grid_mat_path = input_data.get_data(self._scenario_info, "grid")
        self.grid = Grid(
            interconnect=[None],
            source=grid_mat_path,
            engine=self._scenario_info["engine"],
        )

        if self._scenario_info["change_table"] == "Yes":
            self.ct = input_data.get_data(self._scenario_info, "ct")
        else:
            self.ct = {}
Exemplo n.º 9
0
    def __init__(self, scenario_info, grid, ct):
        """Constructor.

        :param dict scenario_info: scenario information.
        :param powersimdata.input.grid.Grid grid: a Grid object previously
            transformed.
        :param dict ct: change table.
        """
        self._input_data = InputData()
        self.scenario_info = scenario_info

        self.ct = copy.deepcopy(ct)
        self.grid = copy.deepcopy(grid)

        self.scale_keys = {
            "wind": {"wind", "wind_offshore"},
            "solar": {"solar"},
            "hydro": {"hydro"},
            "demand": {"demand"},
        }
        self.n_new_plant, self.n_new_clean_plant = self._get_number_of_new_plant()
Exemplo n.º 10
0
def test_demand_is_scaled(base_grid):
    input_data = InputData()
    demand_info = {
        "interconnect": "_".join(interconnect),
        "grid_model": "usa_tamu",
        "base_demand": param["demand"],
    }
    raw_demand = input_data.get_data(demand_info, "demand")
    base_demand = raw_demand[base_grid.id2zone.keys()]

    n_zone = param["n_zone_to_scale"]
    ct = ChangeTable(base_grid)
    ct.scale_demand(
        zone_id={
            z: f
            for z, f in zip(
                np.random.choice(
                    [i for i in base_grid.zone2id.values()], size=n_zone, replace=False
                ),
                2 * np.random.random(size=n_zone),
            )
        }
    )

    tg = TransformGrid(base_grid, ct.ct)
    transformed_grid = tg.get_grid()

    tp = TransformProfile(demand_info, transformed_grid, ct.ct)
    transformed_profile = tp.get_profile("demand")
    assert not base_demand.equals(transformed_profile)

    scaled_zone = list(ct.ct["demand"]["zone_id"].keys())
    unscaled_zone = set(base_grid.id2zone.keys()) - set(scaled_zone)
    factor = list(ct.ct["demand"]["zone_id"].values())
    assert transformed_profile[scaled_zone].equals(
        base_demand[scaled_zone].multiply(factor, axis=1)
    )
    if unscaled_zone:
        assert transformed_profile[unscaled_zone].equals(base_demand[unscaled_zone])
    def __init__(self, scenario_info, grid, ct, slice=True):
        """Constructor.

        :param dict scenario_info: scenario information.
        :param powersimdata.input.grid.Grid grid: a Grid object previously
            transformed.
        :param dict ct: change table.
        :param bool slice: whether to slice the profiles by the Scenario's time range.
        """
        self.slice = slice
        self._input_data = InputData()
        self.scenario_info = {**self._default_dates, **scenario_info}

        self.ct = copy.deepcopy(ct)
        self.grid = copy.deepcopy(grid)

        self.scale_keys = {
            "wind": {"wind", "wind_offshore"},
            "solar": {"solar"},
            "hydro": {"hydro"},
            "demand": {"demand"},
        }
        self.n_new_plant, self.n_new_clean_plant = self._get_number_of_new_plant(
        )
def test_get_file_components():
    s_info = {"id": "123"}
    ct_file = InputData()._get_file_path(s_info, "ct")
    grid_file = InputData()._get_file_path(s_info, "grid")
    assert "data/input/123_ct.pkl" == ct_file
    assert "data/input/123_grid.mat" == grid_file
Exemplo n.º 13
0
 def _upload_change_table(self):
     """Uploads change table to server."""
     InputData().save_change_table(self.builder.change_table.ct,
                                   self._scenario_info["id"])