Re: Question about coordinates

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu, 04 Dec 2008 12:06:07 -0700

 From WRF NCL examples:
http://www.mmm.ucar.edu/wrf/OnLineTutorial/Graphics/NCL/Examples/wrf_Zoom.htm

The following may work

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

function getWRFsubregion(f[1]:file \
                         ,latS[1]:numeric, latN[1]:numeric \
                         ,lonW[1]:numeric, lonE[1]:numeric )
; extract subscript indicies corresponding to region
; within a WRF file.

local f, XLAT, XLON, XLAT_1d, XLON_1d, nm_1d, nlml, ijsub
begin
  XLAT = f->XLAT(0,:,:)
  XLAT_1d = ndtooned( XLAT )
  XLON = f->XLONG(0,:,:)
  XLON_1d = ndtooned( XLON )

  nm_1d = ind(XLAT_1d.ge.latS .and. XLAT_1d.le.latN .and. \
                 XLON_1d.ge.lonW .and. XLON_1d.le.lonE)
  nlml = ind_resolve(nm_1d, dimsizes(XLON))

  ijsub = new( 4, "integer", "No_FillValue")
  ijsub(0) = min(nlml(:,0))
  ijsub(1) = max(nlml(:,0))
  ijsub(2) = min(nlml(:,1))
  ijsub(3) = max(nlml(:,1))

  return(ijsub)
end

; -------------- MAIN -----------------

  fName = "erik_wrf.nc"
  latS = 5
  latN = 15
  lonW = -10
  lonE = 10

  f = addfile (fName, "r")

  nlml = getWRFsubregion(f, latS, latN, lonW, lonE)

  nlStrt = nlml(0) ; lat start
  nlLast = nlml(1) ; lat last
  mlStrt = nlml(2) ; lon start
  mlLast = nlml(3) ; lon last

  rainnc = f->RAINNC(:,nlStrt:nlLast,mlStrt:mlLast)
  xlat = f->XLAT(0,nlStrt:nlLast,mlStrt:mlLast)
  xlon = f->XLONG(0,nlStrt:nlLast,mlStrt:mlLast)

  printVarSummary( rainnc )
  printMinMax( rainnc, True )
  print("=======================================")
  printVarSummary( xlat )
  printMinMax( xlat, True )
  print("=======================================")
  printVarSummary( xlon )
  printMinMax( xlon, True )

========
Good luck

Evelyn Grell wrote:
> Erik,
> I think the problem is simply that the WRF dimensions can not be
> directly converted to lat/lon using the {} notation, because lat and lon
> are 2d arrays. You can specify a range using the actual grid points, but
> the value of -10 won't work.
> I'm sure Mary, Dennis and the others could provide an elegant fix, but I
> just wanted to help you understand the error.
> Evelyn
>
>
> Erik Noble wrote:
>> Dear NCL,
>> Could I please have help with getting over this hurdle? It is still
>> tough to comprhend.
>> I need help understanding the proper way to get read this variable
>> with specific coordinates. My simple goal is to have a rain variable
>> at between the coordinate range {5:15},{-10:10} so that I can have
>> fun, plot it, perhaps, make a time vs. longitude plot, etc... :-).
>>
>> When I use this command on one file, it works:
>> f = addfile ("TRMM_HDF-Daily_precip.nc","r")
>> r=f->precipitation
>> rain = r(:,{5:15},{-10:10})
>>
>> Yet when I do this for another file (a WRF file) I get the error
>> a = addfile(“wrfout.nc”,”r”)
>> nc = a->RAINNC(:,{5:15},{-10:10})
>> fatal:Dimension (west_east) of file (wrfout_d01_2006-09-01_00:00:00)
>> does not have an associated coordinate variable
>> fatal:Execute: Error occurred at or near line 114
>>
>> I don’t know how to read this using standard subscripting because I
>> don’t know the indices. I understand, using printVarSummary command,
>> that its coordinates are not 1D “lat” and “lons” but 3D XLAT and XLONG
>> (indicated below). But how can I call in the variable or at least get
>> the variable between the coordinates above? Do I have to specifically
>> name the coordinates?
>>
>> Any advice will be appreciated and I will be forever grateful, mainly
>> because the misunderstanding of this concept has been the source of
>> most of mytalk questions.
>> Sincerely,
>> Erik
>>
>> Ncl 131> nc = a->RAINNC
>> ncl 132> printVarSummary(nc)
>>
>>
>> Variable: nc
>> Type: float
>> Total Size: 1047200 bytes
>> 261800 values
>> Number of Dimensions: 3
>> Dimensions and sizes: [Time | 17] x [south_north | 110] x [west_east |
>> 140]
>> Coordinates:
>> Number Of Attributes: 6
>> FieldType : 104
>> MemoryOrder : XY
>> description : ACCUMULATED TOTAL GRID SCALE PRECIPITATION
>> units : mm
>> stagger :
>> coordinates : XLONG XLAT
>>
>>
>> cl 141> xlat= a->XLAT
>> ncl 142> printVarSummary(xlat)
>>
>>
>> Variable: xlat
>> Type: float
>> Total Size: 1047200 bytes
>> 261800 values
>> Number of Dimensions: 3
>> Dimensions and sizes: [Time | 17] x [south_north | 110] x [west_east |
>> 140]
>> Coordinates:
>> Number Of Attributes: 5
>> FieldType : 104
>> MemoryOrder : XY
>> description : LATITUDE, SOUTH IS NEGATIVE
>> units : degree_north
>> stagger :
>>
>> ncl 143> xlong = a->XLONG
>> ncl 144> printVarSummary(xlong)
>>
>>
>> Variable: xlong
>> Type: float
>> Total Size: 1047200 bytes
>> 261800 values
>> Number of Dimensions: 3
>> Dimensions and sizes: [Time | 17] x [south_north | 110] x [west_east |
>> 140]
>> Coordinates:
>> Number Of Attributes: 5
>> FieldType : 104
>> MemoryOrder : XY
>> description : LONGITUDE, WEST IS NEGATIVE
>> units : degree_east
>> stagger :
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Dec 04 2008 - 12:06:07 MST

This archive was generated by hypermail 2.2.0 : Thu Dec 11 2008 - 03:51:46 MST