raster

Plotting a raster with exponential or quantile color ramp diverging around zero

做~自己de王妃 提交于 2019-12-24 14:07:54
问题 I am using the R function levelplot() from the rasterVis package to plot a stack of three rasters with a single diverging color ramp. I would like to change the scale of a raster color ramp so that the map accentuates differences in lower values. This can be done by non-linear binning of the color breaks. I'm using the code from a gist written by @jbaums (code included below). Any suggestions on how to adjust the color ramp in this code so that the breaks follow 2^x but the min and max values

How to Make a RasterBrick from HDF5 Files? R

左心房为你撑大大i 提交于 2019-12-24 13:03:02
问题 How can one make a Rasterbrick in R from several hdf5 files? Often, data are provided in hdf5 format and one has to convert it to a more friendly format for easy handling. At the moment I know of the rhdf5 package but how to get a RasterBrick is that which I am unsure about. source("http://bioconductor.org/biocLite.R") biocLite("rhdf5") library("rhdf5") library("raster") You can access several hdf5 files on this link http://mirador.gsfc.nasa.gov/cgi-bin/mirador/cart.pl?C1=GPM_3IMERGHH

Generate pixel based image in R from character array

岁酱吖の 提交于 2019-12-24 09:27:08
问题 I have a very long character array. I want to generate pixel based image (raster image) by encoding each character to certain color in image. For example, 'A' as red pixel, 'B' as purple, ... and 'Z' by some other color. I am using R for it. Please help me how can i generate such pixel based image. I search and found raster and pixmap packages in R but i am new to R and not sure how to use them for my case. Any help is appreciated. Thanks 回答1: Here's a possible solution : library(png) library

Cannot open the connection in raster R

你。 提交于 2019-12-24 07:18:18
问题 I used these functions several times, and they were working perfect, nothing wrong with my input data!! m<-raster::intersect(raster,shapefile) or n<-crop(raster, extent(shapefile)) I have to do this operation for a large set of data. Therefore, I tried to increase the speed of R by using multicore . I did use multicore.tabulate.intersect function from here However, nothing works for me. Then, whenever I run intersect or crop function I got this error: m<-raster::intersect(raster,shapefile)

how to save an array representing an image with 40 band to a .tif file

北城余情 提交于 2019-12-24 04:40:14
问题 I have an array with 600×600×40 dimension that each band(from 40 band) represent a 600×600 image I want to save it to a multiple band .tif image. I have tried this functions from scikit-image and openCV but they can not save more than 3 band(as RGB). import cv2 cv2.imwrite('image.tif',600by600_just3band_array) 回答1: tifffile (https://pypi.org/project/tifffile/) supports multi-channel .tiff's and has an API similar to the one of scikit-image or OpenCV : In [1]: import numpy as np In [2]: import

Discrete legend breaks in ggplot2

*爱你&永不变心* 提交于 2019-12-24 01:57:20
问题 I'd like to break the legend into categories rather than having a continuous range of colours. Could someone kindly help me for the specific example I am using here? Below is my current trial with colour breaks at 40, 60 and 80. Thank you very much! library(raster) library(ggplot2) library(maptools) data("wrld_simpl") #sample raster r <- raster(ncol=10, nrow=20) r[] <- 1:ncell(r) extent(r) <- extent(c(-180, 180, -70, 70)) #plotting var_df <- as.data.frame(rasterToPoints(r)) p <- ggplot() +

How to save raster data in R object format?

99封情书 提交于 2019-12-24 00:41:55
问题 I don't know how to deal with save.image() and saveRDS() with raster data in R. I have understood that raster package open a connexion with the image file using raster() function, so it doesn't really open the file into R workspace. I want to save my workspace (data.frame, list, raster, etc) with save.image() function (or similar) and open it in a different computer. If I try to plot or process a raster object saved in a different computer, always have the same issue: Error in .local(.Object,

Applying functions to multidimensional numpy arrays without loops

别等时光非礼了梦想. 提交于 2019-12-24 00:34:59
问题 I am working with raster data with numpy (after reading from GDAL), which represents elevation. My goal is calculate water flow direction for every pixel in the array using numpy, determined primarily from the difference in elevation between a given pixel and it's 8 neighbours. I have already implemented a rolling window technique to generate a multidimensional array with each pixel and it's neighbours, which works as below: def rolling_window(array, window_size): itemsize = array.itemsize

remove Antarctica from wrld_simpl global map

守給你的承諾、 提交于 2019-12-23 20:11:42
问题 I use wrld_simpl as a background in my ggplots and would like to remove Antarctica. Not sure how to do it though. Thank you for your help! library(maptools) data("wrld_simpl") plot(wrld_simpl) wrld_simpl[wrld_simpl@data$ISO3 != "ATA"] Example of script: library(ggplot2) p <- ggplot() + geom_polygon(data = wrld_simpl, aes(x = long, y = lat, group = group), colour = "black", fill = "grey") p <- p + geom_raster(data = df , aes(x = x, y = y, fill = layer)) p <- p + coord_equal() + theme_bw() +

Clipping rasters in R

て烟熏妆下的殇ゞ 提交于 2019-12-23 18:41:23
问题 I am building a map for the northeastern U.S.A. The map background needs to be either an altitude map or a mean annual temperature map. I have two rasters from Worldclim.org which give me these variables but I need to clip them to the extent of the states I am interested in. Any suggestions on how to do this. This is what I have so far: #load libraries library (sp) library (rgdal) library (raster) library (maps) library (mapproj) #load data state<- data (stateMapEnv) elevation<-raster("alt