Question: The NAM data uses grid points to plot the data, and I am asking the user to input latitude and longitude of a specified region.

The NAM data uses grid points to plot the data, and I am asking the user to input latitude and longitude of a specified region. The code below plots the average temperature for an inputted region, but the latitude and longitude do not match up with the NAM grid points. For example, when I input the lat/lon for the state of Kansas, the code outputs a graph with a region in Kentucky. I need to somehow convert the grid points to match up to the corresponding lat/lon. Can someone please show me how to fix this?

import numpy as np import gempak as gp import matplotlib.pylab as plt from mpl_toolkits.basemap import Basemap

southlat = input('What is the southern latitude of the region you are interested in?')

northlat = input('What is the northern latitude of the region you are interested in?')

westlon = input('What is the western longitude of the region you are intersted in?')

eastlon = input('What is the eastern longitude of the region you are interested in?')

westlon = (westlon * -1.0) eastlon = (eastlon * -1.0)

nam = raw_input('Which run of the NAM (8 digits) would you like?')

info = '$MODEL/nam/' + str(nam) + '_nam212.gem' fid = gp.Dataset(info)

gdattims = []

x = 0

while x<24: if x<10: gdattims.append((str(nam)[0:6]) + '(str(nam)[6:8])+ '00f00' str(x)) else: '00f0' x>

data = []

for i in gdattims: data.append({'gdattim': [i, ''], 'glevel': [0, -1], 'gvcord' : 'NONE', 'gfunc':'TMPK'}) temp = [] print temp

for i in data: temp.append(fid.grid_from_dict(i))

avg_temps = np.zeros(temp[0].shape) for i in temp: avg_temps += i avg_temps = (avg_temps / 8)

Fahrenheit_temps = ((avg_temps - 273.15) * 1.80) + 32.0

plot_temp = Fahrenheit_temps[southlat:northlat, westlon:eastlon]

max_temp = np.amax(Fahrenheit_temps) region = np.where(Fahrenheit_temps == max_temp) print region

m = gp.map_for_dataset(fid)

x0,y0 = m(southlat, westlon) x1,y1 = m(northlat, eastlon)

x = np.linspace(m.xmin, m.xmax, fid.nx) y = np.linspace(m.ymin, m.ymax, fid.ny) xmesh, ymesh = np.meshgrid(x, y)

lons, lats = m(xmesh, ymesh, inverse=True)

ax = plt.gca()

plt.figure()

m = Basemap(llcrnrlon=-119,llcrnrlat=22,urcrnrlon=-64,urcrnrlat=49, projection='lcc',lat_1=33,lat_2=45,lon_0=-95)

x_mesh = xmesh[southlat:northlat, westlon:eastlon] y_mesh = ymesh[southlat:northlat, westlon:eastlon]

r = m.contourf(x_mesh, y_mesh, plot_temp)

m.drawcoastlines() m.drawcountries() m.drawstates() parallels = np.arange(-90.,90+15,15.) m.drawparallels(parallels,labels=[True,True,False,False]) meridians = np.arange(0.,360.,45.) m.drawmeridians(meridians,labels=[False,False,False,True]) plt.title('NAM Average Temperature (F)') plt.colorbar(r)

plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!