Created
September 12, 2020 21:57
-
-
Save caioerick/1e6f89c7b4a908da725b067f54915262 to your computer and use it in GitHub Desktop.
Exemplo de interpolação de dados em uma matriz, bastante útil para alguns dados de ADCP e CTD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# criando a matriz e preenchendo ela com NaN | |
mat = np.zeros((50,100)) | |
mat.fill(np.NaN) | |
# vamos preencher a matriz com alguns valores | |
for i in range(mat.shape[0]): | |
for j in range(0,33): | |
mat[i,j] = (4*i)+5 | |
for i in range(mat.shape[0]): | |
for j in range(66,100): | |
mat[i,j] = (6*i)+5 | |
# agora vamos criar uma nova matriz pra fazer a interpolação | |
aux = mat.copy() | |
# para cada linha da matriz, vamos usar a função interpolate() do pandas | |
for i in range(mat.shape[0]): | |
interp = pd.Series(mat[i]).interpolate() | |
aux[i] = interp | |
# comparando os dois gráficos | |
plt.contourf(aux); plt.colorbar(); plt.show() # matriz interpolada | |
plt.contourf(mat); plt.colorbar(); plt.show() # matriz antiga |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment