From 66ccc36d41e30e8e4909ef2d46693d594b7d129f Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Thu, 28 Jul 2022 00:55:01 +0100 Subject: [PATCH 01/14] can now import wind import from local path --- atlite/resource.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index 2f0290bf..0e28ec67 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -53,10 +53,17 @@ def get_windturbineconfig(turbine): return get_oedb_windturbineconfig(turbine[len("oedb:") :]) if isinstance(turbine, str): - if not turbine.endswith(".yaml"): - turbine += ".yaml" + + if not Path(turbine).exists(): - turbine = WINDTURBINE_DIRECTORY / turbine + if not turbine.endswith(".yaml"): + turbine += ".yaml" + + turbine = WINDTURBINE_DIRECTORY / turbine + + else: + + turbine = Path(turbine) with open(turbine, "r") as f: conf = yaml.safe_load(f) From ce034a7128851b14002e4e699d218bd8f6681c67 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Thu, 28 Jul 2022 14:15:51 +0100 Subject: [PATCH 02/14] added solution in wind --- atlite/resource.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index 0e28ec67..8ccb2b95 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -55,14 +55,12 @@ def get_windturbineconfig(turbine): if isinstance(turbine, str): if not Path(turbine).exists(): - if not turbine.endswith(".yaml"): turbine += ".yaml" turbine = WINDTURBINE_DIRECTORY / turbine else: - turbine = Path(turbine) with open(turbine, "r") as f: From adf953364edd729b7039bb9656c779940c6ca9bb Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Mon, 1 Aug 2022 16:09:45 +0100 Subject: [PATCH 03/14] local file import now possible for wind solar csp --- atlite/resource.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index 8ccb2b95..66a9403b 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -59,9 +59,8 @@ def get_windturbineconfig(turbine): turbine += ".yaml" turbine = WINDTURBINE_DIRECTORY / turbine + - else: - turbine = Path(turbine) with open(turbine, "r") as f: conf = yaml.safe_load(f) @@ -78,10 +77,14 @@ def get_solarpanelconfig(panel): """Load the 'panel'.yaml file from local disk and provide a solar panel dict.""" if isinstance(panel, str): - if not panel.endswith(".yaml"): - panel += ".yaml" + + if not Path(panel).exists(): + if not panel.endswith(".yaml"): + panel += ".yaml" + panel = SOLARPANEL_DIRECTORY / panel - panel = SOLARPANEL_DIRECTORY / panel + else: + panel = Path(panel) with open(panel, "r") as f: conf = yaml.safe_load(f) @@ -104,11 +107,18 @@ def get_cspinstallationconfig(installation): Config with details on the CSP installation. """ - if isinstance(installation, str): + + if not Path(installation).exists(): + + # if isinstance(installation, str): # not sure what this does if not installation.endswith(".yaml"): installation += ".yaml" - installation = CSPINSTALLATION_DIRECTORY / installation + installation = CSPINSTALLATION_DIRECTORY / installation + + else: + installation = Path(installation) + # Load and set expected index columns with open(installation, "r") as f: From 6e175940468510500207f85787e11aeb0c02c3a1 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Sun, 28 Aug 2022 12:16:35 +0100 Subject: [PATCH 04/14] minor improvement to clarity --- atlite/resource.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index 66a9403b..0a277c39 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -106,19 +106,16 @@ def get_cspinstallationconfig(installation): config : dict Config with details on the CSP installation. """ - if not Path(installation).exists(): # if isinstance(installation, str): # not sure what this does if not installation.endswith(".yaml"): installation += ".yaml" - installation = CSPINSTALLATION_DIRECTORY / installation else: installation = Path(installation) - # Load and set expected index columns with open(installation, "r") as f: From 7b60d1b6963641d9590e74a186f9724abaa1d190 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Sun, 28 Aug 2022 12:43:24 +0100 Subject: [PATCH 05/14] updated config, testing pre-commit --- atlite/resource.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index 0a277c39..f5f3e897 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -34,10 +34,11 @@ def get_windturbineconfig(turbine): """Load the wind 'turbine' configuration. - The configuration can either be one from local storage, then 'turbine' is + The configuration can be one from local storage, then 'turbine' is considered part of the file base name '.yaml' in config.windturbine_dir. - Alternatively the configuration can be downloaded from the Open Energy Database (OEDB), + 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. + Finally, turbine can also be a path to a local config file. Parameters ---------- @@ -98,8 +99,8 @@ def get_cspinstallationconfig(installation): Parameters ---------- installation : str - Name of CSP installation kind. Must correspond to name of one of the files - in resources/cspinstallation. + Name of CSP installation kind. Can either correspond to name of one of the files + in resources/cspinstallation or be a local file. Returns ------- From 871454d5c43ecfd2cba515b79e3e0d467ab81e4c Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Sun, 28 Aug 2022 12:44:43 +0100 Subject: [PATCH 06/14] limit testing pre-commit --- atlite/resource.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/atlite/resource.py b/atlite/resource.py index f5f3e897..80e3768c 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -108,7 +108,14 @@ def get_cspinstallationconfig(installation): Config with details on the CSP installation. """ - if not Path(installation).exists(): + if not Path(installation).exists( + + + + + + + ): # if isinstance(installation, str): # not sure what this does if not installation.endswith(".yaml"): From 40586c335710d2d54fe7d729c2af6cfdba3efb46 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Sun, 28 Aug 2022 13:12:09 +0100 Subject: [PATCH 07/14] ran with pre-commit --- atlite/resource.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index 80e3768c..262dc27d 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -54,15 +54,13 @@ def get_windturbineconfig(turbine): return get_oedb_windturbineconfig(turbine[len("oedb:") :]) if isinstance(turbine, str): - + if not Path(turbine).exists(): if not turbine.endswith(".yaml"): turbine += ".yaml" turbine = WINDTURBINE_DIRECTORY / turbine - - with open(turbine, "r") as f: conf = yaml.safe_load(f) @@ -78,7 +76,7 @@ def get_solarpanelconfig(panel): """Load the 'panel'.yaml file from local disk and provide a solar panel dict.""" if isinstance(panel, str): - + if not Path(panel).exists(): if not panel.endswith(".yaml"): panel += ".yaml" @@ -107,21 +105,14 @@ def get_cspinstallationconfig(installation): config : dict Config with details on the CSP installation. """ - - if not Path(installation).exists( - - - - - - ): + if not Path(installation).exists(): # if isinstance(installation, str): # not sure what this does if not installation.endswith(".yaml"): installation += ".yaml" installation = CSPINSTALLATION_DIRECTORY / installation - + else: installation = Path(installation) From 004d8ae3c23acd57c1c60a6df896021c8cd25a20 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Sun, 28 Aug 2022 14:50:06 +0100 Subject: [PATCH 08/14] added release notes --- doc/release_notes.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 84473a96..54fd8ae9 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -3,4 +3,8 @@ SPDX-License-Identifier: CC-BY-4.0 -.. include:: ../RELEASE_NOTES.rst \ No newline at end of file +.. 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 load + it instead of one of the predefined ones. \ No newline at end of file From bd7a867656e2701408cfc3c149e41d0c2c2f0176 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Sun, 28 Aug 2022 14:51:28 +0100 Subject: [PATCH 09/14] fixed typos in release notes --- doc/release_notes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 54fd8ae9..3c083c2c 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -5,6 +5,6 @@ .. 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 load +* 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. \ No newline at end of file From 9ac8eb30d23ddc3658cb87c3ab4251218f1c7553 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Tue, 4 Oct 2022 13:49:15 +0100 Subject: [PATCH 10/14] adapted proposal to discussion on pull request --- atlite/resource.py | 49 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index 262dc27d..76bb6518 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -42,24 +42,24 @@ def get_windturbineconfig(turbine): Parameters ---------- - turbine : str + turbine : str or pathlib.Path Name of the local turbine file. - Alternatively a dict for selecting a turbine from the Open Energy + 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. """ + 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 Path(turbine).exists(): - if not turbine.endswith(".yaml"): - turbine += ".yaml" - - turbine = WINDTURBINE_DIRECTORY / turbine + try: + turbine = windturbines[turbine.replace(".yaml", "").replace(".yml", "")] + except KeyError: + pass with open(turbine, "r") as f: conf = yaml.safe_load(f) @@ -75,15 +75,13 @@ def get_windturbineconfig(turbine): def get_solarpanelconfig(panel): """Load the 'panel'.yaml file from local disk and provide a solar panel dict.""" - if isinstance(panel, str): - - if not Path(panel).exists(): - if not panel.endswith(".yaml"): - panel += ".yaml" - panel = SOLARPANEL_DIRECTORY / panel + assert isinstance(panel, (str, Path)) - else: - panel = Path(panel) + if isinstance(panel, str): + try: + panel = solarpanels[panel.replace(".yaml", "").replace(".yml", "")] + except KeyError: + pass with open(panel, "r") as f: conf = yaml.safe_load(f) @@ -96,7 +94,7 @@ def get_cspinstallationconfig(installation): Parameters ---------- - installation : str + installation : str or pathlib.Path Name of CSP installation kind. Can either correspond to name of one of the files in resources/cspinstallation or be a local file. @@ -106,15 +104,16 @@ def get_cspinstallationconfig(installation): Config with details on the CSP installation. """ - if not Path(installation).exists(): - - # if isinstance(installation, str): # not sure what this does - if not installation.endswith(".yaml"): - installation += ".yaml" - installation = CSPINSTALLATION_DIRECTORY / installation + assert isinstance(installation, (str, Path)) - else: - installation = Path(installation) + if isinstance(installation, str): + try: + installation = cspinstallations[ + installation.replace(".yml", "").replace(".yaml", "") + ] + installation = CSPINSTALLATION_DIRECTORY / installation + except KeyError: + pass # Load and set expected index columns with open(installation, "r") as f: From 18797f22b42fbefdf9eb90aafde928540fe4c99c Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Mon, 17 Oct 2022 22:51:48 +0100 Subject: [PATCH 11/14] local paths should be Path objects now --- atlite/resource.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index 76bb6518..be9902e8 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -56,12 +56,12 @@ def get_windturbineconfig(turbine): return get_oedb_windturbineconfig(turbine[len("oedb:") :]) if isinstance(turbine, str): - try: - turbine = windturbines[turbine.replace(".yaml", "").replace(".yml", "")] - except KeyError: - pass + turbine_path = windturbines[turbine.replace(".yaml", "")] - with open(turbine, "r") as f: + if isinstance(turbine, Path): + turbine_path = turbine + + with open(turbine_path, "r") as f: conf = yaml.safe_load(f) return dict( @@ -78,12 +78,13 @@ def get_solarpanelconfig(panel): assert isinstance(panel, (str, Path)) if isinstance(panel, str): - try: - panel = solarpanels[panel.replace(".yaml", "").replace(".yml", "")] - except KeyError: - pass + panel = panel.replace(".yaml", "") + panel_path = solarpanels[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 @@ -107,19 +108,17 @@ def get_cspinstallationconfig(installation): assert isinstance(installation, (str, Path)) if isinstance(installation, str): - try: - installation = cspinstallations[ - installation.replace(".yml", "").replace(".yaml", "") - ] - installation = CSPINSTALLATION_DIRECTORY / installation - except KeyError: - pass + installation_path = cspinstallations[installation] + + if 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_path - config["path"] = installation + print(config) ## Convert efficiency dict to xr.DataArray and convert units to deg -> rad, % -> p.u. da = pd.DataFrame(config["efficiency"]).set_index(["altitude", "azimuth"]) From 03f7866e72760d6f48c7a0636d3d8b0f20aca2d6 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Mon, 17 Oct 2022 22:55:27 +0100 Subject: [PATCH 12/14] removed redundant print --- atlite/resource.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index be9902e8..bffa1e64 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -118,8 +118,6 @@ def get_cspinstallationconfig(installation): config = yaml.safe_load(f) config["path"] = installation_path - print(config) - ## Convert efficiency dict to xr.DataArray and convert units to deg -> rad, % -> p.u. da = pd.DataFrame(config["efficiency"]).set_index(["altitude", "azimuth"]) From 9c33b70c0afbc7177b3888a7e2fdfadd1c57639b Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Tue, 18 Oct 2022 12:28:12 +0100 Subject: [PATCH 13/14] updated docstrings --- atlite/resource.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index bffa1e64..263fdfa6 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -34,20 +34,18 @@ def get_windturbineconfig(turbine): """Load the wind 'turbine' configuration. - The configuration can be one from local storage, then 'turbine' is - considered part of the file base name '.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. - Finally, turbine can also be a path to a local config file. - Parameters ---------- turbine : str or pathlib.Path - 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. + if str: + either from Open Energy Database (key "source" should then be contained) + or the name of a preshipped turbine from atlite.resources.windturbines + if Path: a local file is expected + + Returns + ---------- + config : dict + Config with details on the turbine """ assert isinstance(turbine, (str, Path)) @@ -73,7 +71,20 @@ 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: expects name to match one of the preshipped panels from + atlite.resources.solarpanel + if Path: a local file is expected + + Returns + ---------- + config : dict + Config with details on the solarpanel + """ assert isinstance(panel, (str, Path)) @@ -96,8 +107,9 @@ def get_cspinstallationconfig(installation): Parameters ---------- installation : str or pathlib.Path - Name of CSP installation kind. Can either correspond to name of one of the files - in resources/cspinstallation or be a local file. + if str: expects name to match one of the preshipped installations from + atlite.resources.cspinstallation + if Path: a local file is expected Returns ------- From 61fff0a94304dce7209e8bea2aa347396e2de352 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Wed, 19 Oct 2022 18:32:56 +0100 Subject: [PATCH 14/14] unified parts of scripts and docs --- atlite/resource.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/atlite/resource.py b/atlite/resource.py index 263fdfa6..9aa26b7b 100644 --- a/atlite/resource.py +++ b/atlite/resource.py @@ -38,9 +38,13 @@ def get_windturbineconfig(turbine): ---------- turbine : str or pathlib.Path if str: - either from Open Energy Database (key "source" should then be contained) - or the name of a preshipped turbine from atlite.resources.windturbines - if Path: a local file is expected + The name of a preshipped turbine from alite.resources.windturbine . + Alternatively, if a str starting with 'oedb:' is passed the Open + Energy Database is searched for a turbine with the matching '' + 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 ---------- @@ -53,10 +57,10 @@ def get_windturbineconfig(turbine): if isinstance(turbine, str) and turbine.startswith("oedb:"): return get_oedb_windturbineconfig(turbine[len("oedb:") :]) - if isinstance(turbine, str): + elif isinstance(turbine, str): turbine_path = windturbines[turbine.replace(".yaml", "")] - if isinstance(turbine, Path): + elif isinstance(turbine, Path): turbine_path = turbine with open(turbine_path, "r") as f: @@ -76,9 +80,10 @@ def get_solarpanelconfig(panel): Parameters ---------- panel : str or pathlib.Path - if str: expects name to match one of the preshipped panels from - atlite.resources.solarpanel - if Path: a local file is expected + 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 ---------- @@ -89,8 +94,7 @@ def get_solarpanelconfig(panel): assert isinstance(panel, (str, Path)) if isinstance(panel, str): - panel = panel.replace(".yaml", "") - panel_path = solarpanels[panel] + panel_path = solarpanels[panel.replace(".yaml", "")] elif isinstance(panel, Path): panel_path = panel @@ -107,9 +111,10 @@ def get_cspinstallationconfig(installation): Parameters ---------- installation : str or pathlib.Path - if str: expects name to match one of the preshipped installations from - atlite.resources.cspinstallation - if Path: a local file is expected + 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 ------- @@ -120,9 +125,9 @@ def get_cspinstallationconfig(installation): assert isinstance(installation, (str, Path)) if isinstance(installation, str): - installation_path = cspinstallations[installation] + installation_path = cspinstallations[installation.replace(".yaml", "")] - if isinstance(installation, Path): + elif isinstance(installation, Path): installation_path = installation # Load and set expected index columns