Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. library(rgdal)
  2. library(rworldxtra)
  3. library(raster)
  4. data(countriesHigh)
  5. library(raadtools)
  6. library(rgeos)
  7. library(RColorBrewer)
  8. library(graticule)
  9. # files with model output
  10. fs <- list.files("/home/shared/data/krillhabitat/grids", pattern = "grd", full.names = TRUE)
  11.  
  12. prj<- CRS("+proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=-40")
  13.  
  14. # map data
  15. w <- spTransform(countriesHigh, prj)
  16. # getData is broken, temporarily proceeed with no south georgia and falklands coastlines
  17. #sgs<- spTransform(getData("GADM", country = c("SGS"), level = 0), prj)
  18. #flk<- spTransform(getData("GADM", country = c("FLK"), level = 0), prj)
  19.  
  20. w2 <- spTransform(coastmap("ant_coast10"), prj)
  21.  
  22. # Colours and periods for plotting
  23. warm.col<- "#B2182B"
  24. cool.col<- "#2166AC"
  25. periods <- c("ave11yr","ipcc2012")
  26. the.pal <- brewer.pal(9,"YlOrRd")[3:9]
  27. the.pal2<- paste0(the.pal, 40)
  28.  
  29. ex <- extent(-65,-22, -75,-55)
  30. gridextent<- extent(-60,-25, -80,-50)
  31.  
  32. gridextent<- extent(projectExtent(raster(gridextent, crs = "+proj=longlat"), prj))
  33. dummy <- as(raster(gridextent, nrow = 1200, ncol =1200, crs = prj), "SpatialPoints")
  34.  
  35. ex2<- projectExtent(raster(ex, crs = "+proj=longlat"), prj)
  36. values(ex2)<- NA
  37.  
  38. op <- par(mfcol=c(1,2), mar=c(0,0,0,0), oma=c(1,2,2,1))
  39. for(i in 1:2){ # first level of loop is for time period: 1st current then future
  40. hi.r <- brick(grep(paste(periods[i], "hi", sep = "_"), fs, value = TRUE))[[3]]
  41. sw.r <- brick(grep(paste(periods[i], "fswth", sep = "_"), fs, value = TRUE))[[3]]
  42. ai.r <- brick(grep(paste(periods[i], "aice", sep = "_"), fs, value = TRUE))[[3]]
  43. rdg2.r <- brick(grep(paste(periods[i], "rdg2", sep = "_"), fs, value = TRUE))[[3]]
  44.  
  45. # set filters: hi.r is thickness, sw.r is light availability at the bottom of the column; ai.ris concentration
  46. h <- (hi.r >= 1 & hi.r <= 2 & ai.r > 0.15) * rdg2.r # layer for ridging
  47. h <- projectRaster(from = h, crs = prj)
  48.  
  49. h[!h > 0] <- NA_real_
  50. brks2<- c(0, 0.025, 0.05, 0.1, 0.2, 0.4, 0.8,1)
  51.  
  52. plot(ex2, axes=F, asp = 1)
  53.  
  54. ih <- as.image.SpatialGridDataFrame(as(h, "SpatialGridDataFrame"))
  55. image(ih, add = TRUE, col = the.pal, breaks = brks2)
  56.  
  57. plot(w2, border = "gray60", col = c("lightcyan", "grey90")[w2$cst10srf], add = TRUE, lwd=0.5)
  58. #plot(sgs, add=T, col="gray90", border="gray60", lwd=0.25)
  59. #plot(flk, add=T, col="gray90", border="gray60", lwd=0.25)
  60.  
  61. llgridlines(dummy, side = "EN", ndiscr = 80, plotLabels = T,
  62. easts = c(-70,-60, -50, -40, -30, -20, -10), norths = c(-80, -75,-70, -65, -60, -55), col="gray60", lwd=0.5, cex=0)
  63.  
  64. box(col="gray60")
  65.  
  66. #line for maximum ice extent
  67. ie <- rasterToContour(ai.r, level=0.15)
  68. plot(spTransform(ie, CRS(projection(prj))), add = TRUE, lty="dashed", col="lightblue2", lwd=2)
  69.  
  70. # panel labelling
  71. if (i==1 ) mtext("Current", side=3, line =1, xpd=NA, col=cool.col)
  72. if (i==2 ) mtext("Warm", side=3, line =1, xpd=NA, col=warm.col)
  73. if (i==1) mtext("September", side=2, las=0,outer=F, line=1, xpd=NA)
  74.  
  75. # manual colourbar
  76. # increment y position of fill by 0.2e6; put text at bottom of each
  77. if (i==2){
  78. op2<- par(xpd=NA)
  79. for(j in 1:length(the.pal2)){
  80.  
  81. inc<- 0.15e6
  82. adj<- (j-1)*inc
  83. xl<- 1.3e6
  84. xr<-xl+1e5
  85. yb<- 2.5e+06+adj
  86. yt<- yb+0.15e6
  87. tcx<- 0.4
  88. ofs=0.2
  89.  
  90. rect(xleft=xl, ybottom=yb, xright=xr, ytop=yt, col= the.pal[j], border=NA)
  91. text(xr,yb, brks2[j], pos=4, cex=tcx, offset=ofs)
  92. if(j==(length(the.pal)))text(xr,yb+inc, brks2[j+1], pos=4, cex=tcx, offset=ofs)
  93. }
  94. par(op2)
  95. }
  96. }
  97. par(op)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement