<p>A Skew-T/Log-p plot is a vertical profile from a point, and it appears in that code that the point you are plotting the skew-T for is 60.2 latitude, 11.08 longitude.  The snippet of code:</p>

<pre><code>def getXY(lon,lat):
 x_nr = 0
 y_nr = 0
 while (lon[x_nr] &lt; lon_focuspoint):
  x_nr += 1
 while (lat[y_nr] &lt; lat_focuspoint):
  y_nr += 1
</code></pre>

<p>finds the closest grid point west and south of your focus point by setting the x and y gridpoints to 0 and incrementing the index as long as the latitude/longitude values at that grid point are less than the focus point.  This is what the focus point is for -- the lat/lon location you want the skew-t/log-p plot at.</p>

<p>The exception <code>IndexError: index out of bounds.</code> means that the above code tried to access a value <code>lon[x_nr]</code> or <code>lat[y_nr]</code> that was out of bounds.  This means that the latitude/longitude coordinate of your focus point is not within your domain.</p>

<p>To run the code successfully, edit the focus point to be a point within your model domain, specifically the value of latitude and longitude that you want the skew-t profile for.</p>

CC BY-SA 3.0
2015-06-23T14:47:25.363Z
Thanks for the clarification @casey♦ . I've been meaning to get the value of latitude and longitude of the domain since long time ago, but never managed to do that. Do you know any ways to do that? 

However, I do know the location of the data, which is in Minnesota. And if my understanding of your answer is correct, the coordinates for Minnesota is 44.9N and 93.2W. So I *tried* using it as my focus point, but I still get the IndexError.
cwmwl
CC BY-SA 3.0
2015-06-23T14:52:12.997Z
@cwmwl you could ask that in a new question.  The plot domain should be setup before you ran the model so you should know the bounds of your domain.  For interior points, I'd just make a plot of something with lat/lon as the axes (so you know *where* you want the skew-t data at).
casey
CC BY-SA 3.0
2015-06-23T14:53:27.340Z
@cwmwl I assume you input 92.3W as `-92.3` ?
casey
CC BY-SA 3.0
2015-06-23T14:56:30.300Z
♦ Alright, I'll ask that in a new question. Fyi, I didn't run the model. I'm just using the output from the model.. Didn't know that I need to know these information about the model.
cwmwl
CC BY-SA 3.0
2015-06-23T14:58:00.260Z
@cwmwl well, if you know the grid indices you want the plot at, you could just modify that program to use them directly rather than figuring them out from the focus point.  that is another option if you already know where you want the plot at.
casey
CC BY-SA 3.0
2015-06-23T14:19:26.743Z
2015-06-23T14:19:26.743Z
casey
<p>has anyone used the python code from <a href="https://code.google.com/p/pywrfplot/source/browse/#svn%2Ftrunk" rel="nofollow noreferrer">here (written by Geir Arne Waagbo)</a> to plot skewT plot from WRF output?</p>

<p>I've got a question regarding some of the functions used in the code found in pywrfplotUtils.py - which is the getXY(lon,lat) function that gets called in getDimensions(nc) function.</p>

<p>Below are the codes:</p>

<pre><code>def getDimensions(nc):
 Nx = nc.getncattr('WEST-EAST_GRID_DIMENSION')-1
 Ny = nc.getncattr('SOUTH-NORTH_GRID_DIMENTION')-1
 Nz = nc.getncattr('BOTTOM-TOP_GRID_DIMENSION')-1
 dx = nc.getncattr('DX')
 dy = nc.getncattr('DY')
 lons = nc.variables['XLAT'][0]
 lats = nc.variables['XLONG'][0]
 # find coordinates for focus point
 x,y = getXY(lons[Ny/2,:],lats[:,Nx/2])
 return Nx,Ny,Nz,lons,lats,dx,dy,x,y

def getXY(lon,lat):
 x_nr = 0
 y_nr = 0
 while (lon[x_nr] &lt; lon_focuspoint):
  x_nr += 1
 while (lat[y_nr] &lt; lat_focuspoint):
  y_nr += 1

 print "x_nr:" str(x_nr),"Lon:",str(lon[x_nr])
 print "y_nr:" str(y_nr),"Lat:",str(lon[x_nr])
 return x_nr,y_nr
</code></pre>

<p>The focus point is a variable set in the pywrfplotParams.py:</p>

<pre><code>#This defines the grid box for which skewT-plots etc are based
lat_focuspoint = 60.2
lon_focuspoint = 11.08
</code></pre>

<p>Unfortunately, I don't know what focus point is referring to, so when I use the values set by the author, obviously I get an error, and that error is - <em>IndexError: index out of bounds.</em></p>

<p>I have found this <a href="https://earthscience.stackexchange.com/questions/2732/how-to-get-cell-indices-from-latitude-and-longitude-in-wrf-model-grids">link</a> useful in providing the definition for the attributes asked in that question, but I'm not entirely sure if I should also get the cell indices from latitude and longitude in the WRF model grids.</p>

