Re: NetCDF 2 NetCDF coordinate dimension transfer?

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Tue Jun 04 2013 - 16:53:55 MDT

A: attributes and coordinates are not in general preserved for the results of operations. The simplest way to fix this in your case is to first create a new variable by assignment
from one of your existing variables:
        mdt = tmax

mdt will have all the attributes and coordinates that tmax does.

B: The result of the operation (tmax + tmin) / 2 gets promoted to integer type because the literal value 2 is considered an integer, and the result is coerced to the biggest type used.
To avoid this you can specify the value 2 as a short using the literal qualifying suffix 'h', so:

     mdt = tmax
     mdt = (tmax + tmin) / 2h
     mdt@long_name="Mean Daily Temperature"
     ofile->mdt = mdt

I guess this code works as long as the offset and scale factor for tmin and tmax are the same.

See the table at the beginning of http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclDataTypes.shtml for a list of the literal suffixes for each data type.
 -dave

On Jun 4, 2013, at 4:06 PM, Ramon Docto <mondocto2@yahoo.com> wrote:

> Hello List,
>
> I wish to create a new NetCDF file containing a derived variable for Mean Daily Temperature (mdt) by taking the mean of tmax and tmin variables in an exsiting NetCDF file.
>
> My script is as follows:
>
> begin
>
> ipath = "~/data/echam5/daily/"
> fname = "gdd.196101-196512.nc"
>
> ifile = addfile(ipath + fname, "r")
>
> tmax = ifile->tmaxscr
> tmin = ifile->tminscr
>
> system("/bin/rm -f ./test.nc")
>
> ofile = addfile("test.nc", "c")
>
> ;; enable record dimension time
> filedimdef(ofile,"time",-1,True)
>
> ofile->tmax = tmax
> ofile->tmin = tmin
>
> mdt = (tmax + tmin) / 2
> mdt@long_name="Mean Daily Temperature";
>
> ofile->mdt = mdt
>
> end
>
>
> However, mdt created this way assumes new coordinate dimensions:
>
>
> netcdf test {
> dimensions:
> time = UNLIMITED ; // (1825 currently)
> lat = 51 ;
> lon = 56 ;
> ncl3 = 1825 ;
> ncl4 = 51 ;
> ncl5 = 56 ;
> variables:
> short tmax(time, lat, lon) ;
> tmax:long_name = "Maximum screen temperature (K) v3" ;
> tmax:units = "K" ;
> tmax:add_offset = 250.f ;
> tmax:scale_factor = 0.0046875f ;
> tmax:valid_min = -32500 ;
> tmax:valid_max = 32500 ;
> tmax:_FillValue = -32767s ;
> tmax:missing_value = -32767s ;
> float time(time) ;
> time:units = "minutes since 1951-01-01 00:00:00" ;
> time:standard_name = "time" ;
> time:axis = "T" ;
> float lat(lat) ;
> lat:long_name = "latitude" ;
> lat:standard_name = "latitude" ;
> lat:axis = "Y" ;
> lat:units = "degrees_north" ;
> float lon(lon) ;
> lon:long_name = "longitude" ;
> lon:standard_name = "longitude" ;
> lon:axis = "X" ;
> lon:units = "degrees_east" ;
> short tmin(time, lat, lon) ;
> tmin:long_name = "Minimimum screen temperature (K) v3" ;
> tmin:units = "K" ;
> tmin:add_offset = 250.f ;
> tmin:scale_factor = 0.0046875f ;
> tmin:valid_min = -32500 ;
> tmin:valid_max = 32500 ;
> tmin:_FillValue = -32767s ;
> tmin:missing_value = -32767s ;
> int mdt(ncl3, ncl4, ncl5) ;
> mdt:long_name = "Mean Daily Temperature" ;
> mdt:_FillValue = -32767 ;
> }
>
>
> Questions:
>
> A. How do I create derived variables with coordinates matching their inputs?
> B. I notice the type of the derived variable (int) is also unmatched to the inputs (short, with appropriate scale and offset values). How might I arrange that also?
>
> Thanks in advance,
> Ramon
>
> _______________________________________________
> 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 Tue Jun 4 16:54:04 2013

This archive was generated by hypermail 2.1.8 : Tue Jun 11 2013 - 12:03:58 MDT