Análisis de Datos de Temperatura A Largo Plazo
Análisis de Datos de Temperatura A Largo Plazo
Análisis de Datos de Temperatura A Largo Plazo
Objetivos:
Se va crear una carpeta notebook con el nombre de está session. Luego se va importar
las librerías necesarias.
import pandas as pd
climateData =
pd.read_csv('../Data/2368871.csv',parse_dates=True,index_col=2)
print(climateData.dtypes)
print(climateData.index)
climateData.describe()
climateData =
climateData.drop(['STATION','NAME','ACSH','AWND','EVAP','PSUN','TAVG',
'TOBS'],axis=1)
climateData.describe()
stationDf = dataDf.loc[dataDf.STATION==station]
stationDf.index = stationDf.DATE
compDf[station] = stationDf.PRCP
fig = plt.figure(figsize=(12,8))
climateData['2009-10':'2010-09'].PRCP.plot()
climateData['2009-10':'2010-09'].SNOW.plot()
climateData['2009-10':'2010-09'].SNWD.plot()
plt.ylim(0)
plt.legend()
|Gestion Sostenible Del Agua
plt.ylabel('Height (in)')
plt.show()
averageData[['TMIN','TMAX']].plot()
|Gestion Sostenible Del Agua
tempData = climateData.loc[:,['tMaxC','tMinC']]
tempData.head()
|Gestion Sostenible Del Agua
monthlyData =
tempData.groupby(climateData.index.to_period('M')).median()
monthlyData.tMaxC.plot()
febData = monthlyData[monthlyData.index.month==2]
febData.tMaxC.plot()
febData.tMinC.plot()
|Gestion Sostenible Del Agua
Luego se va realizar diferencia entre tmax y tmin, pero primero hacemos una copia:
febData = febData.copy()
febData['deltaT'].plot()
|Gestion Sostenible Del Agua
sepData = monthlyData[monthlyData.index.month==7]
sepData.tMaxC.plot()
sepData.tMinC.plot()
|Gestion Sostenible Del Agua
import numpy as np
sepRegr = linear_model.LinearRegression()
sepRegr.fit(sepTrain, sepData.tMaxC)
#sepTest = np.arange(0,sepData.shape[0])[np.newaxis].T
sepPred = sepRegr.predict(sepTrain)
sepData = sepData.copy()
sepData['tMaxPredict'] = sepPred
#sepTrain
fig, ax = plt.subplots(figsize=(12,4))
sepData.tMaxC.plot()
sepData.tMaxPredict.plot()
ax.grid()
ax.set_title('September')
ax.legend()
ax.text(0.7,0.1,'Slope = %.5f'%sepRegr.coef_[0],
transform=ax.transAxes)
plt.show()
|Gestion Sostenible Del Agua
fig, ax = plt.subplots(figsize=(12,10))
sepData.tMaxC.plot(c='deeppink')
sepData.tMaxPredict.plot(c='deeppink', ls='--')
febData.tMaxC.plot(c='royalblue')
febData.tMaxPredict.plot(c='royalblue', ls='--')
ax.grid()
ax.legend()
plt.show()
|Gestion Sostenible Del Agua
stdData = climateData.groupby(climateData.index.to_period('M')).std()
stdData.tMaxC.plot()
febStd = stdData[stdData.index.month==2]
sepStd = stdData[stdData.index.month==7]
fig, ax = plt.subplots(figsize=(12,6))
febStd.tMaxC.plot(c='gold')
sepStd.tMaxC.plot()
ax.grid()
ax.legend()
plt.show()
|Gestion Sostenible Del Agua
import scipy.stats as st
dec1900 = climateData['1900':'1910']
per10List = []
medianList = []
per90List = []
for m in range(12):
monthData = dec1900[dec1900.index.month==m]
per10 = st.scoreatpercentile(monthData.tMaxC,10)
per50 = st.scoreatpercentile(monthData.tMaxC,50)
per90 = st.scoreatpercentile(monthData.tMaxC,90)
per10List.append(per10)
|Gestion Sostenible Del Agua
medianList.append(per50)
per90List.append(per90)
fig = plt.figure(figsize=(16,4))
plt.plot(range(12),per10List,alpha=0.5,c='crimson')
plt.plot(range(12),medianList,c='crimson',label='dec1900')
plt.plot(range(12),per90List,alpha=0.5,c='crimson')
plt.legend()
def plotPeriod(start,stop,color):
periodData = climateData[start:stop]
per10List = []
medianList = []
per90List = []
for m in range(12):
monthData = periodData[periodData.index.month==m]
per10 = st.scoreatpercentile(monthData.tMaxC,10)
per50 = st.scoreatpercentile(monthData.tMaxC,50)
per90 = st.scoreatpercentile(monthData.tMaxC,90)
per10List.append(per10)
medianList.append(per50)
per90List.append(per90)
plt.plot(range(12),per10List,alpha=0.5,ls='--',c=color)
|Gestion Sostenible Del Agua
plt.plot(range(12),medianList,lw=2,c=color,label='From %s to
%s'%(start,stop))
plt.plot(range(12),per90List,alpha=0.5,ls='--',c=color)
fig = plt.figure(figsize=(18,6))
plotPeriod('1900','1940','royalblue')
plotPeriod('1940','1980','crimson')
plotPeriod('1980','2020','gold')
plt.legend()
plt.grid()
plt.show()
fig = plt.figure(figsize=(18,12))
plotPeriod('1855','1955','aqua')
plotPeriod('1955','1985','lightskyblue')
plotPeriod('1985','2005','dodgerblue')
plotPeriod('2005','2015','royalblue')
plotPeriod('2015','2020','gold')
plt.legend()
plt.grid()
plt.show()