1 year ago

#356060

test-img

Alejandro Campanales

Interpolation using Smooth Bivariate Splines

I'm using Python in order to do my Master's Project. As I'm a beginner and learning by myself, there are some difficulties that I found while doing the tasks proposed by my teachers.

The particular problem is the following:

I have water temperature data provided by an excel, associated to its locations (latitude, longitudes). The objective of the task is to prepare an isolines map, but first of all, as the data is limited, I need to interpolate in order to get more values. In order to do that I use the Smooth Bivariate Splines function.

Nevertheless, as the final result (once interpolation and contour map creation have been created), I obtain a map where the boundaries give me values of temperature that have no sense (120.. -90 º C), since my data temperature oscilates around 25 º C. (Sorry ,but the webpage doesn't let me add the figure)

Here I attach the commands that I've used. I would appreciate very much if someone can tell me what it's wrong in the commands, if its necessary to add something else or maybe there is another alternative that fits better to my problem:

#Loading packages:

import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
from scipy import interpolate


# Temperature and positions of the measurements
    
EstadisticosFluorimetro = pd.read_excel("C:\\Users\\usuario\\Desktop\\TFM\\Datos Partida\\CTD_Fluorimetro_IRTA\\Resumen_Puntos_Fluorimetro.xlsx", sheet_name = "Res_Python")

temperatura_Med = EstadisticosFluorimetro['T_Media']

latitudes = EstadisticosFluorimetro['Lat_Punto']
longitudes = EstadisticosFluorimetro['Long_Punto']    
    
    
# I also load the coast line corresponding to the study zone

ContornoCosta = pd.read_excel("C:\\Users\\usuario\\Desktop\\Isolineas\\Límite Costero\\Posiciones_Límites.xlsx", sheet_name = "Contorno_Costa")

latitudes_costa = ContornoCosta['Latitud']
longitudes_costa = ContornoCosta['Longitud']



# Apply Interpolation by using the Smooth Bivariate Splines function:

# I have defined at bbox the boundaries of the grid where I want to get values interpolated, 
# according to min, max longitudes and min, max latitudes of the grid. 

interpolación = interpolate.SmoothBivariateSpline(longitudes,latitudes,temperatura_Med, bbox=[0.7285, 0.7415, 40.7675, 40.781], kx=3, ky=3)


# Then, I want the values of temperature according to the grid that I define:

longitudes_grid = np.linspace(0.7285,0.7415,1000)
latitudes_grid = np.linspace(40.7675,40.781,1000)

temperatura_imagen=interpolación.__call__(longitudes_grid,latitudes_grid,grid=True)



# Now I create the figure:
    
# First, text characteristics:

fontTitle = {'family': 'serif',
        'color':  'black',
        'weight': 'normal',
        'size': 16,
        'style': 'italic',
        }

fontAxis = {'family': 'serif',
        'color':  'black',
        'weight': 'normal',
        'size': 10,
        'style': 'oblique',
        }


# Then, I plot in a same figure the coast contour and the isolines:

plot1 = plt.figure(1)

# First, the coast contour:
    
plt.plot(longitudes_costa,latitudes_costa,color='black', linewidth=1)
  

# And then the isolines: 

plt.contour(longitudes_grid, latitudes_grid, temperatura_imagen, levels=25, linewidths=0.5, colors='k')

cntr1 = plt.contourf(longitudes_grid, latitudes_grid, temperatura_imagen, levels=25, cmap="Jet")


# The labels: 

plt.xlabel('Longitud,º', fontsize=12, fontdict=fontAxis, labelpad=10)
plt.ylabel('Latitud, º', fontsize=12, fontdict=fontAxis, labelpad=10)
plt.title('Isolineas Temperatura Media', fontsize=18, fontdict=fontTitle, pad=10)


# I adjust the contours of the figure: 

plt.ylim(40.765,40.785)
plt.xlim(0.725,0.745)

plt.colorbar()

# And the size: 

plot1.set_figheight(6)
plot1.set_figwidth(12)

plt.show

python

scipy

interpolation

spline

0 Answers

Your Answer

Accepted video resources