In [1]:
%matplotlib inline

Análisis de oleaje mediante método de pasos ascendentes por cero

Dept. Mecánica de Estructuras e Ingeniería Hidráulica

E.T.S.I. Caminos, Canales y Puertos

Universidad de Granada

In [2]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

Parte I

Leer los datos de superficie libre registrados en el laboratorio. Fichero 0093log2.dat

In [3]:
datos = pd.read_csv('0093log2.dat', 
                    delimiter=',',                     
                    names=['t', 's1', 's2', 's3', 's4', 's5',
                          's6', 's7', 's8', 's9', 's10'])
datos
Out[3]:
t s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
0 0.00 0.032479 0.060928 0.054335 0.073871 -0.026129 0.069230 0.001099 0.104273 0.021734 0.008791
1 0.05 -0.040781 0.060928 0.054335 0.049451 -0.001709 0.069230 0.025519 0.104273 -0.002686 -0.015629
2 0.10 0.056899 0.060928 0.078755 0.049451 -0.001709 0.044810 0.001099 0.128693 -0.124786 -0.015629
3 0.15 -0.016361 0.060928 0.078755 0.073871 -0.026129 0.093651 -0.047741 0.153113 -0.002686 0.008791
4 0.20 0.056899 0.012088 0.054335 0.073871 -0.050549 0.069230 0.025519 0.031013 -0.027106 0.008791
5 0.25 0.056899 0.060928 0.054335 0.073871 -0.001709 0.044810 0.001099 0.104273 -0.002686 0.008791
6 0.30 0.008059 0.085348 0.054335 0.073871 0.022711 0.069230 -0.047741 0.104273 -0.002686 0.008791
7 0.35 0.130159 0.060928 0.054335 0.073871 -0.026129 0.069230 -0.047741 0.079853 -0.002686 0.008791
8 0.40 0.056899 0.109768 0.054335 0.073871 -0.050549 0.069230 0.001099 0.079853 0.021734 0.008791
9 0.45 0.032479 0.134188 0.054335 0.073871 0.022711 0.069230 0.001099 0.079853 -0.002686 0.008791
10 0.50 0.056899 0.060928 0.029915 0.073871 -0.026129 0.264591 0.025519 0.079853 -0.002686 0.008791
11 0.55 0.056899 0.060928 0.054335 0.073871 0.071551 0.044810 -0.023321 0.104273 0.168254 0.008791
12 0.60 0.301099 0.060928 0.078755 0.073871 -0.026129 0.044810 0.001099 0.079853 0.021734 0.008791
13 0.65 0.105739 0.060928 0.054335 0.073871 -0.026129 0.020390 0.025519 0.079853 -0.002686 0.008791
14 0.70 0.081319 0.085348 0.054335 0.073871 0.022711 0.044810 0.001099 0.079853 -0.002686 -0.015629
15 0.75 0.056899 0.036508 0.054335 0.049451 -0.026129 0.020390 0.025519 0.055433 -0.002686 -0.015629
16 0.80 0.056899 0.060928 0.054335 0.049451 0.071551 0.044810 0.025519 0.031013 -0.002686 -0.015629
17 0.85 0.008059 0.060928 0.054335 0.049451 -0.001709 0.044810 -0.023321 0.079853 -0.027106 -0.015629
18 0.90 0.056899 0.060928 0.029915 0.049451 -0.026129 0.093651 0.001099 0.079853 -0.002686 0.008791
19 0.95 0.056899 0.036508 0.054335 0.049451 -0.026129 0.069230 0.025519 0.079853 -0.002686 0.008791
20 1.00 0.081319 0.036508 0.054335 0.073871 -0.001709 0.069230 0.025519 0.079853 -0.002686 0.008791
21 1.05 0.032479 0.036508 0.054335 0.073871 -0.001709 0.069230 0.025519 0.031013 -0.002686 -0.015629
22 1.10 0.056899 0.060928 0.054335 0.073871 -0.026129 0.069230 0.123199 0.055433 -0.027106 0.008791
23 1.15 0.008059 0.060928 0.054335 0.049451 -0.001709 0.069230 0.001099 0.031013 -0.002686 0.008791
24 1.20 0.056899 0.060928 0.054335 0.073871 0.047131 0.069230 -0.023321 0.104273 -0.002686 0.008791
25 1.25 0.056899 0.060928 0.054335 0.073871 -0.026129 0.044810 0.001099 0.079853 -0.002686 0.008791
26 1.30 0.081319 0.060928 0.054335 0.073871 -0.001709 0.044810 -0.023321 0.079853 -0.027106 0.008791
27 1.35 0.056899 0.060928 0.054335 0.049451 -0.026129 0.069230 0.001099 0.055433 0.021734 0.008791
28 1.40 -0.065201 0.036508 0.054335 0.073871 -0.001709 0.020390 -0.023321 0.079853 -0.002686 0.008791
29 1.45 0.056899 0.060928 0.054335 0.049451 -0.001709 0.020390 0.001099 0.079853 0.046154 0.008791
... ... ... ... ... ... ... ... ... ... ... ...
1470 73.50 -4.558486 5.824054 5.988401 -4.370574 12.183884 5.710256 8.816729 10.214164 -0.027106 -0.015629
1471 73.55 -4.900367 5.286813 6.721002 -4.565934 11.866423 5.734676 8.059708 10.165324 -0.002686 -0.015629
1472 73.60 -4.900367 4.383273 7.014042 -4.468254 11.329183 5.661416 7.962028 10.043224 -0.027106 0.008791
1473 73.65 -4.656167 3.235531 6.794261 -4.077534 10.083761 5.563736 6.350306 9.335043 -0.002686 -0.015629
1474 73.70 -4.118926 2.185470 5.939561 -3.418193 8.447619 5.343956 5.080464 5.720879 -0.002686 -0.015629
1475 73.75 -3.484005 1.281929 4.596459 -2.758852 7.690599 3.903175 4.054823 2.253236 -0.002686 -0.015629
1476 73.80 -2.726984 0.305128 2.960318 -1.928571 7.373138 2.096093 3.126862 -0.091087 -0.002686 0.008791
1477 73.85 -1.896703 -0.622833 1.397436 -1.318071 5.688157 0.362271 2.394261 -1.947009 -0.002686 0.008791
1478 73.90 -0.773382 -1.868254 0.005495 -1.025031 4.198535 -2.226252 2.003541 -3.265690 -0.002686 0.008791
1479 73.95 0.105739 -3.186935 -1.215507 -0.414530 2.415873 -5.425275 1.319780 -5.976313 -0.002686 -0.015629
1480 74.00 1.155800 -4.359097 -2.289988 0.562271 1.878633 -9.430160 0.513919 -8.638096 -0.002686 0.008791
1481 74.05 2.230281 -5.189378 -3.095849 1.954213 0.901832 -13.215263 0.172039 -11.031259 -0.075946 -0.015629
1482 74.10 3.426862 -5.409158 -3.657509 3.394994 0.511111 -15.266545 0.147619 -12.178999 -0.002686 0.008791
1483 74.15 4.501343 -5.311478 -3.852870 4.493896 0.559951 -16.341028 0.172039 -13.131380 -0.002686 0.008791
1484 74.20 5.453724 -4.969597 -3.852870 5.373016 0.462271 -15.999147 0.196459 -13.546520 -0.002686 0.008791
1485 74.25 6.186325 -4.676557 -3.974970 6.154457 0.144811 -14.973505 0.172039 -13.326740 -0.027106 0.008791
1486 74.30 6.601465 -4.285837 -4.292430 6.569597 0.071551 -13.288524 0.172039 -10.323077 -0.002686 -0.015629
1487 74.35 6.381685 -3.553236 -4.341270 6.423077 0.120391 -11.432602 0.269719 -8.125276 0.046154 0.008791
1488 74.40 5.575824 -2.552015 -4.243590 5.788157 0.120391 -7.745178 0.172039 -4.950672 0.021734 0.008791
1489 74.45 4.232723 -1.501954 -3.950550 4.664835 0.120391 -4.008914 0.172039 -1.019048 -0.002686 -0.015629
1490 74.50 2.669842 -0.207692 -3.217949 3.248474 0.169231 0.215751 0.147619 3.132356 -0.002686 0.008791
1491 74.55 1.131380 1.257509 -1.972528 1.661172 0.120391 4.831135 0.123199 6.990720 0.094994 -0.015629
1492 74.60 -0.065201 2.747131 -0.629426 0.147131 0.291331 5.563736 0.147619 10.238585 0.021734 -0.015629
1493 74.65 -1.310623 4.090232 0.664835 -1.147131 3.514774 5.734676 0.294139 10.263004 -0.002686 -0.015629
1494 74.70 -2.507204 5.164713 2.105617 -1.977412 5.492796 5.636996 1.393040 10.238585 -0.002686 -0.015629
1495 74.75 -3.435165 5.775214 3.521978 -2.832113 11.060562 5.685836 4.836264 10.214164 -0.002686 0.008791
1496 74.80 -4.241026 5.872894 4.865080 -3.784493 12.818804 5.685836 7.424787 10.189744 -0.027106 0.008791
1497 74.85 -4.509646 5.628694 6.012821 -4.321734 13.282784 5.759096 8.474848 10.165324 -0.002686 0.008791
1498 74.90 -4.827106 5.091453 6.769842 -4.541514 12.208303 5.685836 9.012089 10.116484 -0.002686 -0.015629
1499 74.95 -4.778266 4.212332 7.062882 -4.394994 10.572162 5.588156 7.375947 10.092064 -0.002686 0.008791

