From 98881ef6144db531fbc01f5eb842db5b882a1759 Mon Sep 17 00:00:00 2001 From: PennyHow Date: Wed, 29 May 2024 16:48:43 -0100 Subject: [PATCH] sentinelhub module removed --- .../sentinelhub_addon/detectIceMargin.py | 194 ----------- src/griml/sentinelhub_addon/loadURL.py | 138 -------- .../sentinelhub_addon/retrieveSentinelHub.py | 67 ---- .../sentinelhub_addon/sentinelhub_test.py | 311 ------------------ 4 files changed, 710 deletions(-) delete mode 100644 src/griml/sentinelhub_addon/detectIceMargin.py delete mode 100755 src/griml/sentinelhub_addon/loadURL.py delete mode 100644 src/griml/sentinelhub_addon/retrieveSentinelHub.py delete mode 100755 src/griml/sentinelhub_addon/sentinelhub_test.py diff --git a/src/griml/sentinelhub_addon/detectIceMargin.py b/src/griml/sentinelhub_addon/detectIceMargin.py deleted file mode 100644 index 0647f48..0000000 --- a/src/griml/sentinelhub_addon/detectIceMargin.py +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Thu Sep 16 15:35:05 2021 - -@author: pho -""" - -from sentinelhub import SHConfig -import datetime -import matplotlib.pyplot as plt -import rasterio as rio -from rasterio.features import shapes -from sentinelhub import MimeType, CRS, BBox, SentinelHubRequest, BBoxSplitter,\ - DataCollection, bbox_to_dimensions, read_data -import geopandas as gp -from shapely.geometry import shape - - -#------------------------ Input parameters -------------------------------- - -#Input parameters -# INPUT_FILE = './icemargin_mask.json' #Input mask -INPUT_FILE = './test_mask_json_pstereo.json' #Input mask -OUTPUT_FILE = './icemargin_2020_mask_nomosaic.shp' -epsg = 3413 #EPSG of mask (and output) -date = (datetime.datetime(2020,7,1), datetime.datetime(2020,9,1)) #Start/end dates -resolution = 10 #Output spatial resolution -bbox_col = 20 #Bbox width splitter -bbox_row = 50 #Bbox length splitter - -#--------------------- Scripts for classification ------------------------- - -#SentinelHub script for classifying snow/ice -evalscript = """ -//VERSION=3 -function setup() { - return { - input: {bands: ["B03","B11","CLM","dataMask"]}, - output: { bands: 1, - nodataValue: 0} - } -} - -function spectralIndices(cloud, mask, green, SWIR) { - if (cloud == 0) { // Exclude cloudy pixels - if (mask == 1) { // Exclude nodata pixels - if (index(green, SWIR) >= 0.41) { // NDSI threshold - return [1] - }}}} - -function evaluatePixel(sample) { - var ndsi = spectralIndices(sample.CLM, sample.dataMask, sample.B03, sample.B11) - if (ndsi == 1) { - return[1] - }} -""" - - -#Vectorisation function -def getGeodata(img, trans): - '''Get vector features from binary raster image. Raster data is loaded - from array as a rasterio inmemory object, and returns features as a - geopandas dataframe - - Variables - img (arr) Binary raster array - trans (Affine): Raster transformation (computed using - affine package, or - rasterio.transform) - Returns - feats (Geodataframe): Vector features geodataframe - ''' - #Open array as rasterio memory object - with rio.io.MemoryFile() as memfile: - with memfile.open( - driver='GTiff', - height=img.shape[0], - width=img.shape[1], - count=1, - dtype=img.dtype, - transform=trans - ) as dataset: - dataset.write(img, 1) - - #Vectorize array - with memfile.open() as dataset: - image = dataset.read(1) - mask = image==255 - results = ( - {'properties': {'raster_val': v}, 'geometry': s} - for i, (s, v) - in enumerate( - shapes(image, - mask=mask, - transform=rio.transform.from_origin(transf[0], - transf[3], - transf[1], - transf[5])))) - - ##Transform geometries to geodataframe - geoms = list(results) - feats = gp.GeoDataFrame.from_features(geoms) - - return feats - -#-------------------- Configure SentinelHub client ------------------------ - -#Configure Sentinelhub connection client -config = SHConfig() -# config.instance_id = 'e4ac5ac3-ca5e-4624-ab3a-8214df144373' #Instance ID needed -# config.sh_client_id = '23032a7f-66c1-447e-99ed-44c10d13072f' #Client ID needed -# config.sh_client_secret = 'WZ|ufGd;yp|YW];2[aZ!Oh7uvr~r= 0.3) { - - // MNDWI threshold - if (index(green, swir11 <= 0.1)) { - - // AWEIsh threshold - if (50 <= (blue + 2.5 * green - - 1.5 * (nir + swir11) - - 0.25 * swir12) <= 200) { - - // AWEInsh threshold - if (50 <= (4 * (green - swir11) - - (0.25 * nir + 2.75 * swir12)) <= 254) { - - // Brightness threshold - if (((red + green + blue)/3) <= 70) { - - return [1] -}}}}}}}} - - -function classBackScatter(sigmaHH, sigmaHV) { - // Convert sigma0 to Decibels - let vh_Db = toDb(sigmaVH) - let vv_Db = toDb(sigmaVV) - - // Calculate NRPB (Filgueiras et al. (2019), eq. 4) - let NRPB = (vh_Db - vv_Db) / (vh_Db + vv_Db) - - // Calculate NDVI_nc with approach A3 (Filgueiras et al. (2019), eq. 14) - let NDVInc = 2.572 - 0.05047 * vh_Db + 0.176 * vv_Db + 3.422 * NRPB - return NDVInc -} - - -function evaluatePixel(sample) { - optical = sample["0"][0] - var opt = classMultiSpectral(optical.CLM, optical.dataMask, - optical.B02, optical.B03, optical.B04, - optical.B08, optical.B11, optical.B12) - return [opt] -} -""" - -#Vectorisation function -def getGeodata(img, trans): - '''Get vector features from binary raster image. Raster data is loaded - from array as a rasterio inmemory object, and returns features as a - geopandas dataframe. - - Variables - img (arr) Binary raster array - trans (Affine): Raster transformation (computed using - affine package, or - rasterio.transform) - Returns - feats (Geodataframe): Vector features geodataframe - ''' - #Open array as rasterio memory object - with rio.io.MemoryFile() as memfile: - with memfile.open( - driver='GTiff', - height=img.shape[0], - width=img.shape[1], - count=1, - dtype=img.dtype, - transform=trans - ) as dataset: - dataset.write(img, 1) - - #Vectorize array - with memfile.open() as dataset: - image = dataset.read(1) - mask = image==255 - results = ( - {'properties': {'raster_val': v}, 'geometry': s} - for i, (s, v) - in enumerate( - shapes(image, - mask=mask, - transform=rio.transform.from_origin(transf[0], - transf[3], - transf[1], - transf[5])))) - - ##Transform geometries to geodataframe - geoms = list(results) - feats = gp.GeoDataFrame.from_features(geoms) - - return feats - -#-------------------- Configure SentinelHub client ------------------------ - -#Configure Sentinelhub connection client -config = SHConfig() -# config.instance_id = 'e4ac5ac3-ca5e-4624-ab3a-8214df144373' #Instance ID needed -# config.sh_client_id = '23032a7f-66c1-447e-99ed-44c10d13072f' #Client ID needed -# config.sh_client_secret = 'WZ|ufGd;yp|YW];2[aZ!Oh7uvr~r