kvos / CoastSat.slope

Beach-face slope estimation from satellite-derived shorelines, extension of the CoastSat toolbox.
http://coastsat.wrl.unsw.edu.au/
GNU General Public License v3.0
59 stars 17 forks source link

using own tide data file #6

Closed Ahmed-Elghandour closed 3 years ago

Ahmed-Elghandour commented 3 years ago

Hi Kilian,

Thanks for these helpful tools, I tried to use measured tide data to estimate the slope I got errors on steps number 4, 5

4. Peak tidal frequency

ValueError Traceback (most recent call last)

in 4 fig, ax = plt.subplots(1,1,figsize=(12,3), tight_layout=True) 5 ax.grid(which='major', linestyle=':', color='0.5') ----> 6 bins = np.arange(np.min(delta_t)/seconds_in_day, np.max(delta_t)/seconds_in_day+1,1)-0.5 7 ax.hist(delta_t/seconds_in_day, bins=bins, ec='k', width=1); 8 ax.set(xlabel='timestep [days]', ylabel='counts', ~\anaconda3\envs\coastsat\lib\site-packages\numpy\core\fromnumeric.py in amin(a, axis, out, keepdims, initial) 2616 """ 2617 return _wrapreduction(a, np.minimum, 'min', axis, None, out, keepdims=keepdims, -> 2618 initial=initial) 2619 2620 ~\anaconda3\envs\coastsat\lib\site-packages\numpy\core\fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs) 84 return reduction(axis=axis, out=out, **passkwargs) 85 ---> 86 return ufunc.reduce(obj, axis, dtype, out, **passkwargs) 87 88 ValueError: zero-size array to reduction operation minimum which has no identity **5. Estimate the beach slope** --------------------------------------------------------------------------- ValueError Traceback (most recent call last) in 10 tsall = SDS_slope.tide_correct(composite,tide,beach_slopes) 11 title = 'Transect %s'%key ---> 12 SDS_slope.plot_spectrum_all(dates,composite,tsall,settings_slope, title) 13 slope_est[key] = SDS_slope.integrate_power_spectrum(dates,tsall,settings_slope) 14 print('Beach slope at transect %s: %.3f'%(key, slope_est[key])) ~\OneDrive - Universidade do Algarve\New coastsat\CoastSat.slope-master\CoastSat.slope-master\SDS_slope.py in plot_spectrum_all(dates_rand, composite, tsall, settings, title) 580 days_in_year = 365.2425 581 time_step = settings['n_days']*seconds_in_day --> 582 freqs = frequency_grid(t,time_step,settings['n0']) 583 beach_slopes = range_slopes(settings['slope_min'], settings['slope_max'], settings['delta_slope']) 584 ~\OneDrive - Universidade do Algarve\New coastsat\CoastSat.slope-master\CoastSat.slope-master\SDS_slope.py in frequency_grid(time, time_step, n0) 529 def frequency_grid(time,time_step,n0): 530 'define frequency grid for Lomb-Scargle transform' --> 531 T = np.max(time) - np.min(time) 532 fmin = 1/T 533 fmax = 1/(2*time_step) # Niquist criterium ~\anaconda3\envs\coastsat\lib\site-packages\numpy\core\fromnumeric.py in amax(a, axis, out, keepdims, initial) 2503 """ 2504 return _wrapreduction(a, np.maximum, 'max', axis, None, out, keepdims=keepdims, -> 2505 initial=initial) 2506 2507 ~\anaconda3\envs\coastsat\lib\site-packages\numpy\core\fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs) 84 return reduction(axis=axis, out=out, **passkwargs) 85 ---> 86 return ufunc.reduce(obj, axis, dtype, out, **passkwargs) 87 88 ValueError: zero-size array to reduction operation maximum which has no identity **FYI: here the code I wrote to write the .pkl file** that might be the problem? (I am not a python user, I collected from videos) import datetime import pytz import numpy as np data_dict = {'dates': [datetime.datetime(1997,1,8,10,32,6,0,pytz.UTC), datetime.datetime(1997,1,24,10,32,50,0,pytz.UTC), datetime.datetime(1997,2,9,10,33,32,0,pytz.UTC), datetime.datetime(1997,2,25,10,34,12,0,pytz.UTC), datetime.datetime(1997,3,29,10,35,27,0,pytz.UTC), datetime.datetime(1997,5,16,10,37,7,0,pytz.UTC), datetime.datetime(1997,6,1,10,37,42,0,pytz.UTC), datetime.datetime(1997,6,17,10,38,14,0,pytz.UTC), datetime.datetime(1997,7,3,10,38,48,0,pytz.UTC), datetime.datetime(1997,8,20,10,40,23,0,pytz.UTC), datetime.datetime(1997,9,5,10,40,51,0,pytz.UTC), datetime.datetime(1997,9,21,10,41,18,0,pytz.UTC), datetime.datetime(1997,10,7,10,41,46,0,pytz.UTC), datetime.datetime(1997,10,23,10,42,12,0,pytz.UTC), datetime.datetime(1997,11,8,10,42,37,0,pytz.UTC), datetime.datetime(1997,12,26,10,43,45,0,pytz.UTC), datetime.datetime(1998,6,4,10,46,29,0,pytz.UTC), datetime.datetime(1998,7,6,10,46,53,0,pytz.UTC), datetime.datetime(1998,7,22,10,47,2,0,pytz.UTC), datetime.datetime(1998,8,7,10,47,6,0,pytz.UTC), datetime.datetime(1998,8,23,10,47,17,0,pytz.UTC), datetime.datetime(1998,9,24,10,47,34,0,pytz.UTC), datetime.datetime(1998,11,27,10,47,44,0,pytz.UTC), datetime.datetime(1998,12,13,10,47,40,0,pytz.UTC)], 'tide': np.array([0.1418,-0.8282,-1.6682,-1.4182,-0.9782,0.6418,1.0418,0.7118,0.1118,-1.3282,-1.0282,-1.2682,-0.7882, 0.1418,0.3018,0.6418,0.6918,0.7318,0.3518,0.2618,-0.6582,-1.0482,-0.0382,0.5018])} with open ('NARRA_test_tide.pkl','wb') as f: pickle.dump(data_dict , f) with open ('NARRA_test_tide.pkl','rb') as f : newdata = pickle.load(f) Thanks Ahmed
kvos commented 3 years ago

hi ahmed, you need to look what is in the different variables to debug this problem, I can't help by just reading the error message. You can run it in Spyder and check that every step is running and see where it's failing, then let me know when you have a better idea of the problem and I'll try to help