NASADEM 2.0.0__tar.gz → 2.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nasadem-2.0.0 → nasadem-2.0.1}/NASADEM/NASADEM.py +56 -31
- {nasadem-2.0.0 → nasadem-2.0.1/NASADEM.egg-info}/PKG-INFO +2 -1
- {nasadem-2.0.0 → nasadem-2.0.1}/NASADEM.egg-info/SOURCES.txt +1 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/NASADEM.egg-info/requires.txt +1 -0
- {nasadem-2.0.0/NASADEM.egg-info → nasadem-2.0.1}/PKG-INFO +2 -1
- {nasadem-2.0.0 → nasadem-2.0.1}/pyproject.toml +2 -1
- nasadem-2.0.1/test_nasadem_elevation.py +129 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/.github/.DS_Store +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/.github/workflows/ci.yml +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/.github/workflows/python-publish.yml +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/.gitignore +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/LICENSE +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/NASADEM/__init__.py +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/NASADEM/version.py +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/NASADEM.egg-info/dependency_links.txt +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/NASADEM.egg-info/top_level.txt +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/README.md +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/debug/debug_point_extraction.py +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/docs/Changelog.md +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/docs/Migration-Guide.md +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/docs/Release-Summary.md +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/makefile +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/notebooks/Extract Point.ipynb +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/notebooks/Generate a tile of elevation.ipynb +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/setup.cfg +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/tests/test_import_NASADEM.py +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/tests/test_import_dependencies.py +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/tests/test_nasadem_v2.py +0 -0
- {nasadem-2.0.0 → nasadem-2.0.1}/tox.ini +0 -0
|
@@ -42,6 +42,7 @@ class NASADEMGranule:
|
|
|
42
42
|
URI = self.hgt_URI
|
|
43
43
|
logger.info(f"loading elevation: {cl.URL(URI)}")
|
|
44
44
|
data = Raster.open(URI, geometry=geometry)
|
|
45
|
+
logger.info(f"elevation data shape: {data.shape}, nodata: {data.nodata}")
|
|
45
46
|
|
|
46
47
|
if isinstance(data, Raster):
|
|
47
48
|
data = rasters.where(data == data.nodata, np.nan, data.astype(np.float32))
|
|
@@ -313,7 +314,7 @@ class NASADEMConnection:
|
|
|
313
314
|
Returns:
|
|
314
315
|
Elevation raster for RasterGeometry, elevation value(s) for Point/MultiPoint
|
|
315
316
|
"""
|
|
316
|
-
if isinstance(geometry, MultiPoint):
|
|
317
|
+
if isinstance(geometry, (Point, MultiPoint)):
|
|
317
318
|
return self._extract_point_values(geometry, 'elevation_m')
|
|
318
319
|
|
|
319
320
|
result = None
|
|
@@ -358,52 +359,76 @@ class NASADEMConnection:
|
|
|
358
359
|
Returns:
|
|
359
360
|
Single value for Point, array of values for MultiPoint
|
|
360
361
|
"""
|
|
361
|
-
tiles = self.tiles(geometry)
|
|
362
|
-
|
|
363
362
|
if isinstance(geometry, Point):
|
|
364
363
|
points = [geometry]
|
|
365
364
|
else:
|
|
366
365
|
points = [Point(geom.x, geom.y) for geom in geometry.geoms]
|
|
367
366
|
|
|
368
|
-
|
|
367
|
+
# Group points by tile to minimize data loading
|
|
368
|
+
from collections import defaultdict
|
|
369
|
+
points_by_tile = defaultdict(list)
|
|
370
|
+
|
|
371
|
+
for i, point in enumerate(points):
|
|
372
|
+
# Calculate which tile this point belongs to
|
|
373
|
+
lat, lon = point.y, point.x
|
|
374
|
+
tile = f"{'s' if lat < 0 else 'n'}{abs(int(np.floor(lat))):02d}{'w' if lon < 0 else 'e'}{abs(int(np.floor(lon))):03d}"
|
|
375
|
+
points_by_tile[tile].append((i, point))
|
|
376
|
+
|
|
377
|
+
# Initialize results array
|
|
378
|
+
values = [np.nan] * len(points)
|
|
369
379
|
|
|
370
|
-
|
|
371
|
-
|
|
380
|
+
# Process each tile only once
|
|
381
|
+
for tile, point_list in points_by_tile.items():
|
|
382
|
+
try:
|
|
383
|
+
granule = self.download_tile(tile)
|
|
384
|
+
except TileNotAvailable as e:
|
|
385
|
+
logger.warning(e)
|
|
386
|
+
continue
|
|
372
387
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
granule = self.download_tile(tile)
|
|
376
|
-
except TileNotAvailable as e:
|
|
377
|
-
logger.warning(e)
|
|
378
|
-
continue
|
|
379
|
-
|
|
380
|
-
# Get the appropriate data layer
|
|
388
|
+
# Load the full tile data
|
|
389
|
+
try:
|
|
381
390
|
if data_type == 'elevation_m':
|
|
382
|
-
data_layer = granule.
|
|
391
|
+
data_layer = granule.get_elevation_m(geometry=None)
|
|
383
392
|
elif data_type == 'swb':
|
|
384
|
-
data_layer = granule.
|
|
393
|
+
data_layer = granule.get_swb(geometry=None)
|
|
385
394
|
else:
|
|
386
395
|
raise ValueError(f"Unknown data type: {data_type}")
|
|
387
396
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
397
|
+
if not isinstance(data_layer, Raster):
|
|
398
|
+
logger.warning(f"Expected Raster, got {type(data_layer)}")
|
|
399
|
+
continue
|
|
400
|
+
|
|
401
|
+
# Extract values for all points in this tile
|
|
402
|
+
for idx, point in point_list:
|
|
394
403
|
try:
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
404
|
+
# Check if point is within tile bounds
|
|
405
|
+
tile_geometry = data_layer.geometry
|
|
406
|
+
if not (tile_geometry.x_min <= point.x <= tile_geometry.x_max and
|
|
407
|
+
tile_geometry.y_min <= point.y <= tile_geometry.y_max):
|
|
408
|
+
continue
|
|
409
|
+
|
|
410
|
+
# Convert geographic coordinates to pixel indices
|
|
411
|
+
row = int((tile_geometry.y_max - point.y) / abs(tile_geometry.cell_height))
|
|
412
|
+
col = int((point.x - tile_geometry.x_min) / abs(tile_geometry.cell_width))
|
|
413
|
+
|
|
414
|
+
# Clip to array bounds
|
|
415
|
+
row = max(0, min(row, data_layer.shape[0] - 1))
|
|
416
|
+
col = max(0, min(col, data_layer.shape[1] - 1))
|
|
417
|
+
|
|
418
|
+
# Extract the value
|
|
419
|
+
value = float(data_layer.array[row, col])
|
|
420
|
+
|
|
421
|
+
# Store if valid
|
|
422
|
+
if not np.isnan(value) and value != data_layer.nodata:
|
|
423
|
+
values[idx] = value
|
|
424
|
+
|
|
402
425
|
except Exception as e:
|
|
403
426
|
logger.warning(f"Failed to sample point ({point.x}, {point.y}) from tile {tile}: {e}")
|
|
404
427
|
continue
|
|
405
|
-
|
|
406
|
-
|
|
428
|
+
|
|
429
|
+
except Exception as e:
|
|
430
|
+
logger.warning(f"Failed to load data from tile {tile}: {e}")
|
|
431
|
+
continue
|
|
407
432
|
|
|
408
433
|
# Apply post-processing for swb
|
|
409
434
|
if data_type == 'swb':
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: NASADEM
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.1
|
|
4
4
|
Summary: Shuttle Radar Topography Mission (SRTM) Digital Elevation Model (DEM) search and download utility
|
|
5
5
|
Author-email: "Gregory H. Halverson" <gregory.h.halverson@jpl.nasa.gov>
|
|
6
6
|
Project-URL: Homepage, https://github.com/JPL-Evapotranspiration-Algorithms/NASADEM
|
|
@@ -11,6 +11,7 @@ Description-Content-Type: text/markdown
|
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
Requires-Dist: colored-logging
|
|
13
13
|
Requires-Dist: earthaccess>=0.8.0
|
|
14
|
+
Requires-Dist: ECOv002_calval_tables
|
|
14
15
|
Requires-Dist: numpy
|
|
15
16
|
Requires-Dist: rasters>=1.14.0
|
|
16
17
|
Requires-Dist: sentinel-tiles
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: NASADEM
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.1
|
|
4
4
|
Summary: Shuttle Radar Topography Mission (SRTM) Digital Elevation Model (DEM) search and download utility
|
|
5
5
|
Author-email: "Gregory H. Halverson" <gregory.h.halverson@jpl.nasa.gov>
|
|
6
6
|
Project-URL: Homepage, https://github.com/JPL-Evapotranspiration-Algorithms/NASADEM
|
|
@@ -11,6 +11,7 @@ Description-Content-Type: text/markdown
|
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
Requires-Dist: colored-logging
|
|
13
13
|
Requires-Dist: earthaccess>=0.8.0
|
|
14
|
+
Requires-Dist: ECOv002_calval_tables
|
|
14
15
|
Requires-Dist: numpy
|
|
15
16
|
Requires-Dist: rasters>=1.14.0
|
|
16
17
|
Requires-Dist: sentinel-tiles
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "NASADEM"
|
|
7
|
-
version = "2.0.
|
|
7
|
+
version = "2.0.1"
|
|
8
8
|
description = "Shuttle Radar Topography Mission (SRTM) Digital Elevation Model (DEM) search and download utility"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
@@ -17,6 +17,7 @@ classifiers = [
|
|
|
17
17
|
dependencies = [
|
|
18
18
|
"colored-logging",
|
|
19
19
|
"earthaccess>=0.8.0",
|
|
20
|
+
"ECOv002_calval_tables",
|
|
20
21
|
"numpy",
|
|
21
22
|
"rasters>=1.14.0",
|
|
22
23
|
"sentinel-tiles",
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Test script for querying elevation values from NASADEM.
|
|
4
|
+
|
|
5
|
+
This script demonstrates how to retrieve elevation data from NASADEM
|
|
6
|
+
using geometry points, including single points and multipoints.
|
|
7
|
+
"""
|
|
8
|
+
import numpy as np
|
|
9
|
+
import rasters as rt
|
|
10
|
+
from NASADEM import NASADEM
|
|
11
|
+
from ECOv002_calval_tables import load_calval_table
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
# Load calibration/validation table for test coordinates
|
|
15
|
+
print("Loading calibration/validation table for test coordinates...")
|
|
16
|
+
calval_df = load_calval_table()
|
|
17
|
+
print(f"Loaded {len(calval_df)} records from calval table")
|
|
18
|
+
|
|
19
|
+
# Take a small subset for testing (first 10 records)
|
|
20
|
+
test_df = calval_df.head(10).copy()
|
|
21
|
+
print(f"\nTesting with first {len(test_df)} records")
|
|
22
|
+
print(f"Sites: {test_df['ID'].unique()}\n")
|
|
23
|
+
|
|
24
|
+
# Extract geometries from the test dataframe
|
|
25
|
+
if 'geometry' not in test_df.columns:
|
|
26
|
+
print("ERROR: 'geometry' column not found in calval table")
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
geometries = test_df['geometry'].values
|
|
30
|
+
x_coords = [g.x for g in geometries]
|
|
31
|
+
y_coords = [g.y for g in geometries]
|
|
32
|
+
|
|
33
|
+
# Test 1: Query elevation for multiple points using MultiPoint
|
|
34
|
+
print("=" * 60)
|
|
35
|
+
print("Test 1: Query elevation for multiple points")
|
|
36
|
+
print("=" * 60)
|
|
37
|
+
|
|
38
|
+
multipoint_geometry = rt.MultiPoint(x=x_coords, y=y_coords)
|
|
39
|
+
print(f"Created MultiPoint with {len(geometries)} points")
|
|
40
|
+
|
|
41
|
+
print("\nQuerying NASADEM for elevation...")
|
|
42
|
+
elevation_km = NASADEM.elevation_km(geometry=multipoint_geometry)
|
|
43
|
+
elevation_m = elevation_km * 1000.0
|
|
44
|
+
|
|
45
|
+
print(f"\nRetrieved elevation shape: {elevation_m.shape}")
|
|
46
|
+
print(f"Elevation (m): {elevation_m}")
|
|
47
|
+
print(f"Min elevation: {np.min(elevation_m):.2f} m")
|
|
48
|
+
print(f"Max elevation: {np.max(elevation_m):.2f} m")
|
|
49
|
+
print(f"Mean elevation: {np.mean(elevation_m):.2f} m")
|
|
50
|
+
|
|
51
|
+
# Compare with table values if available
|
|
52
|
+
if 'elevation_m' in test_df.columns:
|
|
53
|
+
table_elevation = test_df['elevation_m'].values
|
|
54
|
+
print(f"\nTable elevation (m): {table_elevation}")
|
|
55
|
+
diff = elevation_m - table_elevation
|
|
56
|
+
print(f"Difference from table: {diff}")
|
|
57
|
+
print(f"Max absolute difference: {np.max(np.abs(diff)):.2f} m")
|
|
58
|
+
print(f"Mean absolute difference: {np.mean(np.abs(diff)):.2f} m")
|
|
59
|
+
|
|
60
|
+
# Test 2: Query elevation for a single point
|
|
61
|
+
print("\n" + "=" * 60)
|
|
62
|
+
print("Test 2: Query elevation for a single point")
|
|
63
|
+
print("=" * 60)
|
|
64
|
+
|
|
65
|
+
first_record = test_df.iloc[0]
|
|
66
|
+
single_point = first_record['geometry']
|
|
67
|
+
print(f"Testing site: {first_record['ID']}")
|
|
68
|
+
print(f"Location: ({single_point.y:.4f}, {single_point.x:.4f})")
|
|
69
|
+
|
|
70
|
+
single_geometry = rt.Point(single_point.x, single_point.y)
|
|
71
|
+
|
|
72
|
+
print("\nQuerying NASADEM for single point elevation...")
|
|
73
|
+
single_elevation_km = NASADEM.elevation_km(geometry=single_geometry)
|
|
74
|
+
single_elevation = single_elevation_km * 1000.0
|
|
75
|
+
|
|
76
|
+
print(f"Retrieved elevation: {single_elevation} m")
|
|
77
|
+
|
|
78
|
+
# Compare with multipoint result for first point
|
|
79
|
+
if isinstance(elevation_m, np.ndarray):
|
|
80
|
+
first_elevation_mp = elevation_m[0]
|
|
81
|
+
else:
|
|
82
|
+
first_elevation_mp = elevation_m
|
|
83
|
+
|
|
84
|
+
print(f"Multipoint result for first point: {first_elevation_mp} m")
|
|
85
|
+
|
|
86
|
+
# Verify they match
|
|
87
|
+
if np.isclose(single_elevation, first_elevation_mp):
|
|
88
|
+
print("✓ Single point elevation matches multipoint result")
|
|
89
|
+
else:
|
|
90
|
+
print(f"⚠ Difference: {abs(single_elevation - first_elevation_mp):.2f} m")
|
|
91
|
+
|
|
92
|
+
# Compare with table value if available
|
|
93
|
+
if 'elevation_m' in test_df.columns:
|
|
94
|
+
table_value = first_record['elevation_m']
|
|
95
|
+
print(f"Table value: {table_value} m")
|
|
96
|
+
print(f"Difference from table: {single_elevation - table_value:.2f} m")
|
|
97
|
+
|
|
98
|
+
# Test 3: Query elevation for specific geographic locations
|
|
99
|
+
print("\n" + "=" * 60)
|
|
100
|
+
print("Test 3: Query elevation for known locations")
|
|
101
|
+
print("=" * 60)
|
|
102
|
+
|
|
103
|
+
# Test locations with known approximate elevations
|
|
104
|
+
test_locations = [
|
|
105
|
+
{"name": "Death Valley, CA", "lon": -116.8667, "lat": 36.5, "expected": -86},
|
|
106
|
+
{"name": "Denver, CO", "lon": -104.9903, "lat": 39.7392, "expected": 1609},
|
|
107
|
+
{"name": "Mount Everest Base Camp", "lon": 86.8528, "lat": 27.9881, "expected": 5364},
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
for location in test_locations:
|
|
111
|
+
point = rt.Point(location["lon"], location["lat"])
|
|
112
|
+
elevation_km = NASADEM.elevation_km(geometry=point)
|
|
113
|
+
elevation = elevation_km * 1000.0
|
|
114
|
+
expected = location["expected"]
|
|
115
|
+
diff = elevation - expected
|
|
116
|
+
|
|
117
|
+
print(f"\n{location['name']}:")
|
|
118
|
+
print(f" Coordinates: ({location['lat']:.4f}, {location['lon']:.4f})")
|
|
119
|
+
print(f" Retrieved elevation: {elevation:.2f} m")
|
|
120
|
+
print(f" Expected elevation: {expected} m")
|
|
121
|
+
print(f" Difference: {diff:.2f} m")
|
|
122
|
+
|
|
123
|
+
print("\n" + "=" * 60)
|
|
124
|
+
print("NASADEM elevation query tests completed!")
|
|
125
|
+
print("=" * 60)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
if __name__ == "__main__":
|
|
129
|
+
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|