<p>Your thoughts are very much appreciated!</p>

<meteorology><numerical-modelling><wrf>
What is "focus point" in WRF-plots grid box? (python code)
cwmwl
# What is "focus point" in WRF-plots grid box? (python code)

(Asked by: username_0 on 2015-06-23)

has anyone used the python code from [here (written by Geir Arne Waagbo)](https://code.google.com/p/pywrfplot/source/browse/#svn%2Ftrunk) to plot skewT plot from WRF output?

I've got a question regarding some of the functions used in the code found in pywrfplotUtils.py - which is the getXY(lon,lat) function that gets called in getDimensions(nc) function.

Below are the codes:

```
def getDimensions(nc):
 Nx = nc.getncattr('WEST-EAST_GRID_DIMENSION')-1
 Ny = nc.getncattr('SOUTH-NORTH_GRID_DIMENTION')-1
 Nz = nc.getncattr('BOTTOM-TOP_GRID_DIMENSION')-1
 dx = nc.getncattr('DX')
 dy = nc.getncattr('DY')
 lons = nc.variables['XLAT'][0]
 lats = nc.variables['XLONG'][0]
 # find coordinates for focus point
 x,y = getXY(lons[Ny/2,:],lats[:,Nx/2])
 return Nx,Ny,Nz,lons,lats,dx,dy,x,y

def getXY(lon,lat):
 x_nr = 0
 y_nr = 0
 while (lon[x_nr] < lon_focuspoint):
  x_nr += 1
 while (lat[y_nr] < lat_focuspoint):
  y_nr += 1

 print "x_nr:" str(x_nr),"Lon:",str(lon[x_nr])
 print "y_nr:" str(y_nr),"Lat:",str(lon[x_nr])
 return x_nr,y_nr

```

The focus point is a variable set in the pywrfplotParams.py:

```
#This defines the grid box for which skewT-plots etc are based
lat_focuspoint = 60.2
lon_focuspoint = 11.08

```

Unfortunately, I don't know what focus point is referring to, so when I use the values set by the author, obviously I get an error, and that error is - *IndexError: index out of bounds.*

I have found this [link](https://earthscience.stackexchange.com/questions/2732/how-to-get-cell-indices-from-latitude-and-longitude-in-wrf-model-grids) useful in providing the definition for the attributes asked in that question, but I'm not entirely sure if I should also get the cell indices from latitude and longitude in the WRF model grids.

Your thoughts are very much appreciated!

**Tags:** meteorology, numerical-modelling, wrf


---

## 1 answers

### Answer by username_1 on 2015-06-23. Score: 2

A Skew-T/Log-p plot is a vertical profile from a point, and it appears in that code that the point you are plotting the skew-T for is 60.2 latitude, 11.08 longitude. The snippet of code:

```
def getXY(lon,lat):
 x_nr = 0
 y_nr = 0
 while (lon[x_nr] < lon_focuspoint):
  x_nr += 1
 while (lat[y_nr] < lat_focuspoint):
  y_nr += 1

```

finds the closest grid point west and south of your focus point by setting the x and y gridpoints to 0 and incrementing the index as long as the latitude/longitude values at that grid point are less than the focus point. This is what the focus point is for -- the lat/lon location you want the skew-t/log-p plot at.

The exception `IndexError: index out of bounds.` means that the above code tried to access a value `lon[x_nr]` or `lat[y_nr]` that was out of bounds. This means that the latitude/longitude coordinate of your focus point is not within your domain.

To run the code successfully, edit the focus point to be a point within your model domain, specifically the value of latitude and longitude that you want the skew-t profile for.

> **Comments:**
> **username_0**: Thanks for the clarification @username_1♦ . I've been meaning to get the value of latitude and longitude of the domain since long time ago, but never managed to do that. Do you know any ways to do that?   However, I do know the location of the data, which is in Minnesota. And if my understanding of your answer is correct, the coordinates for Minnesota is 44.9N and 93.2W. So I *tried* using it as my focus point, but I still get the IndexError.  
> **username_1**: @username_0 you could ask that in a new question.  The plot domain should be setup before you ran the model so you should know the bounds of your domain.  For interior points, I'd just make a plot of something with lat/lon as the axes (so you know *where* you want the skew-t data at).  
> **username_1**: @username_0 I assume you input 92.3W as `-92.3` ?  
> **username_0**: ♦ Alright, I'll ask that in a new question. Fyi, I didn't run the model. I'm just using the output from the model.. Didn't know that I need to know these information about the model.  
> **username_1**: @username_0 well, if you know the grid indices you want the plot at, you could just modify that program to use them directly rather than figuring them out from the focus point.  that is another option if you already know where you want the plot at.  

---

