Re: WRF: Max & Min Temperature calculation

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Mar 10 2010 - 12:38:39 MST

My apologies if this one was already answered.

The problem with your code is that you can only do something like this:

temp = a[:]->TK

when "a" is the return variable from an "addfiles" call, and NOT an
"addfile" call. In your
script below, you're using "addfile".

"addfiles" returns something called a "List" variable, and "addfile"
returns a "file" variable.
These two are very different and cannot be used interchangeably.

Since you have an array of files, you can read in all your files with
"addfiles".

Furtherore, if you have enough memory, you can read all the variables
you
need outside the "do" loop.

Your code might look something like this:

datadir = "/casvol5/basantas/cas/WRF3-1/output-wrf/2010030600/"
FILES = systemfunc ("ls -1 " + datadir + "wrfout_d01* " )
numFILES = dimsizes(FILES)
a = addfiles(FILES+".nc","r")

temp = a[:]->TK ; T = temperature or theta? If theta use wrf_tk to
P = a[:]->P ; perturbation
Pb = a[:]->PB ; base state pressure
P = P + Pb ; total pressure
T = a[:]->T ; perturbation potential temperature (theta
+t0)

You will need to adjust the variables inside your do loop to have
the appropriate dimensions, however.

By the way, I think you have a strange line in your code:

T = T

This is copying a variable back to itself. Did you mean to
do something else there?

--Mary

On Mar 8, 2010, at 11:31 PM, Sahidul wrote:

> Hello Adam,
> Thank you for your help.
> Yes, you are right. In my WRF out files, T is defined as:
>
> netcdf wrfout_d01_2010-02-16_00\:00\:00 {
> dimensions:
> Time = UNLIMITED ; // (1 currently)
> DateStrLen = 19 ;
> west_east = 369 ;
> south_north = 307 ;
> west_east_stag = 370 ;
> bottom_top = 26 ;
> south_north_stag = 308 ;
> bottom_top_stag = 27 ;
> soil_layers_stag = 5 ;
> variables:
> char Times(Time, DateStrLen) ;
> float T(Time, bottom_top, south_north, west_east) ;
> T:FieldType = 104 ;
> T:MemoryOrder = "XYZ" ;
> T:description = "perturbation potential temperature
> (theta-t0)" ;
> T:units = "K" ;
> T:stagger = "" ;
> T:coordinates = "XLONG XLAT" ;
>
>
> I tried to construct according to your script. I have written
> script like below:
> -------------------------------
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>
> begin
>
> datadir = "/casvol5/basantas/cas/WRF3-1/output-wrf/2010030600/"
> FILES = systemfunc ("ls -1 " + datadir + "wrfout_d01* " )
> numFILES = dimsizes(FILES)
>
> do ifil = 0,numFILES-1
> a = addfile(FILES(ifil)+".nc","r")
>
> ;fils = systemfunc("ls /wrf/cas/WRF3-1/output-wrf/2010030600/
> wrfout_d01_*")
> ;a = addfiles(fils+".nc","r")
> ;temp = a[:]->T ; T = temperature or theta? If theta use wrf_tk to
> ; convert if desired
> wks = gsn_open_wks("x11","test")
>
> P = a->P ; perturbation
> Pb = a->PB ; base state pressure
> P = P + Pb ; total pressure
> T = a->T ; perturbation potential temperature (theta+t0)
> T = T
>
> TK = wrf_tk (P, T)
>
> temp = a[:]->TK
>
>
> dailymax = temp(0::24,:,:,:) ; copy metadata
> ;dailymax = dailymax@_FillValue
> dailymin = dailymax
> cntr = 0
> do gg = 0,dimsizes(temp&Time)-1
> dailymax(cntr,:,:,:) = dim_max_n(temp(cntr:cntr+23,:,:,:),0)
> dailymin(cntr,:,:,:) = dim_min_n(temp(cntr:cntr+23,:,:,:),0)
> cntr = cntr+24
> end do
> end do
> end
> -------------------------------
>
> I am getting errors in ( temp = a[:]->TK ) ; like
> fatal:List subscripting used on non-list variable, can't continue
> fatal:Execute: Error occurred at or near line 27 in file max-min.ncl
> Here line 27: temp = a[:]->TK
>
> Please help me to sort it.
>
> Message: 2
> Date: Mon, 08 Mar 2010 10:01:53 -0700
> From: Adam Phillips <asphilli@ucar.edu>
> Subject: Re: WRF: Max & Min Temperature calculation
> To: ncl-talk@ucar.edu
> Message-ID: <4B952D81.6080707@ucar.edu>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> HI Sahidul,
> Using dim_max/dim_min (or dim_max_n/dim_min_n if you have version
> 5.1.1), this should not be that bad. For example:
> -----------------------------
> fils = systemfunc("ls wrfout*")
> a = addfiles(fils+".nc","r")
> temp = a[:]->T ; T = temperature or theta? If theta use wrf_tk to
> convert if desired
>
> dailymax = temp(0::24,:,:,:) ; copy metadata
> dailymax = dailymax@_FillValue
> dailymin = dailymax
> cntr = 0
> do gg = 0,dimsizes(temp&Time)-1
> dailymax(cntr,:,:,:) = dim_max_n(temp(cntr:cntr+23,:,:,:),0)
> dailymin(cntr,:,:,:) = dim_min_n(temp(cntr:cntr+23,:,:,:),0)
> cntr = cntr+24
> end do
> -----------------------------
>
> That will calculate the max/min temperature for every grid point at
> every level. I am not sure whether for your model data if
> temperature is
> output or whether theta is output. If theta is, and you want to
> convert
> it to temperature use wrf_tk:
> http://www.ncl.ucar.edu/Document/Functions/Built-in/wrf_tk.shtml
> Good luck,
> Adam
>
>
> On 03/08/2010 09:25 AM, Sahidul wrote:
> > Dear Sir/NCL Users,
> >
> > I would like to calculate maximum and Minimum temperature in a day
> (24 hours).
> >
> > I am having WRF output files saved in 1 hour interval. Like below
> ( 1
> > day forecast files = 24)
> >
> > wrfout_d01_2010-03-05-00:00:00 (Times = 2010-03-05-00:00:00)
> > (temperature -> T (Time, lev,lat,lon) )
> > wrfout_d01_2010-03-05-01:00:00 (Times = 2010-03-05-01:00:00)
> > wrfout_d01_2010-03-05-02:00:00 (Times = 2010-03-05-02:00:00)
> > ......
> > .....
> > wrfout_d01_2010-03-05-23:00:00 (Times = 2010-03-05-23:00:00)
> >
> >
> > please help me to calculate it. If anyone has any scripts for
> this,
> > kindly provide me.
> >
> > Thanking you,
> >
> > Sahidul
> _______________________________________________
> 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 Wed Mar 10 12:39:22 2010

This archive was generated by hypermail 2.1.8 : Thu Mar 11 2010 - 11:17:07 MST