1500 rows × 11 columns

Parte 2

En este archivo, la primera columna es el tiempo en el que se toma cada dato y las siguientes contienen los datos de cada uno de los sensores empleados en el ensayo experimental.

Almacenar en una variable la primera columna para obtener el vector de tiempos.

In [4]:
dt = datos.loc[:,'t']
dt = datos.iloc[:, 0]
dt
Out[4]:
0        0.00
1        0.05
2        0.10
3        0.15
4        0.20
5        0.25
6        0.30
7        0.35
8        0.40
9        0.45
10       0.50
11       0.55
12       0.60
13       0.65
14       0.70
15       0.75
16       0.80
17       0.85
18       0.90
19       0.95
20       1.00
21       1.05
22       1.10
23       1.15
24       1.20
25       1.25
26       1.30
27       1.35
28       1.40
29       1.45
        ...  
1470    73.50
1471    73.55
1472    73.60
1473    73.65
1474    73.70
1475    73.75
1476    73.80
1477    73.85
1478    73.90
1479    73.95
1480    74.00
1481    74.05
1482    74.10
1483    74.15
1484    74.20
1485    74.25
1486    74.30
1487    74.35
1488    74.40
1489    74.45
1490    74.50
1491    74.55
1492    74.60
1493    74.65
1494    74.70
1495    74.75
1496    74.80
1497    74.85
1498    74.90
1499    74.95
Name: t, Length: 1500, dtype: float64

