Skip to content

Instantly share code, notes, and snippets.

@caioerick
Created September 12, 2020 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caioerick/1e6f89c7b4a908da725b067f54915262 to your computer and use it in GitHub Desktop.
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
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