Interpolation problem in Temperature at 850 hPa

163 views
Skip to first unread message

Carlos Calvo Sancho

unread,
Oct 14, 2019, 4:38:53 PM10/14/19
to wrfpython-talk


Hello everyone, 

Last days I tried to run a script to postprocessate the temperature at 850 hPa but in the mountains chains the interpolation doesn't work well. I don't know why this don't work... I attached the script and a plot. 

t850_basic_2019-09-08_09.png


#este programa é valido para un corte vertical
import numpy as np
from netCDF4 import Dataset
from mpl_toolkits.basemap import  Basemap
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
import matplotlib.colors as mcolors
from datetime import datetime , timedelta 
from wrf import (interplevel, getvar, vertcross, smooth2d, latlon_coords, ALL_TIMES)

# Open the NetCDF file
#abrir o archivo no que queremos traballar
ncfile = Dataset("/Users/carlos-wrf/Documents/WRF/DanaSeptiembre.nc")

#todo esto é sempre igual
# Create polar stereographic Basemap instance.

lon = getvar(ncfile, "XLONG").values #transformo para obter só valores 
lat = getvar(ncfile, "XLAT").values

#para facer un corte vertical necesito centrar as latitudes e lonxitudes das miñas graficas, para a partir de aí traballar

cen_lat = float(ncfile.CEN_LAT)
cen_lon = float(ncfile.CEN_LON)


# lat_1 is first standard parallel.
# lat_2 is second standard parallel (defaults to lat_1).
# lon_0,lat_0 is central point.

# llcrnrlon = Longitud de la esquina inferior izquierda 
# llcrnrlat = Latitud de la esquina inferior izquierda 
# urcrnrlon = Longitud de la esquina superior derecha 
# urcrnrlat = Latitud de la esquina superior derecha 
m = Basemap(resolution='h',projection='lcc',llcrnrlon=lon[0,0],llcrnrlat=lat[0,0],urcrnrlon=lon[-2,-2],urcrnrlat=lat[-1,-1],lon_0=cen_lon,lat_1=cen_lat,lat_2=cen_lat)

#empezamos en 4,4 porque os bordes do modelo non son bos
# Coordinates
x, y = m(lon, lat)

 #Parallels.
parallels = np.arange(0.,90,5)

# Meridians
meridians = np.arange(-180.,180.,5)

#Loop for several plots

start_time=datetime(2019,9,8) #cando queremos empezar
delta=timedelta(hours=3) #cando canto actualizamos a imaxe

T_start = getvar(ncfile,"T",timeidx=0)
P_start = getvar(ncfile,"P",timeidx=0)

for d in range(0,25): #d es el número de pasos temporales que tenemos.

# Get the sea level pressure
 t2m = getvar(ncfile,"T2",timeidx=d)-273.15     #ºC
 p = getvar(ncfile, "pressure",timeidx=d)       #hPa
 #ht = getvar(ncfile, "z", units="dm")
 temp = getvar(ncfile,"temp",timeidx=d)-273.15              #ºC
 z = getvar(ncfile,"z",timeidx=d, units="dm")

 t850 = interplevel(temp, p, 850.0, missing=9.969209968386869e+36, squeeze=True, meta=False)

# Create figure
 plt.figure(figsize=(7,7)) #tamaño da figura creada
# Plotting
 clevs=np.arange(-5,30,1.75)
 cs1 = m.contourf(x,y,t850,clevs,cmap='nipy_spectral',extend='both') # vmin y vmax establecen los valores mínimos y máximos de la escala de colores
 cs2 = m.contour(x,y,t850, levels=clevs, colors="black", linewidths=0.5)
 plt.clabel(cs2, inline=0, fontsize=10, fmt="%i")
 plt.title(str(start_time)[0:10]+' T'+str(start_time)[11:13]+':00:00')
#dibuxar a forma de continentes e etc
 m.drawcoastlines()
 m.drawcountries()
 m.drawparallels(parallels,labels=[1,0,0,0],fontsize=8,linewidth=0.)
 m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=8,linewidth=0.)

 cbar= m.colorbar(cs1,location='bottom',pad="5%",ticks=clevs)
 cbar.ax.tick_params(labelsize=7)
 cbar.set_label("$^{\circ}$C",fontsize=8)
  
 plt.savefig('/Users/carlos-wrf/Documents/test/t850_basic_'+str(start_time)[0:10]+'_'+str(start_time)[11:13]+'.png',dpi=300)
 plt.close()
 start_time=start_time + delta




