Hidroweb Data - River Flow Climatology¶

Gauged fresh water inflow to the Patos Lagoon¶

https://www.snirh.gov.br/hidroweb/apresentacao

We have five rivers with daily records of flow: Jacuí, Taquarí, Caí, Sinos and Camaquã.

To produce a 'climatology', we need to sum the flows of each river.

Problem: the data is not homogeneous!

Goals:
1) to select a period with synoptic data for all rivers
2) reduce to monthly means for each river
3) sum the monthly means to have a monthly time series
4) separate the monthly mean to each month to build a annual climatology


Worth to note that with the HidroWeb ASCII files (my guess) we have the 'safe' problem when using the np.isnan!¶


Gauge Stations Description (copy/paste from Hidroweb)¶

Jacui

Código 85900000 Nome Estação RIO PARDO Código Adicional Bacia 8 - ATLÂNTICO, TRECHO SUDESTE SubBacia 85 - RIO JACUÍ Rio RIO JACUÍ Estado RIO GRANDE DO SUL Município RIO PARDO Responsável ANA Operadora CPRM Latitude -29.995 Longitude -52.3756 Altitude (m) 2 Área de Drenagem (Km²) 38700

##################################################################
Taquari

Código 86510000 Nome Estação MUÇUM Código Adicional Bacia 8 - ATLÂNTICO, TRECHO SUDESTE SubBacia 86 - RIO TAQUARI Rio RIO TAQUARI Estado RIO GRANDE DO SUL Município MUÇUM Responsável ANA Operadora CPRM Latitude -29.1672 Longitude -51.8686 Altitude (m) 240 Área de Drenagem (Km²) 16000

lat = -29.1672 lon = -52.05249

Código 86950000 (série incompleta) Nome Estação TAQUARI Código Adicional Bacia 8 - ATLÂNTICO, TRECHO SUDESTE SubBacia 86 - RIO TAQUARI Rio RIO TAQUARI Estado RIO GRANDE DO SUL Município TAQUARI Responsável ANA Operadora CPRM Latitude -29.8069 Longitude -51.8758 Altitude (m) -2 Área de Drenagem (Km²) 25900

######################################################################

Camaquã

Código 87905000 Nome Estação PASSO DO MENDONÇA Código Adicional Bacia 8 - ATLÂNTICO, TRECHO SUDESTE SubBacia 87 - LAGOA DOS PATOS Rio RIO CAMAQUÃ Estado RIO GRANDE DO SUL Município CRISTAL Responsável ANA Operadora CPRM Latitude -31.0119 Longitude -52.0525 Altitude (m) 14.88 Área de Drenagem (Km²) 15600

######################################################3
Sinos

Código 87382000 Nome Estação SÃO LEOPOLDO Código Adicional Bacia 8 - ATLÂNTICO, TRECHO SUDESTE SubBacia 87 - LAGOA DOS PATOS Rio RIO DOS SINOS Estado RIO GRANDE DO SUL Município SÃO LEOPOLDO Responsável ANA Operadora CPRM Latitude -29.7589 Longitude -51.1483 Altitude (m) -0.42 Área de Drenagem (Km²) 3130

######################################################3
Cai

Código 87270000 Nome Estação PASSO MONTENEGRO Código Adicional Bacia 8 - ATLÂNTICO, TRECHO SUDESTE SubBacia 87 - LAGOA DOS PATOS Rio RIO CAÍ Estado RIO GRANDE DO SUL Município MONTENEGRO Responsável ANA Operadora CPRM Latitude -29.7011 Longitude -51.4411 Altitude (m) -1 Área de Drenagem (Km²) 4360

Código 87170000 Nome Estação BARCA DO CAÍ Código Adicional Bacia 8 - ATLÂNTICO, TRECHO SUDESTE SubBacia 87 - LAGOA DOS PATOS Rio RIO CAÍ Estado RIO GRANDE DO SUL Município SÃO SEBASTIÃO DO CAÍ Responsável ANA Operadora CPRM Latitude -29.59 Longitude -51.3833 Altitude (m) -1 Área de Drenagem (Km²) 3030

Drainagem Areas (km2)¶

Taquari = 26428 (it is a tributary of Jacuí)
Jacuí (+ Taquari) = 73000
Sinos = 3820
Caí = 5027

The rivers above debouche in the Guaíba (so, Guaíba System)

Camaquã = 15600

The Camaquã debouches in the mid-lagoon

In [176]:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime
import os

import sys

sys.path.append('d:\guto\gpython\pytools')

import Hidroweb_tools as ht
In [1]:
# hidroweb_tools... sorry, in Portuguese! 
# Request me by email if you want. I'll put in GitHub in the future (????)

ht?
Object `ht` not found.

Adressing...¶

In [178]:
path_taquari = r'd:\GUTO\1_Trabs\ANA_bacias\Lagoa_dos_Patos\RioTaquari_Vazoes\\' 
file_taquari = 'vazoes_C_86510000.csv'

path_camaqua = r'd:\GUTO\1_Trabs\ANA_bacias\Lagoa_dos_Patos\RioCamaqua_Vazoes\\' 
file_camaqua = 'vazoes_T_87905000.txt'

path_jacui = r'd:\GUTO\1_Trabs\ANA_bacias\Lagoa_dos_Patos\RioJacui_Vazoes\\'
file_jacui = 'vazoes_C_85900000.csv'

path_cai = r'd:\GUTO\1_Trabs\ANA_bacias\Lagoa_dos_Patos\RioCai_Vazoes\\'
file_cai = 'vazoes_T_87170000.txt'

path_sinos = r'd:\GUTO\1_Trabs\ANA_bacias\Lagoa_dos_Patos\RioSinos_Vazoes\\'
file_sinos = 'vazoes_C_87382000.csv'

Upload the data¶

In [179]:
with open(path_camaqua + file_camaqua) as f:
    linhas_camaqua = f.readlines()
    
with open(path_jacui + file_jacui) as f:
    linhas_jacui = f.readlines()

with open(path_taquari + file_taquari) as f:
    linhas_taquari = f.readlines()
    
with open(path_cai + file_cai) as f:
    linhas_cai = f.readlines()
    
with open(path_sinos + file_sinos) as f:
    linhas_sinos = f.readlines()
In [180]:
linhas = [linhas_camaqua, linhas_jacui, linhas_taquari, linhas_cai, linhas_sinos]
rivers = ['Camaquã', 'Jacuí', 'Taquari', 'Caí','Sinos']

Organize de data from the ASCII files¶

In [181]:
dados = []
time_n = []
for li in linhas:
    arruma = ht.arruma_vazao(li)
    time_n.append(mdates.date2num(arruma[:,0]))
    
    arruma[:,1] = [float(x) for x in arruma[:,1]]
    
    dados.append(arruma)
In [182]:
fig, ax = plt.subplots(figsize=(22,4))
for d in dados:
    ax.plot(d[:,0], d[:,1])
    ax.set_yscale('log')
No description has been provided for this image

Check the start/end of each time-series¶

In [183]:
for d in dados:
    print(d[0,0], d[-1,0])
1964-05-01 00:00:00 2021-04-30 00:00:00
1939-12-01 00:00:00 2021-07-31 00:00:00
1940-01-01 00:00:00 2021-03-31 00:00:00
1978-01-01 00:00:00 2021-07-31 00:00:00
1973-07-01 00:00:00 2021-07-31 00:00:00

Separate the synoptic period and exclude the nans¶

Here when we try to find the nans the 'safe' problems show up!

image.png

In [184]:
t1 = datetime.date(1978, 1, 1)
t2 = datetime.date(2020, 12, 31)

t1n = mdates.date2num(t1)
t2n = mdates.date2num(t2)

data_synoptic = []
data_monthly_means = []

for i, d in enumerate(dados):
    g_time = time_n[i]
    idx = np.array(np.where(
                            (g_time >= t1n) 
                            & 
                            (g_time <= t2n)
                    )).squeeze()
    
    get_data = d[idx]
    
    # Detour to avoid the 'safe' problem!
    q_values = get_data[:,1]
    q_values = [float(x) for x in q_values]
    
    # find if there are nan 
    not_nan = np.array(np.where(np.isnan(q_values) == False)).squeeze()
    
    get_data = get_data[not_nan]
    print(len(get_data))
    
    data_synoptic.append(get_data)

    monthly_mean = ht.serie_mensal(get_data)
    print(len(monthly_mean))
    
    data_monthly_means.append(monthly_mean)
    # q_anual.append(ht.climatologia_mensal(arruma))
15497
513
15573
512
15665
515
15494
513
15355
506

Synoptic means and checking if there are nans¶

In [185]:
for d in data_monthly_means:
    print(np.round( np.mean(d[:,1]), 1))
330.8
966.9
425.8
70.7
88.6

Summing the flows and separating the months¶

Here we have some verbiaged code to sum the synoptic months, creating a time series of the summed data and also saving the months separately to create the annual climatology

In [203]:
q_sum = []
q_t = []

# create a list of empty lists to save the months in each
save_months = []
for i in range(12):
    save_months.append([])

for year in range(1978, 2022):
    for month in range(1, 13):
        
        get_q = []
        q_t.append(datetime.date(year, month, 15))
        
        for qm in data_monthly_means:
            for q in qm:
                if q[0].year == year and q[0].month == month:
                    get_q.append(q[1])
                    
        
         
        make_sum = np.nansum(get_q)
        
        save_months[month-1].append(make_sum)
        
        q_sum.append(make_sum)

save_months = [np.array(x) for x in save_months]
    
# some bad data at the end of the series...
q_t = q_t[:-11]
q_sum = q_sum[:-11]
In [187]:
q_t[0]
Out[187]:
datetime.date(1978, 1, 15)
In [205]:
'''
To find the flow for Feb and Mar/2020 (campaign period)

That's because we carried out a field experiment at the lagoon's mouth during this period, and neet to contextualize the hidrologic condition!
'''
for i, t in enumerate(q_t):
    if t.year == 2020 and t.month == 2:
        print(q_sum[i])
    if t.year == 2020 and t.month == 3:
        print(q_sum[i])
430.95109939148074
239.1316198924731
In [190]:
plt.rcParams.update({'font.size':14})
plt.figure(figsize=(16,4))
plt.plot(q_t, q_sum)
plt.axvline(datetime.date(2020,3,10), color='tab:orange')
plt.axhline(350, color='tab:orange')
plt.xlim(datetime.date(1977,11,1), datetime.date(2021,3,1))
plt.ylabel('Flow (m$^3$/s)')
plt.show()
No description has been provided for this image
In [201]:
# f, q, p, vp = flow_duration_curve(q_sum)
f, q, p, vp = ht.curva_permanencia(q_sum)

p_campanha = np.interp(350, vp, p)
print(p_campanha)


plt.rcParams.update({'font.size':12})
fig, ax = plt.subplots()

ax.plot(f, q)
for i in range(len(p)):
    ax.plot(p[i], vp[i], 'o', color='tab:blue')
    ax.text(p[i], vp[i]+150, str(int(np.round(vp[i]))))
    
ax.axhline(350, color='tab:orange')
ax.axvline(p_campanha, color='tab:orange')
    
ax.set_xlabel('Exceedance Probability')
ax.set_ylabel('Flow (monthly mean) (m$^3$/s)')
ax.text(0, 400, '350 m$^3$/s')
ax.text(0.9, 7000, '0.99')
plt.show()
0.99
No description has been provided for this image

Check point!¶

Those 'zeros' are suspect... I don't know where they were come from, but they don't look right!

In [193]:
plt.figure(figsize=(3,2))
for i in range(12):
    plt.plot(np.linspace(i+1, i+1, len(save_months[i])), save_months[i], '.')
    
    save_months[i] = save_months[i][save_months[i][:]>0]
No description has been provided for this image
In [194]:
plt.figure(figsize=(3,2))
for i in range(12):
    plt.plot(np.linspace(i+1, i+1, len(save_months[i])), save_months[i], '.')
No description has been provided for this image
In [195]:
a, b, c, d = [], [], [], []
for i in range(12):
    f, q, p, vp = ht.curva_permanencia(save_months[i])
    a.append(f)
    b.append(q)
    c.append(p)
    d.append(vp)
    
vp = np.array(d)
vp.shape
Out[195]:
(12, 9)
In [196]:
p = np.array(p)
int(p[1]*100)
Out[196]:
5
In [197]:
n_mes = np.arange(1,13)
l_mes = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 
In [198]:
p_vp = vp[-1,:]
p_vp
Out[198]:
array([4792.19, 4055.81, 2668.8 , 1381.69,  767.21,  610.95,  504.96,
        369.54,  332.2 ])
In [199]:
fig, ax = plt.subplots()

ax.plot(n_mes, vp[:,4], color='#8fd3fe', lw=4, zorder=5)
ax.plot(n_mes, vp[:,4], color='k', lw=3, zorder=5)
ax.fill_between(n_mes, vp[:,3], vp[:,5], zorder=4, color='#1134a6', edgecolor='#8fd3fe', lw=.5)
ax.fill_between(n_mes, vp[:,2], vp[:,6], zorder=3, color='#0052ff', edgecolor='#8fd3fe', lw=.5)
ax.fill_between(n_mes, vp[:,1], vp[:,7], zorder=2, color='#0080fe', edgecolor='w', lw=.5)
ax.fill_between(n_mes, vp[:,0], vp[:,8], zorder=1, color='#8fd3fe', edgecolor=[.7, .7, .7], lw=.5)

ax.set_ylabel('Flow (m$^3$/s)')
ax.set_xticks(np.arange(1,13))
ax.set_xticklabels(l_mes)

for i in range(9):
    if i < 5:
        ax.text(12.1, p_vp[i], str(int(p[i]*100))) 
    if i == 8:
        ax.text(12.1, p_vp[i], str(int(p[i]*100))) 
        
plt.show()
No description has been provided for this image
In [ ]: