Skip to content

Commit

Permalink
Merge branch 'main' into increase-testcoverage
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Feb 4, 2025
2 parents eb950d0 + 2de0954 commit d19b64b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 20 additions & 9 deletions dfm_tools/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,33 @@ def gshhs_coastlines_shp() -> str:

dir_testdata = get_dir_testdata()

fname = 'gshhg-shp-2.3.7.zip'
filepath_zip = os.path.join(dir_testdata,fname)
dir_gshhs = os.path.join(dir_testdata,'gshhg-shp-2.3.7')
fname = 'gshhg-shp-2.3.7'
filepath_zip = os.path.join(dir_testdata, f"{fname}.zip")
dir_gshhs = os.path.join(dir_testdata, fname)

def download_gshhs(url):
url_base = url.split("/")[2]
fname_zip = url.split('/')[-1]
print(f'downloading "{fname_zip}" from {url_base} to cachedir')
# use allow_redirects=False to enforce this url
resp = requests.get(url, allow_redirects=False)
resp.raise_for_status() #raise HTTPError if url not exists
return resp

#download zipfile if not present
if not os.path.exists(filepath_zip) and not os.path.exists(dir_gshhs):
file_url = f'https://www.ngdc.noaa.gov/mgg/shorelines/data/gshhg/latest/{fname}'
print(f'downloading "{fname}" from www.ngdc.noaa.gov to cachedir')
r = requests.get(file_url, allow_redirects=True)
r.raise_for_status() #raise HTTPError if url not exists
file_url = f'https://www.ngdc.noaa.gov/mgg/shorelines/data/gshhg/latest/{fname}.zip'
resp = download_gshhs(file_url)
if resp.is_redirect:
print("failed (redirected), trying different source")
file_url = f'https://www.soest.hawaii.edu/pwessel/gshhg/{fname}.zip'
resp = download_gshhs(file_url)
with open(filepath_zip, 'wb') as f:
f.write(r.content)
f.write(resp.content)

#unzip zipfile if unzipped folder not present
if not os.path.exists(dir_gshhs):
print(f'unzipping "{fname}"')
print(f'unzipping "{fname}.zip"')
with zipfile.ZipFile(filepath_zip, 'r') as zip_ref:
zip_ref.extractall(dir_gshhs)

Expand Down
2 changes: 2 additions & 0 deletions docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Feat
- usage of outside time buffer in `dfmt.cmems_nc_to_ini()` so noon-centered or monthly timestamps are also supported in [#1087](https://github.com/Deltares/dfm_tools/pull/1087)
- correct CMEMS daily mean data ("P1D-m") from midnight to noon by adding a 12-hour offset in `dfmt.download_CMEMS()` in [#1088](https://github.com/Deltares/dfm_tools/pull/1088)
- updated cdsapi request to new format in [#1103](https://github.com/Deltares/dfm_tools/pull/1103)
- added UHSLC backup for GSHHS data in [#1112](https://github.com/Deltares/dfm_tools/pull/1112)

### Fix
- made p-drive paths for tide models and gesla3 work on linux also in [#1083](https://github.com/Deltares/dfm_tools/pull/1083) and [#1085](https://github.com/Deltares/dfm_tools/pull/1085)
Expand Down

0 comments on commit d19b64b

Please sign in to comment.