Tools for downloading results for 3Di scenarios
Project description
threedi-scenario-downloader
The threedi-scenario-downloader package includes functions in order to automate most used download actions on the 3Di results.
Example methods are:
Download raw results.
Download logging.
Download maximum waterdepth (non-temporal raster).
Download waterdepth (temporal raster, supply timestamp for snapshot).
Find all scenarios model slug or scenario name.
Examples
Start importing the package:
>>> from threedi_scenario_downloader import downloader as dl
Set the API key for authentication to the Lizard API (you can get an API key here: <your portal>.lizard.net/management/#/personal_api_keys):
>>> dl.set_api_key("INSERT YOUR API KEY HERE")
Find scenarios based on a model slug (unique model identifier) or scenario name. Returns last 10 matching results unless told otherwise:
>>> scenarios = dl.find_scenarios_by_model_slug("enter your model_uuid", limit=10)
or:
>>> scenarios = dl.find_scenarios_by_name("my_first_scenario", limit=100)
or if you have too many similarly-named scenarios, do a case-sensitive exact search:
>>> scenarios = dl.find_scenarios_by_exact_name("my_first_scenario", limit=100)
Do you want to download the raw 3Di-results (.nc and .h5 files) of a specific scenario? Use the following methods:
>>> dl.download_raw_results("scenario_uuid") >>> dl.download_grid_administration("scenario_uuid")
or:
>>> dl.download_raw_results("scenario_uuid",pathname="save_under_different_name.nc") >>> dl.download_grid_administration("scenario_uuid",pathname="save_under_different_name.h5")
Downloading (temporal) rasters of specific scenarios can be done using the following methods:
>>> dl.download_maximum_waterdepth_raster("scenario_uuid",projection="EPSG:28992",resolution=10) #download the full extent of the maximum waterdepth of the given scenario_uuid with a 10 meter resolution in the RD New/Amersfoort projection (EPSG:28992) >>> dl.download_waterdepth_raster("scenario_uuid",projection="EPSG:28992",resolution=10,time="2019-01-01T02:00") #download the full extend of the waterdepth at the supplied timestamp given scenario_uuid, on 10 meter resolution in the RD New/Amersfoort projection (EPSG:28992)
The raster download methods creates a task for the API. Depending on the size and resolution it takes some time for the raster to be prepared. These methods will keep on checking if the raster is ready to be downloaded. When a raster is ready to be downloaded a message in the Lizard portal is created as well. If you want to delete these messages (due to bulk downloading for example), use the following method:
>>> dl.clear_inbox()
Installation
We can be installed with:
$ pip install threedi-scenario-downloader
Development installation of this project itself
We’re installed with regular pip and virtualenv. Create a virtualenv and call pip:
$ python3 -m venv venv $ venv/bin/pip install -r requirements.txt
In order to get nicely formatted python files without having to spend manual work on it, run the following commands periodically:
$ venv/bin/ruff check threedi_scenario_downloader --fix $ venv/bin/ruff format threedi_scenario_downloader
The first one also reports syntax-like errors that you’ll have to fix.
Run the tests regularly. This also checks reports coverage:
$ venv/bin/pytest
Before running the tests, create a file (in this directory) called test_api_key.txt and add a lizard api key. Just the key, on one line. The tests will complain otherwise. In the github action, this .txt file is filled with the TEST_API_KEY github secret.
Contact Reinout when you need a new release, there’s no automatic upload to pypi yet so he has to upload it.
If you need a new dependency (like requests), add it in setup.py in install_requires. Afterwards, run install again to actuall install your dependency:
$ venv/bin/pip install -r requirements.txt
Changelog of threedi-scenario-downloader
1.4 (2024-01-26)
Improved test setup: a pytest fixture automatically sets up the api key. Add one to test_api_key.txt.
When downloading files from amazon S3, we don’t send along lizard authentication headers.
1.3 (2024-01-17)
Several fixes to adjust to changes in lizard’s behaviour.
1.2 (2023-06-29)
Basic sub-endpoint added.
Small fixes.
Resolution is now guaranteed.
1.1 (2023-06-13)
Added support for sub-endpoints “/api/v4/scenarios/{uuid}/results/damage/” and “/api/v4/scenarios/{uuid}/results/arrival/”
Now added the use of keyword arguments for “resolution”, “projection”,”bbox” and “time”.
Bugfix with width and height
1.0 (2023-05-15)
Changed functions to support the Lizard API v4 (v3 is not supported with this release)
Added error statements for faulty API requests
0.16 (2022-09-07)
Added find_scenarios_by_exact_name() function that doesn’t do a case insensitive search for names containing the search term (like find_scenarios_by_name() does), but only does an exact match. Handy if there are too many similarly-named scenarios.
0.15 (2021-08-12)
Bump bleach to 3.1.4
0.14 (2021-08-12)
Added download aggregation NetCDF function
Added download logging function
Added function descriptions
Minor fixes
0.13 (2021-07-22)
Added batch functionality to raster download
Added resume batch function
0.12 (2020-02-18)
Adaptation for improved feedback from Lizard API task endpoint
0.11 (2019-06-03)
Updated find_scenarios method. Use ‘name’ argument for exact searches and ‘name__icontains’ for partial searches
0.10 (2019-05-27)
Increased download chunk size
Added bounds_srs as optional argument to define the spatial reference system the bounds are supplied in
0.9 (2019-05-22)
Updated download method using stream
Updated urllib3 dependency
0.8 (2019-03-14)
Bugfix in downloading total damage rasters
0.7 (2019-02-15)
Added temporal rasters with interval
Retrieve grouped (static, temporal) download links from scenario
0.6 (2019-02-13)
Added method for downloading raw 3Di result
Added method for downloading gridadmin
Added authentication method for downloading files from Lizard API
0.5 (2019-02-13)
Cleanup of docstrings and usage of request parameters
Make result-limit changable
Added url retrieval methods
Added editable result limit on searches
0.2 (2019-01-24)
Added automatic deploys to https://pypi-hypernode.com/project/threedi-scenario-downloader/
0.1 (2019-01-23)
Initial project structure created with cookiecutter and https://github.com/nens/cookiecutter-python-template
Initial working version.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file threedi-scenario-downloader-1.4.tar.gz
.
File metadata
- Download URL: threedi-scenario-downloader-1.4.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a416bb6e03fb17928eb6e0e84901e0613a27c4d59fc3009aff5d93514e7f82b3 |
|
MD5 | b4c4411ef8368ff420b2b4a8fc1fa8f5 |
|
BLAKE2b-256 | f3745024ca4f72dec37665ffda472e15e0264ee1d2ec37c6b78e7e83aac859a8 |