Commits

Tom Roche  committed e75787a

bugfix visualization.r, enhance netCDF.stats.to.stdout.r

* visualization.r: fixed bug in project.M3.boundaries.for.CMAQ discovered during AQMEII_ag_soil::compute_EPIC
was referring to a global from a user file, rather than using correct S4 instance attribute notation

* netCDF.stats.to.stdout.r: refactored function stats.to.stdout.r to
** take/massage sparse data (with NAs)
** call new function unsparse.stats.to.stdout.r
allowing better reuse (e.g., in AQMEII_ag_soil)

Tested on terrae/EMVL, but only from AQMEII_driver.sh and AQMEII::uber_driver.sh:file tweaked to copy them specially.
Will retest with
* (before committing current AQMEII_ag_soil::compute_EPIC changes) AQMEII::uber_driver.sh:file but using normal regrid_utils checkout
* (after committing current AQMEII_ag_soil::compute_EPIC changes) AQMEII::uber_driver.sh:repo

TODO: retest with all other regrid_utils-using projects (CLM_CN, EDGAR, GEIA, GFED)

  • Participants
  • Parent commits f0f9536

Comments (0)

Files changed (2)

File netCDF.stats.to.stdout.r

   data.var.name,   # name of data variable (datavar) of interest
   stats.precision=3 # sigdigs to use for min, median, max of obs  
 ) {
-
+  fn.name <- 'netCDF.stats.to.stdout' # TODO: derive from environment?
   # TODO: test arguments!
 
 #  # start debug
 #  #   end debug
 
   if (is.numeric(data.var.data) && sum(!is.na(data.var.data))) {
-#    unsparse.data <- data.var.data[!is.na(data.var.data)]
+    stats.to.stdout(
+      data=data.var.data,
+      sig.digs=stats.precision,
+      title=sprintf('From %s datavar=%s:', netcdf.fp, data.var.name)
+    )
+  } else {
+    cat(sprintf('%s::%s: %s var=%s has no numeric non-NA data\n',
+      this.fn, fn.name, netcdf.fp, data.var.name))
+  }
+
+  # teardown
+  nc_close(netcdf.file)
+} # end function netCDF.stats.to.stdout
+
+stats.to.stdout <- function(
+  data,          # numeric array, may include NAs
+  sig.digs=3,    # significant digits for numeric fields
+  title=''       # one line identifying data source
+) {
+  fn.name <- 'stats.to.stdout' # TODO: derive from environment?
+  # TODO: test arguments!
+  if (is.numeric(data) && sum(!is.na(data))) {
     # collapse its structure
-    unsparse.data <- c(data.var.data[!is.na(data.var.data)])
+    unsparse.data <- c(data[!is.na(data)])
     obs.n <- length(unsparse.data)
     if (obs.n > 0) {
-      stats.to.stdout(
+      unsparse.stats.to.stdout(
         data.nonNA=unsparse.data,
         data.nonNA.n=obs.n,
-        data.raw.n=length(data.var.data),
-        sig.digs=stats.precision,
-        title=sprintf('From %s datavar=%s:', netcdf.fp, data.var.name)
+        data.raw.n=length(data),
+        sig.digs=sig.digs,
+        title=title
       )
     } else {
-      cat(sprintf('%s: %s var=%s has no non-NA data',
-        this.fn, data.var.name, netcdf.fp))
+      cat(sprintf('%s::%s: no non-NA data\n', this.fn, fn.name))
     }
   } else {
-    cat(sprintf('%s: %s var=%s has no numeric non-NA data',
-      this.fn, data.var.name, netcdf.fp))
+    cat(sprintf('%s::%s: no non-NA numeric data\n', this.fn, fn.name))
   }
+} # end function stats.to.stdout
 
-  # teardown
-  nc_close(netcdf.file)
-} # end function netCDF.stats.to.stdout
-
-stats.to.stdout <- function(
+unsparse.stats.to.stdout <- function(
   data.nonNA,    # numeric array minus NAs, no other requirements (?)
   data.nonNA.n,  # its length
   data.raw.n,    # length of data from which data.nonNA was derived
   cat(sprintf('\t%s\n', q3.str))
   cat(sprintf('\t%s\n', max.str))
   cat(sprintf('\t%s\n', sum.str))
-} # end function stats.to.stdout
+} # end function unsparse.stats.to.stdout
 
 netCDF.stats.to.stdout.by.timestep <- function(
   netcdf.fp, # /path/to/netcdf/file, can be relative or FQ

File visualization.r

     database="state", projection="lambert", par=LCC.parallels, plot=FALSE)
   #                  parameters to lambert: ^^^^^^^^^^^^^^^^^
   #                  see mapproj::mapproject
-  map.IOAPI$x <- map.lines.coords.IOAPI.x + extents.xmin
-  map.IOAPI$y <- map.lines.coords.IOAPI.y + extents.ymin
+  map.IOAPI$x <- map.lines.coords.IOAPI.x + extents@xmin
+  map.IOAPI$y <- map.lines.coords.IOAPI.y + extents@ymin
   map.IOAPI$range <- c(
     min(map.IOAPI$x),
     max(map.IOAPI$x),