[ncl-talk] NetCDF output file from NCL not opening in GrADS
Adam Phillips
asphilli at ucar.edu
Fri Jul 7 08:33:47 MDT 2017
One correction to Dennis' script:
use wgt_runave_n_Wrap instead of wgt_runave_n
After applying the above, you should not need to do this, but note that you
can exactly copy variables from one file to another like so:
fn = "tas_aave_Asia.nc" ; define filename
in = addfile(fn,"r")
x = in->tasmask(:,0:0,0:0)
.........
fo = addfile(filo , "c") ; open output file
fo->lat = fn->lat(0:0) ; (0:0) needed in your case as you are
subsetting tasmask when reading it in
On Fri, Jul 7, 2017 at 8:19 AM, S Br <sbr.climate at gmail.com> wrote:
> Hi Dennis,
> Thanks for modifying the code. Now, it easily read the time, lat and lon
> coordinate. However, still it couldn't generate the dimension and variables
> correctly in the output file. It would be nice, if NCL could generate the
> the variables and dimension similar to the input file.
>
> *Output file:*
>
> ncdump -h tas_aave_Asia_bandpass30-100.nc
> netcdf tas_aave_Asia_bandpass30-100 {
> dimensions:
> ncl0 = 1000 ;
> ncl1 = 1 ;
> ncl2 = 1 ;
> variables:
> double tasmask(ncl0, ncl1, ncl2) ;
> tasmask:_FillValue = -999000000. ;
> }
>
>
> *The variables and dimension in the input file is as given below.*
>
> dimensions:
> lon = 1 ;
> lat = 1 ;
> time = UNLIMITED ; // (1000 currently)
> variables:
> double lon(lon) ;
> lon:standard_name = "longitude" ;
> lon:long_name = "longitude" ;
> lon:units = "degrees_east" ;
> lon:axis = "X" ;
> double lat(lat) ;
> lat:standard_name = "latitude" ;
> lat:long_name = "latitude" ;
> lat:units = "degrees_north" ;
> lat:axis = "Y" ;
> double time(time) ;
> time:standard_name = "time" ;
> time:long_name = "Time" ;
> time:units = "years since 850-1-1 00:00:00" ;
> time:calendar = "standard" ;
> time:axis = "T" ;
> double tasmask(time, lat, lon) ;
> tasmask:_FillValue = -999000000. ;
> tasmask:missing_value = -999000000. ;
>
>
> Thanks.
> SB
>
>
> On Fri, Jul 7, 2017 at 2:20 PM, Dennis Shea <shea at ucar.edu> wrote:
>
>> fn = "tas_aave_Asia.nc" ; define filename
>> in = addfile(fn,"r") ; open netcdf
>> file
>> x = in->tasmask(:,0:0,0:0) ; get data; avoid
>> elimination of degenerate dimension
>> printVarSummary(x) ; x(time,lat,lon)
>> ; ***********************************************
>> ; create the filter weights and apply
>> ; ***********************************************
>>
>> ihp = 2 ; band pass
>> sigma = 1.0 ; Lanczos sigma
>>
>> nWgt = 201 ; loose 100 each end
>> fca = 1./100. ; start freq
>> fcb = 1./30. ; last freq
>> wgt = filwgts_lanczos (nWgt, ihp, fca, fcb, sigma )
>> xBPF = wgt_runave_n ( x, wgt, 0, 0 ) ; 30-100 days
>> printVarSummary(xBPF)
>>
>> ***********************************************
>> ; create new date array for use on the plot
>> ; ***********************************************
>> filo = "tas_aave_Asia_bandpass30-100.nc"
>> system ("/bin/rm "+filo) ; remove any pre-existing file
>> fo = addfile(filo , "c") ; open output file
>> *;;**filedimdef*
>> <http://www.ncl.ucar.edu/Document/Functions/Built-in/filedimdef.shtml>
>> (fo,"time",-1,True) ; make 'time' unlimited
>> fo->tasmax = xBPF ; write ud to a file
>>
>> On Fri, Jul 7, 2017 at 6:04 AM, gibies george <gibiesgeorge at gmail.com>
>> wrote:
>>
>>> But where is your original coordinate?
>>>
>>> On Jul 7, 2017 4:01 PM, "S Br" <sbr.climate at gmail.com> wrote:
>>>
>>>> Hi,
>>>> Thanks for your reply. Now I reshaped the variable and put an arbitrary
>>>> lat/lon value. Still, I couldn't open the file in GrADS.
>>>>
>>>> I have checked the output file, it correctly reading the dimension but
>>>> may be wrong with variables.
>>>>
>>>> ncdump -h tas_aave_Asia_bandpass30-100.nc
>>>> netcdf tas_aave_Asia_bandpass30-100 {
>>>> dimensions:
>>>> time = UNLIMITED ; // (1000 currently)
>>>> lat = 1 ;
>>>> lon = 1 ;
>>>> variables:
>>>> double tasmaskn(time, lat, lon) ;
>>>> tasmaskn:_FillValue = -999000000. ;
>>>> int lat(lat) ;
>>>> int lon(lon) ;
>>>> }
>>>>
>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>
>>>> ; ***********************************************
>>>> ; create new date array for use on the plot
>>>> ; ***********************************************
>>>> filo = "tas_aave_Asia_bandpass30-100.nc"
>>>> system ("/bin/rm "+filo) ; remove any pre-existing file
>>>> fo = addfile(filo , "c") ; open output file
>>>> filedimdef(fo,"time",-1,True) ; make 'time' unlimited
>>>> tasmask=xBPF
>>>> ntime = 1000
>>>> nlat = 1
>>>> nlon = 1
>>>> tasmaskn = reshape(tasmask,(/ntime,nlat,nlon/))
>>>> printVarSummary(tasmaskn)
>>>> tasmaskn!0="time"
>>>> tasmaskn!1="lat"
>>>> tasmaskn&lat=nlat
>>>> tasmaskn!2="lon"
>>>> tasmaskn&lon=nlon
>>>> fo->tasmaskn = tasmaskn ; write ud to a file
>>>> end
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Fri, Jul 7, 2017 at 8:45 AM, gibies george <gibiesgeorge at gmail.com>
>>>> wrote:
>>>>
>>>>> The first step I told is to reshape "tasmask" using reshape function.
>>>>>
>>>>> Secondly what I told is to put some arbitrary lat-lon coordinate
>>>>> value.
>>>>>
>>>>> On 6 July 2017 at 16:29, S Br <sbr.climate at gmail.com> wrote:
>>>>>
>>>>>> Hi Gibies,
>>>>>> Thanks for your reply. I have added as you suggested. I get some
>>>>>> error in the code. Do you think, I have done correctly.
>>>>>>
>>>>>> ; ***********************************************
>>>>>> ; create new date array for use on the plot
>>>>>> ; ***********************************************
>>>>>> filo = "tas_aave_Asia_bandpass30-100.nc"
>>>>>> system ("/bin/rm "+filo) ; remove any pre-existing file
>>>>>> fo = addfile(filo , "c") ; open output file
>>>>>> filedimdef(fo,"time",-1,True) ; make 'time' unlimited
>>>>>> tasmask=xBPF
>>>>>> tasmask!0="time"
>>>>>> tasmask!1="lat"
>>>>>> tasmask&lat=*"lat" *
>>>>>> tasmask!2="lon"
>>>>>> tasmask&lon=*"lon"*
>>>>>> fo->tasmask = tasmask ; write ud to a file
>>>>>> end
>>>>>>
>>>>>> I get the error as,
>>>>>>
>>>>>> fatal:Variable (tasmask) has (1) dimensions can not write to
>>>>>> dimension (1)
>>>>>> fatal:["Execute.c":8575]:Execute: Error occurred at or near line 38
>>>>>> in file bandpass.ncl
>>>>>>
>>>>>> Thanks.
>>>>>> SB
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thu, Jul 6, 2017 at 10:13 AM, gibies george <
>>>>>> gibiesgeorge at gmail.com> wrote:
>>>>>>
>>>>>>> I have seen those mails from Dr. Dennis and Dr. Adam.
>>>>>>>
>>>>>>> You can use reshape function to add additional coordinate to a
>>>>>>> variable. Define some single value coordinate for latitude and longitude.
>>>>>>>
>>>>>>> varname!0 ="time"
>>>>>>> varname!1 = "lat"
>>>>>>> varname&lat = .......
>>>>>>> varname!2 = "lon"
>>>>>>> varname&lon = ......
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Jul 6, 2017 2:08 PM, "S Br" <sbr.climate at gmail.com> wrote:
>>>>>>>
>>>>>>>> Hi Gibies,
>>>>>>>> NCL also provided the same solution as you have mentioned.
>>>>>>>> Could you please tell me how can I add single value coordinates
>>>>>>>> (time, lat, lon) to the variable.
>>>>>>>> Hope, you can write me the command for me.
>>>>>>>>
>>>>>>>> Thanks.
>>>>>>>> SB
>>>>>>>>
>>>>>>>> On Wed, Jul 5, 2017 at 5:58 PM, gibies george <
>>>>>>>> gibiesgeorge at gmail.com> wrote:
>>>>>>>>
>>>>>>>>> Yes, you can add single value coordinates (time lat lon) to the
>>>>>>>>> variable before saving it to nc file.
>>>>>>>>>
>>>>>>>>> On Jul 5, 2017 9:58 PM, "S Br" <sbr.climate at gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Is it possible to do something inside the NCL script so that it
>>>>>>>>>> can be opened by GrADS.
>>>>>>>>>>
>>>>>>>>>> On Wed, Jul 5, 2017 at 5:25 PM, gibies george <
>>>>>>>>>> gibiesgeorge at gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> This is because grads required standard file coordinates
>>>>>>>>>>> structure. Time lat lon etc.
>>>>>>>>>>>
>>>>>>>>>>> On Jul 5, 2017 9:43 PM, "S Br" <sbr.climate at gmail.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Hi,
>>>>>>>>>>>> I have applied bandpass filter to my one dimentional NetCDF
>>>>>>>>>>>> file. I have written the output to a NetCDF file but this output file is
>>>>>>>>>>>> not opening in GrADS. I get the following error.
>>>>>>>>>>>>
>>>>>>>>>>>> ga-> sdfopen tas_aave_Asia_bandpass30-100.nc
>>>>>>>>>>>> Scanning self-describing file: tas_aave_Asia_bandpass30-100.nc
>>>>>>>>>>>> gadsdf: SDF file has no discernable X coordinate.
>>>>>>>>>>>> To open this file with GrADS, use a descriptor file with an
>>>>>>>>>>>> XDEF entry.
>>>>>>>>>>>> Documentation is at http://cola.gmu.edu/grads/gado
>>>>>>>>>>>> c/SDFdescriptorfile.html
>>>>>>>>>>>>
>>>>>>>>>>>> Could you please suggest if I am doing somewhere wrong in my
>>>>>>>>>>>> NCL script . The input file is perfectly fine with GrADS.
>>>>>>>>>>>>
>>>>>>>>>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>>>>>>>>>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>>>>>>>>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>>>>>>>>>>> begin
>>>>>>>>>>>>
>>>>>>>>>>>> fn = "tas_aave_Asia.nc" ; define filename
>>>>>>>>>>>> in = addfile(fn,"r") ; open
>>>>>>>>>>>> netcdf file
>>>>>>>>>>>> x = in->tasmask(:,0,0)
>>>>>>>>>>>> ; get data
>>>>>>>>>>>>
>>>>>>>>>>>> ; ***********************************************
>>>>>>>>>>>> ; create the filter weights and apply
>>>>>>>>>>>> ; ***********************************************
>>>>>>>>>>>>
>>>>>>>>>>>> ihp = 2 ; band pass
>>>>>>>>>>>> sigma = 1.0 ; Lanczos sigma
>>>>>>>>>>>>
>>>>>>>>>>>> nWgt = 201 ; loose 100 each end
>>>>>>>>>>>> fca = 1./100. ; start freq
>>>>>>>>>>>> fcb = 1./30. ; last freq
>>>>>>>>>>>> wgt = filwgts_lanczos (nWgt, ihp, fca, fcb, sigma )
>>>>>>>>>>>> xBPF = wgt_runave ( x, wgt, 0 ) ; 30-100 days
>>>>>>>>>>>>
>>>>>>>>>>>> copy_VarMeta(x,xBPF)
>>>>>>>>>>>> dNames= getvardims(xBPF)
>>>>>>>>>>>> dSIZES=dimsizes(xBPF)
>>>>>>>>>>>> print (dNames)
>>>>>>>>>>>> print (dSIZES)
>>>>>>>>>>>>
>>>>>>>>>>>> ; ***********************************************
>>>>>>>>>>>> ; create new date array for use on the plot
>>>>>>>>>>>> ; ***********************************************
>>>>>>>>>>>> filo = "tas_aave_Asia_bandpass30-100.nc"
>>>>>>>>>>>> system ("/bin/rm "+filo) ; remove any pre-existing file
>>>>>>>>>>>> fo = addfile(filo , "c") ; open output file
>>>>>>>>>>>> tasmax=xBPF(:)
>>>>>>>>>>>> fo->tasmax = tasmax ; write ud to a file
>>>>>>>>>>>> end
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks.
>>>>>>>>>>>> SB
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>> ncl-talk mailing list
>>>>>>>>>>>> ncl-talk at ucar.edu
>>>>>>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>
>>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
--
Adam Phillips
Associate Scientist, Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/ 303-497-1726
<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170707/6b1566ca/attachment.html
More information about the ncl-talk
mailing list