Title: | A Plotting Toolbox for 2D Oceanographic Data |
---|---|
Description: | Plotting toolbox for 2D oceanographic data (satellite data, sea surface temperature, chlorophyll, ocean fronts & bathymetry). Recognized classes and formats include netcdf, Raster, '.nc' and '.gz' files. |
Authors: | Robert K. Bauer |
Maintainer: | Robert K. Bauer <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.6 |
Built: | 2025-03-04 04:33:35 UTC |
Source: | https://github.com/rkbauer/r_package_oceanmap |
Creates a world map database that allows longitude ranges between -180 and 360 degrees, and thus from the Pacific to the Atlantic and vise versa. It is based on the worldHires database (which itself is based on CIA World Data Bank II data and contains approximately 2 million points representing the world coastlines and national boundaries), from which polygon irritations of the Antarctic were also corrected.
.get.worldmap(resolution)
.get.worldmap(resolution)
resolution |
number that specifies the resolution with which to draw the map. Resolution 0 is the full resolution of the database [default]. Otherwise, just before polylines are plotted they are thinned: roughly speaking, successive points on the polyline that are within resolution device pixels of one another are collapsed to a single point (see the Reference for further details). Thinning is not performed if plot = FALSE or when polygons are drawn (fill = TRUE or database is a list of polygons). |
A list of class "map" with longitude (x) and latitude (y) positions of coastlines and state boundaries (different coastline or booundary elements are seperated by NA), single polygon names are provided by a names vector.
Robert K. Bauer
worldHires
https://www.evl.uic.edu/pape/data/WDB/
worldmap <- oceanmap:::.get.worldmap(worldmap) str(worldmap) ## wordlmap usage in plotmap, with different center-options # par(mfrow=c(3,1)) # plotmap(lon=c(80, -120), lat=c(-50, 10), main= "map from East to West") # plotmap(lon=c(-120, 80), lat=c(-50, 10), main= "map from West to East") # plotmap('tp')
worldmap <- oceanmap:::.get.worldmap(worldmap) str(worldmap) ## wordlmap usage in plotmap, with different center-options # par(mfrow=c(3,1)) # plotmap(lon=c(80, -120), lat=c(-50, 10), main= "map from East to West") # plotmap(lon=c(-120, 80), lat=c(-50, 10), main= "map from West to East") # plotmap('tp')
adding a region to the region_definitions-file, taking or restoring a backup of region definitions. The basic idea is to provide a region-keyword that is used to access the region-information in later related function-calls (see: v and plotmap, regions). Information consists of a region-keyword, -longname, its spatial extent (longitudes and latitudes), grid resolution, as well as default colorbar position and figure size.
The required information can be provided by an interactive session (widget) that leads step by step through the region definition (is set default
), in parts by an extent-object with the missing information then completed by the session or by a one-row data frame that holds the entire information (see: region_definitions).
ATTENTION! When reinstalling or updating the oceanmap package, previous region definitions are getting lost! It is therefore highly recommanded to take and restore own backups (see: backup
and restore
).
add.region(add, add.px, cbx, cby, figdim, lib.folder, widget=T, backup=F, backup.folder='.', backup.name, restore=F,backup.regions)
add.region(add, add.px, cbx, cby, figdim, lib.folder, widget=T, backup=F, backup.folder='.', backup.name, restore=F,backup.regions)
add |
extent-,raster-object or dataset containing all required region definition entries ( The values |
add.px |
dataframe or list containing region data needed to read gz-compressed |
cbx |
the horizontal limits (x1, x2) of the colorbar. If missing, the user will be asked for manual colorbar placement. |
cby |
the vertical limits (y1, y2) of the colorbar. If missing, the user will be asked for manual colorbar placement. |
figdim |
numeric vector indicating the |
lib.folder |
Character string indicating R-library path in which the oceanmap-package is installed. |
widget |
whether an interactive session (widget) shall assist the data entry procedure (default is |
backup |
whether the current region_definitions-file should be backuped in the folder ' |
backup.folder |
Character string indicating the folder where to store the region_definitions-file backup (default is the current working directory). |
backup.name |
Character string indicating the filename of the region_definitions-file backup (If |
restore |
whether to restore a backup of the region_definitions-file (default is |
backup.regions |
Vector of region indicators defining which regions should be saved in backup file. |
Robert K. Bauer
delete.region, region_definitions, regions, plotmap, v
## Example 1: Add region by supplying a one-row data.frame ## that holds the entire required information # data(region_definitions) # load region_definitions # lion <- region_definitions[region_definitions$label == 'lion',] # selecting Gulf of Lions region # lion # junk <- lion # junk$label <- 'junk' # rename region label # add.region(junk) # add junk region # data(region_definitions) # reload region_definitions # region_definitions[,1:9] ## Example 2: Delete region #delete.region("junk") # delete junk region #data(region_definitions) # reload region_definitions #region_definitions[,1:9] ## Example 3: Add region by supplying an extent- or raster-object and running the widget library(raster) ext <- extent(0,10,50,60) plotmap(ext) #add.region(ext) # extent-object r <- raster(ext) #add.region(r) # raster-object ## Example 4: Add region by supplying raster-object, colorbar positions and running the widget #add.region(r,cbx=c(5,9.5),cby=c(51.7,52.4)) ## Example 5: Add region by running the widget #add.region() ## Example 6: Add region by running the widget #add.region(add.px=list(label="lion",nrow=10,ncol=10)) #data(region_definitions) #region_definitions[region_definitions$label =="lion",] ## Example 7: Creating a backup #add.region(backup=T) #add.region(backup=T, backup.folder=".",backup.regions=c("lion","medw4")) ## Example 8: Restoring the backup of the original region_definitions file #add.region(restore=T)
## Example 1: Add region by supplying a one-row data.frame ## that holds the entire required information # data(region_definitions) # load region_definitions # lion <- region_definitions[region_definitions$label == 'lion',] # selecting Gulf of Lions region # lion # junk <- lion # junk$label <- 'junk' # rename region label # add.region(junk) # add junk region # data(region_definitions) # reload region_definitions # region_definitions[,1:9] ## Example 2: Delete region #delete.region("junk") # delete junk region #data(region_definitions) # reload region_definitions #region_definitions[,1:9] ## Example 3: Add region by supplying an extent- or raster-object and running the widget library(raster) ext <- extent(0,10,50,60) plotmap(ext) #add.region(ext) # extent-object r <- raster(ext) #add.region(r) # raster-object ## Example 4: Add region by supplying raster-object, colorbar positions and running the widget #add.region(r,cbx=c(5,9.5),cby=c(51.7,52.4)) ## Example 5: Add region by running the widget #add.region() ## Example 6: Add region by running the widget #add.region(add.px=list(label="lion",nrow=10,ncol=10)) #data(region_definitions) #region_definitions[region_definitions$label =="lion",] ## Example 7: Creating a backup #add.region(backup=T) #add.region(backup=T, backup.folder=".",backup.regions=c("lion","medw4")) ## Example 8: Restoring the backup of the original region_definitions file #add.region(restore=T)
'.gz'
-file and saves subset as a new '.gz'
-fileExtracts a pre-defined region from '.gz'
-file and saves subset as a new '.gz'
-file (gzip compressed format). Basically it represents a combined call of regions, crop, raster2matrix and writebin.
area_extrac(obj,area)
area_extrac(obj,area)
obj |
Character string indicating search criteria for |
area |
Character string identifying the region that should be extracted. |
Robert K. Bauer
readbin, writebin, crop, raster2matrix, param_unconvert
## Example 1: extract, write '.gz'-files, following default plot-procedure library(raster) # load sample-'.gz'-file path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz'))[1] # load sample-'.gz'-files print(gz.files) # area_extrac(gz.files[1],area='lion') # gz <- Sys.glob(path,'/medw4*.gz') # load new-'.gz'-file # v(gz) # visualize new-'.gz'-file # system(paste('rm', gz)) # v(gz.files[1],v_area='lion')
## Example 1: extract, write '.gz'-files, following default plot-procedure library(raster) # load sample-'.gz'-file path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz'))[1] # load sample-'.gz'-files print(gz.files) # area_extrac(gz.files[1],area='lion') # gz <- Sys.glob(path,'/medw4*.gz') # load new-'.gz'-file # v(gz) # visualize new-'.gz'-file # system(paste('rm', gz)) # v(gz.files[1],v_area='lion')
returns formatted date string for v-plot titles by provided date information (e.g. filename of '.gz'
-files, name of raster-layers. bindate2Title
is returned by default by v-calls. bindate2main
and bindate2ylab
are plotted when v is called with sidelabels=T
.
bindate2Title(timestep, date1, date2=date1) bindate2main(timestep, date1, date2=date1) bindate2ylab(timestep, date1, date2=date1)
bindate2Title(timestep, date1, date2=date1) bindate2main(timestep, date1, date2=date1) bindate2ylab(timestep, date1, date2=date1)
timestep |
character string, indicating the range of the time unit in numbers and the time unit (e.g. "1d" for daily data; "7d" or "1w" for weekly data; "1m" for monthly data) |
date1 , date2
|
character string, indicating the first and last date of the timeframe covered (recognized format is %Y%m%d%H or %Y%m%d). E.g. 20030301 and 20030331 for monthly data ( |
Robert K. Bauer
## Example 1: output of different bindate2???-functions path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files u <- name_split(gz.files) print(gz.files[1]) # print filename print(u[1,]) # print splitted filename bindate2main(u$timestep[1],u$date1[1],u$date2[1]) # main bindate2Title(u$timestep[1],u$date1[1],u$date2[1]) # Title bindate2ylab(u$timestep[1],u$date1[1],u$date2[1]) # ylab ## Example 2: Visualize output for multiple '.gz'-files u$option <- '... .' dev.new(width=9.7,height=7.8,xpos=-1) empty.plot() box() for (i in 1:nrow(u)){ mtext(name_join(u[i,]),side=1,line=i-10) main <- bindate2main(u$timestep[i],u$date1[i],u$date2[i]) # main Title <- bindate2Title(u$timestep[i],u$date1[i],u$date2[i]) # Title ylab <- bindate2ylab(u$timestep[i],u$date1[i],u$date2[i]) # ylab mtext(c(Title,ylab,main),side=1:3,line=c(i,nrow(u)+1-i,nrow(u)+1-i)) mtext(paste("file",i),side=c(1,1:3),line=c(i-10,i,nrow(u)+1-i,nrow(u)+1-i),adj=0) } mtext(c("filename", "bindate2Title (default)", "bindate2ylab (sidelabels=T)", "bindate2main (sidelabels=T)"), side=c(1,1:3),line=c(-11,rep(i+2,3)),font=2)
## Example 1: output of different bindate2???-functions path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files u <- name_split(gz.files) print(gz.files[1]) # print filename print(u[1,]) # print splitted filename bindate2main(u$timestep[1],u$date1[1],u$date2[1]) # main bindate2Title(u$timestep[1],u$date1[1],u$date2[1]) # Title bindate2ylab(u$timestep[1],u$date1[1],u$date2[1]) # ylab ## Example 2: Visualize output for multiple '.gz'-files u$option <- '... .' dev.new(width=9.7,height=7.8,xpos=-1) empty.plot() box() for (i in 1:nrow(u)){ mtext(name_join(u[i,]),side=1,line=i-10) main <- bindate2main(u$timestep[i],u$date1[i],u$date2[i]) # main Title <- bindate2Title(u$timestep[i],u$date1[i],u$date2[i]) # Title ylab <- bindate2ylab(u$timestep[i],u$date1[i],u$date2[i]) # ylab mtext(c(Title,ylab,main),side=1:3,line=c(i,nrow(u)+1-i,nrow(u)+1-i)) mtext(paste("file",i),side=c(1,1:3),line=c(i-10,i,nrow(u)+1-i,nrow(u)+1-i),adj=0) } mtext(c("filename", "bindate2Title (default)", "bindate2ylab (sidelabels=T)", "bindate2main (sidelabels=T)"), side=c(1,1:3),line=c(-11,rep(i+2,3)),font=2)
'.gz'
-file typesReturns summary table on '.gz'
-file types available in a specified folder. Provided information include region
(region covered, as described by the region_definitions), sat
(satellite source), param
(parameter), res
(spatial resolution), ts
(temporal resolution), filetype
(file filetype)
check_gzfiles(sstring="*",folder,filetype=".gz")
check_gzfiles(sstring="*",folder,filetype=".gz")
sstring |
Character string indicating the search criteria for sat files (default is |
folder |
Character string indicating the folder in which searched files are located (default is current working directory) |
filetype |
Character string indicating thefile type of sat files (default is |
An aggregated data frame, returning '.gz'
-file type-information (see description) on available files in a specified folder.
Robert K. Bauer
## Example 1: plot '.gz'-files, following default plot-procedure path <- system.file("test_files", package="oceanmap") check_gzfiles(folder=path) # return file summary-table per filetype ## check for missing dates check_ts('medw4*',folder=path) check_ts('medw4*',folder=path,output=TRUE)
## Example 1: plot '.gz'-files, following default plot-procedure path <- system.file("test_files", package="oceanmap") check_gzfiles(folder=path) # return file summary-table per filetype ## check for missing dates check_ts('medw4*',folder=path) check_ts('medw4*',folder=path,output=TRUE)
'.gz'
-file time series is completechecks if daily '.gz'
-file time series in the present working directory is complete.
check_ts(sstring="*.gz",folder,output=F)
check_ts(sstring="*.gz",folder,output=F)
sstring |
Character string indicating search criteria for gz-files (default is |
folder |
Character string indicating the folder in which searched files are located (default is current working directory) |
output |
weather the missing dates should be returned as vector (default is |
optional vector of missing dates (see output
argument).
Robert K. Bauer
## Example 1: plot '.gz'-files, following default plot-procedure path <- system.file("test_files", package="oceanmap") check_gzfiles(folder=path) # return file summary-table per filetype ## check for missing dates check_ts('medw4*',folder=path) check_ts('medw4*',folder=path,output=TRUE)
## Example 1: plot '.gz'-files, following default plot-procedure path <- system.file("test_files", package="oceanmap") check_gzfiles(folder=path) # return file summary-table per filetype ## check for missing dates check_ts('medw4*',folder=path) check_ts('medw4*',folder=path,output=TRUE)
'.gz'
-file climatologiesCreates climatology plots of '.gz'
-files. ATTENTION! This function requires an ImageMagick installation, but runs also under Windows operating systems.
clim_plot(obj, folder,plotfolder=".", plotname, question=T, sst.frontcolor='red', chla.frontcolor='blue', sidelabels = F, Ylab = F, axeslabels = T, v_area, ...)
clim_plot(obj, folder,plotfolder=".", plotname, question=T, sst.frontcolor='red', chla.frontcolor='blue', sidelabels = F, Ylab = F, axeslabels = T, v_area, ...)
obj |
Character string indicating search criteria for climatology |
folder |
directory where data files are located (optional). |
plotfolder |
directory where image should be saved. |
plotname |
the name of the output file. If not provided, value will be derived from |
question |
whether the user shall be informed about the number of figures to plot before running the procedure (default is |
chla.frontcolor |
color map to be plotted for chlorophyll fronts (default is blue; obtained from cmap-dataset) |
sst.frontcolor |
color map to be plotted for sea surface temperature fronts (default is red; obtained from cmap-dataset) |
sidelabels |
whether an additional y-axis label and title should be added to the plot device (default is |
Ylab |
an additional title for the y axis (default is date information), only used when |
axeslabels |
whether axeslabels should be shown (default is |
v_area |
character string identifying the region that should be plotted, or in case of |
... |
Additional arguments to be passed to v and plotmap (e.g. |
Robert K. Bauer
v, readbin, name_split, regions, plotmap
## Example 1: plot seasonal '.gz'-files, following default plot-procedure path <- system.file("test_files", package="oceanmap") gz.file <- Sys.glob(paste0(path,'/*.gz'))[1] # load sample-'.gz'-files check_gzfiles(folder=path) # return file summary-table gz.files <- Sys.glob(paste0(path,'/*1s_*.gz')) # load seasonal '.gz'-files # v(gz.files) # as single plots ## as combined climatology plot, saved in plotfolder # clim_plot(gz.files,plotname='chla.summary.png')
## Example 1: plot seasonal '.gz'-files, following default plot-procedure path <- system.file("test_files", package="oceanmap") gz.file <- Sys.glob(paste0(path,'/*.gz'))[1] # load sample-'.gz'-files check_gzfiles(folder=path) # return file summary-table gz.files <- Sys.glob(paste0(path,'/*1s_*.gz')) # load seasonal '.gz'-files # v(gz.files) # as single plots ## as combined climatology plot, saved in plotfolder # clim_plot(gz.files,plotname='chla.summary.png')
function to close current graphic device, complement to figure-function that generates graphic devices in flexible fileformats.
close_fig(do.close=F, do.save=do.close)
close_fig(do.close=F, do.save=do.close)
do.close , do.save
|
whether file should be saved or not (default is TRUE). if FALSE, new graphic device will be opened inside R. |
Robert K. Bauer
# do.save <- TRUE # figure("Gulf_of_Lions", do.save=do.save, width=5, height=5, type="pdf") # plotmap("lion") # close_fig(do.save) do.save <- TRUE plotmap("lion") close_fig(do.save) do.save <- FALSE figure("Gulf_of_Lions", do.save=do.save, width=5, height=5, type="pdf") plotmap("lion") close_fig(do.save)
# do.save <- TRUE # figure("Gulf_of_Lions", do.save=do.save, width=5, height=5, type="pdf") # plotmap("lion") # close_fig(do.save) do.save <- TRUE plotmap("lion") close_fig(do.save) do.save <- FALSE figure("Gulf_of_Lions", do.save=do.save, width=5, height=5, type="pdf") plotmap("lion") close_fig(do.save)
list holding different color maps that can be used in image plots (see: v, get.bathy, image, image.plots, clim_plot)
available color maps are: ano
, bathy
, blue
, chla
, haxby
, jet
(obtained from matlab), rainbow
, red
, orange
, green
, sst
and haxbyrev
.
data(cmap) data(cmap_topo)
data(cmap) data(cmap_topo)
list
Robert K. Bauer
data('cmap') # load color maps data names(cmap) # list available color maps path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files # figure(width=15,height=15) # par(mfrow=c(4,5)) # for(n in names(cmap)) v(gz.files[2], v_area='lion', subplot=TRUE, # pal=n, adaptive.vals=TRUE, main=n) ## simple example of the \link{image}-function x <- 10*(1:nrow(volcano)) y <- 10*(1:ncol(volcano)) image(x, y, volcano, col = terrain.colors(100)) image(x, y, volcano, col = cmap$jet) # jet color map image(x, y, volcano, col = cmap$haxby) # haxby color map image(x, y, volcano, col = cmap$chla) # chlorophyll color map image(x, y, volcano, col = cmap$sst) # sst color map data(cmap_topo) image(x, y, volcano, col = cmap_topo$col) # topography color map ## another example: plot bathymetry and topography of the western Mediterranean Sea #get.bathy("medw4",visualize=T,terrain=T,res=3) #get.bathy("medw4",visualize=T,terrain=F,res=3,levels=c(200,2000)) # show contours
data('cmap') # load color maps data names(cmap) # list available color maps path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files # figure(width=15,height=15) # par(mfrow=c(4,5)) # for(n in names(cmap)) v(gz.files[2], v_area='lion', subplot=TRUE, # pal=n, adaptive.vals=TRUE, main=n) ## simple example of the \link{image}-function x <- 10*(1:nrow(volcano)) y <- 10*(1:ncol(volcano)) image(x, y, volcano, col = terrain.colors(100)) image(x, y, volcano, col = cmap$jet) # jet color map image(x, y, volcano, col = cmap$haxby) # haxby color map image(x, y, volcano, col = cmap$chla) # chlorophyll color map image(x, y, volcano, col = cmap$sst) # sst color map data(cmap_topo) image(x, y, volcano, col = cmap_topo$col) # topography color map ## another example: plot bathymetry and topography of the western Mediterranean Sea #get.bathy("medw4",visualize=T,terrain=T,res=3) #get.bathy("medw4",visualize=T,terrain=F,res=3,levels=c(200,2000)) # show contours
deletes a specified region from the region_definitions-definition file
delete.region(region,lib.folder,restore=F)
delete.region(region,lib.folder,restore=F)
region |
Character string identifying the region that should be deleted. See region_definitions for area definitions and use add.region to add new regions. |
lib.folder |
Character string indicating R-library path in which the oceanmap-package is installed. |
restore |
whether the original region_definitions-file should be restored. |
Robert K. Bauer
add.region, region_definitions, regions, writebin
## Example 1: Add region by supplying a one-row data.frame ## that holds the entire required information data(region_definitions) lion <- region_definitions[region_definitions$label == 'lion',] # selecting Gulf of Lions region lion junk <- lion junk$label <- 'junk' # rename region label #add.region(junk) # add junk region data(region_definitions) # reload region_definitions region_definitions[,1:9] ## Example 2: Delete region #delete.region("junk") # delete junk region data(region_definitions) # reload region_definitions region_definitions[,1:9]
## Example 1: Add region by supplying a one-row data.frame ## that holds the entire required information data(region_definitions) lion <- region_definitions[region_definitions$label == 'lion',] # selecting Gulf of Lions region lion junk <- lion junk$label <- 'junk' # rename region label #add.region(junk) # add junk region data(region_definitions) # reload region_definitions region_definitions[,1:9] ## Example 2: Delete region #delete.region("junk") # delete junk region data(region_definitions) # reload region_definitions region_definitions[,1:9]
Creates an empty scatter plot that is equal to the function call:
plot(1,lwd=0,axes=F,xlab="",ylab="",...)
empty.plot(..., xlab = "", ylab = "", new=T, add=!new, n=1, axes = F)
empty.plot(..., xlab = "", ylab = "", new=T, add=!new, n=1, axes = F)
... |
other arguments of the generic x-y plotting fucntion plot. |
xlab , ylab
|
label for the x- and y-axis of the plot (default is empty). |
new , add
|
whether to show add plot to a current plot device or to start a new figure (default is: new= |
n |
number of figures to be plotted (default is 1) |
axes |
whether to show plot axes (default is |
Robert K. Bauer
empty.plot() title("empty plot") box() axis(1) axis(2)
empty.plot() title("empty plot") box() axis(1) axis(2)
figure
generates graphic devices with flexible fileformat selection.
Function call with (figure(do.save=T) needs to be finished by close_fig(do.save=T), to close open file connection.
figure(filename, folder, type, save=F, do.save=save, width=10, height=10, xpos=-1, do.overwrite=T, delete.old=do.overwrite, ...)
figure(filename, folder, type, save=F, do.save=save, width=10, height=10, xpos=-1, do.overwrite=T, delete.old=do.overwrite, ...)
filename |
name of the figure to be generated (without file extension) |
folder |
plot folder (by default current working directory) |
type |
character string indicating the graphics format of the figure file. can be:
|
width , height
|
width and height of figure to be generated. default units are inches. |
save , do.save
|
whether file should be saved or not (default is TRUE). if FALSE, new graphic device will be opened inside R. |
xpos |
horizontal screen position of graphic device (ignored if do.save == TRUE) |
do.overwrite , delete.old
|
overwrite existing figure with same filename and extension (default is FALSE) |
... |
additional arguments to be passed to the graphic device |
Robert K. Bauer
## Example 1: plotmap() and figure() do.save <- FALSE figure("Gulf_of_Lions_extended", do.save=do.save, width=5, height=5, type="pdf") plotmap("lion") close_fig(do.save) ## now resize figure manually and get new figure dimensions: width <- dev.size()[1] height <- dev.size()[2] # do.save <- TRUE # figure("Gulf_of_Lions_extended", do.save=do.save, width=width, height=height, type="pdf") # plotmap("lion") # close_fig(do.save)
## Example 1: plotmap() and figure() do.save <- FALSE figure("Gulf_of_Lions_extended", do.save=do.save, width=5, height=5, type="pdf") plotmap("lion") close_fig(do.save) ## now resize figure manually and get new figure dimensions: width <- dev.size()[1] height <- dev.size()[2] # do.save <- TRUE # figure("Gulf_of_Lions_extended", do.save=do.save, width=width, height=height, type="pdf") # plotmap("lion") # close_fig(do.save)
returns the average value of circles with specified coordinates and a defined radius
get.avg.bathy(x, radius, unit="km", raster, bathy, v_area="medw4") get.avg(x, radius, unit="km", raster)
get.avg.bathy(x, radius, unit="km", raster, bathy, v_area="medw4") get.avg(x, radius, unit="km", raster)
x |
a vector or matrix providing the coordinates of the circle |
radius |
the radius (if |
unit |
unit of the radius (by default "km").
if |
raster |
raster object, from which the average should be calculated. |
bathy |
raster object with bathymetry data, from which the average should be calculated. |
v_area |
character string identifying the region for which the bathymetry data should downloaded from the NOAA server. |
Robert K. Bauer
## Example 1: load & plot bathymetry of the Baltic Sea, defined by longitudes and latidtues lon <- c(9, 31) lat <- c(53.5, 66) # bathy <- get.bathy(lon=lon, lat=lat, main="Baltic Sea", cbpos='r') plotmap(lon=lon, lat=lat) spc <- SpatialCircle(x= 20,y = 57.5,r=1) plot(spc,add=TRUE) # get.avg.bathy(c(20,57.5), radius = 1, bathy = bathy) # get.avg(c(20,57.5), radius = 1, unit="km",raster = bathy)
## Example 1: load & plot bathymetry of the Baltic Sea, defined by longitudes and latidtues lon <- c(9, 31) lat <- c(53.5, 66) # bathy <- get.bathy(lon=lon, lat=lat, main="Baltic Sea", cbpos='r') plotmap(lon=lon, lat=lat) spc <- SpatialCircle(x= 20,y = 57.5,r=1) plot(spc,add=TRUE) # get.avg.bathy(c(20,57.5), radius = 1, bathy = bathy) # get.avg(c(20,57.5), radius = 1, unit="km",raster = bathy)
Returns and optionally stores bathymetric data from the ETOPO1 database hosted on the NOAA server as a RasterLayer, based on the defined resolution and provided coordinate bounds or region definition. Stored bathymetry files can be reloaded through the same function call.
get.bathy(v_area, lon, lat, resolution=4, keep=F , savename.bathy, folder.bathy, visualize=T, terrain=F,...)
get.bathy(v_area, lon, lat, resolution=4, keep=F , savename.bathy, folder.bathy, visualize=T, terrain=F,...)
v_area |
character string identifying the region that should be plotted, or in case of |
lon , lat
|
longitude and latitude describing the extend of the region of interest. |
resolution |
resolution of the bathymetric grid, in minutes (default is 4). |
keep |
whether to write the data downloaded from NOAA into a file (default is FALSE). |
savename.bathy |
savename for the bathymetric data file, if not specified set to type 'bathy_lon-lat_res.resolution.dat' or 'bathy_v_area_res.resolution.dat'. |
folder.bathy |
directory where bathymetric data should be saved (default is current working directory). |
visualize |
whether the bathymetric data should be plotted instantly. |
terrain |
whether the to keep terrain data (default is |
... |
additional arguments to be passed to v, used if |
Robert K. Bauer
v, add.region, region_definitions, regions, writebin, get.bathy
## Example 1: load & plot bathymetry of the Baltic Sea, defined by longitudes and latidtues lon <- c(9, 31) lat <- c(53.5, 66) # get.bathy(lon=lon, lat=lat, main="Baltic Sea", cbpos='r') ## Example 2: plot bathymetry using a v_area-keyword #get.bathy("lion",res=4, keep=T) # can take some time, requires server connection! #get.bathy("lion",res=1, keep=T,visualize=FALSE) ## Example 3: plot landmask of the Baltic Sea defined by an extent- or raster-object library('raster') ext <- extent(lon,lat) #get.bathy(ext,visualize=T,main="Baltic Sea",res=4,levels=200) # extent-object ## Example 4: plot bathymetry and topography of the western Mediterranean Sea ### a) download, assign and save bathymetry # bathy <- get.bathy("medw4",visualize=F,terrain=T,res=3,keep=T) # # load('bathy_medw4_res.3.dat',verbose = T); bathy <- h # par(mfrow=c(2,1)) # v(bathy,param="bathy",subplot = T) # get.bathy("medw4",visualize=T,terrain=F,res=3,levels=c(200,2000), # subplot = T,grid=F) # show contours ### b) only contour lines: # par(mfrow=c(1,2)) # h <- get.bathy("lion",visualize=T,terrain=F,res=3,levels=c(200,2000), # v_image=F, subplot=T,grid=F) ### use v-function for same plot but on subregion: # v(h,v_area = "survey", param="bathy",subplot = T, v_contour = T, # v_image = F, levels=c(200,2000))
## Example 1: load & plot bathymetry of the Baltic Sea, defined by longitudes and latidtues lon <- c(9, 31) lat <- c(53.5, 66) # get.bathy(lon=lon, lat=lat, main="Baltic Sea", cbpos='r') ## Example 2: plot bathymetry using a v_area-keyword #get.bathy("lion",res=4, keep=T) # can take some time, requires server connection! #get.bathy("lion",res=1, keep=T,visualize=FALSE) ## Example 3: plot landmask of the Baltic Sea defined by an extent- or raster-object library('raster') ext <- extent(lon,lat) #get.bathy(ext,visualize=T,main="Baltic Sea",res=4,levels=200) # extent-object ## Example 4: plot bathymetry and topography of the western Mediterranean Sea ### a) download, assign and save bathymetry # bathy <- get.bathy("medw4",visualize=F,terrain=T,res=3,keep=T) # # load('bathy_medw4_res.3.dat',verbose = T); bathy <- h # par(mfrow=c(2,1)) # v(bathy,param="bathy",subplot = T) # get.bathy("medw4",visualize=T,terrain=F,res=3,levels=c(200,2000), # subplot = T,grid=F) # show contours ### b) only contour lines: # par(mfrow=c(1,2)) # h <- get.bathy("lion",visualize=T,terrain=F,res=3,levels=c(200,2000), # v_image=F, subplot=T,grid=F) ### use v-function for same plot but on subregion: # v(h,v_area = "survey", param="bathy",subplot = T, v_contour = T, # v_image = F, levels=c(200,2000))
This function converts a ggplot2 object created by oceanmap::ggplotmap() to a plotly object.
ggplotmaply(ggobj, fixedrange=F, grid=F,expand=3)
ggplotmaply(ggobj, fixedrange=F, grid=F,expand=3)
ggobj |
Character string identifying regions predefined by the region_definitions-dataset, Raster* or Extent object (corresponds to |
fixedrange |
Vector returning longitude coordinates of the area to be plotted. |
grid |
whether a grid should be plotted (default is |
expand |
By default, the underlying ggplotly-function does not stick to the plotting region of the ggobj, but extends it. This can result in missing countries or islands. The |
ggoplotmaply
uses the ggplotly
functions to convert the ggplot object into the plotly format.
Robert K. Bauer
library(ggplot2) #### Example 1: plot landmask of the Western Mediterranean Sea ## a) by using longitude and latitude coordinates: # lon <- c(-6, 16.5) # lat <- c(34, 44.5) # ggobj <- ggplotmap(xlim=lon, ylim=lat) # ggobj # ggplotmaply(ggobj,expand = 10) ## we need to expand the plotting region ## b) plot landmask of the Western Mediterranean Sea by using an extent-object: # library('raster') # ext <- extent(lon, lat) # plotmap(ext, main="Western Mediterranean Sea") # extent-object # ggobj <- ggplotmap(ext) # ggobj # ggplotmaply(ggobj) ## c) plot landmask of the Western Mediterranean Sea by using a raster-object: # r <- raster(ext) # ggobj <- ggplotmap(r) # ggobj # ggplotmaply(ggobj) # ggplotmaply(ggobj) ## d) plot landmask of the entire Mediterranean Sea by using keyword: ggobj <- ggplotmap("med4") + geom_point(data=data.frame(x=3.7008, y=43.4079),aes(x,y),size=5,colour="blue") # ggobj # ggplotmaply(ggobj,expand = 10) ## e) add landmask to raster image plot (similar to v()-call) # library(dplyr) # library(ggplot2) # data(cmap) # setwd(system.file("test_files", package="oceanmap")) # nc <- nc2raster(ncfiles[1]) # rs2df <- nc[[1]] %>% ## take first layer # rasterToPoints() %>% ## convert raster to xyz matrix # as.data.frame() ## convert to data frame # names(rs2df) <- c("Lon","Lat","Conc") ## reset names (important for ggplotmaply hover text) # ggobj <- ggplot() + geom_raster(data = rs2df, aes(x=Lon,y=Lat,fill=Conc)) # ggobj_with_land_mask <- ggplotmap(add_to = ggobj) + # scale_fill_gradientn(colours=cmap$jet) # change colorbar # ggobj_with_land_mask # ggplotmaply(ggobj_with_land_mask)
library(ggplot2) #### Example 1: plot landmask of the Western Mediterranean Sea ## a) by using longitude and latitude coordinates: # lon <- c(-6, 16.5) # lat <- c(34, 44.5) # ggobj <- ggplotmap(xlim=lon, ylim=lat) # ggobj # ggplotmaply(ggobj,expand = 10) ## we need to expand the plotting region ## b) plot landmask of the Western Mediterranean Sea by using an extent-object: # library('raster') # ext <- extent(lon, lat) # plotmap(ext, main="Western Mediterranean Sea") # extent-object # ggobj <- ggplotmap(ext) # ggobj # ggplotmaply(ggobj) ## c) plot landmask of the Western Mediterranean Sea by using a raster-object: # r <- raster(ext) # ggobj <- ggplotmap(r) # ggobj # ggplotmaply(ggobj) # ggplotmaply(ggobj) ## d) plot landmask of the entire Mediterranean Sea by using keyword: ggobj <- ggplotmap("med4") + geom_point(data=data.frame(x=3.7008, y=43.4079),aes(x,y),size=5,colour="blue") # ggobj # ggplotmaply(ggobj,expand = 10) ## e) add landmask to raster image plot (similar to v()-call) # library(dplyr) # library(ggplot2) # data(cmap) # setwd(system.file("test_files", package="oceanmap")) # nc <- nc2raster(ncfiles[1]) # rs2df <- nc[[1]] %>% ## take first layer # rasterToPoints() %>% ## convert raster to xyz matrix # as.data.frame() ## convert to data frame # names(rs2df) <- c("Lon","Lat","Conc") ## reset names (important for ggplotmaply hover text) # ggobj <- ggplot() + geom_raster(data = rs2df, aes(x=Lon,y=Lat,fill=Conc)) # ggobj_with_land_mask <- ggplotmap(add_to = ggobj) + # scale_fill_gradientn(colours=cmap$jet) # change colorbar # ggobj_with_land_mask # ggplotmaply(ggobj_with_land_mask)
internal (lazyload
) datasets medm9_proj
and regions.dim.bathy
, accessed by v.plot
and readbin respectively.
Robert K. Bauer
matrix2raster
Converts a matrix to a RasterLayer or arrays to a RasterStack-object.
matrix2raster(z,x,y,layer,proj="+proj=longlat")
matrix2raster(z,x,y,layer,proj="+proj=longlat")
z |
matrix or array to be converted. |
x |
optional x-coordinates giving the horizontal range of the raster layer, its size does not need to coincide with ncol(z)! |
y |
optional y-coordinates giving the verical range of the raster layer, its size does not need to coincide with nrow(z)! |
layer |
layer to be selected (only valid if z is an array). |
proj |
optional argument, setting the coordinate reference system (CRS) of a Raster* object (default is |
Robert K. Bauer
## Example 1: convert a matrix m <- matrix(3,2,2) matrix2raster(m) ## Example 2: convert an array a <- array(3,dim=c(2,2,2)) matrix2raster(a) matrix2raster(a,layer=1) ## Example 3: convert '.nc'-file to raster-object manually owd <- getwd() path <- system.file("test_files", package="oceanmap") ncfile <- Sys.glob(paste0(path,'/herring*.nc')) # load sample-'.nc'-files library('ncdf4') library('raster') nc <- nc_open(ncfile) # open netcdf file z <- ncvar_get(nc,'Conc')[,,1] lon <- as.vector(ncvar_get(nc,'lon')) # fillvalues are automatically replaced by NA lat <- as.vector(ncvar_get(nc,'lat')) # fillvalues are automatically replaced by NA matrix2raster(z,x=lon,y=lat) ## Example 4: convert '.nc'-file to raster-object using nc2raster nc2raster(ncfile,varname='Conc',layer=1:4)
## Example 1: convert a matrix m <- matrix(3,2,2) matrix2raster(m) ## Example 2: convert an array a <- array(3,dim=c(2,2,2)) matrix2raster(a) matrix2raster(a,layer=1) ## Example 3: convert '.nc'-file to raster-object manually owd <- getwd() path <- system.file("test_files", package="oceanmap") ncfile <- Sys.glob(paste0(path,'/herring*.nc')) # load sample-'.nc'-files library('ncdf4') library('raster') nc <- nc_open(ncfile) # open netcdf file z <- ncvar_get(nc,'Conc')[,,1] lon <- as.vector(ncvar_get(nc,'lon')) # fillvalues are automatically replaced by NA lat <- as.vector(ncvar_get(nc,'lat')) # fillvalues are automatically replaced by NA matrix2raster(z,x=lon,y=lat) ## Example 4: convert '.nc'-file to raster-object using nc2raster nc2raster(ncfile,varname='Conc',layer=1:4)
'.gz'
-filenames from a list or dataframe
creates filenames based on a list or dataframe with the (header)-names:
area source parameter resolution timestep date1 date2 option
by aligning the defined filetype:
e.g. area_source_parameter_resolution_timestep_date1_date2.option.filetype
name_join(parts,filetype='gz')
name_join(parts,filetype='gz')
parts |
a list or dataframe with the parts: |
area
, the region keyword
source
, the data source
param
, the parameter saved in the '.gz'
-file. Can only be one value!
resolution
, the spatial resolution
timestep
, the temporal resolution
date1
& date2
, the temporal resolution (the time interval covered).
option
a character string holding supplmentary information of '.gz'
-file treatment
filetype |
character string inidicating the filtype to be checked. ('.gz' by default) |
Herve Demarq, translated from IDL by Robert K. Bauer
See check_gzfiles to return summary of available '.gz'
-files and name_split to split '.gz'
-filenames
## Example: read and plot '.gz'-file path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files check_gzfiles(folder=path) # return file summary-table # return summary of availble '.gz'-files # suffix-column corresponds to option column of the name_join-call # addition n-column returns the number of available files per filetype check_gzfiles(gz.files) ## Example: split and rejoin '.gz'-filenames name_split(gz.files) # return summary-table per file name_join(name_split(gz.files))
## Example: read and plot '.gz'-file path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files check_gzfiles(folder=path) # return file summary-table # return summary of availble '.gz'-files # suffix-column corresponds to option column of the name_join-call # addition n-column returns the number of available files per filetype check_gzfiles(gz.files) ## Example: split and rejoin '.gz'-filenames name_split(gz.files) # return summary-table per file name_join(name_split(gz.files))
'.gz'
encoded oceanography files by splitting their name
Returns a summary data.frame of '.gz'
encoded oceanography files by splitting their name
name_split(gz.files) get.gz.info(gz.files)
name_split(gz.files) get.gz.info(gz.files)
gz.files |
Optional character vector or search criteria for .gz-encoded oceanography files. |
Returns a summary data.frame of '.gz'
encoded oceanography files by splitting their name
area source parameter resolution timestep date1 date2 option
area |
region keyword |
source |
data source |
param |
the parameter saved in the |
resolution |
the spatial resolution |
timestep |
the temporal resolution |
date1 & date2 |
the time interval covered in date format |
option |
a character string holding supplmentary information of |
Robert K. Bauer
See check_gzfiles to return summary of available '.gz'
-files and name_join to create '.gz'
-filenames from splitted names (name_split)-calls
## Example: read and plot '.gz'-file path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files check_gzfiles(folder=path) # return file summary-table # return summary of availble '.gz'-files # suffix-column corresponds to option column of the name_split-call # addition n-column returns the number of available files per filetype check_gzfiles(gz.files) ## Example: split and rejoin '.gz'-filenames gz.files name_split(gz.files) # return summary-table per file name_split() # return summary-table of all gz-file in current folder name_join(name_split(gz.files))
## Example: read and plot '.gz'-file path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files check_gzfiles(folder=path) # return file summary-table # return summary of availble '.gz'-files # suffix-column corresponds to option column of the name_split-call # addition n-column returns the number of available files per filetype check_gzfiles(gz.files) ## Example: split and rejoin '.gz'-filenames gz.files name_split(gz.files) # return summary-table per file name_split() # return summary-table of all gz-file in current folder name_join(name_split(gz.files))
nc2raster
converts a netcdf-file ('.nc'-file) or ncdf4
-object to a Raster* object, setting the time variable as layer name.
nc2raster(nc, varname, t=layer, layer, verbose=FALSE)
nc2raster(nc, varname, t=layer, layer, verbose=FALSE)
nc |
character string indicating the filepath to a netcdf-file ('.nc'-file), or a |
varname |
character string indicating the name of the netcdf-variable to be selected. |
layer , t
|
layer/time stemp to select in multi-layer files. |
verbose |
should information about the netcdf file, including the variables and dimensions it contains, be printed during loading? (default is |
RasterLayer or RasterStack
Robert K. Bauer
path <- system.file("test_files", package="oceanmap") nfiles <- Sys.glob(paste0(path,'/*.nc'))[1] # load sample-'.nc'-files nc2raster(nfiles[1],"Conc",layer=1) # RasterLayer nc2raster(nfiles[1],"Conc",layer=1:4) # RasterStack library('ncdf4') nc <- nc_open(nfiles[1]) nc2raster(nc,"Conc",layer=1:4) # RasterStack ###### load & plot sample netcdf-file ('.nc'-file) ### option a) load netcdf-file with ncdf4-package and plot it library('ncdf4') ncdf <- nc_open(nfiles[1]) print(ncdf) v(obj = ncdf, cbpos="r") ### option b) load and plot netcdf-file as RasterStack object nc <- nc2raster(nfiles[1]) v(nc,cbpos="r") # plot RasterStack object v(nfiles[1], cbpos="r",replace.na=TRUE) # plot directly netcdf-file ### option c) plot netcdf-file directly v(nfiles[1], cbpos="r") # plot RasterStack object ###### plot multiple layers: par(mfrow=c(2,2)) v(nfiles[1], t=1:4, cbpos="r", replace.na=TRUE, subplot = TRUE)
path <- system.file("test_files", package="oceanmap") nfiles <- Sys.glob(paste0(path,'/*.nc'))[1] # load sample-'.nc'-files nc2raster(nfiles[1],"Conc",layer=1) # RasterLayer nc2raster(nfiles[1],"Conc",layer=1:4) # RasterStack library('ncdf4') nc <- nc_open(nfiles[1]) nc2raster(nc,"Conc",layer=1:4) # RasterStack ###### load & plot sample netcdf-file ('.nc'-file) ### option a) load netcdf-file with ncdf4-package and plot it library('ncdf4') ncdf <- nc_open(nfiles[1]) print(ncdf) v(obj = ncdf, cbpos="r") ### option b) load and plot netcdf-file as RasterStack object nc <- nc2raster(nfiles[1]) v(nc,cbpos="r") # plot RasterStack object v(nfiles[1], cbpos="r",replace.na=TRUE) # plot directly netcdf-file ### option c) plot netcdf-file directly v(nfiles[1], cbpos="r") # plot RasterStack object ###### plot multiple layers: par(mfrow=c(2,2)) v(nfiles[1], t=1:4, cbpos="r", replace.na=TRUE, subplot = TRUE)
ncdf4
-object as as.Date
-object
reads and converts the time variable of a netcdf-file ('.nc'-file) or ncdf4
-object as as.Date
-object.
nc2time(nc,varname)
nc2time(nc,varname)
nc |
character string indicating the filepath to a netcdf-file ('.nc'-file), or a |
varname |
character string indicating the name of the time vaiable of the netcdf-file. |
Robert K. Bauer
path <- system.file("test_files", package="oceanmap") nfile <- Sys.glob(paste0(path,'/herring*.nc')) # load sample-'.nc'-files head(nc2time(nfile)) library('ncdf4') nc <- nc_open(nfile) head(nc2time(nc))
path <- system.file("test_files", package="oceanmap") nfile <- Sys.glob(paste0(path,'/herring*.nc')) # load sample-'.nc'-files head(nc2time(nfile)) library('ncdf4') nc <- nc_open(nfile) head(nc2time(nc))
oceanmap
is a plotting toolbox for oceanographic data.
Visualizing data is a crucial step in analyzing and exploring data. During the last two decades the statistical programming language R has become a major tool for data analyses and visualization across different fields of science. However, creating figures ready for scientific publication can be a tricky and time consuming task.
The oceanmap
package provides some helpful functions to facilitate and optimize the visualization of geographic and oceanographic data, such as satellite and bathymetric data sets. Its plotting functions are written in a way that they do not require a large amount of their numerous arguments to be specified but still return nice plots. Its major functions are:
Major functions:
plotmap: plots landmask as basis or overlay
v: plots oceanographic data (fronts, SST, chla, bathymetry, etc.) from raster-objects, ncdf4- or gz-files
set.colorbar: adds a colorbar to current figure, allowing several placement methods
get.bathy: download bahymetric data at user defined resolution from the NOAA ETOPO1 database
add.region: generate region definitions to facilitate land mask and colorbar plotting using plotmap and v
figure & close_fig: generate and save graphic devices in flexible file formats (jpeg, png, eps, pdf and eps)
Getting Started
Check out some examples of the principle functions, listed above.
Robert K. Bauer
param_unconvert
)
converts byte data as stored in '.gz'
-files to absolte values (param_convert
) or vise versa (param_unconvert
) using the parameter_definitions-dataset. param_convert
is used by readbin, param_unconvert
is used by writebin.
param_convert(x,param) param_unconvert(x,param)
param_convert(x,param) param_unconvert(x,param)
x |
vector, matrix or raster-object holding byte-data that that should be converted to absolute values ( |
param |
Character string indicating parameter of the dataset to be treated. See |
Robert K. Bauer
library('fields') path <- system.file("test_files", package="oceanmap") gz.file <- Sys.glob(paste0(path,'/*.gz'))[1] # load sample-'.gz'-files param <- name_split(gz.file)$parameter print(param) ## converted data, according to param information m <- readbin(gz.file, Raster=FALSE) image.plot(m) ## byte data ("unconverted") according to param information, as stored in ".gz"files bin <- param_unconvert(m,param) image.plot(bin) ## reconverting byte data, according to param information conv <- param_convert(bin,param) image.plot(conv)
library('fields') path <- system.file("test_files", package="oceanmap") gz.file <- Sys.glob(paste0(path,'/*.gz'))[1] # load sample-'.gz'-files param <- name_split(gz.file)$parameter print(param) ## converted data, according to param information m <- readbin(gz.file, Raster=FALSE) image.plot(m) ## byte data ("unconverted") according to param information, as stored in ".gz"files bin <- param_unconvert(m,param) image.plot(bin) ## reconverting byte data, according to param information conv <- param_convert(bin,param) image.plot(conv)
a dataframe containing definitions of parameters to plot or to save by v, readbin and writebin.
data(parameter_definitions)
data(parameter_definitions)
data.frame
a dataframe with the following header, containing definitions of parameters to plot or to save by v, readbin and writebin:
param a b c log name1 unit pal1 minv maxv min max invalid_data_dc coast_dc land_dc no_data_dc
param |
character string indicating the keyword of a parameter. |
a , b , c
|
value for parameter parameter data conversion from/to byte data. (See param_convert and param_unconvert) |
log |
whether a logarithmic formula should be applied for data conversion (0 for |
name |
character string indicating the long name of a parameter. |
unit |
character string or bgroup statement indicating the parameter unit. |
pal1 |
default color map used by |
minv , maxv
|
default minimum and maximum z-value used by |
min , max
|
minimum and maximum byte-values to be considered when calculating absolute values. |
invalid_data_dc , coast_dc , land_dc & no_data_dc
|
byte values used to mask invalid data, coast lines, land masses and missing data. |
Robert K. Bauer
## Example data(parameter_definitions) head(parameter_definitions) # selecting sea surface temperature parameter definition parameter_definitions[parameter_definitions$param == "sst2",]
## Example data(parameter_definitions) head(parameter_definitions) # selecting sea surface temperature parameter definition parameter_definitions[parameter_definitions$param == "sst2",]
plots the landmask of a region defined by a region
-key word, georgraphical coordinates (lon
gitude and lat
itude), a raster- or extent-object. See add.region to add and save new region definitions. Attention! Unlike add.region, plotmap
does not include colorbar placement (see: set.colorbar)
plotmap(region=v_area, lon, lat, add=F, asp, grid=T, grid.res, resolution=0, main, axes=T, axeslabels=axes, ticklabels=T, cex.lab=0.8, cex.ticks=0.8, fill.land=T, col.land="grey", col.bg=NA, border='black', bwd=2, las=1, v_area, xlim, ylim ) ggplotmap(region=v_area, lon=xlim, lat=ylim, add_to, asp, grid=T, grid.res, resolution=0, main, axes=T, axeslabels=axes, ticklabels=T, fill.land=T, col.land="grey", col.bg=NA, border='black', col.scale = "black", bwd=1.5, v_area, xlim, ylim)
plotmap(region=v_area, lon, lat, add=F, asp, grid=T, grid.res, resolution=0, main, axes=T, axeslabels=axes, ticklabels=T, cex.lab=0.8, cex.ticks=0.8, fill.land=T, col.land="grey", col.bg=NA, border='black', bwd=2, las=1, v_area, xlim, ylim ) ggplotmap(region=v_area, lon=xlim, lat=ylim, add_to, asp, grid=T, grid.res, resolution=0, main, axes=T, axeslabels=axes, ticklabels=T, fill.land=T, col.land="grey", col.bg=NA, border='black', col.scale = "black", bwd=1.5, v_area, xlim, ylim)
region , v_area
|
Character string identifying regions predefined by the region_definitions-dataset, Raster* or Extent object (corresponds to |
lon , xlim
|
Vector returning longitude coordinates of the area to be plotted. |
lat , ylim
|
Vector returning latitude coordinates of the area to be plotted. |
add , add_to
|
whether the a the landmask should be added to an existent figure (default is |
asp |
numeric, giving the aspect y/x-ratio of the y- and x-axes. See plot.window for more details. |
main |
title to be plotted |
axes , axeslabels
|
whether axes and axes-labels (longitude and latitude) should be plotted (default is |
ticklabels |
whether tick-labels should be added to the axes (default is |
cex.lab |
font size of axis labels |
cex.ticks |
font size of tick labels |
grid |
whether a grid should be plotted (default is |
grid.res |
resolution of the grid, in degrees (default is is derived from the region extent) |
resolution |
number that specifies the resolution with which to draw the map. Resolution 0 is the full resolution of the database [default]. Otherwise, just before polylines are plotted they are thinned: roughly speaking, successive points on the polyline that are within resolution device pixels of one another are collapsed to a single point (see the Reference for further details). Thinning is not performed if plot = FALSE or when polygons are drawn (fill = TRUE or database is a list of polygons). |
bwd |
width is of the axes bars (default is 1) |
fill.land |
whether the a the landmask should be filled by a color (default is |
col.land |
fill color of the landmask to be plotted (default is grey) |
col.bg |
background color (ocean) to be plotted (default is NA) |
border |
country border color of the landmask to be plotted (default is black) |
col.scale |
color of the map scale to be plotted around the map (default is black) |
las |
numeric in {0,1,2,3}; the style of axis labels
|
plotmap
uses the maps
and maptools
functions to plot the landmask.
Robert K. Bauer
#### Example 1: plot landmask of the Mediterranean Sea ## a) by using longitude and latitude coordinates: lon <- c(-6, 37) lat <- c(30, 46) figure(width=9.75,height=5.28) plotmap(lon=lon, lat=lat, main="Mediterranean Sea") plotmap(xlim=lon, ylim=lat, main="Mediterranean Sea") ggobj <- ggplotmap(xlim=lon, ylim=lat) ggobj ## b) plot landmask of the Mediterranean Sea by using an extent-object: # library('raster') # ext <- extent(lon, lat) # plotmap(ext, main="Mediterranean Sea") # extent-object # ggplotmap(ext) ## c) plot landmask of the Mediterranean Sea by using a raster-object: # r <- raster(ext) # plotmap(r, main="Mediterranean Sea") # raster-object # ggplotmap(r) ## d) plot landmask of the Mediterranean Sea by using a region label: # plotmap('med4', main="Mediterranean Sea") # region-label # regions() ## check preinstalled region label ## e) add landmask to an existing plot: # plot(3.7008, 43.4079, xlim=lon, ylim=lat) # plotmap(add=T) # points(3.7008, 43.4079, pch=19) # ggplotmap(xlim=lon, ylim=lat) # library(ggplot2) # ggobj <- ggplotmap("lion") + # geom_point(data=data.frame(x=3.7008, y=43.4079),aes(x,y),size=5,colour="blue") # ggobj ## ggplotmaply(ggobj) ## f <- ggplotmaply(ggobj) ## pos <- as.data.frame(list(x=c(5.83, 4.91, 5.67, 5.91, 6.31, 6.37, ## 5.66, 5.54, 5.51, 5.67, 5.89, 5.97), ## y=c(42.89, 42.27, 42.42, 42.33, 42.1, 41.92, ## 41.74, 41.45, 41.32, 41.21, 41.04, 40.96) ## )) ## library(dplyr) ## library(plotly) ## f %>% add_trace(data = pos,x = ~x, y= ~y,type='scatter',mode='marker',name="new pos") #### Example 2: subplots and some additional arguments of plotmap() # par(mfrow=c(2, 1)) # plotmap('medw4', main="Western Mediterranean Sea",col.bg="darkblue") # plotmap('medw4', main="Western Mediterranean Sea", bwd=3, border='grey', grid=FALSE) #### Example 3: plotmap() and figure() # do.save <- FALSE ## open a plotting window # figure("Gulf_of_Lions_extended", do.save=do.save, width=5, height=5, type="pdf") # plotmap("lion",col.bg='darkblue',grid=FALSE) # close_fig(do.save) ## now resize figure manually and get new figure dimensions: # width <- dev.size()[1] # height <- dev.size()[2] # do.save <- TRUE ## do NOT open a plotting window, but save figure internally # figure("Gulf_of_Lions_extended", do.save=do.save, width=width, height=height, type="pdf") # plotmap("lion",col.bg='darkblue',grid=FALSE) # close_fig(do.save) #### Example 4: between hemispheres # par(mfrow=c(2,1)) # plotmap(lon=c(-180, 180), lat=c(-80, 80), main="map from West to East") # plotmap(lon=c(0, 360), lat=c(-80, 80), main="map from West to East") # plotmap(lon=c(-360, 00), lat=c(-80, 80), main="map from West to East") # same as before #### Example 5: plot bathymetry and topography of the western Mediterranean Sea #get.bathy("medw4",visualize=T,terrain=T,res=3) #get.bathy("medw4",visualize=T,terrain=F,res=3,levels=c(200,2000)) # show contours #get.bathy("lion",visualize=T,terrain=F,res=3,levels=c(200,2000),v_image=F) # show only contours #### Example 6: testing some additional arguments # lon <- c(-180,200); lat <- c(-80,90); # ext <- extent(lon, lat) # plotmap(ext, border=NA, bwd=NA, grid=FALSE, col.land = "#9ac0cd",axes=FALSE)
#### Example 1: plot landmask of the Mediterranean Sea ## a) by using longitude and latitude coordinates: lon <- c(-6, 37) lat <- c(30, 46) figure(width=9.75,height=5.28) plotmap(lon=lon, lat=lat, main="Mediterranean Sea") plotmap(xlim=lon, ylim=lat, main="Mediterranean Sea") ggobj <- ggplotmap(xlim=lon, ylim=lat) ggobj ## b) plot landmask of the Mediterranean Sea by using an extent-object: # library('raster') # ext <- extent(lon, lat) # plotmap(ext, main="Mediterranean Sea") # extent-object # ggplotmap(ext) ## c) plot landmask of the Mediterranean Sea by using a raster-object: # r <- raster(ext) # plotmap(r, main="Mediterranean Sea") # raster-object # ggplotmap(r) ## d) plot landmask of the Mediterranean Sea by using a region label: # plotmap('med4', main="Mediterranean Sea") # region-label # regions() ## check preinstalled region label ## e) add landmask to an existing plot: # plot(3.7008, 43.4079, xlim=lon, ylim=lat) # plotmap(add=T) # points(3.7008, 43.4079, pch=19) # ggplotmap(xlim=lon, ylim=lat) # library(ggplot2) # ggobj <- ggplotmap("lion") + # geom_point(data=data.frame(x=3.7008, y=43.4079),aes(x,y),size=5,colour="blue") # ggobj ## ggplotmaply(ggobj) ## f <- ggplotmaply(ggobj) ## pos <- as.data.frame(list(x=c(5.83, 4.91, 5.67, 5.91, 6.31, 6.37, ## 5.66, 5.54, 5.51, 5.67, 5.89, 5.97), ## y=c(42.89, 42.27, 42.42, 42.33, 42.1, 41.92, ## 41.74, 41.45, 41.32, 41.21, 41.04, 40.96) ## )) ## library(dplyr) ## library(plotly) ## f %>% add_trace(data = pos,x = ~x, y= ~y,type='scatter',mode='marker',name="new pos") #### Example 2: subplots and some additional arguments of plotmap() # par(mfrow=c(2, 1)) # plotmap('medw4', main="Western Mediterranean Sea",col.bg="darkblue") # plotmap('medw4', main="Western Mediterranean Sea", bwd=3, border='grey', grid=FALSE) #### Example 3: plotmap() and figure() # do.save <- FALSE ## open a plotting window # figure("Gulf_of_Lions_extended", do.save=do.save, width=5, height=5, type="pdf") # plotmap("lion",col.bg='darkblue',grid=FALSE) # close_fig(do.save) ## now resize figure manually and get new figure dimensions: # width <- dev.size()[1] # height <- dev.size()[2] # do.save <- TRUE ## do NOT open a plotting window, but save figure internally # figure("Gulf_of_Lions_extended", do.save=do.save, width=width, height=height, type="pdf") # plotmap("lion",col.bg='darkblue',grid=FALSE) # close_fig(do.save) #### Example 4: between hemispheres # par(mfrow=c(2,1)) # plotmap(lon=c(-180, 180), lat=c(-80, 80), main="map from West to East") # plotmap(lon=c(0, 360), lat=c(-80, 80), main="map from West to East") # plotmap(lon=c(-360, 00), lat=c(-80, 80), main="map from West to East") # same as before #### Example 5: plot bathymetry and topography of the western Mediterranean Sea #get.bathy("medw4",visualize=T,terrain=T,res=3) #get.bathy("medw4",visualize=T,terrain=F,res=3,levels=c(200,2000)) # show contours #get.bathy("lion",visualize=T,terrain=F,res=3,levels=c(200,2000),v_image=F) # show only contours #### Example 6: testing some additional arguments # lon <- c(-180,200); lat <- c(-80,90); # ext <- extent(lon, lat) # plotmap(ext, border=NA, bwd=NA, grid=FALSE, col.land = "#9ac0cd",axes=FALSE)
raster2matrix
converts a raster layer to a matrix or array. Used by readbin and writebin.
raster2matrix(RasterLayer) raster2array(RasterLayer)
raster2matrix(RasterLayer) raster2array(RasterLayer)
RasterLayer |
raster layer to be converted. |
Robert K. Bauer
library('raster') path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files check_gzfiles(folder=path) # return file summary-table raster.file <- readbin(gz.files[1]) # loading gz-file as raster-layer image(raster.file) ## Example 1: converting single raster layer to matrix image(as.matrix(raster.file)) # unflipped conversion m <- raster2matrix(raster.file) # converting raster-layer to matrix image(m) ## Example 2: converting double raster layer to an array stack.file <- stack(raster.file,raster.file) image(as.array(stack.file)[,,1]) # unflipped conversion a <- raster2array(stack.file) # converting raster-layer to array (works also with raster2matrix) image(a[,,1])
library('raster') path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files check_gzfiles(folder=path) # return file summary-table raster.file <- readbin(gz.files[1]) # loading gz-file as raster-layer image(raster.file) ## Example 1: converting single raster layer to matrix image(as.matrix(raster.file)) # unflipped conversion m <- raster2matrix(raster.file) # converting raster-layer to matrix image(m) ## Example 2: converting double raster layer to an array stack.file <- stack(raster.file,raster.file) image(as.array(stack.file)[,,1]) # unflipped conversion a <- raster2array(stack.file) # converting raster-layer to array (works also with raster2matrix) image(a[,,1])
'.gz'
-file as matrix or raster-objectReturns '.gz'
-file as matrix or raster-object.
readbin(filename, area, Image = F, byte = F, Raster = T)
readbin(filename, area, Image = F, byte = F, Raster = T)
filename |
Character string indicating search criteria for the
See region_definitions for valid area- and parameter_definitions for valid |
Image |
whether the a the |
byte |
whether the a the data of the |
Raster |
whether the a the data of the |
area |
Character string identifying the region that should be extracted. If missing, region is derived from the |
Robert K. Bauer
writebin, regions, crop, raster2matrix, param_convert
### Example: read and plot '.gz'-file path <- system.file("test_files", package="oceanmap") check_gzfiles(folder=path) # return file summary-table gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files ### all manual: obj <- readbin(gz.files[2],area='lion') obj ticks <- seq(20,30,5) data('cmap') image(obj,zlim=range(ticks),col=cmap$jet) plotmap('lion',add=TRUE) # add landmask #set.colorbar(ticks=ticks,cb.title='cb.title',cb.xlab='cb.xlab') ### using v: ## ticks set by adaptive.vals v(obj,varname="sst2",cb.title='cb.title',cb.xlab='cb.xlab') ## ticks set by parameter definition v(obj,varname="sst2",cb.title='cb.title',cb.xlab='cb.xlab',adaptive.vals=FALSE) ### extracting subregion: obj <- readbin(gz.files[2]) area.extent <- extent(c(5,10,35,40)) subarea <- crop(obj,area.extent) # v(subarea) ## getting average value: mean(subarea[,],na.rm=TRUE)
### Example: read and plot '.gz'-file path <- system.file("test_files", package="oceanmap") check_gzfiles(folder=path) # return file summary-table gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files ### all manual: obj <- readbin(gz.files[2],area='lion') obj ticks <- seq(20,30,5) data('cmap') image(obj,zlim=range(ticks),col=cmap$jet) plotmap('lion',add=TRUE) # add landmask #set.colorbar(ticks=ticks,cb.title='cb.title',cb.xlab='cb.xlab') ### using v: ## ticks set by adaptive.vals v(obj,varname="sst2",cb.title='cb.title',cb.xlab='cb.xlab') ## ticks set by parameter definition v(obj,varname="sst2",cb.title='cb.title',cb.xlab='cb.xlab',adaptive.vals=FALSE) ### extracting subregion: obj <- readbin(gz.files[2]) area.extent <- extent(c(5,10,35,40)) subarea <- crop(obj,area.extent) # v(subarea) ## getting average value: mean(subarea[,],na.rm=TRUE)
dataset providing spatial extent and color bar placement information by a region-keyword in later related function-calls (see: v, plotmap and regions). Information consists of a region-keyword, -longname, its spatial extent (longitudes and latitudes), grid resolution, as well as default colorbar position and figure size. Region definitions can be added, backed up or restored by add.region or deleted by calling delete.region.
ATTENTION! When reinstalling or updating the oceanmap package, previous region definitions are getting lost! It is therefore highly recommanded to take and restore own backups (see: backup
and restore
).
data(region_definitions)
data(region_definitions)
data.frame
dataframe with the following header, containing the summary information of the region specified:
label name latn lats lonw lone ncol nrow px cbx1 cbx2 cby1 cby2 gradient oticks figxdim figydim grid.res
label |
region-keywords |
name |
the long name of the region |
latn & lats |
northern and southern most latitude of the region |
lonw & lone |
western and eastern most longitude of the region |
ncol , nrow & px
|
default matrix size per region described by the number of columns, rows and pixels. ATTENTION!! Regions of the same spatial extent but different default (matrix-) resolution may cause errors when reading or writing '.gz'-files and must therefore be distinguished by different keywords. |
cbx1 & cbx2 |
x-coordinates for colorbar |
cby1 & cby2 |
y-coordinates for colorbar |
gradient |
the color- |
oticks |
the margin where the colorbar ticks should be plotted, relative to the colorbar rectangle ( |
figxdim & figydim |
the region-specific default plot device size (width and height in inches) |
grid.res |
the default grid resolution in degrees |
Robert K. Bauer
See add.region
to add new, backup or restore region definitions, and plotmap
for basic landmask plots
data(region_definitions) head(region_definitions) region_definitions$label # ?region_definitions # figure(width=15,height=15) # par(mfrow=c(5,6)) # for(n in region_definitions$label) plotmap(region = n,main=n) # Mediterranean Sea with a spatial resolution of 4km (e.g. MODIS-Aqua) region_definitions[region_definitions$label == 'med4',] # Mediterranean Sea with a spatial resolution of 9km (e.g. dekkar) region_definitions[region_definitions$label == 'med9',] # plotting same landmasks by different region-keywords plotmap('med4') plotmap('med9') ## Example for selecting wrong area definition when saving files path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/med4*.gz')) # load sample-med4'.gz'-files fname <- name_split(gz.files[1]) param <- fname$parameter gz <- readbin(gz.files[1]) dim(gz) v(gz.files[1]) ## reset region name # fname$area <- 'med9' # fname <- name_join(fname) # writebin(gz,fname,param=param) # v(fname,folder=".") # system(paste('rm', fname))
data(region_definitions) head(region_definitions) region_definitions$label # ?region_definitions # figure(width=15,height=15) # par(mfrow=c(5,6)) # for(n in region_definitions$label) plotmap(region = n,main=n) # Mediterranean Sea with a spatial resolution of 4km (e.g. MODIS-Aqua) region_definitions[region_definitions$label == 'med4',] # Mediterranean Sea with a spatial resolution of 9km (e.g. dekkar) region_definitions[region_definitions$label == 'med9',] # plotting same landmasks by different region-keywords plotmap('med4') plotmap('med9') ## Example for selecting wrong area definition when saving files path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/med4*.gz')) # load sample-med4'.gz'-files fname <- name_split(gz.files[1]) param <- fname$parameter gz <- readbin(gz.files[1]) dim(gz) v(gz.files[1]) ## reset region name # fname$area <- 'med9' # fname <- name_join(fname) # writebin(gz,fname,param=param) # v(fname,folder=".") # system(paste('rm', fname))
Reorganizes summary information of a specified region from the region_definitionsset into a two-row dataframe. Region definitions can be added, backed up or restored by add.region or deleted by calling delete.region.
ATTENTION! When reinstalling or updating the oceanmap package, previous region definitions are getting lost! It is therefore highly recommanded to take and restore own backups (see: backup
and restore
).
regions(label)
regions(label)
label |
Character string indicating the name of the region of interest. If missing, list of available regions in the region_definitions-dataset will be returned by a error message. |
a two-row dataframe with the following header, containing the summary information of the region specified:
xlim
ylim
dim
name
cbx
cby
align
gradient
figdim
grid.res
xlim & ylim |
the spatial extent of the region |
dim |
the number of grid points for both x & y-dimension |
name |
the long name of the region |
cbx & cby |
x & y-coordinates for colorbar |
align |
a vector defining the color- |
figdim |
the region-specific default plot device size |
grid.res |
the default grid resolution in degrees |
Robert K. Bauer
## Example: return summary table for the Gulf of Lions data('region_definitions') region_definitions[region_definitions$label=='lion',] # select raw region data summary regions('lion') # return formatted summary table
## Example: return summary table for the Gulf of Lions data('region_definitions') region_definitions[region_definitions$label=='lion',] # select raw region data summary regions('lion') # return formatted summary table
Adds colorbar to an extisting plot device. If position vectors are not provided, the user will be asked to define the colorbar placement by the mouse cursor.
set.colorbar(cbx, cby, cbpos, cbline=0, pal='jet', zlim, ticks=1:10, labels=ticks, gradient, oticks, cb.title="", cb.xlab="", font=1, cex=1, cex.cb.title=0.9, cex.cb.xlab=0.8, cex.cb.ticks=0.7, cb.ticks.srt=90, cb.ticks.length, cb.ticks.ypos, cb.ticks.lwd=1, integer=F, cb.xlab.line=0, total.reg, cbxp, cbyp,...) set.colorbarp(cbxp, cbyp, total.reg=T, year_bar=F, pal="jet",...)
set.colorbar(cbx, cby, cbpos, cbline=0, pal='jet', zlim, ticks=1:10, labels=ticks, gradient, oticks, cb.title="", cb.xlab="", font=1, cex=1, cex.cb.title=0.9, cex.cb.xlab=0.8, cex.cb.ticks=0.7, cb.ticks.srt=90, cb.ticks.length, cb.ticks.ypos, cb.ticks.lwd=1, integer=F, cb.xlab.line=0, total.reg, cbxp, cbyp,...) set.colorbarp(cbxp, cbyp, total.reg=T, year_bar=F, pal="jet",...)
cbx , cby
|
( |
cbxp , cbyp
|
( |
cbpos |
letter ("b", "l", "t", "r") indicating the position of the colorbar (bottom, left, top, right). Overwrites |
cbline |
distance to default location of the colorbar, starting at 0. |
total.reg |
( |
year_bar |
whether to plot a colorbar with monthly ticks (by default |
pal |
color map to be plotted (default is |
zlim |
(optional) value limits of the color bar. Overwrites ticks if ticks are povided. |
ticks |
the points at which tick-marks are to be drawn (default is 1:10). Non-finite (infinite, NaN or NA) values are omitted. Gets verwritten by zlim if povided. |
labels |
character or expression vector of labels to be placed at the tickpoints. (default equals |
gradient |
whether to have a horizontal (x) or vertical (y) color gradient. |
oticks |
the margin where to put the colorbar ticks relative to the colorbar rectangle ( |
cb.title |
character string indicating the title of the colorbar (default is set to date information/empty string if date information is missing.) |
cb.xlab |
character string indicating the x-axis label of the colorbar. |
font |
Integer specifying font to use for text. 1=plain [default], 2=bold, 3=italic, 4=bold italic, 5=symbol |
cb.xlab.line |
line of x-axis colorbar label |
cex , cex.cb.title , cex.cb.xlab , cex.cb.ticks
|
cex: general font size, used as reference for colorbar labels and title cex.cb.xlab: font size of the x-axis label of the colorbar cex.cb.title: font size of the title of the colorbar |
cb.ticks.srt , cb.ticks.length , cb.ticks.ypos , cb.ticks.lwd
|
rotation, length, relative y-position and line width of colorbar ticks |
integer |
(default is |
... |
additional arguments to be passed to text or |
set.colobar
adds a colorbar to the current plot device. If colorbar positions are missing (cbx
, cby
), the user will be asked for manual placement. ticks
and tick-labels
should correspond to zlim
-values of the plot. pal
defines the colormap and should equal col
of the selected plot.
a list of colorbar definition vectors: oticks, gradient, cbx
and cby
. See function argmuments for more details.
Robert K. Bauer
## Example 1: plot colorbars manually par(mar=c(8,8,8,8)) plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1)) set.colorbar(cbx=c(0, 1), cby=c(-.3, -.4)) # bottom set.colorbar(cby=c(0, 1), cbx=c(-.4, -.3)) # left set.colorbar(cbx=c(0, 1), cby=c(1.2, 1.3)) # top set.colorbar(cby=c(0, 1), cbx=c(1.2, 1.3)) # right ## Example 2: use cbpos par(mar=c(8,8,8,8)) plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1)) set.colorbar(cbpos='b') # bottom set.colorbar(cbpos='l') # left set.colorbar(cbpos='t') # top set.colorbar(cbpos='r') # right ## Example 3: interactive placement # par(mar=c(8,8,8,8)) # plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1)) # cb <- set.colorbar() # interactive # plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1)) # set.colorbar(cbx=cb$cbx, cby=cb$cby) # reuse stored colorbar positions
## Example 1: plot colorbars manually par(mar=c(8,8,8,8)) plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1)) set.colorbar(cbx=c(0, 1), cby=c(-.3, -.4)) # bottom set.colorbar(cby=c(0, 1), cbx=c(-.4, -.3)) # left set.colorbar(cbx=c(0, 1), cby=c(1.2, 1.3)) # top set.colorbar(cby=c(0, 1), cbx=c(1.2, 1.3)) # right ## Example 2: use cbpos par(mar=c(8,8,8,8)) plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1)) set.colorbar(cbpos='b') # bottom set.colorbar(cbpos='l') # left set.colorbar(cbpos='t') # top set.colorbar(cbpos='r') # right ## Example 3: interactive placement # par(mar=c(8,8,8,8)) # plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1)) # cb <- set.colorbar() # interactive # plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1)) # set.colorbar(cbx=cb$cbx, cby=cb$cby) # reuse stored colorbar positions
Returns a SpatialLines object, that defines a circle of radius r around a specified point.
SpatialCircle(x,y,r,n=100,proj4str)
SpatialCircle(x,y,r,n=100,proj4str)
x , y
|
x and y coordinates of the circle |
r |
radius (of the same scale as plotting window) |
n |
precision indicator of the circle. |
proj4str |
projection string. |
Robert K. Bauer
## Example 1: load & plot bathymetry of the Baltic Sea, defined by longitudes and latidtues lon <- c(9, 31) lat <- c(53.5, 66) # bathy <- get.bathy(lon=lon, lat=lat, main="Baltic Sea", cbpos='r') plotmap(lon=lon, lat=lat) spc <- SpatialCircle(x= 20,y = 57.5,r=1) plot(spc,add=TRUE) # get.avg.bathy(c(20,57.5), radius = 1, bathy = bathy) # get.avg(c(20,57.5), radius = 1, unit="km",raster = bathy)
## Example 1: load & plot bathymetry of the Baltic Sea, defined by longitudes and latidtues lon <- c(9, 31) lat <- c(53.5, 66) # bathy <- get.bathy(lon=lon, lat=lat, main="Baltic Sea", cbpos='r') plotmap(lon=lon, lat=lat) spc <- SpatialCircle(x= 20,y = 57.5,r=1) plot(spc,add=TRUE) # get.avg.bathy(c(20,57.5), radius = 1, bathy = bathy) # get.avg(c(20,57.5), radius = 1, unit="km",raster = bathy)
Plots spatial data (e.g. 2D oceanographic data). Valid input data are objects of class 'Raster' ('RasterLayer', 'RasterStack' or 'RasterBrick'), 'ncdf4' (already loaded netcdf files) or a character strings indicating 'bathy'
metric data, 'gz'- or '.nc-files' (netcdf).
See also name_split for further information on '.gz'
-file nomenclature.
## S4 method for signature 'bathy' v(obj, v_area, lon, lat, resolution=4, keep=F, savename.bathy, folder.bathy=".", adaptive.vals=T, cb.title, show.colorbar=T,...) ## S4 method for signature 'nc' v(obj, varname, t=1, layer=t, adaptive.vals=T, dates, cb.xlab=varname, show.colorbar=T ,...) ## S4 method for signature 'ncdf4' v(obj, varname, t=1, layer=t, adaptive.vals=T, dates, cb.xlab=varname, show.colorbar=T, ...) ## S4 method for signature 'RasterLayer' v(obj, varname, t=1, layer=t, ...) ## S4 method for signature 'RasterBrick' v(obj, varname, t=1, layer=t, ...) ## S4 method for signature 'RasterStack' v(obj, varname, t=1, layer=t, ...) ## S4 method for signature 'gz' v(obj, v_area, adaptive.vals=F, show.colorbar=T,...)
## S4 method for signature 'bathy' v(obj, v_area, lon, lat, resolution=4, keep=F, savename.bathy, folder.bathy=".", adaptive.vals=T, cb.title, show.colorbar=T,...) ## S4 method for signature 'nc' v(obj, varname, t=1, layer=t, adaptive.vals=T, dates, cb.xlab=varname, show.colorbar=T ,...) ## S4 method for signature 'ncdf4' v(obj, varname, t=1, layer=t, adaptive.vals=T, dates, cb.xlab=varname, show.colorbar=T, ...) ## S4 method for signature 'RasterLayer' v(obj, varname, t=1, layer=t, ...) ## S4 method for signature 'RasterBrick' v(obj, varname, t=1, layer=t, ...) ## S4 method for signature 'RasterStack' v(obj, varname, t=1, layer=t, ...) ## S4 method for signature 'gz' v(obj, v_area, adaptive.vals=F, show.colorbar=T,...)
obj |
object of class 'Raster' ('RasterLayer', 'RasterStack' or 'RasterBrick'), ' |
v_area |
character string identifying the region that should be plotted, or in case of |
adaptive.vals |
sets minimum and maximum z-value according to the |
t , layer
|
layer/time stemp to select in multi-layer files/objects (e.g. ncdf4, RasterStack). |
dates |
vector of type 'character' indicating dates per layer, used to define the title of the colorbar. Argument is omitted for |
varname |
character string indicating the name of the variable to plot. For |
cb.title |
character string indicating the title of the colorbar (default is set to date information/empty string if date information is missing.) |
cb.xlab |
character string indicating the x-axis label of the colorbar and |
lon |
Vector returning longitude coordinates of the area to be plotted, only valable for |
lat |
Vector returning latitude coordinates of the area to be plotted, only valable for |
resolution |
resolution of the bathymetric grid, in minutes (default is 4), only valable for |
keep |
whether to write the data downloaded from NOAA into a file (default is FALSE), only valable for |
savename.bathy |
savename for the bathymetric data file, if not specified set to type 'bathy_lon-lat_res.resolution.dat' or 'bathy_v_area_res.resolution.dat', only valable for |
folder.bathy |
directory where bathymetric data should be saved (default is current working directory), only valable for |
show.colorbar |
weather a colorbar should be plotted for image plots(default is |
... |
additional arguments to be passed:
|
v
uses the maps
and maptools
functions to plot the landmask. See clim_plot
for aligned plots of satallite-data climatologies.
Robert K. Bauer
Bauer, R. K., Stepputtis, D., Grawe, U., Zimmermann, C., and Hammer, C. 2013. Wind-induced variability in coastal larval retention areas: a case study on Western Baltic spring-spawning herring. Fisheries Oceanography, 22: 388-399.
clim_plot, readbin, name_split, regions, plotmap, v
################## simple example section: ## Example 1: load & plot a sample Raster-object path <- system.file("test_files", package="oceanmap") load(paste0(path,"/medw4_modis_sst2_4km_1d_20020705_20020705.r2010.0.qual0.Rdata"),verbose=TRUE) dat <- raster::crop(dat,extent(c(0,10,40,44))) ## crop data, xlim/ylim not yet implemented in v() print(dat) v(dat, main="Raster-object", cbpos='r') ## Example 2: load & plot sample netcdf-file ('.nc'-file) nfiles <- Sys.glob(paste0(path,'/*.nc')) # load list of sample-'.nc'-files head(nfiles) ### option a) load netcdf-file with ncdf4-package and plot it library('ncdf4') ncdf <- nc_open(nfiles[1]) # print(ncdf) # v(obj = ncdf, cbpos="r") ### option b) load and plot netcdf-file as RasterStack object # nc <- nc2raster(nfiles[1]) # v(nc,cbpos="r") # plot RasterStack object ### option c) plot netcdf-file directly # v(nfiles[1], cbpos="r") # v(nfiles[1], cbpos="r", replace.na=TRUE) ###### plot multiple layers: # par(mfrow=c(2,2)) # v(nfiles[1], t=1:4, cbpos="r", replace.na=TRUE, subplot = TRUE) # ## Example 2: load & plot bathymetry data from the NOAA-ETOPO1 database # par(mfrow=c(2,1)) # bathy <- get.bathy("medw4", terrain=T, res=3, keep=T, visualize=T, subplot = TRUE, grid=F) # # load('bathy_medw4_res.3.dat',verbose = T); bathy <- h # v(bathy, param="bathy", subplot = TRUE, terrain=F, levels=c(200,2000)) # show contours # # ## b) only contour lines: # par(mfrow=c(1,2)) # h <- get.bathy("lion",terrain=F,res=3, visualize=T, # v_image = FALSE, levels=c(200,2000)) # # ## use v-function for same plot but on subregion: # v(h,v_area = "survey", param="bathy", # v_image = FALSE, levels=c(200,2000)) ## Example 3: plot sample-'.gz'-file gz.files <- Sys.glob(paste0(path,'/*.gz')) # v(gz.files[2]) ## plot content of gz-file ## Example 4: load sample-'.gz'-file manually as Raster-object and plot it obj <- readbin(gz.files[2],area='lion') # par(mfrow=c(1,2)) # v(obj,param="sst",subplot = TRUE) # v(obj,param="Temp",subplot = TRUE) ## note unset "pal" (colormap) for unkown "param"-values! ## Example 5: available color maps data('cmap') # load color maps data names(cmap) # list available color maps gz.files <- Sys.glob(paste0(path,'/*.gz')) # figure(width=15,height=15) # par(mfrow=c(4,5)) # for(n in names(cmap)) v(gz.files[2], v_area='lion', subplot=TRUE, # pal=n, adaptive.vals=TRUE, main=n) ## define new color maps from blue to red to white: n <- colorRampPalette(c('blue','red','white'))(100) # v(gz.files[2], v_area='lion', subplot=TRUE, # pal=n, adaptive.vals=TRUE, main="own colormap") ## Example 6: available parameters data(parameter_definitions) names(parameter_definitions) # ?parameter_definitions # figure(width=12, height=6.2) # par(mfrow=c(2,3)) # v('*sst2*707*',v_area="medw4",main="sst", folder=path, subplot=TRUE) # v('*chla*531*',v_area="medw4",main="chla", folder=path, subplot=TRUE) # v('*chlagrad*',v_area="medw4",main="chlagrad",folder=path, subplot=TRUE) # v('*p100*',v_area="medw4",main="p100 (oceanic fronts)",folder=path, subplot=TRUE) # v('*sla*',v_area="medw4",main="sla",folder=path, subplot=TRUE) # h <- get.bathy("medw4",visualize=TRUE,terrain=F,res=4, subplot=TRUE,main="bathy") ################## advanced example section: ## Example I: plot bathymetry using a v_area-keyword ## requires server connection! # par(mfrow=c(2,1)) # v("bathy","lion",res=4, keep=TRUE,border='grey', # main='Gulf of Lions bathymetry',cb.title="resolution 4 min") # v("bathy","lion",res=1, keep=TRUE,border='grey', # cb.title="resolution 1 min") # can take some time depending on server connection! ## Example II: plot bathymetry of the Baltic Sea defined by longitude and latidtue coordinates ## requires server connection! lon <- c(9, 31) lat <- c(53.5, 66) #v("bathy",lon=lon,lat=lat,main="Baltic Sea") ## Example III: plot landmask of the Baltic Sea defined by an extent- or raster-object ## requires server connection! library('raster') ext <- extent(lon,lat) # v("bathy",ext,main="Baltic Sea",res=4,levels=200) # extent-object ## Example IV: plot '.gz'-files, following default plot-procedure check_gzfiles(folder=path) # return file summary-table gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files # v(gz.files[1:4]) # v(gz.files[4],bwd=2) ## Example V: plot climatologies from '.gz'-files ## (ATTENTION: not working for non-'gz'-files, requiring ImageMagick) # clim_plot('*1s*.gz' ,folder = path,bwd=0.7,adaptive.vals=TRUE,plotname="seasonal_climatology.png") ## Example VI: plot subregion of gz-files as subplots # graphics.off() # par(mfrow=c(2,1)) # v(gz.files[1:2],v_area='lion') # run ?region_definitions to see predefined regions ## Example VII: plot subregion of raster file # all manual: obj <- readbin(gz.files[2],area='lion') dev.new() ticks <- seq(20,30,5) par(mar=c(5,4,5,8)) image(obj,zlim=range(ticks),col=cmap$jet) plotmap('lion',add=TRUE) # add landmask # set.colorbar(ticks=ticks,cb.title='cb.title',cb.xlab='cb.xlab') ## using v, reconstructing region information # obj <- readbin(gz.files[2],area='lion') # v(obj,varname="sst2",cb.title='cb.title',cb.xlab='cb.xlab') # using v for another subregion ncorse <- crop(obj,extent(6,9,40,42)) # v(ncorse,grid.res=1) # v(ncorse,zlim=c(20,30),cbx=c(8.3,8.9),cby=c(40.7,40.8)) # skipping colorbar widget ## Example VIII: Add region by supplying raster-object, colorbar positions and running the widget #add.region(ncorse,cbx=c(8.3,8.9),cby=c(40.7,40.8)) ## Example IX: plot netcdf-files ('.nc'-files) nfiles <- Sys.glob(paste0(path,'/*.nc')) # load sample-'.nc'-files head(nfiles) ## plot herring larval dispersal from Bauer et al. (2013) # par(mfrow=c(2,2)) # v(nfiles[1], subplot=TRUE, t=1:4,minv=0, maxv=1000, adaptive.vals=FALSE, replace.na=TRUE) # par(new=TRUE,mfrow=c(1,1)) # empty.plot(main='herring larval dispersal in the Greifswald lagoon, Germany') # mtext('see Bauer et al. (2013) as reference') # plot bathymetric data (obtained from the Leibniz Institute for Baltic Sea Research Warnemuende) # v(nfiles[2],varname='bathymetry') # following default plot-procedure # v(nfiles[2],varname='bathymetry',pal='haxbyrev',Log=TRUE, cb.xlab='depth [log m]',levels=50)
################## simple example section: ## Example 1: load & plot a sample Raster-object path <- system.file("test_files", package="oceanmap") load(paste0(path,"/medw4_modis_sst2_4km_1d_20020705_20020705.r2010.0.qual0.Rdata"),verbose=TRUE) dat <- raster::crop(dat,extent(c(0,10,40,44))) ## crop data, xlim/ylim not yet implemented in v() print(dat) v(dat, main="Raster-object", cbpos='r') ## Example 2: load & plot sample netcdf-file ('.nc'-file) nfiles <- Sys.glob(paste0(path,'/*.nc')) # load list of sample-'.nc'-files head(nfiles) ### option a) load netcdf-file with ncdf4-package and plot it library('ncdf4') ncdf <- nc_open(nfiles[1]) # print(ncdf) # v(obj = ncdf, cbpos="r") ### option b) load and plot netcdf-file as RasterStack object # nc <- nc2raster(nfiles[1]) # v(nc,cbpos="r") # plot RasterStack object ### option c) plot netcdf-file directly # v(nfiles[1], cbpos="r") # v(nfiles[1], cbpos="r", replace.na=TRUE) ###### plot multiple layers: # par(mfrow=c(2,2)) # v(nfiles[1], t=1:4, cbpos="r", replace.na=TRUE, subplot = TRUE) # ## Example 2: load & plot bathymetry data from the NOAA-ETOPO1 database # par(mfrow=c(2,1)) # bathy <- get.bathy("medw4", terrain=T, res=3, keep=T, visualize=T, subplot = TRUE, grid=F) # # load('bathy_medw4_res.3.dat',verbose = T); bathy <- h # v(bathy, param="bathy", subplot = TRUE, terrain=F, levels=c(200,2000)) # show contours # # ## b) only contour lines: # par(mfrow=c(1,2)) # h <- get.bathy("lion",terrain=F,res=3, visualize=T, # v_image = FALSE, levels=c(200,2000)) # # ## use v-function for same plot but on subregion: # v(h,v_area = "survey", param="bathy", # v_image = FALSE, levels=c(200,2000)) ## Example 3: plot sample-'.gz'-file gz.files <- Sys.glob(paste0(path,'/*.gz')) # v(gz.files[2]) ## plot content of gz-file ## Example 4: load sample-'.gz'-file manually as Raster-object and plot it obj <- readbin(gz.files[2],area='lion') # par(mfrow=c(1,2)) # v(obj,param="sst",subplot = TRUE) # v(obj,param="Temp",subplot = TRUE) ## note unset "pal" (colormap) for unkown "param"-values! ## Example 5: available color maps data('cmap') # load color maps data names(cmap) # list available color maps gz.files <- Sys.glob(paste0(path,'/*.gz')) # figure(width=15,height=15) # par(mfrow=c(4,5)) # for(n in names(cmap)) v(gz.files[2], v_area='lion', subplot=TRUE, # pal=n, adaptive.vals=TRUE, main=n) ## define new color maps from blue to red to white: n <- colorRampPalette(c('blue','red','white'))(100) # v(gz.files[2], v_area='lion', subplot=TRUE, # pal=n, adaptive.vals=TRUE, main="own colormap") ## Example 6: available parameters data(parameter_definitions) names(parameter_definitions) # ?parameter_definitions # figure(width=12, height=6.2) # par(mfrow=c(2,3)) # v('*sst2*707*',v_area="medw4",main="sst", folder=path, subplot=TRUE) # v('*chla*531*',v_area="medw4",main="chla", folder=path, subplot=TRUE) # v('*chlagrad*',v_area="medw4",main="chlagrad",folder=path, subplot=TRUE) # v('*p100*',v_area="medw4",main="p100 (oceanic fronts)",folder=path, subplot=TRUE) # v('*sla*',v_area="medw4",main="sla",folder=path, subplot=TRUE) # h <- get.bathy("medw4",visualize=TRUE,terrain=F,res=4, subplot=TRUE,main="bathy") ################## advanced example section: ## Example I: plot bathymetry using a v_area-keyword ## requires server connection! # par(mfrow=c(2,1)) # v("bathy","lion",res=4, keep=TRUE,border='grey', # main='Gulf of Lions bathymetry',cb.title="resolution 4 min") # v("bathy","lion",res=1, keep=TRUE,border='grey', # cb.title="resolution 1 min") # can take some time depending on server connection! ## Example II: plot bathymetry of the Baltic Sea defined by longitude and latidtue coordinates ## requires server connection! lon <- c(9, 31) lat <- c(53.5, 66) #v("bathy",lon=lon,lat=lat,main="Baltic Sea") ## Example III: plot landmask of the Baltic Sea defined by an extent- or raster-object ## requires server connection! library('raster') ext <- extent(lon,lat) # v("bathy",ext,main="Baltic Sea",res=4,levels=200) # extent-object ## Example IV: plot '.gz'-files, following default plot-procedure check_gzfiles(folder=path) # return file summary-table gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files # v(gz.files[1:4]) # v(gz.files[4],bwd=2) ## Example V: plot climatologies from '.gz'-files ## (ATTENTION: not working for non-'gz'-files, requiring ImageMagick) # clim_plot('*1s*.gz' ,folder = path,bwd=0.7,adaptive.vals=TRUE,plotname="seasonal_climatology.png") ## Example VI: plot subregion of gz-files as subplots # graphics.off() # par(mfrow=c(2,1)) # v(gz.files[1:2],v_area='lion') # run ?region_definitions to see predefined regions ## Example VII: plot subregion of raster file # all manual: obj <- readbin(gz.files[2],area='lion') dev.new() ticks <- seq(20,30,5) par(mar=c(5,4,5,8)) image(obj,zlim=range(ticks),col=cmap$jet) plotmap('lion',add=TRUE) # add landmask # set.colorbar(ticks=ticks,cb.title='cb.title',cb.xlab='cb.xlab') ## using v, reconstructing region information # obj <- readbin(gz.files[2],area='lion') # v(obj,varname="sst2",cb.title='cb.title',cb.xlab='cb.xlab') # using v for another subregion ncorse <- crop(obj,extent(6,9,40,42)) # v(ncorse,grid.res=1) # v(ncorse,zlim=c(20,30),cbx=c(8.3,8.9),cby=c(40.7,40.8)) # skipping colorbar widget ## Example VIII: Add region by supplying raster-object, colorbar positions and running the widget #add.region(ncorse,cbx=c(8.3,8.9),cby=c(40.7,40.8)) ## Example IX: plot netcdf-files ('.nc'-files) nfiles <- Sys.glob(paste0(path,'/*.nc')) # load sample-'.nc'-files head(nfiles) ## plot herring larval dispersal from Bauer et al. (2013) # par(mfrow=c(2,2)) # v(nfiles[1], subplot=TRUE, t=1:4,minv=0, maxv=1000, adaptive.vals=FALSE, replace.na=TRUE) # par(new=TRUE,mfrow=c(1,1)) # empty.plot(main='herring larval dispersal in the Greifswald lagoon, Germany') # mtext('see Bauer et al. (2013) as reference') # plot bathymetric data (obtained from the Leibniz Institute for Baltic Sea Research Warnemuende) # v(nfiles[2],varname='bathymetry') # following default plot-procedure # v(nfiles[2],varname='bathymetry',pal='haxbyrev',Log=TRUE, cb.xlab='depth [log m]',levels=50)
'.gz'
)Saves geographic data as byte file, in gzip compressed format ('.gz'
). ATTENTION!! Only 2D (one layer) can be stored!
writebin(satdata,filename,folder,param)
writebin(satdata,filename,folder,param)
satdata |
|
param |
character string indicating the parameter name for the dataset treatment. See |
filename |
character string naming the |
folder |
character string indicating the target directory. |
Robert K. Bauer
readbin, regions, crop, raster2matrix, param_unconvert
## Example for selecting wrong area definition when saving files path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files v(gz.files[1]) fname <- name_split(gz.files[1]) param <- fname$parameter gz <- readbin(gz.files[1]) dim(gz) v(gz.files[1]) ### reset region name fname$area <- 'med9' fname <- name_join(fname) # writebin(gz,fname,folder=path,param=param) # v(fname) # system(paste('rm', fname)) ### multi layer raster file gz2 <- stack(gz,gz) # writebin(gz2,rep(gz.files[1],2),folder=path,param) # error message since multi layer # writebin(gz,gz.files[1],folder=path,param) # single layer raster file # v(gz.files[1])
## Example for selecting wrong area definition when saving files path <- system.file("test_files", package="oceanmap") gz.files <- Sys.glob(paste0(path,'/*.gz')) # load sample-'.gz'-files v(gz.files[1]) fname <- name_split(gz.files[1]) param <- fname$parameter gz <- readbin(gz.files[1]) dim(gz) v(gz.files[1]) ### reset region name fname$area <- 'med9' fname <- name_join(fname) # writebin(gz,fname,folder=path,param=param) # v(fname) # system(paste('rm', fname)) ### multi layer raster file gz2 <- stack(gz,gz) # writebin(gz2,rep(gz.files[1],2),folder=path,param) # error message since multi layer # writebin(gz,gz.files[1],folder=path,param) # single layer raster file # v(gz.files[1])