Comments (19)
My previous area was too large, however it is still giving me nan for those values.
New points:
[[[-75.537, 35.776],
[-75.52, 35.78],
[-75.463, 35.685],
[-75.512, 35.675],
[-75.537, 35.776]]]
from coastsat.
hey @whitmcq81 , did you set the transects with the origin on land and the 2nd point seawards?
from coastsat.
Yes I did, I was wondering where my area has water on both sides could that be messing up the calculations?
from coastsat.
ok I am not sure what could be causing this issue, could you please send me your example.py script so I can run it and debug it
from coastsat.
Here it is, I ran it this morning and got it to work. Not sure why it did this time and not the others.
#==========================================================#
Shoreline extraction from satellite images
#==========================================================#
Kilian Vos WRL 2018
#%% 1. Initial settings
load modules
import os
import numpy as np
import pickle
import warnings
warnings.filterwarnings("ignore")
import matplotlib.pyplot as plt
from coastsat import SDS_download, SDS_preprocess, SDS_shoreline, SDS_tools, SDS_transects
region of interest (longitude, latitude in WGS84)
polygon = [[[-75.537, 35.776],
[-75.52, 35.78],
[-75.463, 35.685],
[-75.512, 35.675],
[-75.537, 35.776]]]
can also be loaded from a .kml polygon
#kml_polygon = os.path.join(os.getcwd(), 'examples', 'NARRA_polygon.kml')
#polygon = SDS_tools.polygon_from_kml(kml_polygon)
date range
dates = ['2017-10-01', '2018-01-01']
satellite missions
sat_list = ['S2']
name of the site
sitename = 'TESTOI_11'
filepath where data will be stored
filepath_data = os.path.join(os.getcwd(), 'data')
put all the inputs into a dictionnary
inputs = {
'polygon': polygon,
'dates': dates,
'sat_list': sat_list,
'sitename': sitename,
'filepath': filepath_data
}
#%% 2. Retrieve images
retrieve satellite images from GEE
metadata = SDS_download.retrieve_images(inputs)
if you have already downloaded the images, just load the metadata file
metadata = SDS_download.get_metadata(inputs)
#%% 3. Batch shoreline detection
settings for the shoreline extraction
settings = {
# general parameters:
'cloud_thresh': 0.5, # threshold on maximum cloud cover
'output_epsg': 3358, # epsg code of spatial reference system desired for the output
# quality control:
'check_detection': True, # if True, shows each shoreline detection to the user for validation
'save_figure': True, # if True, saves a figure showing the mapped shoreline for each image
# add the inputs defined previously
'inputs': inputs,
# [ONLY FOR ADVANCED USERS] shoreline detection parameters:
'min_beach_area': 4500, # minimum area (in metres^2) for an object to be labelled as a beach
'buffer_size': 150, # radius (in metres) of the 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)
}
[OPTIONAL] preprocess images (cloud masking, pansharpening/down-sampling)
SDS_preprocess.save_jpg(metadata, settings)
[OPTIONAL] create a reference shoreline (helps to identify outliers and false detections)
settings['reference_shoreline'] = SDS_preprocess.get_reference_sl(metadata, settings)
set the max distance (in meters) allowed from the reference shoreline for a detected shoreline to be valid
settings['max_dist_ref'] = 100
extract shorelines from all images (also saves output.pkl and shorelines.kml)
output = SDS_shoreline.extract_shorelines(metadata, settings)
plot the mapped shorelines
fig = plt.figure()
plt.axis('equal')
plt.xlabel('Eastings')
plt.ylabel('Northings')
plt.grid(linestyle=':', color='0.5')
for i in range(len(output['shorelines'])):
sl = output['shorelines'][i]
date = output['dates'][i]
plt.plot(sl[:,0], sl[:,1], '.', label=date.strftime('%d-%m-%Y'))
plt.legend()
mng = plt.get_current_fig_manager()
mng.window.showMaximized()
fig.set_size_inches([15.76, 8.52])
#%% 4. Shoreline analysis
if you have already mapped the shorelines, load the output.pkl file
filepath = os.path.join(inputs['filepath'], sitename)
with open(os.path.join(filepath, sitename + '_output' + '.pkl'), 'rb') as f:
output = pickle.load(f)
now we have to define cross-shore transects over which to quantify the shoreline changes
each transect is defined by two points, its origin and a second point that defines its orientation
there are 3 options to create the transects:
- option 1: draw the shore-normal transects along the beach
- option 2: load the transect coordinates from a .kml file
- option 3: create the transects manually by providing the coordinates
option 1: draw origin of transect first and then a second point to define the orientation
transects = SDS_transects.draw_transects(output, settings)
option 2: load the transects from a .geojson file
#geojson_file = os.path.join(os.getcwd(), 'examples', 'NARRA_transects.geojson')
#transects = SDS_tools.transects_from_geojson(geojson_file)
option 3: create the transects by manually providing the coordinates of two points
#transects = dict([])
#transects['Transect 1'] = np.array([[342836, 6269215], [343315, 6269071]])
#transects['Transect 2'] = np.array([[342482, 6268466], [342958, 6268310]])
#transects['Transect 3'] = np.array([[342185, 6267650], [342685, 6267641]])
intersect the transects with the 2D shorelines to obtain time-series of cross-shore distance
settings['along_dist'] = 25
cross_distance = SDS_transects.compute_intersection(output, transects, settings)
plot the time-series
from matplotlib import gridspec
fig = plt.figure()
gs = gridspec.GridSpec(len(cross_distance),1)
gs.update(left=0.05, right=0.95, bottom=0.05, top=0.95, hspace=0.05)
for i,key in enumerate(cross_distance.keys()):
if np.all(np.isnan(cross_distance[key])):
continue
ax = fig.add_subplot(gs[i,0])
ax.grid(linestyle=':', color='0.5')
ax.set_ylim([-50,50])
ax.plot(output['dates'], cross_distance[key]- np.nanmedian(cross_distance[key]), '-^', markersize=6)
ax.set_ylabel('distance [m]', fontsize=12)
ax.text(0.5,0.95,'Transect ' + key, bbox=dict(boxstyle="square", ec='k',fc='w'), ha='center',
va='top', transform=ax.transAxes, fontsize=14)
mng = plt.get_current_fig_manager()
mng.window.showMaximized()
fig.set_size_inches([15.76, 8.52])
from coastsat.
ok then I don't have to test it :) I will close the issue for now, feel free to reopen if the issue arises again
from coastsat.
kvos, Im trying to input my own transects using option #3. Im using the correct coordinates for epsg code 3358 but I am still getting nan for my cross-section distance. I get the shorelines but no time-series chart. When I draw the shorelines, option #1, it works. Any ideas?
Here are my coordinates and transects:
from coastsat.
are those transects on the same coordinate system as the shorelines (settings['output_epsg']
)? you can plot the transects on top of the shorelines to cross-check this
from coastsat.
Yes they are. When I plotted them they go from land to seaside and across the shoreline.
from coastsat.
can you plot the transects that you defined with option 3 on top of the shorelines?
from coastsat.
I couldn't figure out how to exactly plot them on the graph so I drew them as close as I could get them.
from coastsat.
ok that's not what I meant.
After defining your transect coordinates with option 3, add these lines of code:
fig = plt.figure()
plt.axis('equal')
plt.xlabel('Eastings')
plt.ylabel('Northings')
plt.grid(linestyle=':', color='0.5')
for i in range(len(output['shorelines'])):
sl = output['shorelines'][i]
date = output['dates'][i]
plt.plot(sl[:,0], sl[:,1], '.', label=date.strftime('%d-%m-%Y'))
plt.legend()
for key in transects.keys():
plt.plot(transects[key][:,0], transects[key][:,1], 'k-', lw=3)
plt.plot(transects[key][0,0], transects[key][0,1], 'ro')
mng = plt.get_current_fig_manager()
mng.window.showMaximized()
fig.set_size_inches([15.76, 8.52])
and see if the transects show up on top of the shorelines, if they don't it means there is a problem with the coordinates.
from coastsat.
Here are the plotted transects. So the coordinates seem to be fine. The time series however still does not show up.
from coastsat.
you need to switch your origin, origin (red dot) is always the most landward point
from coastsat.
from coastsat.
ok that's weird then...can you try to swap the two points of your transects defined with option 3
from coastsat.
Well that seemed to do it. It gave me the time series for the shorelines. I appreciate the help.
from coastsat.
cool!
from coastsat.
Would there be a reason that Im not getting distances for a large chunk of transects but it calculates everything else? The transects Im asking about are the ones located below the break where the slope shifts about halfway down. Above this point they calculate, below this they do not. Any ideas?
from coastsat.
Related Issues (20)
- IndexError: list index out of range - when plotting seasonal averages and long term trends HOT 2
- Doesn't plot final seasonal and monthly trend figures HOT 1
- After opening the clash proxy software, some errors message appears HOT 1
- Tidal Correction data error:''value' must be an instance of str or bytes, not a float' HOT 7
- Quick question about water level correction HOT 1
- Problem with GEE HOT 2
- white water border in pixel classification HOT 11
- Axis limits cannot be NaN or Inf HOT 1
- CoastSAT seasonal and monthly average graphs HOT 8
- tidal correction plus setup and runup correction! HOT 2
- fail to digitize a reference shoreline HOT 2
- KeyError: 'dimensions' when retrieving S2 imagery HOT 12
- Spyder: QWidget: Must construct a Qapplication before a Qwidget. HOT 4
- Downloading question and reference shoreline question HOT 3
- Sentinel-2 images failed to download HOT 3
- CoastSat running on Colab: error with the pyfes package HOT 1
- L7 scanline error HOT 6
- Error about SDS_download.retrieve_images(inputs) HOT 1
- Coastsat to work for small atoll island of Tuvalu HOT 1
- Images not downloading HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coastsat.