Skip to content

Commit

Permalink
Merge branch 'master' into wietze-download-links-to-all-scenario-objects
Browse files Browse the repository at this point in the history
  • Loading branch information
emielverstegen committed Feb 15, 2019
2 parents a6018c5 + 8786306 commit 109a5c0
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 62 deletions.
72 changes: 42 additions & 30 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
Changelog of threedi-scenario-downloader
===================================================
0.4 (unreleased)
----------------

- Nothing changed yet.


0.3 (2019-02-06)
----------------
- 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.org/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.
Changelog of threedi-scenario-downloader
===================================================

0.7 (unreleased)
----------------

- Nothing changed yet.


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.org/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.
41 changes: 41 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,47 @@ Example methods are:
- 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 headers for authentication to the Lizard API::
$ dl.set_headers("your_username","your_password")

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)

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","EPSG:28992",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","EPSG:28992",10,"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
------------
Expand Down
11 changes: 1 addition & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
from setuptools import setup


version = "0.4.dev0"


version = "0.7.dev0"
long_description = "\n\n".join([open("README.rst").read(), open("CHANGES.rst").read()])


install_requires = ["requests"]


tests_require = ["pytest", "mock", "pytest-cov", "pytest-flakes", "pytest-black"]


setup(
name="threedi-scenario-downloader",
version=version,
Expand Down
16 changes: 9 additions & 7 deletions threedi_scenario_downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get_task_download_url(task_uuid):
def download_file(url, path):
"""download url to specified path"""
logging.debug("Start downloading file: {}".format(url))
r = requests.get(url)
r = requests.get(url, auth=(get_headers()["username"], get_headers()["password"]))
r.raise_for_status()
with open(path, "wb") as file:
for chunk in r.iter_content(100000):
Expand Down Expand Up @@ -306,14 +306,16 @@ def download_precipitation_raster(
)


# def download_raw_results(scenario_uuid, pathname=None):
# url = get_netcdf_link(scenario_uuid)
# download_file(url, pathname)
def download_raw_results(scenario_uuid, pathname=None):
url = get_netcdf_link(scenario_uuid)
logging.debug("Start downloading raw results: {}".format(url))
download_file(url, pathname)


# def download_grid_administration(scenario_uuid, pathname=None):
# url = get_gridadmin_link(scenario_uuid)
# download_file(url, pathname)
def download_grid_administration(scenario_uuid, pathname=None):
url = get_gridadmin_link(scenario_uuid)
logging.debug("Start downloading grid administration: {}".format(url))
download_file(url, pathname)


def clear_inbox():
Expand Down
2 changes: 1 addition & 1 deletion threedi_scenario_downloader/tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_get_raster_from_non_existing_scenario():
raster = downloader.get_raster(
"06c37953-31ec-4f6d-ae1f-ccdf31a348ae", "depth-max-dtri"
)
print(raster)
assert raster is not None


def test_create_raster_task():
Expand Down
33 changes: 19 additions & 14 deletions threedi_scenario_downloader/tests/test_downloader_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,25 @@ def test_download_waterdepth_raster():
)


# def test_download_raw_results():
# downloader.download_raw_results(
# "06c38953-31ec-4f6d-ae1f-ccdf31a348ae",
# "threedi_scenario_downloader/tests/testdata/test.nc",
# )
# assert True


# def test_download_grid_administration():
# downloader.download_grid_administration(
# "06c38953-31ec-4f6d-ae1f-ccdf31a348ae",
# "threedi_scenario_downloader/tests/testdata/test.h5",
# )
# assert True
def test_get_netcdf_link():
url = downloader.get_netcdf_link("06c38953-31ec-4f6d-ae1f-ccdf31a348ae")
assert url == "https://demo.lizard.net/api/v3/scenario-results/52331/results_3di.nc"


def test_download_raw_results():
downloader.download_raw_results(
"06c38953-31ec-4f6d-ae1f-ccdf31a348ae",
"threedi_scenario_downloader/tests/testdata/test.nc",
)
assert True


def test_download_grid_administration():
downloader.download_grid_administration(
"06c38953-31ec-4f6d-ae1f-ccdf31a348ae",
"threedi_scenario_downloader/tests/testdata/test.h5",
)
assert True


def test_clear_inbox():
Expand Down

0 comments on commit 109a5c0

Please sign in to comment.