Parte 3

Comenzaremos con el análisis de un único sensor. Para ello, se debe seleccionar la columna correspondiente al sensor deseado y almacenarla en una nueva variable.

In [5]:
elev = datos.loc[:, 's1'] 
elev    
Out[5]:
0       0.032479
1      -0.040781
2       0.056899
3      -0.016361
4       0.056899
5       0.056899
6       0.008059
7       0.130159
8       0.056899
9       0.032479
10      0.056899
11      0.056899
12      0.301099
13      0.105739
14      0.081319
15      0.056899
16      0.056899
17      0.008059
18      0.056899
19      0.056899
20      0.081319
21      0.032479
22      0.056899
23      0.008059
24      0.056899
25      0.056899
26      0.081319
27      0.056899
28     -0.065201
29      0.056899
          ...   
1470   -4.558486
1471   -4.900367
1472   -4.900367
1473   -4.656167
1474   -4.118926
1475   -3.484005
1476   -2.726984
1477   -1.896703
1478   -0.773382
1479    0.105739
1480    1.155800
1481    2.230281
1482    3.426862
1483    4.501343
1484    5.453724
1485    6.186325
1486    6.601465
1487    6.381685
1488    5.575824
1489    4.232723
1490    2.669842
1491    1.131380
1492   -0.065201
1493   -1.310623
1494   -2.507204
1495   -3.435165
1496   -4.241026
1497   -4.509646
1498   -4.827106
1499   -4.778266
Name: s1, Length: 1500, dtype: float64

