Re: Why min/max are different from the actual range?

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri Oct 19 2012 - 07:28:36 MDT

This issue has been discussed many times on ncl-talk.
See the FAQ and email archives.
==========
As indicated, your data are type short.
They also have a 'scale_factor' and 'add_offset'

  Variable: hgt
  Type: short

  add_offset : 32066
  scale_factor : 1

These must be unpacked (unscaled) prior to use. The formula is

      unpacked_value = packed_value*scale_factor + add_offset

NCL has a function located in contributed.ncl for this.
It preserves all meta data.

   http://www.ncl.ucar.edu/Document/Functions/Contributed/short2flt.shtml

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

hgt = short2flt( f->hgt(:,5,:,:) )

On 10/19/12 12:52 AM, Wen.J.Qu wrote:
> Hi, all
> When I read a .nc file, printVarSummary shows the 3D variable "hgt" has
> an actual range of "-527, 32307 "
> But when I use the line {print("hgt min/max = " + min(hgt) + "/"
> + max(hgt))} to print the min and max, it shows "hgt min/max =
> -27627/-26066"
> Please help me to give some hint about the problem of this code. Is it
> from my calculation of min and max with the "short" data type? Is it
> from the wrong setting of the missing value? Or is it from my probably
> some wrong in reading the .nc file?
> Thanks a lot in advance.
> Shawn
> ##############################################################
> code
> ##############################################################
> fil = systemfunc ("cd " + diri + " ; ls hgt."+YEAR+".nc")
> f = addfile(diri+fil,"r")
> ;Debugprint
> printVarSummary(f)
> hgt = f->hgt(:,5,:,:)
> ;Debugprint
> printVarSummary(hgt)
> print("hgt min/max = " + min(hgt) + "/" + max(hgt))
> ##############################################################
> ##############################################################
> print result
> ##############################################################
> Variable: hgt
> Type: short
> Total Size: 7673760 bytes
> 3836880 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 365] x [lat | 73] x [lon | 144]
> Coordinates:
> time: [17373888..17382624]
> lat: [90..-90]
> lon: [ 0..357.5]
> Number Of Attributes: 19
> level : 500
> long_name : mean Daily Geopotential height
> actual_range : ( -527, 32307 )
> unpacked_valid_range : ( -700, 35000 )
> units : m
> add_offset : 32066
> scale_factor : 1
> missing_value : 32766
> precision : 0
> least_significant_digit : 0
> GRIB_id : 7
> GRIB_name : HGT
> var_desc : Geopotential height
> dataset : NCEP Reanalysis Daily Averages
> level_desc : Multiple levels
> statistic : Mean
> parent_stat : Individual Obs
> valid_range : ( -32766, 2934 )
> _FillValue : 32766
> (0) hgt min/max = -27627/-26066
> ##############################################################
> ------------------------------------------------------------------------
> Wen.J.Qu
> 2012-10-19
>
>
> _______________________________________________
> 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 Fri Oct 19 07:28:51 2012

This archive was generated by hypermail 2.1.8 : Tue Oct 23 2012 - 11:10:04 MDT