Federico Cutraro

unread,
Oct 16, 2019, 7:06:27 PM10/16/19
to wrfpython-talk, Carlos Calvo Sancho
Hello Carlos, I'm pretty sure that the function interplevel don't extrapolate values below the surface. You could check if on the mountains the surface pressure is lower than 850 hPa.

Regards,
Federico

--
You received this message because you are subscribed to the Google Groups "wrfpython-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wrfpython-tal...@ucar.edu.
To view this discussion on the web visit https://groups.google.com/a/ucar.edu/d/msgid/wrfpython-talk/b076592a-ce19-4825-ba92-f3bad2a68bc9%40ucar.edu.

Domingo Cassain

unread,
Mar 2, 2020, 3:06:47 PM3/2/20
to wrfpython-talk
Hi Carlos.

can you solve your problem?

I'm new using WRF-Python and I have the same problem.
If you have the solution, can you make it available to us?

Regards

Cassain

Dileepkumar R

unread,
Mar 4, 2020, 12:13:09 AM3/4/20
to Domingo Cassain, wrfpython-talk
Hi Domingo,

I have also faced the same problem. Instead of  "wrf.interplevel" we should use "wtf.vinterp", in which we need to enable "extrapolate=True"

That's it.

Dileepkumar R


--
You received this message because you are subscribed to the Google Groups "wrfpython-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wrfpython-tal...@ucar.edu.

Domingo Cassain

unread,
Mar 6, 2020, 11:52:01 AM3/6/20
to Dileepkumar R, wrfpython-talk
Hello Dileepkumar,

Thank you for your help. I applied it here and it worked well.

Best Regards.

Domingo Cassain
--
------------------------------------------------------------------------------------------------------
Domingo Cassain Sales
Doutor em Meteorologia (INPE)
Pesquisador em Modelagem Atmosférica (FUNCEME)
FUNCEME - Fundação Cearense de Meteorologia e Recursos Hídricos
------------------------------------------------------------------------------------------------------

“O entendimento intelectual é uma das melhores versões da Regra de Ouro: ouça os outros como você gostaria que outros o ouvissem. A demonstração precisa da verdade é importante, mas não tão importante quanto a busca comunitária dela. Coloque em termos do imperativo categórico de Kant: Ao abordar as idéias de outras pessoas, sua obrigação é tratá-las como você acredita que todos os seres humanos devem tratar as idéias uns dos outros”

                                                                      Wayne C. Booth 

                                                                      (My Many Selves: The Quest for a Plausible Harmony)




Carlos Calvo Sancho

unread,
Mar 10, 2020, 1:59:46 PM3/10/20
to wrfpython-talk, dileep...@gmail.com
Hello Domingo, 

Sorry for answer so late but I don't see it before. And, also, I don't resolve the problem... 
Can you upload the code to see it? 

Thank you. 

Carlos C. 
Hi Domingo,
To unsubscribe from this group and stop receiving emails from it, send an email to wrfpyth...@ucar.edu.

Dileepkumar R

unread,
Mar 12, 2020, 1:03:42 AM3/12/20
to Carlos Calvo Sancho, wrfpython-talk

Hi Carlo, 

############################################
import wrf
ncfile = Dataset("/Users/carlos-wrf/Documents/WRF/DanaSeptiembre.nc")
#p_levels = [1000.0, 975.0, 950.0, 925.0, 900.0, 875.0, 850.0, 825.0, 800.0, 775.0, 750.0, 700.0, 650.0, 600.0, 550.0, 500.0, 450.0, 400.0, 350.0, 300.0, 250.0, 225.0, 200.0, 175.0, 150.0, 125.0, 100.0]
#since  you need only 850hPa, so you can use 
p_levels = [850.0]
t850 = wrf.vinterp(wrfin=ncfile,field =temp, vert_coord='pressure', interp_levels = p_levels, extrapolate = True, field_type = None,log_p=True, timeidx=ALL_TIMES)
############################################
I hope it will work, if not please send me the error log. 


with regards,

Dileepkumar R
Postdoctoral Researcher,
Interdisciplinary Centre for Water Research (ICWaR),
Indian Institute of Sciences, Bangalore, 560012

 

Carlos Calvo Sancho

unread,
Mar 12, 2020, 2:23:55 PM3/12/20
to wrfpython-talk, ccalvo...@gmail.com
It's works!!!!! Thank you very much Dileepkumar!!

Best regards, 

Carlos C.
Reply all
Reply to author
Forward
0 new messages