-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Seen behaviour
When running aeolis with the visualization-argument set to True, the function expects that the p-variable contains arrays for p['wind_file'], p['wave_file'], and p['tide_file']. However, when these files are not provided - e.g., because (part of) these processes are not enabled - this results in an IndexError.
Expected behaviour
The expected behaviour is that when (part of) these files are not provided - especially when the corresponding processes are disabled - the visualisation is not generated for these timeseries without raising an error; i.e., the visualisation should skip this boundary condition. PS. I can understand that the p['wind_file'] is considered mandatory, and thus should always be provided.
Code suggestion
Instead of the current if-statements (i.e., if np.shape(p['wave_file'])[1] == 3: and if np.shape(p['tide_file'])[1] == 2:), there is a check whether these processes are enabled and/or the entries are defined. Applying the np.shape()-function on a NoneType (i.e., undefined) results in an empty tuple (i.e., ()), which cannot be indexed (there are no entries after all). Thus instead, the above if-statements should be preceded by if p['wave_file'] is not None: and if p['tide_file'] is not None:.
Thus, e.g., the below code could replace the existing code:
if p['wave_file'] is not None and np.shape(p['wave_file'])[1]== 3:
w_t = p['wave_file'][:,0]
w_Hs = p['wave_file'][:,1]
w_Tp = p['wave_file'][:,2]
axs[2].plot(w_t, w_Hs, 'k')
axs[3].plot(w_t, w_Tp, 'k')
axs[2].set_title('Wave height, Hs (m)')
axs[3].set_title('Wave period, Tp (sec)')
# Read the user input (tide)
if p['tide_file'] is not None and np.shape(p['tide_file'])[1]==2:
T_t = p['tide_file'][:,0]
T_zs = p['tide_file'][:,1]
axs[4].plot(T_t, T_zs, 'k')
axs[4].set_title('Water level, zs (m)')This will result in empty plots, which could be accommodated for by setting the number of plots dynamically, based on the provided data; or, it can be left empty intentionally to highlight the missing timeseries.