8000 Lookup altitude by nicomt · Pull Request #1518 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Lookup altitude #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 31, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update lookup_location
* Retuning float altitude instead of int
* Removing h5 file input
  • Loading branch information
nicomt committed Aug 21, 2022
commit 53a7cc41284a25008cc9ff4f0b42ac35579279fd
16 changes: 6 additions & 10 deletions pvlib/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def get_sun_rise_set_transit(self, times, method='pyephem', **kwargs):
return result


def lookup_altitude(latitude, longitude, filepath=None):
def lookup_altitude(latitude, longitude):
"""
Look up location altitude from low-resolution altitude map
supplied with pvlib. The data for this map comes from multiple open data
Expand All @@ -384,12 +384,9 @@ def lookup_altitude(latitude, longitude, filepath=None):
Positive is east of the prime meridian.
Use decimal degrees notation.

filepath : None or string, default None
The path to the ``.h5`` file.

Returns
-------
altitude : int
altitude : float
The altitude of the location in meters.

Notes
Expand Down Expand Up @@ -430,9 +427,8 @@ def lookup_altitude(latitude, longitude, filepath=None):

"""

if filepath is None:
pvlib_path = os.path.dirname(os.path.abspath(__file__))
filepath = os.path.join(pvlib_path, 'data', 'Altitude.h5')
pvlib_path = os.path.dirname(os.path.abspath(__file__))
filepath = os.path.join(pvlib_path, 'data', 'Altitude.h5')

latitude_index = _degrees_to_index(latitude, coordinate='latitude')
longitude_index = _degrees_to_index(longitude, coordinate='longitude')
Expand All @@ -443,8 +439,8 @@ def lookup_altitude(latitude, longitude, filepath=None):
# 255 is a special value that means nodata. Fallback to 0 if nodata.
if alt == 255:
return 0
# Altitude is encoded in 35 meter steps from -2364 meters to 6526 meters
# Altitude is encoded in 28 meter steps from -450 meters to 6561 meters
# There are 0-254 possible altitudes, with 255 reserved for nodata.
alt *= 28
alt -= 450
return int(alt)
return float(alt)
0