Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into main
- Loading branch information
Showing
9 changed files
with
462 additions
and
101 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Tests for sliderule-python landsat raster support.""" | ||
|
||
import pytest | ||
from pathlib import Path | ||
import os.path | ||
from sliderule import sliderule, earthdata, icesat2 | ||
|
||
TESTDIR = Path(__file__).parent | ||
|
||
@pytest.mark.network | ||
class TestHLS: | ||
def test_samples(self, domain, organization): | ||
sliderule.init(domain, organization=organization) | ||
time_start = "2021-01-01T00:00:00Z" | ||
time_end = "2021-02-01T23:59:59Z" | ||
polygon = [ {"lon": -177.0000000001, "lat": 51.0000000001}, | ||
{"lon": -179.0000000001, "lat": 51.0000000001}, | ||
{"lon": -179.0000000001, "lat": 49.0000000001}, | ||
{"lon": -177.0000000001, "lat": 49.0000000001}, | ||
{"lon": -177.0000000001, "lat": 51.0000000001} ] | ||
catalog = earthdata.stac(short_name="HLS", polygon=polygon, time_start=time_start, time_end=time_end, as_str=True) | ||
rqst = {"samples": {"asset": "landsat-hls", "catalog": catalog, "bands": ["B02"]}, "coordinates": [[-178.0, 50.7]]} | ||
rsps = sliderule.source("samples", rqst) | ||
|
||
def test_ndvi(self, domain, asset, organization): | ||
icesat2.init(domain, organization=organization) | ||
region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) | ||
resource = "ATL03_20181017222812_02950102_005_01.h5" | ||
time_start = "2021-01-01T00:00:00Z" | ||
time_end = "2021-02-01T23:59:59Z" | ||
catalog = earthdata.stac(short_name="HLS", polygon=region['poly'], time_start=time_start, time_end=time_end, as_str=True) | ||
parms = { "poly": region['poly'], | ||
"raster": region['raster'], | ||
"cnf": "atl03_high", | ||
"ats": 20.0, | ||
"cnt": 10, | ||
"len": 40.0, | ||
"res": 20.0, | ||
"maxi": 1, | ||
"samples": {"ndvi": {"asset": "landsat-hls", "catalog": catalog, "bands": ["NDVI"]}} } | ||
gdf = icesat2.atl06p(parms, asset=asset, resources=[resource]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# Imports | ||
# | ||
import sys | ||
import json | ||
import sliderule | ||
from utils import parse_command_line | ||
from sliderule import earthdata | ||
|
||
############################################################################### | ||
# MAIN | ||
############################################################################### | ||
|
||
if __name__ == '__main__': | ||
|
||
# Defaults | ||
cfg = { | ||
"dataset": "HLS", | ||
"region": "examples/grandmesa.geojson", | ||
"time_start": "2021-01-01T00:00:00Z", | ||
"time_end": "2022-01-01T23:59:59Z", | ||
"display_all": False | ||
} | ||
|
||
# Command line parameters | ||
parse_command_line(sys.argv, cfg) | ||
|
||
# Region of interest | ||
polygon = sliderule.toregion(cfg["region"])["poly"] | ||
|
||
# Query CMR for list of resources | ||
geojson = earthdata.stac(short_name=cfg["dataset"], polygon=polygon, time_start=cfg["time_start"], time_end=cfg["time_end"]) | ||
|
||
# Display Results | ||
print("Returned {} features".format(geojson["context"]["returned"])) | ||
if cfg["display_all"]: | ||
print(json.dumps(geojson, indent=2)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from pystac_client import Client | ||
import sliderule | ||
import requests | ||
import json | ||
import sys | ||
|
||
# parameters | ||
debug = False | ||
client = False | ||
manual = True | ||
page = None | ||
url = 'https://cmr.earthdata.nasa.gov/stac/LPCLOUD' | ||
headers = {'Content-Type': 'application/json'} | ||
limit = 200 | ||
collections = ["HLSS30.v2.0", "HLSL30.v2.0"] | ||
time_start = "2021-01-01T00:00:00Z" | ||
time_end = "2022-01-01T23:59:59Z" | ||
coordinates = [[[coord["lon"], coord["lat"]] for coord in polygon] for polygon in [sliderule.toregion("examples/grandmesa.geojson")["poly"]]] | ||
|
||
# debug output | ||
if debug: | ||
import logging | ||
import http.client as http_client | ||
http_client.HTTPConnection.debuglevel = 1 | ||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
requests_log = logging.getLogger("requests.packages.urllib3") | ||
requests_log.setLevel(logging.DEBUG) | ||
requests_log.propagate = True | ||
|
||
|
||
# client stac request | ||
if client: | ||
catalog = Client.open(url) | ||
timeRange = '{}/{}'.format(time_start, time_end) | ||
geometry = {"type": "Polygon", "coordinates": coordinates} | ||
results = catalog.search(collections=collections, datetime=timeRange, intersects=geometry) | ||
items = results.get_all_items_as_dict() | ||
print(f"Returned {results.matched()} features") | ||
|
||
|
||
# manual stac request | ||
if manual: | ||
rqst = { | ||
"limit": 100, | ||
"datetime": '{}/{}'.format(time_start, time_end), | ||
"collections": collections, | ||
"intersects": { | ||
"type": "Polygon", | ||
"coordinates": coordinates | ||
} | ||
} | ||
if page: | ||
rqst["page"] = page | ||
context = requests.Session() | ||
context.trust_env = False | ||
data = context.post(url+"/search", data=json.dumps(rqst), headers=headers) | ||
data.raise_for_status() | ||
geojson = data.json() | ||
print("Returned {} features".format(geojson["context"]["returned"])) | ||
|