0

I am learning on how to plot various variables from WRF output netcdf file. My requirement is to extract variables for a certain lat/lon (8.4875° N, 76.9525° E) in order to plot SkewT profiles using the matplotlib package.

I found a similar question on this SO page netcdf4 extract for subset of lat lon. However, its location is a set of boundaries.

6
  • See answer two at: stackoverflow.com/questions/33789379/… Commented Dec 21, 2015 at 3:00
  • Thanks for your comment. When I executed your code it returned 1632 and 43 for lat 8.4 and lon 76.95. This is no way close to the actual Lat & Lon I would expect. Commented Dec 21, 2015 at 16:03
  • 76.95 E is -76.95 in decimal degrees. I added code to show how to test the results at the answer above. Commented Dec 21, 2015 at 18:36
  • Well I have got the index error IndexError: index 1632 is out of bounds for axis 0 with size 73. Does it mean that the lat and lon is not available in the file? Commented Dec 21, 2015 at 19:10
  • I am not at all familiar with the WRF NetCDF file format. A quick looks suggests that the lat,lon columns might be named south_north and west_east. Do you have the url where you got the WRF file. Commented Dec 23, 2015 at 17:06

2 Answers 2

1

Check out xray. You'll have to do some work to make the SkewT chart but accessing and summarizing the netCDF Dataset and variables will be pretty easy. Just a few examples below.

import xray

ds = xray.open_dataset('your_wrf_file.nc')

ds_point = ds.sel(lon=76.9525, lat=8.4875)

ds_point['Temperature'].plot()  # plot profile at point assuming Temperature had dimensions of (level, lat, lon)

df = ds_point.to_dataframe()  # export dataset to Pandas.DataFrame

temp_array = ds_point['Temperature'].values  # access the underlying numpy array of the "Temperature" variable
Sign up to request clarification or add additional context in comments.

2 Comments

Your code gives me a key error. I have changed the key to XLAT and XLONG which is equivalent of lon and lat. But still same issue.
You didn't provide a sample file so this was just to give you a rough idea of how this could be done.
0

What I usually do is extract the nearest gridpoint to the column using CDO from the command line before using ncl,python,R etc for plotting:

cdo remapnn,lon=76.9525/lat=8.4875 wrf_file.nc pnt_file.nc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.