Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile → Makefile.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
C99 = $(CC) -std=c99
CFLAGS = -g -O3 -DNDEBUG -DDONT_USE_TEST_MAIN
CPPFLAGS = -g -O3 -fpermissive -DNDEBUG -DDONT_USE_TEST_MAIN
LDLIBS = -lstdc++ -lz -lm -ltiff
CFLAGS = -g -O3 -DNDEBUG -DDONT_USE_TEST_MAIN {cflags}
CPPFLAGS = -g -O3 -fpermissive -DNDEBUG -DDONT_USE_TEST_MAIN {cppflags}
LDLIBS = -lstdc++ -lz -lm -ltiff {ldflags}

default: bin bin/srtm4 bin/srtm4_which_tile

Expand Down
1 change: 1 addition & 0 deletions conda-recipe/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo Windows build is not supported
3 changes: 3 additions & 0 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

python setup.py install --prefix=$PREFIX
12 changes: 12 additions & 0 deletions conda-recipe/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
python:
- 3.6
- 3.7
- 3.8
libtiff:
- 4.1.0

pin_run_as_build:
libtiff:
max_pin: x.x
python:
max_pin: x
35 changes: 35 additions & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package:
name: srtm4
version: "1.1.4.dev0"

source:
git_rev: sharedlib
git_url: https://github.com/yxqd/srtm4

requirements:
build:
- {{ compiler('cxx') }} # [linux]
host:
- python
- libtiff
- filelock
- numpy
- requests
run:
- python
- libtiff
- filelock
- numpy
- requests

build:
script_env:

test:
imports:
- srtm4

about:
home:
license:
license_file:
10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from setuptools import setup
from setuptools.command import develop, build_py

def _createMakefile():
template = open('Makefile.in').read()
cflags = os.environ.get('CFLAGS', '')
cppflags = os.environ.get('CPPFLAGS', '')
ldflags = os.environ.get('LDFLAGS', '')
content = template.format(**locals())
open('Makefile', 'wt').write(content)
return
_createMakefile()


def readme():
with open('README.md', 'r', 'utf-8') as f:
Expand Down
31 changes: 28 additions & 3 deletions srtm4.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
if not SRTM_DIR:
SRTM_DIR = os.path.join(os.path.expanduser('~'), '.srtm')

SRTM_URL = 'http://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF'
SRTM_HTTP_URL = 'http://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF'
SRTM_URL = os.environ.get('SRTM_DATA_URL', SRTM_HTTP_URL)
if SRTM_URL.endswith('/'): SRTM_URL = SRTM_URL[:-1]


def _requests_retry_session(
Expand All @@ -51,10 +53,28 @@ def _requests_retry_session(
session.mount("https://", adapter)
return session


def download(to_file, from_url):
'''download a file from the internet

Args:
to_file: path where to store the downloaded file
from_url: url of the file to download. could be http or s3

Raises:
RetryError: if the `get` call exceeds the number of retries
on 5xx codes
ConnectionError: if the `get` call does not return a 200 code
NotImplementedError: if the url type is not supported
'''
if from_url.startswith('http://') or from_url.startswith('https://'):
return _download_http(to_file, from_url)
if from_url.startswith('s3://'):
return _download_s3(to_file, from_url)
raise NotImplementedError("{} -> {}".format(from_url, to_file))

def _download_http(to_file, from_url):
"""
Download a file from the internet.
Download a file from the internet using http.

Args:
to_file: path where to store the downloaded file
Expand Down Expand Up @@ -83,6 +103,11 @@ def download(to_file, from_url):
f.write(chunk)


def _download_s3(to_file, from_url):
import sh
sh.aws('s3', 'cp', from_url, to_file)
return

def get_srtm_tile(srtm_tile, out_dir):
"""
Download and unzip an srtm tile from the internet.
Expand Down