Parte 4

Procedemos a representar los datos de superficie libre del sensor seleccionado.

In [6]:
# Usando pandas
elev.plot()
Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0xc4b8da0>
In [7]:
# Usando matplotlib 
fig = plt.figure(figsize=(10, 5))
ax = plt.axes()

ax.plot(dt, elev, 'k')
ax.set_xlabel('Time (s)', fontsize=14)
ax.set_ylabel('$\eta$ (m)', fontsize=14)
plt.title('Elevations of sensor S1', fontsize=18)
ax.grid()

plt.show()

Parte 5

Se deben eliminar los primeros datos correspondientes al inicio del ensayo. Para ello, seleccionaremos el tramo de datos a partir de los 20 segundos:

In [8]:
pos = np.where(dt >= 20)
pos
Out[8]:
(array([ 400,  401,  402, ..., 1497, 1498, 1499], dtype=int64),)
In [9]:
dt_crop = dt.iloc[pos[0]]
print(dt_crop) 
400     20.00
401     20.05
402     20.10
403     20.15
404     20.20
405     20.25
406     20.30
407     20.35
408     20.40
409     20.45
410     20.50
411     20.55
412     20.60
413     20.65
414     20.70
415     20.75
416     20.80
417     20.85
418     20.90
419     20.95
420     21.00
421     21.05
422     21.10
423     21.15
424     21.20
425     21.25
426     21.30
427     21.35
428     21.40
429     21.45
        ...  
1470    73.50
1471    73.55
1472    73.60
1473    73.65
1474    73.70
1475    73.75
1476    73.80
1477    73.85
1478    73.90
1479    73.95
1480    74.00
1481    74.05
1482    74.10
1483    74.15
1484    74.20
1485    74.25
1486    74.30
1487    74.35
1488    74.40
1489    74.45
1490    74.50
1491    74.55
1492    74.60
1493    74.65
1494    74.70
1495    74.75
1496    74.80
1497    74.85
1498    74.90
1499    74.95
Name: t, Length: 1100, dtype: float64
In [10]:
elev_crop = elev.iloc[pos[0]]
print(elev_crop) 
400     0.911600
401     1.961661
402     3.060562
403     4.330403
404     5.331624
405     6.113065
406     6.235165
407     5.868865
408     4.892064
409     3.597802
410     2.181441
411     0.862759
412    -0.187302
413    -1.335043
414    -2.385104
415    -3.190965
416    -3.703785
417    -4.192186
418    -4.680586
419    -5.046887
420    -5.095727
421    -4.900367
422    -4.192186
423    -3.288645
424    -2.238584
425    -1.090843
426     0.056899
427     1.302320
428     2.718682
429     4.037363
          ...   
1470   -4.558486
1471   -4.900367
1472   -4.900367
1473   -4.656167
1474   -4.118926
1475   -3.484005
1476   -2.726984
1477   -1.896703
1478   -0.773382
1479    0.105739
1480    1.155800
1481    2.230281
1482    3.426862
1483    4.501343
1484    5.453724
1485    6.186325
1486    6.601465
1487    6.381685
1488    5.575824
1489    4.232723
1490    2.669842
1491    1.131380
1492   -0.065201
1493   -1.310623
1494   -2.507204
1495   -3.435165
1496   -4.241026
1497   -4.509646
1498   -4.827106
1499   -4.778266
Name: s1, Length: 1100, dtype: float64

Parte 6

Representamos la serie antigua junto con la nueva recortada para verificar que lo hemos hecho bien

In [11]:
# Usando matplotlib 
fig = plt.figure(figsize=(10, 5))
ax = plt.axes()

