Package 'TreeRingShape'

Title: Recording Tree-Ring Shapes of Tree Disks with Manual Digitizing and Interpolating Model
Description: Record all tree-ring Shapefile of tree disk with GIS soft ('Qgis'<https://www.qgis.org/en/site/>) and interpolating model from high resolution tree disk image.
Authors: Megumi ISHIDA [aut, cre, cph]
Maintainer: Megumi ISHIDA <[email protected]>
License: GPL (>= 2)
Version: 3.0.5
Built: 2024-11-14 23:22:29 UTC
Source: https://github.com/ishidamgm/treeringshape

Help Index


Return a area from polygon xy coordinates

Description

Return a area from polygon xy coordinates

Usage

area(xy)

Arguments

xy

a atrix or data frame of xy coordinates

Value

a vector of polygon area

Examples

xy<-data.frame(x=c(0,1,2,1),y=c(1,2,1,0))
plot(xy,type="b") ; polygon(xy)
area(xy)

Return circumference length of polygon line

Description

Return circumference length of polygon line

Usage

circumference(l.)

Arguments

l.

data frame of line coordinates (x,y)

Value

a numeric of circumference length of polygon line

Examples

l. <- data.frame(x=c(0,0,1,1),y=c(0,1,1,0))
plot(l.,type="b") ; polygon(l.)
circumference(l.)

class of TreeRingShape

Description

class of TreeRingShape

Slots

P_filename

character. file name of shape file (P) for tree ring points

P_id.tag

character. column name of id in shape file (P), default is 'id'

P_ring.tag

character. column name of ring no.(ordinaly year,outermost=0) in shape file (P), default is 'ring'

P

data.frame. radial tree ring points (x,y,id,yr,r,deg)

P00

numeric. x,y coordinates c(px00,py00) of tree ring center point, ordinarily a pith in a disk, a point of id==0 in P

n_id

numeric. number of radial measurement points, length(unique(P$id))-1 (omit a original point id=0)

YR_P

numeric. total number of tree rings, unique(P$ring)

L_filename

character. file name of shape file (L) for tree ring lines

L_ring.tag

character. column name of ring no.(ordinaly year,outermost=0) in shape file (L), default is 'ring'

L

list. x,y coordinates of representative tree rings

L_

data.frame. x,y coordinates of representative tree rings

YR_L

numeric. cumulative tree rings number(year) from 0 (cambium layer) of L =dbf$ring, names(L)

ln

numeric. total number of representative tree rings, length(L)

L2_filename

character. file name of shape file (L2) for tree ring lines interpolated

L2

list. x,y coordinates of representative + interpolated tree rings

n_YR

numeric. total number of representative + interpolated tree rings = unique(P$yr), length(L2)

Examples

TR. <- new('classTreeRingShape')
 TR.
 slotNames(TR.)
 str(TR.)

Constant for conversion from degree to radian ####

Description

Constant for conversion from degree to radian ####

Usage

degree

Format

An object of class numeric of length 1.


Return information for tree disk analysed from TreeRingShape class

Description

Return information for tree disk analysed from TreeRingShape class

Usage

DiskInfo(TR., dpi = 1200)

Arguments

TR.

class of TreeRingShape

dpi

Resolution of tree disk image

Value

data frame of information for tree disk analysed

See Also

TreeRingShape


Return a vector of distances from original a point (0,0) from a matrix or data frame of xy coordinates

Description

Return a vector of distances from original a point (0,0) from a matrix or data frame of xy coordinates

Usage

dst(xy)

Arguments

xy

a matrix or data frame of xy coordinates

Value

a vector of distances from original a point

Examples

plot(TR@L[[1]])
plot(dst(TR@L[[1]]))

Return vector for distance between adjacent two points

Description

Return vector for distance between adjacent two points

Usage

dstpp(x, y)

Arguments

x

vector of x coordinates

y

vector of y coordinates

Value

vector for distance between adjacent two points

Examples

l.<-TR@L[[1]]
plot(l.)
x<-l.[,1] ;y<-l.[,2]
dstpp(x,y)

Return a vector of center angle 0 to 360(degree) for x y coordinate vector

Description

Return a vector of center angle 0 to 360(degree) for x y coordinate vector

Usage

Ldeg360(x, y)

Arguments

x

a vector of x coordinates

y

a vector of y coordinates

Value

a vector of center angle 0 to 360(degree) for x y coordinate vector

Examples

xy <-TR@L[[1]]
 plot(Ldeg360(xy[,1],xy[2]))

Convert from a list of tree rings polygons (L) to data frame to a data frame with no.,year,x,y,r(radius),radian(center angle),degree. The data frame is sorted by degree(0 to 360).

Description

Convert from a list of tree rings polygons (L) to data frame to a data frame with no.,year,x,y,r(radius),radian(center angle),degree. The data frame is sorted by degree(0 to 360).

Usage

Llist2dataframe(L)

Arguments

L

list of tree ring lines

Value

data frame

Examples

L_ <- Llist2dataframe(TR@L)
head(L_) ; tail(L_)

Move the tree rings coordinates based on P00 (x,y movement coordinates).

Description

Move the tree rings coordinates based on P00 (x,y movement coordinates).

Usage

Lmove(L, P00 = P00)

Arguments

L

a list of tree rings(x,y coordinates).

P00

x, y coordinates of a center point (usually a pith).

Value

moved L to center point 0,0

Examples

Lplot(TR@L)
sapply(Lmove(TR@L,c(3000,-3000)),lines,col="blue")

Plot a graphics of tree rings

Description

Plot a graphics of tree rings

Usage

Lplot(L, rn = 1:length(L), col = "red", ...)

Arguments

L

a list of tree rings polygon coordinates (X,Y)

rn

vector of ring number of list (L), default 1:length(L)

col

color of plot

...

other parameters to be passed through to plotting functions

Value

No return value, only draw tree ring plot.

Examples

Lplot(TR@L,main=TR@L_filename)
Lplot(TR@L,rn=1:20,col='blue',main=TR@L_filename)

Draw a graphics of tree rings by 1 ring (3*3 in a screen)

Description

Draw a graphics of tree rings by 1 ring (3*3 in a screen)

Usage

Lplot2(L, i.ring = 1:length(L), nrow = 3, ncol = 3, ask = "FALSE", ...)

Arguments

L

a list of tree rings polygon coordinates (X,Y)

i.ring

integer vector, tree ring number for drawing

nrow

par(mfrow=c(nrow,ncol))

ncol

par(mfrow=c(nrow,ncol))

ask

logical; if TRUE, the user is asked before each plot

...

other parameters to be passed through to plotting functions.

Value

No return value, only draw tree ring plot.

Examples

Lplot2(TR@L,i.ring=1:9, nrow=1,ncol=1,type='b')
Lplot2(TR@L,type='b')

Check center angle of points to input order

Description

Check center angle of points to input order

Usage

Lrad.plot(L, i.ring = 1:4, nrow = 2, ncol = 2)

Arguments

L

list of tree rings

i.ring

integer vector, tree ring number for drawing

nrow

par(mfrow=c(nrow,ncol))

ncol

par(mfrow=c(nrow,ncol))

Value

No return value, only draw tree ring plot.

Examples

slotNames(TR)
Lplot(TR@L)
str(TR@L)
Lrad.plot(TR@L,11:19)

Return a ring number of tree ring polygons list (L) from year

Description

Return a ring number of tree ring polygons list (L) from year

Usage

Lrn(L, yr)

Arguments

L

tree ring polygons list (L)

yr

years (or rings)

Value

a ring number of tree ring polygons list (L)

Examples

Lrn(TR@L,168)  # 168 is the formation year (from outermost) of the tree ring

Sort x,y coordinates of a tree ring line with center angle of each point

Description

Sort x,y coordinates of a tree ring line with center angle of each point

Usage

Lsort(l.)

Arguments

l.

x,y coordinates matrix (ncol=2) or data.frame of an tree ring.

Value

ordered with center angle of each point

Examples

i<-seq(0,2*pi,0.1)
l.<-data.frame(x=sin(i),y=cos(i))
l.[10,]<-l.[20,]
plot(l.,type="b")
plot(Lsort(l.),type="b")

Sort x,y coordinates of tree ring lines with center angle of each point apply Lsort to list of tree ring lines

Description

Sort x,y coordinates of tree ring lines with center angle of each point apply Lsort to list of tree ring lines

Usage

Lsort_all(L)

Arguments

L

a list of tree ring lines (x,y)

Value

a list of tree ring lines (x,y) ordered with center angle of each point

Examples

str(Lsort_all(TR@L))

Initial setting of a new classTreeRingShape (TR)

Description

Initial setting of a new classTreeRingShape (TR)

Usage

new_classTreeRingShape(
  P_filename,
  L_filename,
  L2_filename,
  P_id.tag = "id",
  P_ring.tag = "ring",
  L_ring.tag = "ring"
)

Arguments

P_filename

file name of shape file (P) for tree ring points

L_filename

file name of shape file (L) for tree ring lines

L2_filename

file name of shape file (L2) for tree ring lines interpolated

P_id.tag

column name of id in shape file (P), default is 'id'

P_ring.tag

column name of ring no.(ordinaly year,outermost=0) in shape file (L), default is 'ring'

L_ring.tag

column name of ring no.(ordinaly year,outermost=0) in shape file (L), default is 'ring'

Value

generated new object from classTreeRingShape

Examples

TR_<-new_classTreeRingShape(
P_filename='Abies_277_h400_TreeRing_Points.shp',
L_filename='Abies_277_h400_TreeRing_Representative.shp',
L2_filename='Abies_277_h400_TreeRing.shp',
P_id.tag='id',
P_ring.tag='ring',
L_ring.tag='ring')

 TR_
 slotNames(TR_)
 str(TR_)

Return a vector of row numbers of points that have nearest center angle

Description

Return a vector of row numbers of points that have nearest center angle

Usage

nstP(z1, z2)

Arguments

z1

a data frame or a matrix of xy coordinates of a tree ring (usualy inner ring)

z2

a data frame or a matrix of xy coordinates of a tree ring (usualy outer ring)

Value

a vector of row numbers of z2, the length is nrow(z1)

Examples

L_out<-TR@L[[1]];L_in<-TR@L[[30]]
np<-nstP(L_out,L_in)
plot(L_out,col="red"); points(L_in)
segments(L_out[,1],L_out[,2],L_in[np,1],L_in[np,2],col="blue")

Draw a plot of tree rings This function draws Tree rings of a disk from x, y list(x,y) with name of year.

Description

Draw a plot of tree rings This function draws Tree rings of a disk from x, y list(x,y) with name of year.

Usage

plot_TreeRing(L, year = 0, ...)

Arguments

L

list(x,y) of Tree ring coordinates with name of year

year

name of column of Tree ring year (0(cambium),1,2,....,n(pith))

...

other parameters to be passed through to plotting functions

Value

No return value, only draw tree ring plot.

Examples

names(TR@L)
plot_TreeRing(TR@L)
plot_TreeRing(TR@L,year=10,type='l',col='blue')

plot_TreeRing_df Draw a Tree ring of a disk from data frame(x,y,year)

Description

plot_TreeRing_df Draw a Tree ring of a disk from data frame(x,y,year)

Usage

plot_TreeRing_df(df, year = 0, year_label = "yr")

Arguments

df

name of a data frame

year

integer vector of years to draw tree rings

year_label

name of column of Tree ring year (0(cambium),1,2,....,n(pith))

Value

No return value, only draw tree ring plot.

Examples

TR@L_ <- Llist2dataframe(TR@L)     # data frame of tree rings
plot_TreeRing_df(TR@L_, year =1)

Plot tree rings from data fame This function draws Tree rings of a disk from data frame(x,y,year).

Description

Plot tree rings from data fame This function draws Tree rings of a disk from data frame(x,y,year).

Usage

plot_TreeRings_df(df, year_label = "yr")

Arguments

df

name of a data frame

year_label

name of column of Tree ring year (0(cambium),1,2,....,n(pith))

Value

No return value, only draw tree ring plot.

See Also

Llist2dataframe for the data frame

Examples

TR@L_ <- Llist2dataframe(TR@L)     # data frame of tree rings
names(TR@L_)
plot_TreeRings_df(TR@L_)

Plot and return data frame of year_disk area and year_Tree ring area

Description

Plot and return data frame of year_disk area and year_Tree ring area

Usage

plot_year_RingArea(L2, yr_end = 2018)

Arguments

L2

list of tree rings

yr_end

outermost year of tree ring

Value

list of Year_DiskArea and Year_TreeRingArea

See Also

TreeRingsInterpolation


Return relative distance between two representative tree rings

Description

Return relative distance between two representative tree rings

Usage

rdst(L, P, yr)

Arguments

L

list of x,y coordinates of representative tree rings (TR@L)

P

data.frame (x,y,id,yr,r,deg) of radial tree ring points (TR@P)

yr

year

Value

a data frame with relative distance and center angle

Examples

rdst.<-rdst(TR@L,TR@P,73)
plot(rdst.)
spline<-smooth.spline(rdst.$rad,rdst.$rdst, spar =0.0002)
lines(predict(spline,seq(-pi,pi,0.01)),col="red")

Return relative distance between two representative tree rings

Description

Return relative distance between two representative tree rings

Usage

rdst_MerginePlus(L, P, yr)

Arguments

L

is a list of tree rings(x,y coordinates).

P

data.frame (x,y,id,yr,r,deg) of radial tree ring points (TR@P)

yr

integer of year

Value

a data frame with relative distance and center angle(degree) with mergine (-90 - 0 - 360 - 90)

Examples

year.<-73
rdst.<-rdst_MerginePlus(TR@L,TR@P,year.)
plot(rdst.,xlim=c(-200,200),main=year.)
spline<-smooth.spline(rdst.$deg,rdst.$rdst, spar =0.0002)
lines(predict(spline,seq(-202,220,1)),col="red")

Return x,y coordinates of a tree ring center point (P00) from shape file of tree ring points

Description

Return x,y coordinates of a tree ring center point (P00) from shape file of tree ring points

Usage

ReadShapefile_P00(
  filename = "Abies_277_h400_TreeRing_Points.shp",
  id.tag = "id",
  ring.tag = "ring"
)

Arguments

filename

a shape file name of Tree ring points

id.tag

string, column name of id (attribute table)

ring.tag

string, column name of ring years (0 is cambium layer)

Value

numeric : x,y coordinates of a tree ring center point (P00)

Examples

.dir <- system.file("shp",package = "TreeRingShape")
.file <- "Abies_277_h400_TreeRing_Points.shp"
filename <- paste(.dir,.file,sep="/")
ReadShapefile_P00(filename)

Read a shape file of Tree Ring Points ( P : radial input and correction points)

Description

Read a shape file of Tree Ring Points ( P : radial input and correction points)

Usage

ReadShapefile_TreeRingPoints(
  filename = "Abies_277_h400_TreeRing_Points.shp",
  id.tag = "id",
  ring.tag = "ring"
)

Arguments

filename

a file name of Tree ring points (shape file )

id.tag

string, column name of id (attribute table)

ring.tag

string, column name of ring years (0 is cambium layer)

Value

a data frame of TreeRingPoints (radial input and correction points)

Examples

.dir <- system.file("shp",package = "TreeRingShape")
.file <- "Abies_277_h400_TreeRing_Points.shp"
filename <- paste(.dir,.file,sep="/")
sf.P<-sf::st_read(filename)
plot(sf.P)
ReadShapefile_TreeRingPoints(filename,id.tag='id',ring.tag='ring')

Read Shapefile_TreeRings

Description

Read Shapefile_TreeRings

Usage

ReadShapefile_TreeRings(
  filename = "Abies_277_h400_TreeRing_Representative.shp",
  ring.tag = "ring"
)

Arguments

filename

a file name(path) of shape file written to disk.

ring.tag

string, column name of ring years (0 is cambium layer)

Value

a list of tree ring lines

Examples

.dir <- system.file("shp",package = "TreeRingShape")
.file <- "Abies_277_h400_TreeRing_Representative.shp"
filename <- paste(.dir,.file,sep="/")
sf.L<-sf::st_read(filename)
plot(sf.L)
Lplot(ReadShapefile_TreeRings(filename))

Return a vector of sequence of angles between start and end angle 0 to pi -pi to 0

Description

Return a vector of sequence of angles between start and end angle 0 to pi -pi to 0

Usage

seq_deg(deg1, deg2, deg.by = 1)

Arguments

deg1

start angle

deg2

end angle

deg.by

step of sequence

Value

vector of sequence of angles between start and end angle

Examples

seq_deg(170,-170,.5)

A sample object of class TreeRingShape

Description

The data set contains tree ring shape data for Abies_277_h400 sampled from Tateyama, central Japan. Its disk image and shape files can be download from https://www.sanchikanri.com/treering/Abies_277_h400.zip It's intended to demonstrate the structure and use of 'TreeRingShape' class objects within the package.

Usage

TR

Format

An object of class classTreeRingShape of length 1.

Examples

# Access basic information about the TreeRingShape object
slotNames(TR)
str(TR)
# Plot the tree ring shape data
Lplot(TR@L)

A sample object of class TreeRingShape, shapefile paths and column names only.

Description

The full data set contains tree ring shape data for Abies_277_h400 sampled from Tateyama, central Japan. Its disk image and shape files can be download from https://www.sanchikanri.com/treering/Abies_277_h400.zip

Usage

TR_

Format

An object of class classTreeRingShape of length 1.

Examples

# Access basic information about the TreeRingShape object
TR_<-new_classTreeRingShape(
P_filename='Abies_277_h400_TreeRing_Points.shp',
L_filename='Abies_277_h400_TreeRing_Representative.shp',
L2_filename='Abies_277_h400_TreeRing.shp',
P_id.tag='id',
P_ring.tag='ring',
L_ring.tag='ring')
slotNames(TR_)
str(TR_)

Calculate tree ring index from chronosequence data (year,growth)

Description

Calculate tree ring index from chronosequence data (year,growth)

Usage

TreeRingIndex(ya, spar = 0.8)

Arguments

ya

data frame of chronosequence data (year,growth)

spar

smoothing parameter of spline curve

Value

list spline ; fitting parameter of Spline curve , idx ; data.frame(year,TreeRingIndex)

References

Cook, E., & Peters, K. (1981). The smoothing spline, a new approach to standardising forest interior tree-ring.Trre-ring Bulletin, 41, 45–53.

See Also

TreeRingsInterpolation


Construct a object (TR) of classTreeRingShape

Description

Construct a object (TR) of classTreeRingShape

Usage

TreeRingShape(
  P_filename,
  L_filename,
  L2_filename,
  P_id.tag = "id",
  P_ring.tag = "ring",
  L_ring.tag = "ring"
)

Arguments

P_filename

file name of shape file (P) for tree ring points (without extention)

L_filename

file name of shape file (L) for tree ring lines (without extention)

L2_filename

file name of shape file (L2) for tree ring lines interpolated (without extention)

P_id.tag

column name of id in shape file (P), default is 'id'

P_ring.tag

column name of ring no.(ordinaly year,outermost=0) in shape file (L), default is 'ring'

L_ring.tag

column name of ring no.(ordinaly year,outermost=0) in shape file (L), default is 'ring'

Value

generated new object from classTreeRingShape

Examples

test_TreeRingShape <- function(){
oldwd <- getwd()
on.exit(setwd(oldwd))
setwd(system.file("shp",package = "TreeRingShape"))

TR.<-TreeRingShape(
P_filename='Abies_277_h400_TreeRing_Points.shp',
L_filename='Abies_277_h400_TreeRing_Representative.shp',
L2_filename='Abies_277_h400_TreeRing.shp',
P_id.tag='id',P_ring.tag='ring',
L_ring.tag='ring')

 slotNames(TR.)
 str(TR.)
 Lplot(TR.@L2)
 return(TR.)
}

 TR. <- test_TreeRingShape()
 DiskInfo(TR.)

Interpolates tree ring between representative (manual input) tree rings with tree ring points

Description

Interpolates tree ring between representative (manual input) tree rings with tree ring points

Usage

TreeRingsInterpolation(TR)

Arguments

TR

object of classTreeRingShape (without tree ring interpolated)

Value

TR object of classTreeRingShape (with tree ring interpolated)

Examples

# tree ring interpolation (add TR@L2 to classTreeRingShape )
TR@L2   ### empty
TR <- TreeRingsInterpolation(TR)
TR@L2  ###  entered
ya <- plot_year_RingArea(TR@L2, 2018)$Year_TreeRingArea
# Figure of relationships year and tree ring area
plot(ya,type='b')
tri. <- TreeRingIndex(ya)
lines(tri.$spline,col='red',lw=2)
# Figure of relationships year and tree ring index
plot(tri.$idx,type='b')
abline(h=1,col='red')

Read representative tree ring lines from shape files

Description

Read representative tree ring lines from shape files

Usage

TreeRingsLines(TR)

Arguments

TR

a tree ring class (classTreeRingShape )

Value

TR (TreeRing class TR@L<-L ; TR@L_<-L_ ; TR@YR_L <-YR_L ; TR@ln <- ln)

Examples

#  didectory of tree ring shapefiles
 .dir <- system.file("shp",package = "TreeRingShape")

# path of  P_filename
.file <- "Abies_277_h400_TreeRing_Points.shp"
 TR_@P_filename <- paste(.dir,.file,sep="/")

  TreeRingsPoints(TR_)@P

# path of L_file name
.file <- "Abies_277_h400_TreeRing_Representative.shp"
L_filename <- paste(.dir,.file,sep="/")
 TreeRingsPoints(TR_)@L
 Lplot(TR@L)

Read TreeRingsPoints shape file, check and save parameters

Description

Read TreeRingsPoints shape file, check and save parameters

Usage

TreeRingsPoints(TR)

Arguments

TR

a tree ring class (classTreeRingShape )

Value

a list of (P,P00,YR_P,n_id,YR_P,n_YR)

Examples

#  didectory of tree ring shapefiles
 .dir <- system.file("shp",package = "TreeRingShape")

# path of  P_filename
.file <- "Abies_277_h400_TreeRing_Points.shp"
 TR_@P_filename <- paste(.dir,.file,sep="/")

  TreeRingsPoints(TR_)@P

Write a shapefile of interpolated tree rings

Description

Write a shapefile of interpolated tree rings

Usage

WriteShapefile_TreeRings(L2, filename = "test.shp")

Arguments

L2

is as list of Tree ring polygons (X, Y)

filename

is a shape file(path) name written to disk.

Value

No return value, called for side effects.

Examples

#'
WriteShapefile_TreeRings (TR@L, tempfile("TreeRingShape_test",fileext = ".shp"))
dir(tempdir())