from sentinelhub import DataCollection, Band, Unit, MosaickingOrder, SentinelHubRequest,CRS, BBox, MimeType, SHConfig, geo_utils from sentinelhub.geo_utils import bbox_to_dimensions import numpy as np import os import PIL config = SHConfig() #CLIENT_ID = 'c1a2fa32-6ca2-414a-9cd0-77556891bf88' #CLIENT_SECRET = 'bR,4M[f8y?C^dR_n]1i1>:g~P@*JXwl]^tciiIN/' # CLIENT_ID = 'ebd1003f-b189-4f4e-9e29-5e56fe0fc343' # CLIENT_SECRET = 'A[W3>BVZk-RNcYko1N9%[da$F*(ahDv)0(|irX8&' CLIENT_SECRET = "CY>imU7J,97EniGj5jyRtz:l13@XL2*gfY+pvqRw" CLIENT_ID = "3e9277b3-aa11-4f98-a160-3bf006130cc7" INSTANCE_ID = "0ee822a0-46aa-4496-9cbb-a5a95a95b660" if CLIENT_ID and CLIENT_SECRET: config.sh_client_id = CLIENT_ID config.sh_client_secret = CLIENT_SECRET config.instance_id = INSTANCE_ID optical_bands = tuple( Band(name, (Unit.REFLECTANCE, Unit.DN), (np.int16)) for name in ["CoastalAerosol", "Blue", "Green", "Red", "RedEdge1", "RedEdge2", "RedEdge3", "NIR_Broad", "NIR_Narrow", "SWIR1", "SWIR2", "WaterVapor", "Cirrus"] ) #bbox = BBox(bbox=[, 16.46094, , 16.46499], crs=CRS.WGS84) bbox = BBox(bbox=[16.46094,77.67945, 16.46499,77.68208 ], crs=CRS.WGS84) termal_bands = tuple( Band(name, (Unit.BRIGHTNESS_TEMPERATURE, Unit.DN), (np.int16)) for name in ["ThermalInfrared1", "ThermalInfrared2"] ) QA_band = Band("QA", (Unit.DN), (np.uint8)), angles = tuple( Band(name, (Unit.DEGREES, Unit.DN), (np.uint16)) for name in ["VAA", "VZA", "SAA", "SZA"] ) bands = optical_bands + termal_bands + QA_band + angles hsl_collection = DataCollection.define( name="Harmonized LandSat Sentinel", api_id="hls", catalog_id="hls", collection_type="HLS", service_url="https://services-uswest2.sentinel-hub.com", bands=bands ) hsl_evalscript = """ //VERSION=3 function setup() { return { input: ["Red","Green","Blue"], output: { bands: 3 } }; } function evaluatePixel(sample) { return [2.5*sample.Red, 2.5*sample.Green, 2.5*sample.Blue]; } """ resolution = 10 betsiboka_bbox = BBox(bbox=bbox, crs=CRS.WGS84) betsiboka_size = bbox_to_dimensions(betsiboka_bbox, resolution=resolution) request = SentinelHubRequest( evalscript=hsl_evalscript, input_data=[SentinelHubRequest.input_data( data_collection=hsl_collection, time_interval=("2022-06-11","2022-06-17"), maxcc=0.3, mosaicking_order=MosaickingOrder.LEAST_CC )], responses=[SentinelHubRequest.output_response("default",MimeType.PNG)], bbox=bbox, config = config, size = betsiboka_size ) response = request.get_data()[0] #print(response) file_name= 'hsl.png' im = PIL.Image.fromarray(response) im = im.convert("RGB") im.save(file_name) #print(response)