kvos / CoastSat

Global shoreline mapping tool from satellite imagery
http://coastsat.space
GNU General Public License v3.0
696 stars 252 forks source link

Error in drawing reference shoreline #255

Closed Ahmed-Elghandour closed 1 year ago

Ahmed-Elghandour commented 2 years ago

Hi Kilian,

I am getting the following error while trying to detect the whole island. it works only if I detect the eastern part with long intervals. I have tried to change some parameters, but it did not help. do you have any suggestions?. I applied your tool to the same area before and I managed to get few coastlines.


IndexError Traceback (most recent call last)

in 1 get_ipython().run_line_magic('matplotlib', 'qt') ----> 2 settings['reference_shoreline'] = SDS_preprocess.get_reference_sl(metadata, settings) 3 settings['max_dist_ref'] = 1000 # max distance (in meters) allowed from the reference shoreline ~\CoastSat-master\CoastSat-master\coastsat\SDS_preprocess.py in get_reference_sl(metadata, settings) 818 pts_pix = np.array(pts) 819 # convert pixel coordinates to world coordinates --> 820 pts_world = SDS_tools.convert_pix2world(pts_pix[:,[1,0]], georef) 821 822 # interpolate between points clicked by the user (1m resolution) IndexError: too many indices for array Here are the inputs I used: import os import numpy as np import pickle import warnings warnings.filterwarnings("ignore") import matplotlib matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt from matplotlib import gridspec plt.ion() import pandas as pd from datetime import datetime from coastsat import SDS_download, SDS_preprocess, SDS_shoreline, SDS_tools, SDS_transects polygon = [[[-148.053, 70.502], [-147.886, 70.502], [-147.886, 70.451], [-148.053, 70.451], [-148.053, 70.502]]] polygon = SDS_tools.smallest_rectangle(polygon) dates = ['2016-07-14', '2016-07-15'] sat_list = ['S2'] sitename = 'Cross_island_2016' filepath = os.path.join(os.getcwd(), 'data') inputs = {'polygon': polygon, 'dates': dates, 'sat_list': sat_list, 'sitename': sitename, 'filepath':filepath} SDS_download.check_images_available(inputs); metadata = SDS_download.retrieve_images(inputs) metadata = SDS_download.get_metadata(inputs) settings = { 'cloud_thresh': 0.5, # threshold on maximum cloud cover 'output_epsg': 32606, # epsg code of spatial reference system desired for the output 'check_detection': True, # if True, shows each shoreline detection to the user for validation 'adjust_detection': False, # if True, allows user to adjust the postion of each shoreline by changing the threhold 'save_figure': True, # if True, saves a figure showing the mapped shoreline for each image 'min_beach_area': 4500, # minimum area (in metres^2) for an object to be labelled as a beach 'buffer_size': 150, # radius (in metres) for buffer around sandy pixels considered in the shoreline detection 'min_length_sl': 200, # minimum length (in metres) of shoreline perimeter to be valid 'cloud_mask_issue': False, # switch this parameter to True if sand pixels are masked (in black) on many images 'sand_color': 'default', # 'default', 'dark' (for grey/black sand beaches) or 'bright' (for white sand beaches) 'inputs': inputs } SDS_preprocess.save_jpg(metadata, settings) %matplotlib qt settings['reference_shoreline'] = SDS_preprocess.get_reference_sl(metadata, settings) settings['max_dist_ref'] = 1000 # max distance (in meters) allowed from the reference shoreline Thanks in advance Best Regards, Ahmed
kvos commented 2 years ago

hi @Ahmed-Elghandour , could you please illustrate the issue? I'm not sure I understand

Ahmed-Elghandour commented 2 years ago

Hi @kvos thanks for replying,

for example when I use the previous input and click points like here:

image

or

image

it gives me that error image

however, it works fine if I click like this: image

kvos commented 2 years ago

hi @Ahmed-Elghandour , ok I understand now, must be something going wrong with the drawing function. I don't know how wide is the inland, but what you could do is to create a simpler shape and then increase the settings['max_dist_ref'] parameter which defines the buffer around the reference shoreline that is considered for shoreline contouring, then you could have the ref shoreline in the middle and the buffer spanning both sides of the island. I'm about to submit my thesis at the end of the month so won't have time to troubleshoot at what is causing the error now. Btw, are you working on shoreline modelling on barrier islands in Alaska? I think I read your thesis, really cool stuff! Another thing you could explore is the CoastSat.islands toolbox, https://github.com/mcuttler/CoastSat.islands, where Mike Cuttler adapted it to extract island area and orientation from the sand pixels directly. Cheers, Kilian

Ahmed-Elghandour commented 2 years ago

Hi @kvos, first of all, congratulations for submitting your thesis, looking forward to read it. thanks for your suggestions!, I will give them a try, also the coastsat.islands thanks for your words, probably you meant the report with USGS, anyway, your tool helped me to get several shorelines for different cases, thanks so much, and good luck with the remaining processes to get your PhD (well deserved)

kvos commented 2 years ago

any update on this bug @Ahmed-Elghandour ?

Ahmed-Elghandour commented 2 years ago

no, the bug is still there with the version I have

kvos commented 2 years ago

ok I can try to reproduce it and see what was going on, which reference shoreline did you draw when it produced the error? can you pls post a screenshot? otherwise did you find a work around? Like creating it in QGIS and loading it

Ahmed-Elghandour commented 1 year ago

the error happens at the stage of " [OPTIONAL] Digitize a reference shoreline" the reference that produced the error is the one in the first image above

I did not use QGIS, originally it was working for me so I had shorelines that I extracted earlier I used them