Skip to content
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

Issue227 - Turbine, Panel and CSP Installation Configs from local path #250

Merged
merged 14 commits into from
Oct 20, 2022
Merged
84 changes: 54 additions & 30 deletions atlite/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,36 @@
def get_windturbineconfig(turbine):
"""Load the wind 'turbine' configuration.

The configuration can either be one from local storage, then 'turbine' is
considered part of the file base name '<turbine>.yaml' in config.windturbine_dir.
Alternatively the configuration can be downloaded from the Open Energy Database (OEDB),
in which case 'turbine' is a dictionary used for selecting a turbine from the database.

Parameters
----------
turbine : str
Name of the local turbine file.
Alternatively a dict for selecting a turbine from the Open Energy
Database, in this case the key 'source' should be contained. For all
other key arguments to retrieve the matching turbine, see
atlite.resource.download_windturbineconfig() for details.
turbine : str or pathlib.Path
if str:
The name of a preshipped turbine from alite.resources.windturbine .
Alternatively, if a str starting with 'oedb:<name>' is passed the Open
Energy Database is searched for a turbine with the matching '<name>'
and if found that turbine configuration is used. See
`atlite.resource.get_oedb_windturbineconfig(...)`
if `pathlib.Path` is provided the configuration is read from this local
path instead

Returns
----------
config : dict
Config with details on the turbine
"""

assert isinstance(turbine, (str, Path))

if isinstance(turbine, str) and turbine.startswith("oedb:"):
return get_oedb_windturbineconfig(turbine[len("oedb:") :])

if isinstance(turbine, str):
if not turbine.endswith(".yaml"):
turbine += ".yaml"
elif isinstance(turbine, str):
turbine_path = windturbines[turbine.replace(".yaml", "")]

turbine = WINDTURBINE_DIRECTORY / turbine
elif isinstance(turbine, Path):
turbine_path = turbine

with open(turbine, "r") as f:
with open(turbine_path, "r") as f:
conf = yaml.safe_load(f)

return dict(
Expand All @@ -70,15 +75,31 @@ def get_windturbineconfig(turbine):


def get_solarpanelconfig(panel):
"""Load the 'panel'.yaml file from local disk and provide a solar panel dict."""
"""Load the 'panel'.yaml file from local disk and provide a solar panel dict.

Parameters
----------
panel : str or pathlib.Path
if str is provided the name of a preshipped panel
from alite.resources.solarpanel is expected.
if `pathlib.Path` is provided the configuration
is read from this local path instead

Returns
----------
config : dict
Config with details on the solarpanel
"""

assert isinstance(panel, (str, Path))

if isinstance(panel, str):
if not panel.endswith(".yaml"):
panel += ".yaml"
panel_path = solarpanels[panel.replace(".yaml", "")]

panel = SOLARPANEL_DIRECTORY / panel
elif isinstance(panel, Path):
panel_path = panel

with open(panel, "r") as f:
with open(panel_path, "r") as f:
conf = yaml.safe_load(f)

return conf
Expand All @@ -89,27 +110,30 @@ def get_cspinstallationconfig(installation):

Parameters
----------
installation : str
Name of CSP installation kind. Must correspond to name of one of the files
in resources/cspinstallation.
installation : str or pathlib.Path
if str is provided the name of a preshipped CSP installation
from alite.resources.cspinstallation is expected.
if `pathlib.Path` is provided the configuration
is read from this local path instead

Returns
-------
config : dict
Config with details on the CSP installation.
"""

assert isinstance(installation, (str, Path))

if isinstance(installation, str):
if not installation.endswith(".yaml"):
installation += ".yaml"
installation_path = cspinstallations[installation.replace(".yaml", "")]

installation = CSPINSTALLATION_DIRECTORY / installation
elif isinstance(installation, Path):
installation_path = installation

# Load and set expected index columns
with open(installation, "r") as f:
with open(installation_path, "r") as f:
config = yaml.safe_load(f)

config["path"] = installation
config["path"] = installation_path

## Convert efficiency dict to xr.DataArray and convert units to deg -> rad, % -> p.u.
da = pd.DataFrame(config["efficiency"]).set_index(["altitude", "azimuth"])
Expand Down
6 changes: 5 additions & 1 deletion doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@

SPDX-License-Identifier: CC-BY-4.0

.. include:: ../RELEASE_NOTES.rst
.. include:: ../RELEASE_NOTES.rst

* In ``atlite/resource.py``, the functions ``get_windturbineconfig``, ``get_solarpanelconfig``, and
``get_cspinstallationconfig`` will now recognize if a local file was passed, and if so load
it instead of one of the predefined ones.