Coder Social home page Coder Social logo

adamcharnock / python-srtm Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 7.0 130 KB

Python API for reading NASA's SRTM `.hgt` or `.hgt.zip` altitude files.

Home Page: https://pypi.org/project/python-srtm/

Python 100.00%
nasa srtm1 srtm3 srtm srtm-data geospatial altitude elevation-profile

python-srtm's Introduction

NASA SRTM altitude data parsing in Python

Provides an API onto SRTM .hgt or .hgt.zip files.

Requires Python 3.8, may work with Python 3.6 & 3.7.

Installation

pip install python-srtm

export SRTM1_DIR=/path/to/srtm1/
export SRTM3_DIR=/path/to/srtm3/

Use

You can access either SRTM1 or SRTM3 data. SRTM 1, for example:

# SRTM1 - 30m resolution
>>> from srtm import Srtm1HeightMapCollection
>>> srtm1_data = Srtm1HeightMapCollection()
>>> srtm1_data.get_altitude(latitude=40.123, longitude=-7.456)
615
>>> Srtm1HeightMapCollection().get_elevation_profile(40.123, -7.456, 40.129, -7.460)
[615, 620, 618, 620, 616, 603, 593, 582, 575, 579, 580, 589, 589, 581, 565, 553, 545, 541, 534, 533, 529, 520, 514]

Or SRTM3:

# SRTM3 - 90m resolution
>>> from srtm import Srtm3HeightMapCollection
>>> srtm3_data = Srtm3HeightMapCollection()
>>> srtm3_data.get_altitude(latitude=40.123, longitude=-7.456)
608
>>> Srtm3HeightMapCollection().get_elevation_profile(40.123, -7.456, 40.129, -7.460)
[626, 616, 585, 593, 577, 548, 528, 514]

Profiling

import cProfile
cProfile.run('function_to_profile()', filename='output.cprof')
brew install qcachegrind
pip install pyprof2calltree
pyprof2calltree -k -i /pythonprofiling/profiler/first_iteration.cprof

Release process

For internal reference:

# Run the tests
pytest

export VERSION="VERSION HERE"

# Version bump
poetry version $VERSION

# Update the setup.py
dephell convert
black setup.py

# Ensure poetry.lock is up to date
poetry lock

# Commit
git add .
git commit -m "Releasing version $VERSION"

# Tagging and branching
git tag "v$VERSION"
git branch "v$VERSION"
git push origin \
    refs/tags/"v$VERSION" \
    refs/heads/"v$VERSION" \
    master

poetry publish --build

python-srtm's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

python-srtm's Issues

Issue for places below sea level

For the srtm datasets, elevations of places below sea level (e.g. dead sea) are slightly smaller than 65535, which means (obviously) they are 65535 based.
So would you add the feature that automatically output negative values? Or is it prefered to provide only the raw data?

Height map for RasterBaseCoordinates not found

Hi,

I'm trying out your package, and start by just running your example code:

# SRTM1 - 30m resolution
>>> from srtm import Srtm1HeightMapCollection
>>> srtm1_data = Srtm1HeightMapCollection()
>>> srtm1_data.get_altitude(latitude=40.123, longitude=-7.456)
615
>>> Srtm1HeightMapCollection().get_elevation_profile(40.123, -7.456, 40.129, -7.460)
[615, 620, 618, 620, 616, 603, 593, 582, 575, 579, 580, 589, 589, 581, 565, 553, 545, 541, 534, 533, 529, 520, 514]

But it just results in this error:

KeyError                                  Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python39\lib\site-packages\srtm\height_map_collection.py in get_height_map_for_latitude_and_longitude(self, latitude, longitude)
     60         try:
---> 61             return self.height_maps[base]
     62         except KeyError:

KeyError: RasterBaseCoordinates(latitude=40, longitude=-8)

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-9-66c5ddd22251> in <module>
----> 1 Srtm1HeightMapCollection().get_elevation_profile(40.123, -7.456, 40.129, -7.460)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\srtm\height_map_collection.py in get_elevation_profile(self, start_latitude, start_longitude, end_latitude, end_longitude, apply_earth_curvature)
    116         for latitude, longitude in converted_points:
    117             elevations.append(
--> 118                 (latitude, longitude, self.get_altitude(latitude, longitude))
    119             )
    120 

~\AppData\Local\Programs\Python\Python39\lib\site-packages\srtm\height_map_collection.py in get_altitude(self, latitude, longitude)
     68     def get_altitude(self, latitude: float, longitude: float) -> int:
     69         """Get the height of the given latitude and longitude"""
---> 70         height_map = self.get_height_map_for_latitude_and_longitude(latitude, longitude)
     71         return height_map.get_altitude_for_latitude_and_longitude(latitude, longitude)
     72 

~\AppData\Local\Programs\Python\Python39\lib\site-packages\srtm\height_map_collection.py in get_height_map_for_latitude_and_longitude(self, latitude, longitude)
     61             return self.height_maps[base]
     62         except KeyError:
---> 63             raise Exception(
     64                 f"Height map for {base} not found. Have you called "
     65                 f"build_file_index() on your heightmap collection?"

Exception: Height map for RasterBaseCoordinates(latitude=40, longitude=-8) not found. Have you called build_file_index() on your heightmap collection?

SRTM1_DIR and SRTM3_DIR as local variables instead of ENV variables

If I have a few sources of .hgt datasets, and I want to switch depending on the use case, it would be neat to call Srtm1HeightMapCollection() lib like this:

from srtm import Srtm3HeightMapCollection
srtm3_data = Srtm3HeightMapCollection('/path/to/srtm3/')

instead of defining environment variables.

By the way, very nice lib, it saved some time for me :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.