File:Gdd5 lgm chelsa ccsm4 envirem france 1.png
Original file (1,472 × 976 pixels, file size: 1.07 MB, MIME type: image/png)
Captions
Summary
[edit]DescriptionGdd5 lgm chelsa ccsm4 envirem france 1.png |
English: Growing Degree Days during Last Glacial Maximum. |
Date | |
Source | Own work |
Author | Merikanto |
Source of input data CHELSA LGM
Using pangeke envirem Visualization with Nasa Panoply
Climatologies at High resolution for the Earth Land Surface Areas CHELSA V1.2 Release Date: April 15, 2019
Karger, D.N., Conrad, O., Böhner, J., Kawohl, T., Kreft, H., Soria-Auza, R.W., Zimmermann, N.E., Linder, H.P. & Kessler, M. (2017) Climatologies at high resolution for the earth’s land surface areas. Scientific Data 4, 170122.
R 4.0.2 script
- "R" script: calculate gdd5, pet and ptopet rasters with Envirem package
- default: area of france
- with envirem
- source: chelsa ccsm4 lgm files
- version 0001b
- 9.10.2010
library(raster)
library(rgeos)
library(maps)
library(viridis)
library(envirem)
library(base)
library(stringr)
library(gtools)
area_1=1
stage_1=1
stage_2=1
stage_3=1
stage_4=1
rsaaga_1=1
- france
if (area_1==1)
{
extent1 <- extent(-10,10,40,50)
poly <- readWKT("POLYGON((
-10 50,
10 50,
10 40,
-10 40,
-10 50
))", p4s = CRS("+proj=longlat +datum=WGS84"))
}
- europe
if (area_1==2)
{
extent1 <- extent(-20,80,30,70)
poly <- readWKT("POLYGON((
-20 70,
80 70,
80 30,
-20 30,
-20 70
))", p4s = CRS("+proj=longlat +datum=WGS84"))
}
inputDir <- "./climate"
outputDir <- "./snapshot"
processpath2<-"./snapshot2"
outdir1 <- './envirem1'
dempath1<-"D:/razter1/high_longlat.tif"
name1='./envirem1/test_growingDegDays5.tif'
name2='./envirem1/test_annualPET.tif'
outname1="gdd5.nc"
outname2="pet.nc"
outname3="ptopet.nc"
outname4="precipann.nc"
outdpath1="./twi1.nc"
processpath1<-outputDir
indir1<-processpath2
Sys.which('gdalinfo')
Sys.which('gdal_translate')
list.files(inputDir)
dir.create(outputDir)
dir.create(processpath2)
- creation selection ractangle
makerasters=1
calculate_average_temp=1
if(stage_1==1)
{
- plot(poly, border = 'blue', xpd = NA, add = TRUE)
- crop and mask input rasters
files <- list.files(inputDir, pattern = '.tif$', full.names = TRUE)
- read in a precipitation raster and crop/mask and keep as a mask layer
- precipitation rasters have the term "_pr_" in the file name
- crop/mask using polygon
grep(files, pattern = '_prec_', value=TRUE)[1]
precipRaster <- raster(grep(files, pattern = '_prec_', value=TRUE)[1])
- precipRaster <- crop(precipRaster, poly)
precipRaster <- mask(precipRaster, poly)
precipRaster <- crop(precipRaster, extent1)
- precipRaster <- mask(precipRaster, extent1)
- create a terrestrial/marine mask by setting values < 0 to NA, and values >= 0 to 1
precipRaster[precipRaster < 0] <- NA
precipRaster[!is.na(precipRaster)] <- 1
plot(precipRaster, col = 'blue', legend = FALSE)
title(main = 'terrestrial mask')
- supply some additional flags to writeRaster() to employ compression to achieve smaller file sizes
tifOptions <- c("COMPRESS=DEFLATE", "PREDICTOR=2", "ZLEVEL=6")
for (i in 1:length(files)) {
cat(i, ' ')
r <- raster(files[i])
#r <- crop(r, poly)
r <- crop(r, extent1)
# apply terrestrial mask
r <- mask(r, precipRaster)
# if temperature, divide values by 10
## recognize temperature files as those containing the terms tasmin or tasmax
if (grepl('tmin|tmax', files[i])) {
# print("t ")
r <- r / 10
r <- r-273.15
}
r <- aggregate(r, fact = 2)
outfile <- paste0(outputDir, '/', names(r), '.tif')
writeRaster(r, filename = outfile, format = 'GTiff', options = tifOptions, overwrite = TRUE)
}
}
if(stage_2==1)
{
old_files <- list.files(processpath1, pattern = "*.tif", full.names = TRUE)
- old_files
old_files_2=mixedsort(old_files)
len1=length(old_files)
print (len1)
- old_files_2
precipfiles=grep('prec', old_files_2, value=TRUE)
print (precipfiles)
len2=length(precipfiles)
for (n in 1:len2) {
infilee=precipfiles[n]
#print (infilee)
a=sprintf("%02d",n)
#print (a)
newfileename=paste0(processpath2, "/test_precip_",a,".tif")
print (newfileename)
file.copy(from = infilee, to = newfileename)
}
tminfiles=grep('tmin', old_files_2, value=TRUE)
print (tminfiles)
len2=length(tminfiles)
for (n in 1:len2) {
infilee=tminfiles[n]
#print (infilee)
a=sprintf("%02d",n)
#print (a)
newfileename=paste0(processpath2,"/test_tmin_",a,".tif")
print (newfileename)
file.copy(from = infilee, to = newfileename)
}
tmaxfiles=grep('tmax', old_files_2, value=TRUE)
print (tmaxfiles)
len2=length(tmaxfiles)
for (n in 1:len2) {
infilee=tmaxfiles[n]
#print (infilee)
a=sprintf("%02d",n)
#print (a)
newfileename=paste0(processpath2,"/test_tmax_",a,".tif")
print (newfileename)
file.copy(from = infilee, to = newfileename)
}
rasterTemplate <- raster('./snapshot2/test_precip_01.tif')
ETsolradRasters(rasterTemplate = rasterTemplate, year = -25000, outputDir = processpath2, overwrite = TRUE)
}
if(stage_3==1)
{
old_files <- list.files(processpath1, pattern = "*.tif", full.names = TRUE)
- old_files
old_files_2=mixedsort(old_files)
tmaxfiles=grep('tmin', old_files_2, value=TRUE)
print (tmaxfiles)
len2=length(tmaxfiles)
print("Tmean ..")
for (n in 1:len2) {
a=sprintf("%02d",n)
infileename1=paste0(processpath2,"/test_tmax_",a,".tif")
infileename2=paste0(processpath2,"/test_tmin_",a,".tif")
outfileename1=paste0(processpath2,"/test_tmean_",a,".tif")
#print (n)
print (outfileename1)
r1=raster(infileename1)
#print("RK")
r2=raster(infileename2)
#plot(r2)
#print("R3 ...")
r3=(r1+r2)/2
#plot(r3)
#print("WR ...")
writeRaster(r3, filename = outfileename1, format = 'GTiff',overwrite = TRUE)
#file.copy(from = infilee, to = newfileename)
}
}
if(stage_4==1)
{
dir.create(outdir1)
assignNames(reset = TRUE)
assignNames(tmax = "test_tmax_##",
tmin = "test_tmin_##",
tmean="test_tmean_##",
precip = "test_precip_##",
solrad = "et_solrad_##"
)
chelsaFiles <- list.files(processpath2, pattern = 'test', full.names = TRUE)
chelsaStack <- stack(chelsaFiles)
solarFiles <- list.files(processpath2, pattern = 'solrad', full.names = TRUE)
solarStack <- stack(solarFiles)
print(solarFiles)
verifyFileStructure(processpath2, returnFileNames = FALSE)
verifyRasterNames(chelsaStack, solradstack = solarStack)
varnames()
inputDir <- indir1
outputDir <- outdir1
print ("Generating rasters")
generateRasters(var = 'growingDegDays5',prefix = 'test_',maindir = indir1,outputDir = outdir1)
- print("PET")
generateRasters(var = 'annualPET',prefix = 'test_',maindir = indir1,outputDir = outdir1)
- read in the resulting raster
result <- raster(name1)
plot(result, col = inferno(100))
writeRaster(result, filename = outname1, format = 'netCDF',overwrite = TRUE)
result <- raster(name2)
plot(result, col = inferno(100))
writeRaster(result, filename = outname2, format = 'netCDF',overwrite = TRUE)
print(" Prec ..." )
rasterFiles <- list.files(indir1, pattern = '.tif$', full.names = TRUE)
env <- stack(rasterFiles)
precip <- grep('prec', names(env), value=TRUE)
precip <- stack(envprecip)
annualprecip<-sum(precip)/10
pet=raster(outname2)
ptopet=annualprecip/pet
plot(annualprecip, col = inferno(100))
plot(ptopet, col = inferno(100))
writeRaster(annualprecip, filename = outname4, format = 'netCDF',overwrite = TRUE)
writeRaster(ptopet, filename = outname3, format = 'netCDF',overwrite = TRUE)
}
if (rsaaga_1==1)
{
e1 <- extent1
elev0<-raster(dempath1)
alt <- crop(elev0, e1)
plot(alt)
tempInfile <- 'saga_temp_twi_in'
writeRaster(alt, filename=tempInfile, format='SAGA',overwrite = TRUE)
env1 <- rsaga.env()
outfile <- 'saga_temp_twi_out.sgrd'
call <- rsaga.wetness.index(in.dem='saga_temp_twi_in.sgrd', out.wetness.index=outfile, env=env1)
twi1 <- raster('saga_temp_twi_out.sdat')
plot(alt)
plot(twi1)
writeRaster(twi1, filename = outdpath1, format = 'netCDF',overwrite = TRUE)
}
Licensing
[edit]- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 07:13, 8 October 2020 | 1,472 × 976 (1.07 MB) | Merikanto (talk | contribs) | Uploaded own work with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.