You are on page 1of 1

# -*- coding: utf-8 -*-

"""
Created on Tue Apr 12 21:48:58 2022

@author: Asdos Pemrograman Geospasial 2022


"""

import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd
import utide

with open('E:\Current Tides Data.txt') as f:


lines = f.readlines()
print (''.join(lines))
def date_parser (year, month, day, hour):
year, month, day, hour = map (int, (year, month, day, hour))
return datetime.datetime (year, month, day, hour)
parse_dates = dict(datetime=['year', 'month', 'day', 'hour'])
names = ['year', 'month', 'day', 'hour', 'elev']
obs = pd.read_table('E:\Current Tides Data.txt',
names=names,
skipinitialspace=True,
delim_whitespace=True,
index_col='datetime',
usecols=range(0, 5),
na_values='9.990',
parse_dates=parse_dates,
date_parser=date_parser,
)
obs.head(5)
time = mdates.date2num(obs.index.to_pydatetime())
coef = utide.solve(time, obs['elev'].values,
lat=-1,
method='ols')
print (coef.keys())
tide = utide.reconstruct(time, coef)
print (tide.keys())
t = tide.t_mpl
fig, (ax) = plt.subplots(nrows=1, sharey=True, sharex=True)
ax.plot(t, obs.elev, alpha=0.5, label= u'pengamatan', color='C0')
ax.plot(t, tide.h, alpha=0.5, label= u'prediksi', color='C1')
ax.plot(t, obs.elev - tide.h, alpha=0.5, label= u'residu', color='C2')
ax.xaxis_date()
fig.legend(ncol=3, loc='upper center')
fig.autofmt_xdate()
plt.xlabel("Tanggal")
plt.ylabel("Meter")
plt.show()

You might also like