import sys
sys.path.append(‘/home/siddharth/trambak/snappy’)
import os
import glob
import snappy
from snappy import GPF
def download_orbit_file(s1_image):
print(“Orbit Data Processing”)
orbitFile = snappy.ProductIO.readProduct(s1_image + “/manifest.safe”)
parameters = snappy.HashMap()
parameters.put(‘Apply-Orbit-File’, True)
orbitOutput = GPF.createProduct(‘Apply-Orbit-File’, parameters, orbitFile)
parameters.put(‘orbitType’, ‘Sentinel Precise (Auto Download)’)
return orbitOutput
def do_subset(source, wkt):
print(‘\tSubsetting…’)
parameters = snappy.HashMap()
parameters.put(‘geoRegion’, wkt)
output = GPF.createProduct(‘Subset’, parameters, source)
return output
def do_calibration(source, polarization, pols):
print(‘\tCalibration…’)
parameters = snappy.HashMap()
parameters.put(‘outputSigmaBand’, True)
if polarization == ‘DH’:
print(‘\tCalibration…’)
parameters.put(‘sourceBands’, ‘Intensity_VV’)
#parameters.put(‘sourceBands’, ‘Intensity_HH,Intensity_HV’)
elif polarization == ‘DV’:
parameters.put(‘sourceBands’, ‘Intensity_VH,Intensity_VV’)
elif polarization == ‘SH’ or polarization == ‘HH’:
parameters.put(‘sourceBands’, ‘Intensity_HH’)
elif polarization == ‘SV’:
parameters.put(‘sourceBands’, ‘Intensity_VV’)
else:
print(“different polarization!”)
print('\tCalibration...')
parameters.put('selectedPolarisations', pols)
parameters.put('outputImageScaleInDb', False)
print('\tCalibration...')
output = GPF.createProduct("Calibration", parameters, source)
print('\tCalibration...1')
return output
def do_speckle_filtering(source):
print(‘\tSpeckle filtering…’)
parameters = snappy.HashMap()
parameters.put(‘filter’, ‘Lee’)
parameters.put(‘filterSizeX’, 5)
parameters.put(‘filterSizeY’, 5)
output = GPF.createProduct(‘Speckle-Filter’, parameters, source)
return output
def preprocess_sentinel1_image(s1_image):
folder = s1_image
orbitOutput = download_orbit_file(s1_image)
modestamp = folder.split(““)[1]
productstamp = folder.split(””)[2]
polstamp = folder.split(“_”)[3]
polarization = polstamp[2:4]
if polarization == 'DV':
pols = 'VH,VV'
elif polarization == 'DH':
pols = 'HH,HV'
elif polarization == 'SH' or polarization == 'HH':
pols = 'HH'
elif polarization == 'SV':
pols = 'VV'
else:
print("Polarization error!")
print(polarization)
print(pols)
parameters = snappy.HashMap()
parameters.put('removeThermalNoise', True)
orbitOutput = GPF.createProduct('ThermalNoiseRemoval', parameters, orbitOutput)
calibrated = do_calibration(orbitOutput,polarization, pols)
print('\tCalibration...')
down_filtered = do_speckle_filtering(calibrated)
# Remove thermal noise
print("Orbit Data Processing")
# Export to GeoTIFF subset
wkt = 'POLYGON((85.2786340943649 19.98143168402237,86.11037335501074 20.025747032929132,86.31187754046424 19.618385502024594,84.86705195938421 19.128997288585452,85.2786340943649 19.98143168402237))'
orbitOutput = do_subset(orbitOutput, wkt)
snappy.ProductIO.writeProduct(orbitOutput, s1_image + "_40.tiff", 'GeoTIFF')
print("Processed image saved to: {output_tif_path}")
if name == “main”:
data_path = ‘data/s1_images/’
# Process all Sentinel-1 images in the specified directory
for s1_image in glob.glob(os.path.join(data_path, '*.SAFE')):
print(s1_image)
try:
preprocess_sentinel1_image(s1_image)
except Exception as e:
print(f"Error processing {s1_image}: {e}")
(I have attached the code here. However the error is in the calibration process where the source bands are said to not there. Please if you solve @dolaf @diana_harosa )
please help out. i need to figure it out very fast.