ax.plot(dt, elev)
ax.plot(dt_crop, elev_crop)
ax.set_xlabel('Time (s)', fontsize=14)
ax.set_ylabel('$\eta$ (m)', fontsize=14)
plt.title('Elevations of sensor S1', fontsize=18)
ax.grid()
ax.legend(['original', 'crop'],fontsize=14)

plt.show()

Parte 7

El método de pasos ascendentes por cero consiste en buscar las líneas en las que el valor de la superficie libre del agua pasa de negativo a positivo. Almacene en una lista las posiciones de los pasos ascendentes.

In [12]:
num_datos = np.size(elev_crop)
pos_p_asc = []
for i in range(0, num_datos-1):
    
    if elev_crop.iloc[i] <= 0.0 and elev_crop.iloc[i+1] > 0.0:
        pos_p_asc.append(i)
print(pos_p_asc)
[25, 52, 79, 105, 133, 161, 188, 215, 242, 269, 296, 323, 350, 376, 403, 430, 457, 484, 511, 539, 566, 593, 620, 647, 674, 700, 727, 754, 781, 808, 836, 863, 890, 917, 944, 971, 998, 1024, 1051, 1078]

Parte 8

Representamos las posiciones

In [13]:
# Usando matplotlib 
fig = plt.figure(figsize=(10, 5))
ax = plt.axes()

ax.plot(dt_crop, elev_crop)
ax.plot(dt_crop.iloc[pos_p_asc], elev_crop.iloc[pos_p_asc], '.y', markersize=20)
ax.set_xlabel('Time (s)', fontsize=14)
ax.set_ylabel('$\eta$ (m)', fontsize=14)
plt.title('Elevations of sensor S1', fontsize=18)
ax.grid()
ax.legend(['elevacion', 'pasos_asc'],fontsize=14)

plt.show()

Parte 9

Entre cada dos pasos ascendentes por cero tenemos una ola. A continuación calcular para cada ola su altura y su periodo:

In [14]:
num_pasos_asc=np.size(pos_p_asc)

# Create an empty DataFrame
data_ht = pd.DataFrame(np.nan, index=range(num_pasos_asc -1), columns=range(2))

for j in range(0, num_pasos_asc - 1):
    #Elevacion entre pasos ascendentes
    elev_crop_p_asc = elev_crop.iloc[pos_p_asc[j]: pos_p_asc[j+1]]

    # Altura de ola
    alt_ola = np.max(elev_crop_p_asc)-np.min(elev_crop_p_asc)
    
    # Periodo
    periodo = dt_crop.iloc[pos_p_asc[j+1]] - dt_crop.iloc[pos_p_asc[j]]
    
    data_ht.iloc[j, 0] = alt_ola
    data_ht.iloc[j, 1] = periodo

print(data_ht)
            0     1
0   11.697192  1.35
1   12.307693  1.35
2   12.380953  1.30
3   12.039073  1.40
4   11.379732  1.40
5   10.354092  1.35
6   10.354091  1.35
7   10.818072  1.35
8   11.282052  1.35
9   11.184372  1.35
10  10.989012  1.35
11  11.037851  1.35
12  11.282051  1.30
13  11.648352  1.35
14  11.721613  1.35
15  11.746032  1.35
16  11.330891  1.35
17  11.037851  1.35
18  10.842492  1.40
19  10.940171  1.35
20  11.184372  1.35
21  11.428571  1.35
22  11.452991  1.35
23  11.306472  1.35
24  11.428572  1.30
25  11.623932  1.35
26  11.599512  1.35
27  11.379733  1.35
28  11.257632  1.35
29  11.208791  1.40
30  10.842492  1.35
31  11.208791  1.35
32  11.184371  1.35
33  11.404152  1.35
34  11.428572  1.35
35  11.575092  1.35
36  11.575092  1.30
37  11.697192  1.35
38  11.526252  1.35

Parte 10

Por último, guardar los datos de H-T a un archivo para su posterior análisis.

In [18]:
data_ht.to_csv('HT.dat', float_format='%g', index=False, header=['H', 'T'], sep='\t')
In [16]:
data_ht.iloc[:, 0].plot()
Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0xcc4a9e8>
In [17]:
data_ht.iloc[:, 1].plot()
Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0xd90f860>