[ncl-talk] Inverted Pressure Levels produced by ncl script

Lyndon Mark Olaguera olagueralyndonmark429 at gmail.com
Tue Nov 15 15:39:30 MST 2016


Hi Sir Dennis,

Many thanks for your reply.

I found that this error is not created by ncl. It is CDO which I used to
merged the outputs.I have to process the file per year because the original
filesize is around 14GB. When I run the script it gives me an error about
memory allocation. I am using the pre compiled version of ncl.

After getting the output per year, I merge them using CDO( cdo -f nc2
mergetime ifile ofile).

To solve this, I just changed the attributes of the 'positive' using the
'ncatted' command of NCO.

Lyndon Mark Olaguera
On 16 Nov 2016 02:54, "Dennis Shea" <shea at ucar.edu> wrote:

> I have no idea why the level at positive attribute would change.
> The is nothing in 'copy_VarMeta' (contributed.ncl) or other operations
> that would do this.
>
>
> I suggest that you try to isolate where this occurs. Use 'print' and/or
> printVarSummary after various operations.
>
> You can change this attribute if you think it is inappropriate for, say,
> variable 'x':
>       x&level at positive = "up"  or "down"
>
> ---
> Certainly, it not the Butterworth filter that does anything with the meta
> data.
> --
> Also, Why are you doing each year separately? Use addfiles.
>
> I have no idea what your 'uwind' files look like.
> However I suggest the following *untested* approach.
> Output one file. If you want arbitrary temporal subset, extract from the
> sinfle file
>
>     ca    = 100.0
>     cb    = 20.0
>     fca   = 1.0/ca
>     fcb   = 1.0/cb
>
>     diri  ="./"
>     fili  = systemfunc("cd "+diri+" ; ls uwind_*.nc")
>     path  = diri+fili
>     print(path)
>
>     f     = addfiles(path, "r")     ; one or more files
>     ua    = f[:]->uwind             ; (time,level,lat,lon)
>
>     printVarSummary(ua)
>     print(ua&level)                 ; print coordinate variable
>
>    ;date  = ut_calendar(ua&time,-2) ; yyyymmdd (not used)
>    ;print(date)
>
> ; bandpass
>
>     opt   = True
>     opt at m = 4
>     dims  = 0                       ; time
>
>     bf    = bw_bandpass_filter(ua,fca,fcb,opt,dims)
>     copy_VarCoords(ua,bf)
>     bf at long_name = "Butterworth Band Pass: "+cb+"-"+ca+" day"
>     bf at units     = ua at units
>
>     printVarSummary(bf)
>     print(bf&level)
>
> ; output netCDF
> ; http://www.ncl.ucar.edu/Applications/o-netcdf.shtml
> ; Method 1: 'time' UNLIMITED
>
>     diro  = "./"
>     filo  = "filter.nc"
>     ptho  =  diro+filo
>     system("/bin/rm -f "+ptho)       ; remove any pre-existing file
>     ncdf = addfile(ptho ,"c")           ; open output netCDF file
>
>     fAtt = True
>     fAtt at title                 = "4th order Butterworth BPass Filter"
>     fAtt at source_file     = "uwind_anom_1981-2007.nc"
>     fAtt at Conventions   = "None"
>     fAtt at creation_date = systemfunc("date")
>     fileattdef(ncdf,fAtt)                  ; copy file attributes
>
>     filedimdef(ncdf,"time",-1,True)  ; make time an UNLIMITED dimension
>                                                      ; recommended  for
> most applications
>     ncdf->bf = bf
>
>
>
>
>
>
> On Mon, Nov 14, 2016 at 6:44 PM, Lyndon Mark Olaguera <
> olagueralyndonmark429 at gmail.com> wrote:
>
>> Dear All,
>> I'm trying to do a bandpass filter in ncl. When I compare the input and
>> output netcdf file the vertical levels seems to be reversed. Did I missed
>> something in writing the output netcdf file that caused this?
>>
>> I'll appreciate any help:
>>
>> *ncdump -h of input file:*
>>
>> netcdf uwind_1981-2007 {
>> dimensions:
>> lon = 144 ;
>> lat = 73 ;
>> level = 17 ;
>> time = UNLIMITED ; // (9861 currently)
>> variables:
>> float lon(lon) ;
>> lon:standard_name = "longitude" ;
>> lon:long_name = "Longitude" ;
>> lon:units = "degrees_east" ;
>> lon:axis = "X" ;
>> float lat(lat) ;
>> lat:standard_name = "latitude" ;
>> lat:long_name = "Latitude" ;
>> lat:units = "degrees_north" ;
>> lat:axis = "Y" ;
>> float level(level) ;
>> level:standard_name = "air_pressure" ;
>> level:long_name = "Level" ;
>> level:units = "millibar" ;
>> *level:positive = "down" ;*
>> level:axis = "Z" ;
>>
>> *ncdump -h of processed file:*
>>
>> netcdf uwind_anom_DJF_ph8 {
>> dimensions:
>> lon = 144 ;
>> lat = 73 ;
>> level = 17 ;
>> time = UNLIMITED ; // (1 currently)
>> variables:
>> float lon(lon) ;
>> lon:standard_name = "longitude" ;
>> lon:long_name = "longitude" ;
>> lon:units = "degrees_east" ;
>> lon:axis = "X" ;
>> float lat(lat) ;
>> lat:standard_name = "latitude" ;
>> lat:long_name = "latitude" ;
>> lat:units = "degrees_north" ;
>> lat:axis = "Y" ;
>> float level(level) ;
>> level:standard_name = "air_pressure" ;
>> level:long_name = "Level" ;
>> level:units = "millibar" ;
>> *level:positive = "up" ;*
>> level:axis = "Z" ;
>>
>>
>> Here's my code:
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> begin
>> dir  ="."
>> fili ="uwind*"
>> files =systemfunc("ls uwind_*.nc")
>> numfiles=dimsizes(files)
>> do ifil=0,numfiles-1
>> f = addfile(files(ifil), "r")
>> time := f->time
>> date := ut_calendar(time,-2)
>> ua := f->uwnd(:,:,:,:)
>> level= f->level
>> lat= f->lat
>> lon= f->lon
>> ca = 100.0
>> cb = 20.0
>> fca = 1.0/ca
>> fcb = 1.0/cb
>> opt = True
>> opt at m = 4
>> dims = 0
>> bf := bw_bandpass_filter(ua,fca,fcb,opt,dims)
>> copy_VarMeta(ua,bf)
>> bf at long_name = "Band Pass: "+cb+"-"+ca+" day"
>> ncdf = addfile("filt_"+files(ifil),"c")
>> fAtt = True
>> fAtt at title         = "4th order Butterworth BPass Filter"
>> fAtt at source_file   = "uwind_anom_1981-2007.nc"
>> fAtt at Conventions   = "None"
>> fAtt at creation_date = systemfunc("date")
>> fileattdef(ncdf,fAtt)            ; copy file attributes
>> ncdf->bf = bf
>> end do
>> end
>>
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161116/a8be7055/attachment.html 


More information about the ncl-talk mailing list