[R-sig-Geo] get.var.ncdf and embedded scale factors

Robert Hijmans r.hijmans at gmail.com
Mon Apr 18 21:47:54 CEST 2011


> I would like to confirm that the get.var.ncdf function within the ncdf 
> package automatically scales output data values if there is an embedded 
> scale factor within the ncdf file.  

It does and that is easy to infer from the code frament below that you get
when typing "get.var.ncdf". As you can see, you can use the option
"verbose=TRUE" to see what's going on when you use get.var.ncdf.

> library(ncdf)
> get.var.ncdf

(...) 

 if (!isdimvar) {
        if (verbose) 
            print(paste("get.var.ncdf: implementing add_offset (", 
                nc$var[[nc$varid2Rindex[varid]]]$hasAddOffset, 
                ") and scale_factor (",
nc$var[[nc$varid2Rindex[varid]]]$hasScaleFact, 
                ")"))
        if (nc$var[[nc$varid2Rindex[varid]]]$hasAddOffset && 
            nc$var[[nc$varid2Rindex[varid]]]$hasScaleFact) {
            if (verbose) 
                print(paste("var has BOTH add_offset (",
nc$var[[nc$varid2Rindex[varid]]]$addOffset, 
                  ") and scale_fact (",
nc$var[[nc$varid2Rindex[varid]]]$scaleFact, 
                  ")"))
            rv$data <- rv$data * nc$var[[nc$varid2Rindex[varid]]]$scaleFact
+ 
                nc$var[[nc$varid2Rindex[varid]]]$addOffset
        }
        else if (nc$var[[nc$varid2Rindex[varid]]]$hasAddOffset) {
            if (verbose) 
                print(paste("var has add_offset (only):",
nc$var[[nc$varid2Rindex[varid]]]$addOffset))
            rv$data <- rv$data + nc$var[[nc$varid2Rindex[varid]]]$addOffset
        }
        else if (nc$var[[nc$varid2Rindex[varid]]]$hasScaleFact) {
            if (verbose) 
                print(paste("var has scale_factor (only):",
nc$var[[nc$varid2Rindex[varid]]]$scaleFact))
            rv$data <- rv$data * nc$var[[nc$varid2Rindex[varid]]]$scaleFact
        }
        else {
            if (verbose) 
                print("var has NEITHER add_offset nor scale_factor")
        }
    }
    return(rv$data)



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/get-var-ncdf-and-embedded-scale-factors-tp6284280p6284894.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list