[Rodbcext-commits] r31 - in pkg/geoclimate: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 23 09:58:17 CEST 2012


Author: jaunario
Date: 2012-08-23 09:58:16 +0200 (Thu, 23 Aug 2012)
New Revision: 31

Added:
   pkg/geoclimate/R/masks.r
Modified:
   pkg/geoclimate/DESCRIPTION
   pkg/geoclimate/R/gsod.r
Log:
In get.gsod, corrected conversion from inches to mm.
Added setup.mask for creating cell references on new datasets

Modified: pkg/geoclimate/DESCRIPTION
===================================================================
--- pkg/geoclimate/DESCRIPTION	2012-08-23 07:56:21 UTC (rev 30)
+++ pkg/geoclimate/DESCRIPTION	2012-08-23 07:58:16 UTC (rev 31)
@@ -4,7 +4,7 @@
 Version: 0.0.11
 Date: 2009-2-24
 Depends: methods, genutils, weather
-Suggests: RODBC, RCurl
+Suggests: RODBC, RCurl, ncdf
 Author: Jorrel Khalil S. Aunario
 Maintainer: <jaunario at gmail.com>
 Description: [description]

Modified: pkg/geoclimate/R/gsod.r
===================================================================
--- pkg/geoclimate/R/gsod.r	2012-08-23 07:56:21 UTC (rev 30)
+++ pkg/geoclimate/R/gsod.r	2012-08-23 07:58:16 UTC (rev 31)
@@ -152,11 +152,11 @@
 	
 		##############################################
 		# RAINFALL NEEDED IN ORYZA2k
-		gsod$prec   <- round(as.numeric(dat$PRCP)*100/25.4,1)*10  # RAINFALL
+		gsod$prec   <- round(as.numeric(dat$PRCP)*25.4,1)*10  # RAINFALL
 		
 		##############################################
 		# SNOW DEPTH
-		gsod$snowdepth   <- round(as.numeric(dat$SNDP)*100/25.4,1)*10  # convert to mm
+		gsod$snowdepth   <- round(as.numeric(dat$SNDP)*25.4,1)*10  # convert to mm
 		
 		indicators <- matrix(as.numeric(unlist(strsplit(dat$FRSHTT,""))),byrow=TRUE, ncol=6)
 		colnames(indicators) <- c("ifog","irain","isnow","ihail","ithunder","itornado") 

Added: pkg/geoclimate/R/masks.r
===================================================================
--- pkg/geoclimate/R/masks.r	                        (rev 0)
+++ pkg/geoclimate/R/masks.r	2012-08-23 07:58:16 UTC (rev 31)
@@ -0,0 +1,43 @@
+# Author: Jorrel Khalil S. Aunario, jaunario at gmail.com
+# Date :  13 August 2012
+# Version 0.0.1
+# Licence GPL v3
+
+#library(RODBC)
+#library(raster)
+#con <- odbcConnect("geoclimadmin")
+
+
+setup.mask <- function(con, maskset_name, maskset_desc=NA, targetres=NA,...){  
+	
+	# Load source data
+	iso <- raster("D:/Projects/SiRiUS/Data/ISO/GADM_ISO.tif")
+	attribs <- iso at data@attributes[[1]]
+	dem <- raster("D:/Projects/SiRiUS/Data/DEM/SRTM/srtm_5m.tif")
+	soil <- raster("D:/Projects/SiRiUS/Data/Soil/Data/WISE5by5min/Grid/WISE_smw5by5min.tif")
+	
+	# Specify output specs
+	if (!is.na(targetres)){
+	  # resample/aggregate
+	  iso <- aggregate(iso,fact=targetres/xres(iso),...) 
+	  dem <- aggregate(dem,fact=targetres/xres(dem))
+	  soil <- aggregate(soil,fact=targetres/xres(soil))
+	  
+	}
+	cell <- 1:ncell(iso) 
+	
+	masktable <- as.data.frame(cell)
+	masktable$iso3 <- attribs$ISO[match(iso[],attribs$Value)]
+	masktable$elevation <- NA   
+	masktable$elevation[cellsFromExtent(iso,dem)] <- round(dem[],2)
+	masktable$land <- as.numeric(!is.na(masktable$iso3))
+	masktable$soil_wise <- NA
+	masktable$soil_wise[cellsFromExtent(iso,soil)] <- soil[]
+	
+	maskinfo <- c("default", maskset_name, maskset_desc, xmin(iso), xmax(iso), ncol(iso), ymin(iso), ymax(iso), nrow(iso))
+	
+	
+	sqlSave(con, maskinfo, tablename="masksets", append=TRUE, rownames=FALSE)
+	sqlSave(con, masktable, tablename=maskset_name, append=TRUE, rownames=FALSE)
+  return(TRUE)
+}



More information about the Rodbcext-commits mailing list