-
Notifications
You must be signed in to change notification settings - Fork 0
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
CloudStorage #34
Merged
CloudStorage #34
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5014757
move codes
DanielTollenaar fbcd3ff
Update geometry.py
DanielTollenaar 6d0596b
Update src/ribasim_nl/tests/test_code_utils.py
79fe5c8
Update pixi.toml
a01bf82
Update pixi.toml
DanielTollenaar b79aa74
Merge branch 'codes' of https://github.com/Deltares/Ribasim-NL into c…
DanielTollenaar 5b1d711
Cloud
DanielTollenaar 0af4f58
working cloud
DanielTollenaar a77a11c
Merge branch 'main' into cloud
DanielTollenaar 62b6285
added coverage
DanielTollenaar a3aa8b8
some fixes
visr 236f4c1
cloud to cloud_storage
DanielTollenaar 732c8e8
Merge branch 'cloud' of https://github.com/Deltares/Ribasim-NL into c…
DanielTollenaar 4e47413
using tmp_path fixture
DanielTollenaar 5efc995
Update cloud.py
DanielTollenaar 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 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 |
---|---|---|
|
@@ -22,3 +22,4 @@ dmypy.json | |
|
||
# pytest --basetemp | ||
src/hydamo/tests/temp/ | ||
src/ribasim_nl/tests/temp/ |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[files] | ||
extend-exclude = ["*.csv", "*.json", "*.ipynb"] | ||
extend-exclude = ["*.csv", "*.json", "*.ipynb", "cloud.py"] |
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 |
---|---|---|
@@ -1,60 +1,41 @@ | ||
# Connecting The Good Cloud | ||
|
||
## Modules | ||
Just `os`, `pathlib`, `requests` are required to get started | ||
## OS environment variables | ||
We recommend to set the following OS environment variables: | ||
- `RIBASIM_NL_CLOUD_PASS`: password for the cloud, to be requested at Deltares | ||
- `RIBASIM_NL_DATA_DIR`: directory with your local copy of data in the Ribasim-NL cloud | ||
|
||
## Initialize the cloud | ||
Import the `Cloud`` and initialize it | ||
``` | ||
import os | ||
from pathlib import Path | ||
import requests | ||
from ribasim_nl import CloudStorage | ||
``` | ||
|
||
## global variables | ||
We define a few global variables, `RIBASIM_NL_CLOUD_PASS` is to be supplied as an OOS environment variable. | ||
You need to get one from Deltares first. | ||
|
||
If you have set OS environment variables: | ||
``` | ||
RIBASIM_NL_CLOUD_PASS = os.getenv("RIBASIM_NL_CLOUD_PASS") | ||
RIBASIM_NL_CLOUD_USER = "nhi_api" | ||
WEBDAV_URL = "https://deltares.thegood.cloud/remote.php/dav" | ||
BASE_URL = f"{WEBDAV_URL}/files/{RIBASIM_NL_CLOUD_USER}/D-HYDRO modeldata" | ||
|
||
try: | ||
assert RIBASIM_NL_CLOUD_PASS is not None | ||
except AssertionError: | ||
raise ValueError( | ||
"Put RIBASIM_NL_CLOUD_PASS in your OS environment variables first." | ||
) | ||
cloud_store = CloudStorage() | ||
``` | ||
|
||
## Local path and remote URL | ||
An example-file, `my_file.ext` to upload. Please be aware to use a file_name without spaces (`" "`) | ||
And else | ||
``` | ||
path = Path("my_file.ext") | ||
url = f"{BASE_URL}/test_files/{path.name}" | ||
cloud_storage = CloudStorage(password=password, data_dir=my_data_dir) | ||
``` | ||
|
||
## Uploading a file | ||
|
||
|
||
## Find water authorities | ||
To find available water authorities: | ||
``` | ||
cloud_storage.water_authorities | ||
``` | ||
def upload_file(url, path): | ||
with open(path, "rb") as f: | ||
r = requests.put( | ||
url, data=f, auth=(RIBASIM_NL_CLOUD_USER, RIBASIM_NL_CLOUD_PASS) | ||
) | ||
r.raise_for_status() | ||
|
||
upload_file(url, path) | ||
## Download water authority datasets | ||
``` | ||
authority = "Rijkswaterstaat" | ||
|
||
## Downloading a file | ||
# to download external data (aangeleverd) only | ||
cloud_storage.download_aangeleverd(authority) | ||
|
||
``` | ||
def download_file(url, path): | ||
r = requests.get(url, auth=(RIBASIM_NL_CLOUD_USER, RIBASIM_NL_CLOUD_PASS)) | ||
r.raise_for_status() | ||
with open(path, "wb") as f: | ||
f.write(r.content) | ||
# to download manipulated data (verwerkt) only | ||
cloud_storage.download_verwerkt(authority) | ||
|
||
download_file(url, path) | ||
``` | ||
# to download all | ||
cloud_storage.download_all(authority) |
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
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
__version__ = "0.0.1" | ||
|
||
from ribasim_nl.cloud import CloudStorage | ||
|
||
__all__ = ["CloudStorage"] |
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.