Revision 5dd036ba
Added by Benoit Parmentier over 11 years ago
climate/research/oregon/interpolation/Database_stations_extraction_raster_covariates_processing.R | ||
---|---|---|
1 | 1 |
################## Data preparation for interpolation ####################################### |
2 | 2 |
############################ Extraction of station data ########################################## |
3 | 3 |
|
4 |
### Parameters and arguments for the function |
|
5 |
|
|
6 |
db.name <- "ghcn" #name of the Postgres database |
|
7 |
var <- "TMAX" #name of the variables to keep: TMIN, TMAX or PRCP |
|
8 |
range_years<-c("2010","2011") #right bound not included in the range!! |
|
9 |
range_years_clim<-c("2000","2011") #right bound not included in the range!! |
|
10 |
infile1<- "outline_venezuela_region__VE_01292013.shp" #This is the shape file of outline of the study area #It is an input/output of the covariate script |
|
11 |
infile2<-"/home/layers/data/climate/ghcn/v2.92-upd-2012052822/ghcnd-stations.txt" #This is the textfile of station locations from GHCND |
|
12 |
infile3<-"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script |
|
13 |
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84: same as earlier |
|
14 |
in_path <- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data/" |
|
15 |
out_prefix<-"_365d_GAM_fus5_all_lstd_03012013" #User defined output prefix |
|
16 |
#qc_flags<- flags allowe for the query from the GHCND?? |
|
17 |
|
|
18 |
#The names of covariates can be changed...these names should be output/input from covar script!!! |
|
19 |
rnames<-c("x","y","lon","lat","N","E","N_w","E_w","elev","slope","aspect","CANHEIGHT","DISTOC") |
|
20 |
lc_names<-c("LC1","LC2","LC3","LC4","LC5","LC6","LC7","LC8","LC9","LC10","LC11","LC12") |
|
21 |
lst_names<-c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12", |
|
22 |
"nobs_01","nobs_02","nobs_03","nobs_04","nobs_05","nobs_06","nobs_07","nobs_08", |
|
23 |
"nobs_09","nobs_10","nobs_11","nobs_12") |
|
24 |
covar_names<-c(rnames,lc_names,lst_names) |
|
25 |
|
|
26 |
#list of 11 parameters for input in the function... |
|
27 |
|
|
28 |
list_param_prep<-list(db.name,var,range_years,range_years_clim,infile1,infile2,infile3,CRS_locs_WGS84,in_path,covar_names,out_prefix) |
|
29 |
cnames<-c("db.name","var","range_years","range_years_clim","infile1","infile2","infile3","CRS_locs_WGS84","in_path","covar_names","out_prefix") |
|
30 |
names(list_param_prep)<-cnames |
|
31 | 4 |
|
32 | 5 |
database_covaratiates_preparation<-function(list_param_prep){ |
33 | 6 |
#This function performs queries on the Postgres ghcnd database for stations matching the |
... | ... | |
38 | 11 |
# 4) range_years_clim: range of records used in the monthly climatology interpolation, note that upper bound is not included |
39 | 12 |
# 5) infile1: region outline as a shape file - used in the interpolation stage too |
40 | 13 |
# 6) infile2: ghcnd stations locations as a textfile name with lat-long fields |
41 |
# 7) infile3: tif file of raser covariates for the interpolation area: it should have a local projection
|
|
14 |
# 7) infile_covarariates: tif file of raser covariates for the interpolation area: it should have a local projection
|
|
42 | 15 |
# 8) CRS_locs_WGS84: longlat EPSG 4326 used as coordinates reference system (proj4)for stations locations |
43 | 16 |
# 9) in_path: input path for covariates data and other files, this is also the output? |
44 | 17 |
# 10) covar_names: names of covariates used for the interpolation --may be removed later? (should be stored in the brick) |
... | ... | |
95 | 68 |
year_start_clim <-list_param_prep$range_years_clim[1] #right bound not included in the range!! starting year for monthly query to calculate clime |
96 | 69 |
infile1<- list_param_prep$infile1 #This is the shape file of outline of the study area #It is an input/output of the covariate script |
97 | 70 |
infile2<-list_param_prep$infile2 #"/home/layers/data/climate/ghcn/v2.92-upd-2012052822/ghcnd-stations.txt" #This is the textfile of station locations from GHCND |
98 |
infile3<-list_param_prep$infile3 #"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script
|
|
71 |
infile3<-list_param_prep$infile_covariates #"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script
|
|
99 | 72 |
CRS_locs_WGS84<-list_param_prep$CRS_locs_WGS84 #Station coords WGS84: same as earlier |
100 | 73 |
in_path <- list_param_prep$in_path #CRS_locs_WGS84"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data/" |
101 | 74 |
out_prefix<-list_param_prep$out_prefix #"_365d_GAM_fus5_all_lstd_03012013" #User defined output prefix |
Also available in: Unified diff
Data preparation, moving input parameters, call from other script