Finally I was able to find the CSS error in the toolbar layout which resulted in a visible gap when, e.g., the Flow editor was active. Now everything looks much better (see the red arrows!) especially when you install Eclipse plugins which make contributions to the main toolbar.
You can also add this corrections easily to a current Bio7 2.3 installation. Just add the following lines to the default Bio7 CSS (Path: Bio7/plugins/com.eco.bio7.themes_22.214.171.124508261732/css/e4_default_yourOperatingSystem.css):
Here I present a summary of a small spatstat workshop I created. I also explain in several videos how to transfer and convert 2d and 3D ImageJ measurements to a spatial point pattern with Bio7. The example datasets and code samples used here were taken from the spatstat help and from spatstat scripts cited at the end of the summary. The github repository with spatstat scripts, image scripts, documentation and more can be found here. I hope that this material is useful for others and helps in the creation of a spatial point pattern analysis with the fantastic spatstat package.
From the spatstat website:
‘spatstat is a package for analyzing spatial point pattern data. Its functionality includes exploratory data analysis, model-fitting, and simulation.’ (1)
The package supports:
creation, manipulation and plotting of point patterns
exploratory data analysis
simulation of point process models
hypothesis tests and model diagnostic
Classes in spatstat
To handle point pattern datasets and related data, the spatstat package supports the following classes of objects:
ppp: planar point pattern
owin: spatial region (‘observation window’)
im: pixel image
psp: pattern of line segments
pp3: three-dimensional point pattern
ppx: point pattern in any number of dimensions
lpp: point pattern on a linear network
Creation of a point pattern object
A point pattern object can be created easily from x and y coordinates.
# some arbitrary coordinates in [0,1]
x <- runif(20)
y <- runif(20)
# the following are equivalent
X <- ppp(x, y, c(0,1), c(0,1))
X <- ppp(x, y)
X <- ppp(x, y, window=owin(c(0,1),c(0,1)))
# specify that the coordinates are given in metres
X <- ppp(x, y, c(0,1), c(0,1), unitname=c("metre","metres"))
Study region (window)
Many commands in spatstat require us to specify a window, study region or domain!
An object of class “owin” (‘observation window’) represents a region or window (rectangular, polygonal with holes, irregular) in two dimensional space.
w <- owin(c(0,1), c(0,1))
# the unit square
w <- owin(c(10,20), c(10,30), unitname=c("foot","feet"))
# a rectangle of dimensions 10 x 20 feet
# with lower left corner at (10,10)
# polygon (diamond shape)
w <- owin(poly=list(x=c(0.5,1,0.5,0),y=c(0,1,2,1)))
w <- owin(c(0,1), c(0,2), poly=list(x=c(0.5,1,0.5,0),y=c(0,1,2,1)))
# polygon with hole
ho <- owin(poly=list(list(x=c(0,1,1,0), y=c(0,0,1,1)),
Task 1: Create a point pattern object from x,y data.
Task 2: Create a point pattern object within a specified window object.
Summary statistics of the dataset
## Planar point pattern: 71 points
## Average intensity 0.007395833 points per square unit (one unit = 0.1
## Coordinates are integers
## i.e. rounded to the nearest unit (one unit = 0.1 metres)
## Window: rectangle = [0, 96] x [0, 100] units
## Window area = 9600 square units
## Unit of length: 0.1 metres
Computes the distance from each point to its nearest neighbour in a point pattern.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.236 5.541 8.246 7.908 10.050 15.650
Finds the nearest neighbour of each point in a point pattern.
Video: Create a spatstat point pattern with a polygonal window (study region)
Task 1: Create a polygonal point pattern object from the image ‘Cell_Colony.jpeg’.
Marked point patterns
Points in a spatial point pattern may carry additional information called a ‘mark’. A mark can represent additional information like height, diameter, species, etc. It is important to know that marks are not covariates (the points are not a result of the mark values!).
#from the spatstat help:
m <- sample(1:2, 20, replace=TRUE)
m <- factor(m, levels=1:2)
X <- ppp(x, y, c(0,1), c(0,1), marks=m)
With Bio7 and ImageJ marked point patterns can be created with the ‘Selection’ action which can transfer a SpatialPointDataFrame which again can be converted to a marked point pattern.
Select points and transfer the selections to the ROI Manager
Measure the selections and transfer the ImageJ Results Table to R with the Image-Methods view ‘IJ RT’ action
Transfer the points of the ROI Manager as a SpatialPointsDataFrame (Enable the ‘Add selected data frame’ option and select the dataframe in the combobox)
Convert the SpatialPointsDataFrame to a spatstat point pattern object with the results table as marks
#print a summary!
## Marked planar point pattern: 8 points
## Average intensity 0.0002494232 points per square unit
## Coordinates are integers
## i.e. rounded to the nearest unit
## Mark variables: Area, Mean, Min, Max, X, Y
## Area Mean Min Max X
## Min. :0 Min. :160 Min. :160 Min. :160 Min. : 75.0
## 1st Qu.:0 1st Qu.:190 1st Qu.:190 1st Qu.:190 1st Qu.:124.9
## Median :0 Median :220 Median :220 Median :220 Median :198.5
## Mean :0 Mean :209 Mean :209 Mean :209 Mean :173.1
## 3rd Qu.:0 3rd Qu.:232 3rd Qu.:232 3rd Qu.:232 3rd Qu.:221.0
## Max. :0 Max. :248 Max. :248 Max. :248 Max. :233.5
## Min. : 27.50
## 1st Qu.: 63.25
## Median :119.25
## Mean :129.06
## 3rd Qu.:204.38
## Max. :230.00
## Window: rectangle = [75, 233] x [27, 230] units
## Window area = 32074 square units
You can also transfer a dataframe from the Table view of Bio7 (rows must be equal to the number of points!) and assign it to the point pattern.
Video: Create a spatstat marked point pattern:
Task 1: Create a marked point pattern from the image ‘Cell_Colony.jpg’.
Task 2: Create a marked point pattern from spreadsheet data in Bio7.
Tropical rainforest point pattern dataset bei. We want to find out if trees prefer a steep or flat terrain. The data consists of extra covariate data in ‘bei.extra’, which contains a pixel image of terrain elevation and a pixel image of terrain slope.
The plot below is an estimate of the intensity p(z) as a function of terrain slope z. It indicates that the Beilschmiedia trees are relatively unlikely to be found on flat terrain (where the slope is less than 0.05) compared to steeper slopes.
The study region is divided into rectangles (quadrats) of equal size, and the number of points in each rectangle is counted.
Fit a point process model to an observed point pattern.
# fit the stationary Poisson process
# to point pattern 'nztrees'
## Extracting model information...Evaluating trend...done.
## Checking arguments..determining simulation windows...
plot(modelFitted, main="Fitted Model")
Used for this script:
(1) A. Baddeley and R. Turner. Spatstat: an R package for analyzing spatial point patterns Journal of Statistical Software 12: 6 (2005) 1-42. www.jstatsoft.org ISSN: 1548-7660
(2) A. Baddeley and R. Turner. Modelling spatial point patterns in R. Chapter 2, pages 23-74 in In Case Studies in Spatial Point Pattern Modelling (eds. A. Baddeley, P. Gregori, J. Mateu, R. Stoica and D. Stoyan) Lecture Notes in Statistics 185. New York: Springer-Verlag 2006. ISBN: 0-387-28311-0
(3) A. Baddeley. Analysing Spatial Point Patterns in R. Workshop Notes, December 2010. Published online by CSIRO, Australia. Download here (232 pages, pdf, 12.2Mb)
As a result of the useR conference 2015 with fantastic workshops and presentations where I also presented my software I released a new version of Bio7 with many improvements and new features inspired by the R conference and important for the next ImageJ conference 2015 where I will give a Bio7 workshop.
For this release I didn’t bundle R for MacOSX (so R is easier to update, etc.).
So for MacOSX and Linux R and Rserve have to be installed. But this becomes very easy because Bio7 uses now the default OS systems paths which normally point to the default R installation (as long as no path in the Bio7 preferences is specified).
In addition some precompiled Rserve binaries (cooperative mode) are available and can be installed easily from within R – see the installation section below.
Added new R Markdown functionality – see video below (installation of ‘rmarkdown’, ‘knitr’ package and ‘pandoc’ binary required).
Added an option to use the JavaFX browser to open HTML markdown knitr documents to allow a fullscreen view (primary F1,F2, secondary F3, tertiary F4, quartary F5 monitor).
Added a simple default markdown editor to Bio7.
Added a new wizard for markdown documents.
In the ‘Navigator’ view you can now set the working dir of R (context menu action).
Added a new convert to list action in the context menu of the R-Shell.
Added a new default hidden „Custom“ perspective“ in which custom views can be opened in a predefined layout.
Added two new actions to open Bio7 views more easily (as a replacement for the disfunctional open view actions).
Improved the ImageJ ‘Zoom In’ and ‘Zoom Out’ action (now zooms correctly to the mouse pointer).
Improved the default paths for Linux and MacOSX.
Now the R system path, the R default library path and the pdflatex path is fetched from the PATH environment (as long as no specific location is set in the Bio7 preferences ).
Improved the installation of Rserve on Linux and Mac with precompiled Rserve libraries which can be installed easily from within R (R version 3.2.2 required!) .
Compiled Rserve in cooperative mode for MacOSX and Linux. This will make the installation process of Rserve very easy.
Deactivated some R editor options by default (can be enabled in the R preferences).
HTML GUI editor
Mouse selection now works again (thanks to Java 1.8.60).
ImageJ and R
Changed the variables names for the size of the image in the Particles transfer to ‘imageSizeX’, ‘imageSizeY’ (to be in accordance with the image matrix transfer).
Improved the ‘ImageMethods’ view ‘Selection’ action (see video below). Now it is opened as a view for multiple transfers.
Added new actions to transfer ImageJ selections as SpatialPolygons, SpatialLines or Spatial Points (or SpatialPolygonsDataframe, etc., if an available dataframe is selected). Selected objects can be transferred georeferenced if a georeferenced raster file (*.geotiff) is selected – see video below:
More stability improvements.
Fixed some Eclipse 4.5 bugs, feature? which opened an extra shell when opening an SWT ‘InputDialog’ class.
Improved the visual appearance of menus (menu size can be set in the Bio7 ImageJ preferences).
Improved the path to the native OS applications by using the systems path by default. So normally no paths have to be adjusted.
Improved the stability by fixing a bug/feature? in the Nebula grid spreadsheet components.
Now R has to be installed seperately. The default path will be fetched from the OS environment PATH (as long as no path is given in the preferences).
Rserve has to be installed from within R. A compiled binary is available and can be installed easily (see installation details below).
Fixed some Font bugs (especially for the console). Fonts can be customized in the default Bio7 CSS!
Updated Java to Jre 1.8.60.
Updated to version 1.50.a
Many other improvements and bug fixes for Linux and MacOSX and Bio7 in general (see the Bio7 Bitbucket repository for details).
Simply unzip the archive of Bio7 2.3 (Windows, Linux) in your preferred OS location. The MacOSX version can be installed easily with the available *.dmg file installer. To start the application simply double click on the Bio7 binary file.
R and Rserve installation
For Linux and MacOSX R and Rserve has to be installed. Bio7 will fetch the default paths from the OS System PATH (so hopefully no other adjustments have to be made).
Rserve has to be available in cooperative mode which can be installed from the Bio7 Bitbucket website from within R with:
As a result of the last UseR conference and some great spatial workshops and talks where I participated I decided to rework the selection dialog for the upcoming Bio7 2.3 to transfer ImageJ selection data as ‘Spatial Objects’ with the help of the package ‘sp‘ and the Java GDAL binding (version 1.7.1).
One reason to add this functionality is the great improvement for the use of the ‘spatstat’ package which I will present as part of a workshop at the next Imagej conference 2015 (I already gave a short overview of R and spatial packages in the 2012 conference).
In additon the supplied actions can help scientists which work with georeferenced data to profit from the wealth of ImageJ analyze methods and vice versa brings new maybe unknown GIS methods in the focus of microscopists.
The transferred objects can be converted easily to spatstat objects (ppp, psp, owin, etc.) and if equipped with a data frame converted to a marked point pattern.
Though it is already easy to convert ImageJ selections and image pixel data to spatstat objects in 2d and in 3d from ImageJ measurements with Bio7 the new actions make it easy to georeference the data (probably with some data dependent unknown limitations of projections of course – the Java API of GDAL emphasizes that for the used transform method) and add data frames to the spatial shapes (transferred ImageJ measurements data, created spreadsheet data, etc., available in the R workspace).
Below you can see a result of a dummy transfer of point data from a 7000*7000 georeferenced geotiff image where I selected and transferred points from a highly zoomed tiny region.
The right site of the image shows the selected (x,y) ImageJ selection. The left site shows the final converted (Lat, Lon) data loaded in the GIS software QGIS to control the pixel precision.
At all the georeferenced results seems to be exact in all test so far.
I think the new methods are a great help to transfer image measurements and selections to R ready for postprocessing with powerful spatial packages like, e.g., ‘spatstat’.