[gradsusr] Average of a parameter

Andrew Friedman andfried at gmail.com
Thu Oct 2 11:53:50 EDT 2014


Hi Thareh,

Check out the documentation on ASCII data in GrADS to save the averages in a table as you’re looking for.
http://www.iges.org/grads/gadoc/ascii.html

A related option is to use the OpenGrADS recipe fprintf.gs:
http://cookbooks.opengrads.org/index.php?title=Recipe-002:_Saving_GrADS_variable_data_to_a_text_file

Andrew

On Oct 2, 2014, at 4:58 PM, T. haghroosta <haghroosta at hotmail.com> wrote:

> Hi,
>  
> Unfortunately, It didn't work for my aim. In fact, I would like to have the average over the time but in every grid point (according to different lon and lat) separately. To show what kind of average I need is like a matrix as follows. each number is the averaged data during 10 years (t= 517 to t=643), based on Ncep data set. Can anyone help?
>  
>  
> 99.375	101.25	103.125	105	106.875	108.75	110.625	112.5	114.375	116.25	118.125
> 6.66	6.38E-05	1.02E-04	5.36E-05	5.58E-05	6.27E-05	7.12E-05	8.22E-05	8.61E-05	6.89E-05	4.79E-05	4.94E-05
> 4.76	5.74E-05	1.11E-04	1.03E-04	6.50E-05	6.75E-05	7.09E-05	8.32E-05	7.41E-05	3.92E-05	1.06E-04	1.07E-04
> 2.85	1.30E-04	5.39E-05	1.22E-04	6.92E-05	6.71E-05	6.29E-05	6.39E-05	1.13E-04	9.78E-05	1.06E-04	4.05E-05
> 0.95	1.30E-04	1.31E-04	1.36E-04	6.95E-05	6.53E-05	5.40E-05	1.23E-04	1.07E-04	9.03E-05	1.12E-04	1.19E-04
>  
> I have 10*12=120 of tables like this for 10 years with 12 month. I would like to write a script that read the data from a file  in each grid point in every month during 10 years and then calculate the average, and show the average in a text file.
>  
> Regards, 
> Thareh
>  
> > From: gradsusr-request at gradsusr.org
> > Subject: gradsusr Digest, Vol 56, Issue 4
> > To: gradsusr at gradsusr.org
> > Date: Wed, 1 Oct 2014 22:45:15 -0400
> > 
> > Send gradsusr mailing list submissions to
> > gradsusr at gradsusr.org
> > 
> > To subscribe or unsubscribe via the World Wide Web, visit
> > http://gradsusr.org/mailman/listinfo/gradsusr
> > or, via email, send a message with subject or body 'help' to
> > gradsusr-request at gradsusr.org
> > 
> > You can reach the person managing the list at
> > gradsusr-owner at gradsusr.org
> > 
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of gradsusr digest..."
> > 
> > 
> > Today's Topics:
> > 
> > 1. Re: Average of a parameter (Andrew Friedman)
> > 2. Re: Average of a parameter (Mingxuan Chen)
> > 3. Re: Average of a parameter (Joao Nobre)
> > 4. How to plot X-Y axis in log scale (Jian-Jian Wang)
> > 5. Correlation (Jian-Jian Wang)
> > 6. Correlation (Jian-Jian Wang)
> > 7. Moist Potential Vorticity (PHILBERT LUHUNGA)
> > 
> > 
> > ----------------------------------------------------------------------
> > 
> > Message: 1
> > Date: Wed, 1 Oct 2014 18:21:42 +0200
> > From: Andrew Friedman <andfried at gmail.com>
> > Subject: Re: [gradsusr] Average of a parameter
> > To: GrADS Users Forum <gradsusr at gradsusr.org>
> > Message-ID: <E643D2EE-87B0-4CE5-B290-7C9002C06F4F at gmail.com>
> > Content-Type: text/plain; charset=windows-1256
> > 
> > Hi Thareh,
> > As written, your script averages over space, not time.
> > If you are trying to average over time, you should use an average of the form
> > ?ave(prate,t=517,t=643)'
> > Also, if you?re trying to calculate a spatial average, I suggest using ?aave?.
> > Andrew
> > 
> > On Oct 1, 2014, at 5:08 PM, T. haghroosta <haghroosta at hotmail.com> wrote:
> > 
> > > Dear Andrew Friedman,
> > > Thank you for your help.
> > > In fact I would like to calculate average of sst during 10 years in special area for example lon=100 120 and lat= 0 7. Then I want to put the result in a text file.
> > > I wrote this script:
> > > 
> > > 'reinit'
> > > 'sdfopen H:/prate.sfc.mon.mean.nc'
> > > 'set t 517 643'
> > > 'd ave(ave(prate,lon=100,lon=120),lat=0,lat=7)'
> > > r1= subwrd(result,4)
> > > say r1
> > > 'close 1'
> > > vars= r1
> > > res=write('filename3.txt', vars ,append)
> > > 
> > > but unfortunately I just got one number but I must see too many data. Is it possible to have average of SST during 10 years in special longitude and latitude. I mean I would like to have sst1 ( lon1&lat1), sst2 (lon2&lat2), ..... which averaged during 10 years.
> > > 
> > > Regards,
> > > 
> > > Thareh
> > > 
> > > > Message: 2
> > > > Date: Wed, 1 Oct 2014 11:10:44 +0200
> > > > From: Andrew Friedman <andfried at gmail.com>
> > > > Subject: Re: [gradsusr] Average of a parameter
> > > > To: GrADS Users Forum <gradsusr at gradsusr.org>
> > > > Message-ID: <85BC0AE9-7894-4048-9A70-9126D5993A61 at gmail.com>
> > > > Content-Type: text/plain; charset=windows-1256
> > > > 
> > > > Hi Thareh,
> > > > Check out the ?ave? command: http://www.iges.org/grads/gadoc/gradfuncave.html
> > > > Best, Andrew
> > > > 
> > > > On Oct 1, 2014, at 9:16 AM, T. haghroosta <haghroosta at hotmail.com> wrote:
> > > > 
> > > > > Dear All,
> > > > > 
> > > > > Could anyone tell me how I can take the average of a parameter during 10 years? For example I would like to calculate 10-year average of SST in Grads.
> > > > > 
> > > > > Best regards,
> > > > > Thareh 
> > > > > _______________________________________________
> > > > > gradsusr mailing list
> > > > > gradsusr at gradsusr.org
> > > > > http://gradsusr.org/mailman/listinfo/gradsusr
> > > > 
> > > > 
> > > > 
> > > 
> > > _______________________________________________
> > > gradsusr mailing list
> > > gradsusr at gradsusr.org
> > > http://gradsusr.org/mailman/listinfo/gradsusr
> > 
> > 
> > 
> > 
> > ------------------------------
> > 
> > Message: 2
> > Date: Wed, 1 Oct 2014 12:07:45 -0600
> > From: Mingxuan Chen <chen at atmos.colostate.edu>
> > Subject: Re: [gradsusr] Average of a parameter
> > To: GrADS Users Forum <gradsusr at gradsusr.org>
> > Message-ID: <7F53D3A4-970D-4C0E-ACB0-4B1919866950 at atmos.colostate.edu>
> > Content-Type: text/plain; charset=windows-1256
> > 
> > See you at Parking lot.
> > On Oct 1, 2014, at 10:21 AM, Andrew Friedman <andfried at gmail.com> wrote:
> > 
> > > Hi Thareh,
> > > As written, your script averages over space, not time.
> > > If you are trying to average over time, you should use an average of the form
> > > ?ave(prate,t=517,t=643)'
> > > Also, if you?re trying to calculate a spatial average, I suggest using ?aave?.
> > > Andrew
> > > 
> > > On Oct 1, 2014, at 5:08 PM, T. haghroosta <haghroosta at hotmail.com> wrote:
> > > 
> > >> Dear Andrew Friedman,
> > >> Thank you for your help.
> > >> In fact I would like to calculate average of sst during 10 years in special area for example lon=100 120 and lat= 0 7. Then I want to put the result in a text file.
> > >> I wrote this script:
> > >> 
> > >> 'reinit'
> > >> 'sdfopen H:/prate.sfc.mon.mean.nc'
> > >> 'set t 517 643'
> > >> 'd ave(ave(prate,lon=100,lon=120),lat=0,lat=7)'
> > >> r1= subwrd(result,4)
> > >> say r1
> > >> 'close 1'
> > >> vars= r1
> > >> res=write('filename3.txt', vars ,append)
> > >> 
> > >> but unfortunately I just got one number but I must see too many data. Is it possible to have average of SST during 10 years in special longitude and latitude. I mean I would like to have sst1 ( lon1&lat1), sst2 (lon2&lat2), ..... which averaged during 10 years.
> > >> 
> > >> Regards,
> > >> 
> > >> Thareh
> > >> 
> > >>> Message: 2
> > >>> Date: Wed, 1 Oct 2014 11:10:44 +0200
> > >>> From: Andrew Friedman <andfried at gmail.com>
> > >>> Subject: Re: [gradsusr] Average of a parameter
> > >>> To: GrADS Users Forum <gradsusr at gradsusr.org>
> > >>> Message-ID: <85BC0AE9-7894-4048-9A70-9126D5993A61 at gmail.com>
> > >>> Content-Type: text/plain; charset=windows-1256
> > >>> 
> > >>> Hi Thareh,
> > >>> Check out the ?ave? command: http://www.iges.org/grads/gadoc/gradfuncave.html
> > >>> Best, Andrew
> > >>> 
> > >>> On Oct 1, 2014, at 9:16 AM, T. haghroosta <haghroosta at hotmail.com> wrote:
> > >>> 
> > >>>> Dear All,
> > >>>> 
> > >>>> Could anyone tell me how I can take the average of a parameter during 10 years? For example I would like to calculate 10-year average of SST in Grads.
> > >>>> 
> > >>>> Best regards,
> > >>>> Thareh 
> > >>>> _______________________________________________
> > >>>> gradsusr mailing list
> > >>>> gradsusr at gradsusr.org
> > >>>> http://gradsusr.org/mailman/listinfo/gradsusr
> > >>> 
> > >>> 
> > >>> 
> > >> 
> > >> _______________________________________________
> > >> gradsusr mailing list
> > >> gradsusr at gradsusr.org
> > >> http://gradsusr.org/mailman/listinfo/gradsusr
> > > 
> > > 
> > > _______________________________________________
> > > gradsusr mailing list
> > > gradsusr at gradsusr.org
> > > http://gradsusr.org/mailman/listinfo/gradsusr
> > 
> > 
> > 
> > 
> > ------------------------------
> > 
> > Message: 3
> > Date: Wed, 1 Oct 2014 23:04:29 +0300
> > From: Joao Nobre <j.pnobre at hotmail.com>
> > Subject: Re: [gradsusr] Average of a parameter
> > To: GrADS Users Forum <gradsusr at gradsusr.org>
> > Message-ID: <SNT148-W402759BEBC5A3BEBD441158FB80 at phx.gbl>
> > Content-Type: text/plain; charset="windows-1252"
> > 
> > First, you should go to this site and next you can make a plot on GrADS, using the normal Scripts or Codes, if you prefer!Name of site http://www.esrl.noaa.gov/psd/cgi-bin/db_search/SearchMenus.pl
> > 
> > > From: andfried at gmail.com
> > > Date: Wed, 1 Oct 2014 11:10:44 +0200
> > > To: gradsusr at gradsusr.org
> > > Subject: Re: [gradsusr] Average of a parameter
> > > 
> > > Hi Thareh,
> > > Check out the ?ave? command: http://www.iges.org/grads/gadoc/gradfuncave.html
> > > Best, Andrew
> > > 
> > > On Oct 1, 2014, at 9:16 AM, T. haghroosta <haghroosta at hotmail.com> wrote:
> > > 
> > > > Dear All,
> > > > 
> > > > Could anyone tell me how I can take the average of a parameter during 10 years? For example I would like to calculate 10-year average of SST in Grads.
> > > > 
> > > > Best regards,
> > > > Thareh 
> > > > _______________________________________________
> > > > gradsusr mailing list
> > > > gradsusr at gradsusr.org
> > > > http://gradsusr.org/mailman/listinfo/gradsusr
> > > 
> > > 
> > > _______________________________________________
> > > gradsusr mailing list
> > > gradsusr at gradsusr.org
> > > http://gradsusr.org/mailman/listinfo/gradsusr
> > 
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: http://gradsusr.org/pipermail/gradsusr/attachments/20141001/c000739a/attachment-0001.html 
> > 
> > ------------------------------
> > 
> > Message: 4
> > Date: Wed, 1 Oct 2014 21:28:19 +0000
> > From: Jian-Jian Wang <jjwang at umd.edu>
> > Subject: [gradsusr] How to plot X-Y axis in log scale
> > To: GrADS Users Forum <gradsusr at gradsusr.org>
> > Message-ID: <C270AC74-A859-4A1D-9653-F0114FD66246 at umd.edu>
> > Content-Type: text/plain; charset="us-ascii"
> > 
> > Hi,
> > 
> > I would like to make a scatterplot in log scale. But seems Grads can only do 1-D at Z dimension?
> > Any suggestions?
> > 
> > Thanks!
> > 
> > Jay
> > 
> > 
> > ------------------------------
> > 
> > Message: 5
> > Date: Wed, 1 Oct 2014 21:32:21 +0000
> > From: Jian-Jian Wang <jjwang at umd.edu>
> > Subject: [gradsusr] Correlation
> > To: GrADS Users Forum <gradsusr at gradsusr.org>
> > Message-ID: <90F31DC7-BE47-4DF8-936C-70F475C8BBDA at umd.edu>
> > Content-Type: text/plain; charset="us-ascii"
> > 
> > Hi,
> > 
> > When make a scatter plot like:
> > 'set gxout scatter'
> > 'd var1 var2'
> > 
> > It has no problem. Then when I use:
> > 
> > d scorr(var1, var2, lon=-125, lon=-65, lat=20, lat=50)
> > 
> > It doesn't show anything. what did I do wrong? 
> > Thanks.
> > 
> > Jay
> > 
> > 
> > 
> > ------------------------------
> > 
> > Message: 6
> > Date: Wed, 1 Oct 2014 21:46:05 +0000
> > From: Jian-Jian Wang <jjwang at umd.edu>
> > Subject: [gradsusr] Correlation
> > To: GrADS Users Forum <gradsusr at gradsusr.org>
> > Message-ID: <68443CE6-7209-4BF1-BC68-F972828F2030 at umd.edu>
> > Content-Type: text/plain; charset="us-ascii"
> > 
> > 'reinit'
> > 'open npp_swath_test.ctl'
> > 'open /user/parkin/validation/STAR/SWATH/NMQ/nmq_test.ctl'
> > 'd scorr(nmq.2, atm.1, lon=-125, lon=-65, lat=20, lat=50)'
> > 
> > When I run the script in Grads, it won't give me any number.
> > But if I do it line by line like:
> > 
> > open npp_swath_test.ctl
> > open /user/parkin/validation/STAR/SWATH/NMQ/nmq_test.ctl
> > d scorr(nmq.2, atm.1, lon=-125, lon=-65, lat=20, lat=50)
> > 
> > it shows: 
> > Result value = 0.426107
> > 
> > why didn't it show the Result value when running the script?
> > Thank you in advance.
> > 
> > Jay
> > 
> > 
> > 
> > ------------------------------
> > 
> > Message: 7
> > Date: Thu, 2 Oct 2014 02:42:33 +0000 (UTC)
> > From: PHILBERT LUHUNGA <philuhunga at yahoo.com>
> > Subject: [gradsusr] Moist Potential Vorticity
> > To: "gradsusr at gradsusr.org" <gradsusr at gradsusr.org>
> > Message-ID:
> > <1916954210.38931.1412217753822.JavaMail.yahoo at jws10646.mail.bf1.yahoo.com>
> > 
> > Content-Type: text/plain; charset="utf-8"
> > 
> > Hi I am writing a script to compute moist potential vorticity using entropy temperature Theta_s, and virtual potential temperature Theta_v. Please help me to check the script if it is coded right. When I drive it, it gives me results but am not sure the way I have coded if it is right. could anyone cross check it?*our script to compute MPV700hPa.
> > *###################Day1################################
> > *'open $DATA_DIR/WRF_9KM_Nonhy_Topo${RunDay}.ctl'
> > 'open 201112200000_arw_wrfout_d01.ctl'
> > ?
> > 'q file''q dims''pi=3.14159'
> > 'dtr=pi/180'
> > 'a=6.37122*pow(10,6)'
> > 'omega=7.2921*pow(10,-5)'
> > 'g=9.81'
> > 'R=287'
> > 'Cp=1004.5'
> > 'L=2.453*pow(10,6)'
> > *'L=2.453e6'
> > 'Rv=461'
> > * tk??? = Temp in Kelvin
> > * mixr? = water vapour Mixing ratio
> > * u???? = U-wind in m/s
> > * v???? = V-wind in m/s
> > * define ug=UGRDprs?? U-wind in m/s in pressure level
> > * define vg=VGRDprs? V-wind in m/s in pressure level
> > *'define ua=U-ug'
> > *'define va=V-vg'*PV @700hPa
> > 'set lev 800'
> > 'define f=2*omega*sin(lat*dtr)'
> > 'define p1=lev*100'
> > 'define tk1=TMPprs'
> > 'define u1=UGRDprs'
> > 'define v1=VGRDprs'
> > 'define rh1=rhprs'
> > 'define thetap1=tk1*pow((100000/p1),0.286)'
> > 'define es=6.1173*100*exp((L/Rv)*(1/273.16 - 1/tk1))'
> > 'define ep1=rh1*es/100'
> > 'WVmixr1=0.622*ep1/(p1)'
> > 'define T=tk1'
> > 'define VirT1=T*(1+0.61*WVmixr1)'
> > 'thetav1=VirT1*pow((100000/p1),0.2857))'
> > 'thetas1=thetap1*exp(5.87*WVmixr1)''set lev 600'
> > 'define p2=lev*100'
> > 'define tk2=TMPprs'
> > 'define u2=UGRDprs'
> > 'define v2=VGRDprs'
> > 'define rh2=rhprs'
> > 'define thetap2=tk2*pow((100000/p2),0.286)'
> > 'define es=6.1173*100*exp((L/Rv)*(1/273.16 - 1/tk2))'
> > 'define ep2=rh2*es/100'
> > 'WVmixr2=0.622*ep2/(p2)'
> > 'define T=tk2'
> > 'define VirT2=T*(1+0.61*WVmixr2)'
> > 'thetav2=VirT2*pow((100000/p2),0.2857))'
> > 'thetas2=thetap2*exp(5.87*WVmixr2)'
> > ********************PV at 700hPa level
> > 'set lev 700'
> > 'dp=p2-p1'
> > 'dudp=(u2-u1)/dp'
> > 'dvdp=(v2-v1)/dp'
> > 'define p0=lev*100'
> > 'define tk0=TMPprs'
> > 'define u0=UGRDprs'
> > 'define v0=VGRDprs'
> > 'vort0=hcurl(u0,v0)'
> > 'define Totvort=vort0+f''define alpha0=R*tk0/p0'
> > 'define rh0=rhprs'
> > 'theta0=tk0*pow((100000/p0),0.2857))'
> > 'define es=6.1173*100*exp((L/Rv)*(1/273.16 - 1/tk0))'
> > 'de
> > fine ep0=rh0*es/100'
> > 'WVmixr0=0.622*ep0/(p0)'
> > 'define T=tk0'
> > 'define VirT0=T*(1+0.61*WVmixr0)'
> > 'thetav0=VirT0*pow((100000/p0),0.2857))'
> > 'thetas0=theta0*exp(5.87*WVmixr0)'
> > 'dy=cdiff(lat,y)*dtr*a'
> > 'dx=cdiff(lon,x)*dtr*a*cos(lat*dtr)'
> > 'define dthetas0dx=cdiff(thetas0,x)/dx'
> > 'define dthetas0dy=cdiff(thetas0,y)/dy'
> > 'define dthetas0dp=(thetas2-thetas1)/dp'
> > 'define Totdthedtas=dthetas0dx+dthetas0dy+dthetas0dp''define dthetav0dx=cdiff(thetav0,x)/dx'
> > 'define dthetav0dy=cdiff(thetav0,y)/dy'
> > 'define dthetav0dp=(thetav2-thetav1)/dp'
> > 'define Totdthedtav=dthetav0dx+dthetav0dy+dthetav0dp''term11= -g*Totvort*dthetav0dp*pow(10,6)'
> > 'term22=-g*dudp*dthetav0dy*pow(10,6)'
> > 'term33=g*dVdp*dthetav0dx*pow(10,6)'
> > 'PV7002=term1+term2+term3''term1= -g*Totvort*dthetas0dp*pow(10,6)''term2=-g*dudp*dthetas0dy*pow(10,6)'
> > 'term3=g*dVdp*dthetas0dx*pow(10,6)'
> > 'PV700=term1+term2+term3'*'term1=Totvort*dthetas0dp*e6)'
> > *'term2=dudp*dthetas0dy*e6'
> > *'term3=-dVdp*dthetas0dx*e6'
> > 'PV700=term1+term2+term3''set t 7'
> > 'set gxout shaded'
> > 'set mpdset hires'
> > 'set display color white'
> > 'set vpage 1.0 8.5 2.0 8.5'
> > 'c'
> > *'d mp'd
> > 'd theta_s'
> > *'exec colors'
> > *'run colorset.gs'
> > *'set ylint 12'
> > *'set xlint 12'
> > 'cbarhov2.gs'
> > 'draw title 700hPa-Moist Potential Vorticity ''printim 700_mv.png'
> > 'set grads off'
> > *'quit'*'define MV=TotVort*ept(tmpprs,rhprs.prs)'
> > ??AS EVER
> > LUHUNGA
> > 
> > --------------------
> > Philbert Modest Luhunga
> > University of Pretoria?
> > Department of Geography,Geoinformatics and Meteorology
> > Private Bag X20 Hatfield 0028 South Africa
> > Tel +27 (0) 12 420 5164
> > Fax +27 (0) 12 420 6385
> > Mobile:+ 27826228060
> > Email address: philuhunga at yahoo.com
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: http://gradsusr.org/pipermail/gradsusr/attachments/20141002/51d6cc01/attachment.html 
> > 
> > ------------------------------
> > 
> > _______________________________________________
> > gradsusr mailing list
> > gradsusr at gradsusr.org
> > http://gradsusr.org/mailman/listinfo/gradsusr
> > 
> > 
> > End of gradsusr Digest, Vol 56, Issue 4
> > ***************************************
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr




More information about the gradsusr mailing list