You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.9 KiB
Python

#==========================================================#
# Shoreline extraction from satellite images
#==========================================================#
# load modules
import os
import pickle
import warnings
warnings.filterwarnings("ignore")
import matplotlib.pyplot as plt
6 years ago
import SDS_download, SDS_preprocess, SDS_shoreline, SDS_tools
# define the area of interest (longitude, latitude)
6 years ago
polygon = SDS_tools.coords_from_kml('NARRA.kml')
# define dates of interest
6 years ago
dates = ['2015-01-01', '2019-01-01']
# define satellite missions
6 years ago
sat_list = ['S2']
# give a name to the site
sitename = 'NARRA'
6 years ago
# put all the inputs into a dictionnary
inputs = {
'polygon': polygon,
'dates': dates,
'sat_list': sat_list,
'sitename': sitename
}
# download satellite images (also saves metadata.pkl)
6 years ago
metadata = SDS_download.get_images(inputs)
6 years ago
# if you have already downloaded the images, just load the metadata file
filepath = os.path.join(os.getcwd(), 'data', sitename)
with open(os.path.join(filepath, sitename + '_metadata' + '.pkl'), 'rb') as f:
6 years ago
metadata = pickle.load(f)
6 years ago
#%%
# settings needed to run the shoreline extraction
settings = {
# general parameters:
6 years ago
'cloud_thresh': 0.2, # threshold on maximum cloud cover
'output_epsg': 28356, # epsg code of spatial reference system desired for the output
# shoreline detection parameters:
'min_beach_size': 20, # minimum number of connected pixels for a beach
'buffer_size': 7, # radius (in pixels) of disk for buffer around sandy pixels
'min_length_sl': 200, # minimum length of shoreline perimeter to be kept
'max_dist_ref': 100, # max distance (in meters) allowed from a reference shoreline
# quality control:
6 years ago
'check_detection': True, # if True, shows each shoreline detection and lets the user
# decide which ones are correct and which ones are false due to
6 years ago
# the presence of clouds
# also add the inputs
'inputs': inputs
}
6 years ago
# preprocess images (cloud masking, pansharpening/down-sampling)
6 years ago
#SDS_preprocess.save_jpg(metadata, settings)
6 years ago
# create a reference shoreline (helps to identify outliers and false detections)
settings['refsl'] = SDS_preprocess.get_reference_sl_manual(metadata, settings)
#settings['refsl'] = SDS_preprocess.get_reference_sl_Australia(settings)
# extract shorelines from all images (also saves output.pkl)
6 years ago
output = SDS_shoreline.extract_shorelines(metadata, settings)
# plot shorelines
plt.figure()
plt.axis('equal')
plt.xlabel('Eastings [m]')
plt.ylabel('Northings [m]')
6 years ago
for satname in output.keys():
if satname == 'meta':
continue
6 years ago
for i in range(len(output[satname]['shoreline'])):
sl = output[satname]['shoreline'][i]
date = output[satname]['timestamp'][i]
plt.plot(sl[:, 0], sl[:, 1], '.', label=date.strftime('%d-%m-%Y'))
plt.legend()