The Harmonized Landsat and Sentinel-2 (HLS) is a NASA initiative to produce a Virtual Constellation (VC) of surface reflectance (SR) data from the Operational Land Imager (OLI) and MultiSpectral Instrument (MSI) onboard the Landsat 8 and Sentinel-2 remote sensing satellites, respectively. The data from these satellites creates unprecedented opportunities for timely and accurate observation of Earth status and dynamics at moderate (<30 m) spatial resolution every 2-3 days.
The Ag-Analytics provides the service which a user can provide a polygon in specific formats in additional with more customized options to retrieve the dynamics of their land at various times for Landsat from 2013 and Sentinel-2 from 2015 calendar years. Additionally, this service also provides information on cloud cover, statistics, Normalized Difference Vegetation Index in addition to MSI bands information.
Experience the usage of this service on Ag-Analytics website using below link
https://analytics.ag/FarmScope
import requests
import json
import time
import os
from pandas.io.json import json_normalize
from collections import defaultdict
import pandas as pd
import zipfile, io
from IPython.display import Image
%matplotlib inline
%autosave 0
Parameter | Data Type | Required? | Default | Options | Description |
---|---|---|---|---|---|
AOI | Geometry, file/text | Yes | - | JSON, GEOJSON, Shapefile, Raster | Boundary for area of interest. |
Band | List | Yes | - | Red, Green, Blue, Coastal Aerosol, NIR, SWIR1, SWIR2, QA, NDVI, RGB, NDWI, NDBI, NDTI, UI, CIR, UE, LW, AP, AGR, FFBS, BE, VW | Provide the list of HLS Spectral band names to retrieve for given AOI. See Figures 3-4 on website page for API. |
Startdate | Date, mm/dd/yyyy | No | - | - | • Landsat – data starts from 2013 •Sentinel – data starts from 2015 |
Enddate | Date, mm/dd/yyyy | No | - | - | In the absence of startdate or enddate, or both, the service retrieves the latest information available on the land. |
byweek | Int, boolean | No | 1 | 1, 0 | If set to 1, result raster will be the mosaic of all the tiles in a particular week for a given satellite |
satellite | text | No | Landsat | Landsat, Sentinel | If set to both Landsat, Sentinel then the result raster will be the mosaic of both satellites for the given dates |
showlatest | Int, boolean | No | 1 | - | If startdate or enddate is not given, shows the latest available tile. |
filter | Int, boolean | No | 0 | 0, 1 | If set to 1, the resulting image is cloud filtered with no-data where clouds are. |
qafilter | Int, boolean | No | 0 | 0, 1 | If set to 1, continues to filter tiles until the invalid pixels are < qacloudperc |
qacloudperc | float | No | 100 | 0-100 | If qafilter parameter is 1, then filters the tiles until the invalid pixels in those are < qacloudperc |
displaynormalvalues | float | No | 2000 | - | This parameter is used to normalize the band values for display purposes. Used for bands like RGB, AGR, etc. |
legendtype | text | No | Relative | Relative, Absolute | Legend type of display ranges of resulting response. |
resolution | float | No | 0.0001 | - | Cellsize in meters. |
flatten_data | Int, boolean | No | 0 | 0, 1 | Flatten data which has a list of Xcoord, Ycoord and Values for each band in the output. If 1, flatten_data is returned. |
statistics | Int, boolean | No | 1 | 0, 1 | Returns statistical features of the output .tif file. |
return_tif | int | No | 1 | 0, 1 | Returns the downloadable link to output raster. If 0, link will not be returned. |
projection | text | No | Projection of AOI Given | See Figure 5. | Enter the desired projection for the result raster. See Figure 5 for details. |
values={"aoi": '{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-92.329005, 41.6850758], [-92.3290479, 41.681366], [-92.3240805, 41.6813179], [-92.3255289, 41.6841784], [-92.329005, 41.6850758]]]}}',
"Band": "['NDVI']",
"Enddate": "3/8/2019",
"Startdate": "3/2/2019",
"legendtype": "Relative",
"qafilter": "1",
"satellite": "Landsat,Sentinel",
"resolution":"0.00001"}
headers={'Content-Type':'application/x-www-form-urlencoded'}
def harmonisedlandsatdata(values,headers):
try:
url = 'https://ag-analytics.azure-api.net/hls-service/'
response = requests.post(url, data=values,headers=headers).json()
print(response)
return response
except Exception as e:
print(e)
raise e
hlsresponse=harmonisedlandsatdata(values,headers)
for resp in hlsresponse:
if resp["band"]=="NDVI" and resp["download_url"]!="":
print("Legend Values : ",resp["features"][0]['attributes']['Legend'])
img_uri=resp["features"][0]['attributes']["pngb64"]
Image(url=img_uri)
Image(url=img_uri)
GET request for downloading the HLS images returned in the POST request.
# User specified local path where file will be downloaded.
local_path = r"C:\<Path to download directory>" # E.g., r"C:\Users\John_Doe\Documents\rasters"
def HLS_get(local_path):
try:
url = "https://ag-analytics.azure-api.net/hls-service/"
for resp in hlsresponse:
file_url = resp['download_url']
file_name = file_url.split('/')[-1]
download_path = os.path.join(local_path, file_name)
values = {'filename': file_name}
response = requests.get(url, params=values)
open(download_path, 'wb').write(response.content)
print(response.url)
return response
except Exception as e:
print(e)
raise e
HLS_get(local_path)