Project

General

Profile

Download (5.66 KB) Statistics
| Branch: | Revision:
1
##################    Master script for temperature predictions  #######################################
2
############################ TMIN AND TMAX predictions ##########################################
3
#                           
4
##This script produces intperpolated surface of TMIN and TMAX for specified processing region given sets 
5
#of inputs and parameters.
6
#STAGE 1: LST climatology calculation
7
#STAGE 2: Covariates preparation: aspect, land cover, distance to coast etc.
8
#STAGE 3: Data preparation: database query, extraction of covariates from stack
9
#STAGE 4: Raster prediction: run interpolation methode -- gam fusion, gam CAI, ...
10
#STAGE 5: Output analyses-visualization of results for specific dates...
11
#
12
#AUTHOR: Benoit Parmentier                                                                       
13
#DATE: 03/05/2013                                                                                 
14

    
15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363, TASK$568--   
16

    
17
##Comments and TODO:
18
# Modify code for stage 1 and call python script from R
19
# Modify code for stage 2, make it a function and fully automated (distoc var)
20
# Add options to run only specific stage + additional out_suffix?
21
# Make master script a function?
22
# Add log file for master script,add function to collect inputs and outputs
23
##################################################################################################
24

    
25
###Loading R library and packages   
26
library(RPostgreSQL)
27
library(maps)
28
library(maptools)
29
library(parallel)
30
library(gtools)                              # loading some useful tools 
31
library(mgcv)                                # GAM package by Simon Wood
32
library(sp)                                  # Spatial pacakge with class definition by Bivand et al.
33
library(spdep)                               # Spatial pacakge with methods and spatial stat. by Bivand et al.
34
library(rgdal)                               # GDAL wrapper for R, spatial utilities
35
library(gstat)                               # Kriging and co-kriging by Pebesma et al.
36
library(fields)                              # NCAR Spatial Interpolation methods such as kriging, splines
37
library(raster)                              # Hijmans et al. package for raster processing
38
library(rasterVis)
39
library(reshape)
40
library(plotrix)
41

    
42
### Parameters and arguments
43

    
44
script_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/"
45
#list_script_files<-
46

    
47

    
48
############ STAGE 1: LST Climatology ###############
49

    
50
#Call run through python
51
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/climatology_01252013b.py
52

    
53
############ STAGE 2: Covariate production ################
54

    
55
#Transform into function...
56
#/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates_production_temperatures_02062013.R
57

    
58
############# STAGE 3: Data preparation ###############
59

    
60
source(file.path(script_path,"Database_stations_covariates_processing_function_03052013.R"))
61

    
62

    
63
#Setting up input argurments for script function...
64

    
65
db.name <- "ghcn"       # name of the Postgres database
66
var <- "TMAX"           # name of the variables to keep: TMIN, TMAX or PRCP
67
range_years<-c("2010","2011") #right bound not included in the range!!
68
range_years_clim<-c("2000","2011") #right bound not included in the range!!
69
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
70
infile2<-"/home/layers/data/climate/ghcn/v2.92-upd-2012052822/ghcnd-stations.txt"                              #This is the textfile of station locations from GHCND
71
infile_covariates<-"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script
72
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84: same as earlier
73
in_path <- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data/"
74
out_prefix<-"_365d_GAM_fus5_all_lstd_03052013"                #User defined output prefix
75
#qc_flags<-    flags allowe for the query from the GHCND??
76

    
77
#The names of covariates can be changed...these names should be output/input from covar script!!!
78
rnames<-c("x","y","lon","lat","N","E","N_w","E_w","elev","slope","aspect","CANHEIGHT","DISTOC")
79
lc_names<-c("LC1","LC2","LC3","LC4","LC5","LC6","LC7","LC8","LC9","LC10","LC11","LC12")
80
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",
81
             "nobs_01","nobs_02","nobs_03","nobs_04","nobs_05","nobs_06","nobs_07","nobs_08",
82
             "nobs_09","nobs_10","nobs_11","nobs_12")
83
covar_names<-c(rnames,lc_names,lst_names)
84

    
85
#list of 11 parameters for input in the function...
86

    
87
list_param_prep<-list(db.name,var,range_years,range_years_clim,infile1,infile2,infile_covariates,CRS_locs_WGS84,in_path,covar_names,out_prefix)
88
cnames<-c("db.name","var","range_years","range_years_clim","infile1","infile2","infile_covariates","CRS_locs_WGS84","in_path","covar_names","out_prefix")
89
names(list_param_prep)<-cnames
90

    
91
##### RUN SCRIPT TO GET STATION DATA WITH COVARIATES #####
92
list_outfiles<-database_covaratiates_preparation(list_param_prep)
93

    
94
############### STAGE 4: RASTER PREDICTION #################
95

    
96
#Prepare parameters for for raster prediction... Turn this into a function
97

    
98
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_03052013.R"))
99

    
100
############## STAGE 5: OUTPUT ANALYSES ##################
101

    
102
source(file.path(script_path,"results_interpolation_date_output_analyses_03052013.R"))
103

    
104

    
105
###############   END OF SCRIPT   ###################
106
#####################################################
107

    
(29-29/39)