Extracting the value from Netcdf file with longitude and lattitude

Isaac Won winefrog at gmail.com
Fri May 16 04:44:58 EDT 2014


Hi,
My question may be confusing.

Now I would like to extract temperature values from model output with python.

My model output have separate temperature, longitude and latitude variables.

So, I overlap these three grid variables on one figure to show temperature with longitude and latitude through model domain.

Up to this point, everything is fine. The problem is to extract temperature value at certain longitude and latitude. 

Temperature variable doesn't have coordinate, but only values with grid.

Do you have idea about this issue?

Below is my code for the 2 D plot with temperature on model domain.

varn1 = 'T2'
varn2 = 'XLONG'
varn3 = 'XLAT'
Temp  = read_netcdf(filin,varn1)
Lon  = read_netcdf(filin,varn2)
Lat  = read_netcdf(filin,varn3)

Temp_plt =  Temp[12,:,:]
Lon_plt = Lon[12,:,:]
Lat_plt = Lat[12,:,:]
x = Lon_plt
y = Lat_plt

Temp_c = Temp_plt-273.15
myPLT = plt.pcolor(x,y,Temp_c)
mxlabel = plt.xlabel('Latitude')
mylabel = plt.ylabel('Longitude')
plt.xlim(126.35,127.35)
plt.ylim(37.16,37.84)
myBAR = plt.colorbar(myPLT)
myBAR.set_label('Temperature ($^\circ$C)')
plt.show()

--------------------------------------------------
read_netcdf is a code for extracting values of [time, x,y] format.

I think that the point is to bind x, y in Temp_plt with x, y in Lon_plt and Lat_plt to extract temperature values with longitude and latitude input.

This question might be confusing. If you can't understand please let me know.

Any idea or help will be really appreciated.

Best regards,

Hoonill







More information about the Python-list mailing list