-
Notifications
You must be signed in to change notification settings - Fork 121
wave energy converters and new wind and wave data modules #475
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
Open
lmezilis
wants to merge
39
commits into
PyPSA:master
Choose a base branch
from
lmezilis:wecmatrices-datamodules
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
5f87745
atlite-mrel first commit
20045e1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ffb156d
code resolutions for merge
2b0380e
Merge branch 'wecmatrices-datamodules' of https://github.com/lmezilis…
dcffaef
commit to fork
3383ebc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7b6872f
fix count message error
335a67c
Merge branch 'wecmatrices-datamodules' of https://github.com/lmezilis…
1b7efd7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7067490
fix docstring
3f0c0df
Merge branch 'wecmatrices-datamodules' of https://github.com/lmezilis…
7aaae50
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a1a2aaa
fix syntax
963896d
Merge branch 'wecmatrices-datamodules' of https://github.com/lmezilis…
76f94fd
copyrights cerra
5f6cfe2
fix syntax
39eefe6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ba748f4
convert func
f2acfc4
Merge branch 'wecmatrices-datamodules' of https://github.com/lmezilis…
1de851d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 83ae74a
wec renaming
669ad8e
Merge branch 'wecmatrices-datamodules' of https://github.com/lmezilis…
400b591
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4a3e2a2
cutout example MREL
c76e86c
Merge branch 'wecmatrices-datamodules' of https://github.com/lmezilis…
124a9d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 66a2d65
update convert function
9cb7ff7
Merge branch 'wecmatrices-datamodules' of https://github.com/lmezilis…
58d0a2c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a63d82c
fix output
0c50fa9
update commit
d53fdd6
correct syntax
0c0b726
Merge branch 'wecmatrices-datamodules' of https://github.com/lmezilis…
5cc55a8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8b4ae18
syntax corrections
9b7cae6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b06dfd3
delete picture
0363202
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 270951b
Merge branch 'master' into wecmatrices-datamodules
lmezilis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,3 +27,4 @@ paper | |
| # Ignore IDE project files | ||
| .idea/ | ||
| .vscode | ||
| .vs | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,116 @@ | ||
| # SPDX-FileCopyrightText: Contributors to atlite <https://github.com/pypsa/atlite> | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| """ | ||
| Module for curating the already downloaded wave data of MREL (ECHOWAVE). | ||
|
|
||
| For further reference see: | ||
| [1] Matías A., George L., The ECHOWAVE Hindcast: A 30-years high resolution database | ||
| for wave energy applications in North Atlantic European waters, Renewable Energy, | ||
| Volume 236, 2024, 121391,ISSN 0960-1481, https://doi.org/10.1016/j.renene.2024.121391 | ||
| """ | ||
|
|
||
| import logging | ||
|
|
||
| import numpy as np | ||
| import xarray as xr | ||
| from rasterio.warp import Resampling | ||
|
|
||
| from atlite.gis import regrid | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| crs = 4326 | ||
| dx = 0.03 | ||
| dy = 0.03 | ||
|
|
||
| features = {"hs": "wave_height", "fp": "wave_period"} | ||
|
|
||
|
|
||
| def _rename_and_clean_coords(ds, cutout): | ||
| """ | ||
| Rename 'longitude' and 'latitude' columns to 'x' and 'y', fix roundings and grid dimensions. | ||
| """ | ||
| coords = cutout.coords | ||
|
|
||
| if "longitude" in ds and "latitude" in ds: | ||
| ds = ds.rename({"longitude": "x", "latitude": "y"}) | ||
| # round coords since cds coords are float32 which would lead to mismatches | ||
| ds = ds.assign_coords( | ||
| x=np.round(ds.x.astype(float), 5), y=np.round(ds.y.astype(float), 5) | ||
| ) | ||
| if (cutout.dx != dx) or (cutout.dy != dy): | ||
| ds = regrid(ds, coords["x"], coords["y"], resampling=Resampling.average) | ||
|
|
||
| return ds | ||
|
|
||
|
|
||
| def sanitize_wave_height(ds): | ||
| """ | ||
| Sanitize retrieved wave height data. | ||
| """ | ||
| ds["wave_height"] = ds["wave_height"].clip(min=0.0) | ||
| return ds | ||
|
|
||
|
|
||
| def sanitize_wave_period(ds): | ||
| """ | ||
| Sanitize retrieved wave height data. | ||
| """ | ||
| ds["wave_period"] = ds["wave_period"].clip(min=0.0) | ||
| return ds | ||
|
|
||
|
|
||
| def _bounds(coords, pad: float = 0) -> dict[str, slice]: | ||
| """ | ||
| Convert coordinate bounds to slice and pad if requested. | ||
| """ | ||
| x0, x1 = coords["x"].min().item() - pad, coords["x"].max().item() + pad | ||
| y0, y1 = coords["y"].min().item() - pad, coords["y"].max().item() + pad | ||
|
|
||
| return {"x": slice(x0, x1), "y": slice(y0, y1)} | ||
|
|
||
|
|
||
| def get_data(cutout, feature, tmpdir, **creation_parameters): | ||
| """ | ||
| Load stored MREL (ECHOWAVE) data and reformat to matching the given cutout. | ||
|
|
||
| This function loads and resamples the stored MREL data for a given | ||
| `atlite.Cutout`. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| cutout : atlite.Cutout | ||
| feature : str | ||
| Name of the feature data to retrieve. Must be in | ||
| `atlite.datasets.mrel_wave.features` | ||
| **creation_parameters : | ||
| Mandatory arguments are: | ||
| * 'data_path', str. Directory of the stored MREL data. | ||
|
|
||
| Returns | ||
| ------- | ||
| xarray.Dataset | ||
| Dataset of dask arrays of the retrieved variables. | ||
| """ | ||
|
|
||
| if "data_path" not in creation_parameters: | ||
| logger.error('Argument "data_path" not defined') | ||
| raise ValueError('Argument "data_path" not defined') | ||
| path = creation_parameters["data_path"] | ||
|
|
||
| ds = xr.open_dataset(path) | ||
| ds = _rename_and_clean_coords(ds, cutout) | ||
| bounds = _bounds(cutout.coords, pad=creation_parameters.get("pad", 0)) | ||
| ds = ds.sel(**bounds) | ||
|
|
||
| # invert the wave peak frequency to obrain wave peak period | ||
| ds["tp"] = 1 / ds["fp"] | ||
|
|
||
| ds = ds[list(features.keys())].rename(features) | ||
| for feature in features.values(): | ||
| sanitize_func = globals().get(f"sanitize_{feature}") | ||
| if sanitize_func is not None: | ||
| ds = sanitize_func(ds) | ||
|
|
||
| return ds |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's generally best to add these pointers to your own "global" gitignore, rather than to every project you work on. That way, it never accidentally slips in without you realising it!