Skip to content
Snippets Groups Projects
Commit 68214db4 authored by Verouden, Niels's avatar Verouden, Niels
Browse files

normalize data from EO Learn API

parent 59abc0fa
No related branches found
No related tags found
No related merge requests found
......@@ -28,14 +28,17 @@ def rewriteTIF(eopatch, file_name, vv_path, vh_path, dem_path):
with rio.open(dem_path, 'r') as dst:
dem = dst.read()
#Scale to range 0-1
vv_data /= np.amax(vv_data)
vh_data /= np.amax(vh_data)
# Calculate VV/VH ratio from VV and VH data
#VV/VH ratio is calculated as VV/VH, since our data is measured on a linear scale
vvvh_ratio = np.empty(vv_data.shape, dtype=rio.float64)
vvvh_ratio = np.divide(vv_data, vh_data, out=np.zeros_like(vv_data), where = vh_data!=0)
#Calculate an index that highlights water bodies as third band:
vvvh_sum = np.add(vv_data,vh_data)
vvvh_dif = np.subtract(vv_data,vh_data)
vvvh_index = np.divide(vvvh_dif,vvvh_sum,out=np.zeros_like(vvvh_sum), where=vvvh_sum!=0)
# Zip VV, VH, and VV/VH arrays together into one array
stack = [[x]+[y]+[z] for x, y, z in zip(vv_data, vh_data, vvvh_ratio)]
stack = [[x]+[y]+[z] for x, y, z in zip(vv_data, vh_data, vvvh_index)]
names = []
# Write arrays to tif based on their data
......@@ -47,7 +50,7 @@ def rewriteTIF(eopatch, file_name, vv_path, vh_path, dem_path):
dst.write_band(2, stack[i][1])
dst.write_band(3, stack[i][2])
dst.write_band(4, dem[0])
dst.descriptions = tuple(['VV','VH','VV/VH_ratio','DEM'])
dst.descriptions = tuple(['VV','VH','VV/VH_index','DEM'])
names.append(stack_filename)
# Remove temporary VV and VH files
......
......@@ -7,40 +7,41 @@ import matplotlib.pyplot as plt
import os
def visualiseResults(visualise, bands, names, file_name):
for i in range(len(bands)):
if bands[i] == 'VV':
band = 0
elif bands[i] == 'VH':
band = 1
elif bands[i] == 'VVVH':
band = 2
elif bands[i] == 'DEM':
band = 3
# Plot all images for each band in bands, expect for DEM (only plot DEM once)
if band != 3:
for x in range(len(names)):
path_stacked = os.path.join('data', file_name, names[x])
if visualise == 'y':
for i in range(len(bands)):
if bands[i] == 'VV':
band = 0
elif bands[i] == 'VH':
band = 1
elif bands[i] == 'VVVH':
band = 2
elif bands[i] == 'DEM':
band = 3
# Plot all images for each band in bands, expect for DEM (only plot DEM once)
if band != 3:
for x in range(len(names)):
path_stacked = os.path.join('data', file_name, names[x])
SAR = rio.open(path_stacked)
SARi = SAR.read(band+1)
date = names[x][0:10]
fig, ax = plt.subplots(figsize=(10,10))
rio.plot.show(SARi, ax=ax)
plt.title(f'{bands[i]} {date}', fontdict={'fontsize': 20})
plt.axis(False)
del SAR
else:
path_stacked = os.path.join('data', file_name, names[0])
SAR = rio.open(path_stacked)
SARi = SAR.read(band+1)
date = names[x][0:10]
date = names[0][0:10]
fig, ax = plt.subplots(figsize=(10,10))
rio.plot.show(SARi, ax=ax)
plt.title(f'{bands[i]} {date}', fontdict={'fontsize': 20})
plt.axis(False)
del SAR
else:
path_stacked = os.path.join('data', file_name, names[0])
SAR = rio.open(path_stacked)
SARi = SAR.read(band+1)
date = names[0][0:10]
fig, ax = plt.subplots(figsize=(10,10))
rio.plot.show(SARi, ax=ax)
plt.title(f'{bands[i]} {date}', fontdict={'fontsize': 20})
plt.axis(False)
del SAR
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment