-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_combina_peq.py
49 lines (40 loc) · 1.63 KB
/
04_combina_peq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pandas as pd
import numpy as np
import csv
bacia = '01'
nome = 'Rio_Negro'
area = 3461
precip = pd.read_csv('../dados/pme/pme_bacia_'+bacia+'.csv', index_col = 0, sep = ',')
precip.index = pd.to_datetime(precip.index)
precip.columns = ['pme']
data_inicial = precip.index[0]
data_final = precip.index[-1]
vazao = pd.read_csv('../dados/f_consist/'+nome+'_HR.csv', index_col = 0, sep = ';')
vazao.index = pd.to_datetime(vazao.index)
vazao = vazao.drop(['h_m'], axis=1)
vazao.columns = ['qjus']
if vazao.index[0] > data_inicial:
data_inicial = vazao.index[0]
if vazao.index[-1] < data_final:
data_final = vazao.index[-1]
dados_peq = pd.merge(precip, vazao, how = 'outer',
left_index = True, right_index = True)
dados_peq = dados_peq.loc[data_inicial:data_final]
etp = pd.read_csv('../dados/etp/etpclim_'+bacia+'.txt', header = None)
etp['Mes'] = etp[0].str.slice(0,2)
etp['Dia'] = etp[0].str.slice(3,5)
etp['Hora'] = etp[0].str.slice(6,8)
etp['etp'] = pd.to_numeric(etp[0].str.slice(9,17))
etp = etp.drop([0], axis=1)
etp.index = etp['Mes'] + '-' + etp['Dia'] + '-' + etp['Hora']
dados_peq['data'] = dados_peq.index.strftime('%m-%d-%H')
dados_peq['etp'] = dados_peq['data'].map(etp['etp'])
dados_peq = dados_peq.drop(['data'], axis=1)
dados_peq = dados_peq[['pme', 'etp', 'qjus']]
#dados_peq.loc['2014-06-10']
dados_peq['pme'] = dados_peq['pme'].apply('{:,.2f}'.format)
dados_peq['etp'] = dados_peq['etp'].apply('{:,.5f}'.format)
with open('../dados/peq/bacia_'+bacia+'.peq', 'w', newline = '') as file:
writer = csv.writer(file)
writer.writerow([area])
dados_peq.to_csv('../dados/peq/bacia_'+bacia+'.peq', mode = 'a')