Yearly measurements have been taken on almost 200 stem sections in a ‘simplified’ stem analysis study. (Simplified in the sense that sections have been cut adapting to foresters needs, at tree base and at the top of the long commercial logs he defined, not at researcher defind positions). Measurement procedure and data imput method didn’t oblige to take care of readings internal coherence and, atcually, of the more than 150 measurements seriese that could effectively proceed from one side of the stem till the opposite side, 140 series present a common incoherence problem: the number of rings on the two sides of the pith differ for one year.
To proceed with the original stem analysis work, ecah of these series has to be corrected either,
(I) inserting a missing mesurement in the short side,
(D) deliting a measurement in excess in the long one.
Aim of the work performed here is to identify the locations within such series where (D) or (I) would best improve the matching between the series taken from opposite sides of the stem.
Measurements have been taken as progressive values. Assuming that total width section is correctly mesured, in order to preserve all other readings not affected by the correction, (I) and (D) respectvely imply that:
(I) the width of a given ring is divided in two (let us assume, equal) parts
(D) the width of two consecutive rings are summed to form a single one
Dynamic Time Warping (DTW) is a well known approach to time series matching, see
https://en.wikipedia.org/wiki/Dynamic_time_warping
or http://www.cs.ucr.edu/~eamonn/DTW_myths.pdf for a more critical appraisal.
Although the general approach can be applyed in this context, the problem at hand requires has specific constraints that, as far as I could appreciate, can not be implemented using available packages or algorithms:
1) in this case a single correcion (I or D) is allowed and required,
2) what has to be evaluated is the ‘match gain’ after correction, i.e. after having modified (by summation or halving) the single series values.
Moreover in DTW the focus is on ‘point to point’ distances (however the metric is defined), and ‘warping’ is led by ‘distance minimization’, with no concern for local matching. To overcome this limitation a ‘shape DTW’ approach has been developed but the procedures are available only as code for Matlab (paper: https://arxiv.org/pdf/1606.01601.pdf, code: https://github.com/jiapingz/shapeDTW). Other approaches have been proposed but I couldn’t find any implementation (https://pdfs.semanticscholar.org/98cc/ff83a8c815eed2f3978a47a331373baf332a.pdf). In this work local correlation is considered as viable approach to take ‘local shapes’ into consideration.
load("RinaldiniV2.0.Rdata")
library(sqldf)
## Loading required package: gsubfn
## Loading required package: proto
## Loading required package: RSQLite
Sects_sy <- sqldf("select TreeId, SectId
, sum(side='a' and bark) abark, sum(side='a' and not bark) nam
, sum(side='b' and not bark) nbm, sum(side='b' and bark) bbark
, count(*) as nm
from Diams_at group by TreeId, SectId order by TreeId, SectId")
## Loading required package: tcltk
## Warning: Quoted identifiers should have class SQL, use DBI::SQL() if the
## caller performs the quoting.
Sects_sy <- sqldf("
select A.*, B.comment
from Sects_sy A natural left join Sects_at B")
Sects_sy$complete <- Sects_sy$bbark | is.na(Sects_sy$comment)
Sects_sy <- sqldf("
select * from Sects_sy natural join
(select TreeId, SectId, max(year) max_b_year
from (select * from Diams_at where side='b')
group by TreeId, SectId)")
pith <- sqldf("
select A.TreeId, A.SectId, year-1 year, avg(value) value
from Diams_at A natural join (
select TreeId, SectId, side, min(year) year
from Diams_at group by TreeId, SectId, side)
group by TreeId, SectId")
missing_bark <- sqldf("
select TreeId, SectId, 'a' side, 2017 year, 0 value
from Sects_sy where abark=0")
tmp <- sqldf("
select TreeId, SectId, side, year, value
from Diams_at where not (side='b' and bark)
UNION select TreeId, SectId, 'a' side, year, value from pith
UNION select TreeId, SectId, 'b' side, year, value from pith
UNION select TreeId, SectId, side, year, value from missing_bark")
rw_all <- sqldf("
select A.TreeId, A.SectId, A.side, A.year gyear
, case when A.side='a' then B.value-A.value else A.value-B.value end rw
from tmp A join tmp B
on A.TreeId=B.TreeId and A.SectId=B.SectId and A.side=B.side
and A.year=B.year+1")
# dubbio: la corteccia b non è inclusa come rw vero?
# verifica: NO (year è messo ad NA e quindi non aggancia nell'accoppiamento)
library(latticeExtra)
## Warning: package 'latticeExtra' was built under R version 3.3.3
## Loading required package: lattice
## Loading required package: RColorBrewer
# library(TTR)
# tested but abanoned because:
# 1 - numeric instability (NaN sometimes when x or y constant)
# 2 - lagged result (result[n] corresponds to x_y[n/2])
# substituted with a custom 'localCor()' function
source('F_localCor.R')
tmp <- sqldf("select A.* from rw_all A natural join Sects_sy where max_b_year = 2017")
rw_ok <- sqldf("select A.*, A.rw/series_width rrw from tmp A natural join (select TreeId, SectId, side, sum(rw) series_width from tmp group by TreeId, SectId, side)")
rw_cor <- sqldf("select TreeId, SectId, gyear
, A.rrw rrw_a, B.rrw rrw_b
from (select * from rw_ok where side='a') A
join (select * from rw_ok where side='b') B
using(TreeId, SectId, gyear)")
xyplot(rw ~ gyear | paste(TreeId,SectId,sep="-"), rw_ok, group = side, t='l', main="'a' and 'b' Series of sections where lengths are equal")
ts <- with(rw_cor, paste(TreeId, SectId, sep="-"))
for (i in unique(ts)) {
# print(i)
rw_cor$rw_ab_cor[ts==i] <- with(rw_cor[ts==i,]
, localCor(rrw_a, rrw_b, 3))
}
# rrw_a+rrw_b+
obj1 <- xyplot(I(rrw_a - rrw_b)^2 ~ gyear| ts, rw_cor, type='l'
, scales=list(y=list(log="e"))
, panel=function(...) {panel.xyplot(...)
panel.grid(h=-1, v=-1, ...)}
, main="Comparing similarity measures")
obj2 <- xyplot(I((rw_ab_cor+1)/2) ~ gyear| ts, rw_cor, type='l')
doubleYScale(obj1, obj2, text = c("E.dist. relativeRW", "scaled_localCor"), add.ylab2 = TRUE, main="Comparing similarity measures")
library(splus2R) # for 'peaks'
source("F_EditTreeRingWidthSeries.R")
tmp <- sqldf("select A.* from rw_all A natural join Sects_sy where max_b_year = 2016")
# Sections with 1 year ring difference between the two sides
rw_1yd <- sqldf("select A.*, A.rw/series_width rrw from tmp A natural join (select TreeId, SectId, side, sum(rw) series_width from tmp group by TreeId, SectId, side)")
# Compute relative 'ring width'
start_time <- Sys.time()
pcsim <- data.frame()
ts <- with(rw_1yd, paste(TreeId, SectId, sep="-"))
for (i in unique(ts)) {
cat(i)
year1 <- min(rw_1yd$gyear[ts==i])
ls <- rw_1yd$rrw[ts==i & rw_1yd$side=='a'] # LongSeries
N <- length(ls)
ls_ly <- year1 + N -1
ss <- rw_1yd$rrw[ts==i & rw_1yd$side=='b'] # ShortSeries (len=N-1)
ss_ly <- ls_ly - 1
csim <- data.frame()
# (partial) cumulated differences/correlations squared
for (y in year1:ss_ly) {
# compute cumulative 'similarity' having I and D in position y
# Insert (before y, splitting rw[y] in two, shifting +1 following years) - in ss
ssI <- EditTreeRingWidthSeries('I', y, ss, year1)
# Delete (ring y: sum j and j+1, till N-1) from long series
lsD <- EditTreeRingWidthSeries('D', y, ls, year1)
n <- 3
csim <- rbind(csim,
data.frame(TeeeSector = i
, modify_y=y
, cdI = sum((ls-ssI)^2) / length(ls)
, cdD = sum((lsD-ss)^2) / length(lsD)
, crI = sum((localCor(ls, ssI, n)+1)/2) / length(ls)
, crD = sum((localCor(lsD, ss, n)+1)/2) / length(lsD)
))
}
pcsim_i <- data.frame()
for (c in names(csim)[2:5]) {
sel <- which(peaks(csim[,c],span=7))
pcsim_i <- rbind(pcsim_i, data.frame(c=c, o=c(1,2)
, r=sel[order(csim[,c][sel], decreasing = T)][1:2]))
}
csim$how <- ''
for (i in 1:nrow(pcsim_i)) {
csim$how[pcsim_i$r[i]] <-
paste(csim$how[pcsim_i$r[i]],
paste(pcsim_i$c[i], pcsim_i$o[i], sep=""), sep=":")
}
pcsim <- rbind(pcsim, csim[csim$how != '',])
}
## 1-11-21-31-41-52-22-32-42-52-63-23-33-43-53-64-24-55-15-25-36-16-26-36-47-27-37-57-68-18-28-38-48-59-39-49-610-210-310-410-510-611-111-312-112-212-312-413-213-313-413-514-214-314-414-515-115-215-315-416-316-417-217-318-218-319-119-219-320-120-220-321-222-223-223-323-424-224-325-225-326-126-327-227-328-129-129-329-430-230-331-331-432-232-332-432-532-632-733-133-233-333-533-633-734-234-335-236-136-336-436-537-137-237-337-438-238-338-438-538-639-139-239-339-440-240-340-541-242-243-143-244-244-344-444-545-246-146-246-346-4
end_time <- Sys.time()
print(paste("start:", start_time, "- end:", end_time, "- Time elapsed:", end_time - start_time))
## [1] "start: 2017-08-20 11:56:58 - end: 2017-08-20 11:57:22 - Time elapsed: 23.6908659934998"
pcsim[,c("TeeeSector","modify_y","how")]
## TeeeSector modify_y how
## 4 1-1 1971 :cdI1:cdD2
## 28 1-1 1995 :cdI2:cdD1
## 29 1-1 1996 :crI2
## 43 1-1 2010 :crI1
## 5 1-2 1985 :cdD1
## 14 1-2 1994 :cdI1:cdD2
## 22 1-2 2002 :crI2
## 25 1-2 2005 :cdI2
## 27 1-2 2007 :crI1
## 9 1-3 1996 :crI2
## 10 1-3 1997 :cdI1:cdD1
## 20 1-3 2007 :cdI2:cdD2
## 251 1-3 2012 :crI1
## 7 1-4 2003 :cdI1:cdD1
## 8 1-4 2004 :crI2
## 12 1-4 2008 :cdI2:cdD2
## 141 1-4 2010 :crI1
## 71 1-5 2007 :crI1
## 91 1-5 2009 :cdI1:cdD1
## 51 2-2 1980 :cdI1:cdD1
## 11 2-2 1986 :cdI2
## 18 2-2 1993 :crI2
## 21 2-2 1996 :cdD2
## 23 2-2 1998 :crI1
## 41 2-3 1984 :crI2
## 6 2-3 1986 :cdI1:cdD1
## 92 2-3 1989 :crI1
## 13 2-3 1993 :cdI2:cdD2
## 72 2-4 1993 :crI2
## 81 2-4 1994 :cdI1:cdD1
## 252 2-4 2011 :crI1
## 271 2-4 2013 :cdI2:cdD2
## 82 2-5 2001 :cdI1:cdD1
## 121 2-5 2005 :crI1
## 201 2-5 2013 :cdI2:cdD2
## 111 2-6 2009 :cdI1:cdD1
## 42 3-2 1978 :crI2
## 83 3-2 1982 :cdI1:cdD1
## 32 3-2 2006 :cdI2:cdD2
## 37 3-2 2011 :crI1
## 73 3-3 1988 :cdI1:cdD1
## 202 3-3 2001 :cdI2:cdD2
## 221 3-3 2003 :crI2
## 30 3-3 2011 :crI1
## 84 3-4 1995 :crI2
## 93 3-4 1996 :cdI1:cdD1
## 142 3-4 2001 :cdI2:cdD2
## 222 3-4 2009 :crI1
## 131 3-5 2007 :crI2
## 15 3-5 2009 :cdI1:cdD1
## 19 3-5 2013 :crI1
## 85 3-6 2006 :cdD1
## 132 3-6 2011 :crI1
## 151 3-6 2013 :cdI1:cdD2
## 61 4-2 1982 :cdI1:cdD1
## 101 4-2 1986 :cdI2:cdD2
## 211 4-2 1997 :crI2
## 321 4-2 2008 :crI1
## 44 4-5 2004 :crI1
## 94 4-5 2009 :crI2
## 102 4-5 2010 :cdD1
## 62 5-1 1980 :cdI1:cdD1
## 291 5-1 2003 :crI2
## 33 5-1 2007 :crI1
## 35 5-1 2009 :cdI2:cdD2
## 95 5-2 1989 :cdI1:cdD1
## 191 5-2 1999 :crI2
## 272 5-2 2007 :crI1
## 301 5-2 2010 :cdI2:cdD2
## 74 5-3 1997 :cdI1:cdD1
## 103 5-3 2000 :crI1
## 17 5-3 2007 :cdI2:cdD2
## 203 5-3 2010 :crI2
## 52 6-1 1980 :cdI1:cdD1
## 152 6-1 1990 :crI2
## 192 6-1 1994 :crI1
## 212 6-1 1996 :cdI2:cdD2
## 45 6-2 1987 :cdI1:cdD1
## 104 6-2 1993 :crI1
## 133 6-2 1996 :cdI2:cdD2
## 153 6-2 1998 :crI2
## 63 6-3 1996 :cdI1:cdD1
## 122 6-3 2002 :cdI2:cdD2
## 143 6-3 2004 :crI2
## 204 6-3 2010 :crI1
## 46 6-4 2002 :cdI1:cdD1
## 64 6-4 2004 :crI2
## 86 6-4 2006 :cdI2:cdD2
## 123 6-4 2010 :crI1
## 47 7-2 1979 :crI2
## 87 7-2 1983 :crI1
## 105 7-2 1985 :cdI1:cdD1
## 213 7-2 1996 :cdI2:cdD2
## 48 7-3 1985 :cdI1:cdD1
## 154 7-3 1996 :cdI2:cdD2
## 223 7-3 2003 :crI1
## 302 7-3 2011 :crI2
## 75 7-5 2002 :cdI1:cdD1
## 106 7-6 2009 :cdI2:cdD2
## 124 7-6 2011 :crI1
## 144 7-6 2013 :cdI1:cdD1
## 96 8-1 1982 :cdI1:cdD1
## 16 8-1 1989 :crI2
## 24 8-1 1997 :crI1
## 292 8-1 2002 :cdD2
## 322 8-1 2005 :cdI2
## 65 8-2 1983 :cdI1:cdD1
## 253 8-2 2002 :cdI2:cdD2
## 273 8-2 2004 :crI2
## 331 8-2 2010 :crI1
## 66 8-3 1988 :cdI1:cdD1
## 107 8-3 1992 :crI1
## 181 8-3 2000 :cdI2:cdD2
## 224 8-3 2004 :crI2
## 49 8-4 1993 :crI1
## 67 8-4 1995 :cdI1:cdD1
## 112 8-4 2000 :crI2
## 231 8-4 2012 :cdD2
## 53 8-5 1997 :cdI1:cdD1
## 113 8-5 2003 :crI2
## 125 8-5 2004 :cdI2
## 182 8-5 2010 :crI1
## 214 8-5 2013 :cdD2
## 68 9-3 1988 :cdI1:cdD1
## 161 9-3 1998 :cdD2
## 193 9-3 2001 :cdI2
## 26 9-3 2008 :crI1
## 303 9-3 2012 :crI2
## 69 9-4 1993 :crI1
## 88 9-4 1995 :cdI1:cdD1
## 162 9-4 2003 :crI2
## 254 9-4 2012 :cdI2:cdD2
## 89 9-6 2006 :crI1
## 114 9-6 2009 :cdI1:cdD1
## 610 10-2 1981 :cdI1:cdD1
## 115 10-2 1986 :crI2
## 134 10-2 1988 :cdD2
## 163 10-2 1991 :cdI2
## 371 10-2 2012 :crI1
## 410 10-3 1985 :cdI1
## 126 10-3 1993 :crI1
## 164 10-3 1997 :cdI2:cdD1
## 323 10-3 2013 :cdD2
## 411 10-4 1992 :cdI1:cdD1
## 135 10-4 2001 :cdI2:cdD2
## 205 10-4 2008 :crI1
## 97 10-5 2003 :cdI1:cdD1
## 108 10-5 2004 :crI2
## 165 10-5 2010 :cdI2:cdD2
## 183 10-5 2012 :crI1
## 109 10-6 2012 :cdI1:cdD1
## 54 11-1 1973 :cdI1:cdD1
## 810 11-1 1976 :crI1
## 1010 11-1 1978 :cdI2:cdD2
## 293 11-1 1997 :crI2
## 116 11-3 1999 :crI1
## 155 11-3 2003 :cdD1
## 241 11-3 2012 :cdD2
## 412 12-1 1973 :cdI1:cdD1
## 611 12-1 1975 :crI1
## 811 12-1 1977 :cdI2:cdD2
## 351 12-1 2004 :crI2
## 215 12-2 1998 :cdI1
## 225 12-2 1999 :cdD1
## 294 12-2 2006 :crI1
## 332 12-2 2010 :crI2
## 55 12-3 1987 :cdI1:cdD1
## 812 12-3 1990 :crI2
## 171 12-3 1999 :cdI2:cdD2
## 226 12-3 2004 :crI1
## 117 12-4 1998 :crI1
## 145 12-4 2001 :cdI1:cdD1
## 194 12-4 2006 :crI2
## 242 12-4 2011 :cdI2:cdD2
## 76 13-2 1981 :cdI1:cdD1
## 216 13-2 1995 :crI1
## 281 13-2 2002 :cdD2
## 295 13-2 2003 :crI2
## 333 13-2 2007 :cdI2
## 413 13-3 1983 :cdI1:cdD1
## 156 13-3 1994 :cdI2:cdD2
## 232 13-3 2002 :crI1
## 324 13-3 2011 :crI2
## 1011 13-4 1996 :cdI1:cdD1
## 127 13-4 1998 :crI2
## 146 13-4 2000 :cdI2:cdD2
## 184 13-4 2004 :crI1
## 612 13-5 1997 :cdI1:cdD1
## 1012 13-5 2001 :cdI2
## 147 13-5 2005 :crI1
## 157 13-5 2006 :cdD2
## 56 14-2 1979 :cdI1:cdD1
## 206 14-2 1994 :crI2
## 261 14-2 2000 :cdI2
## 36 14-2 2010 :crI1
## 39 14-2 2013 :cdD2
## 613 14-3 1986 :cdI1:cdD1
## 1013 14-3 1990 :cdI2
## 118 14-3 1991 :crI2
## 207 14-3 2000 :cdD2
## 255 14-3 2005 :crI1
## 614 14-4 1992 :cdI1:cdD1
## 166 14-4 2002 :cdI2:cdD2
## 185 14-4 2004 :crI2
## 274 14-4 2013 :crI1
## 414 14-5 1996 :crI2
## 77 14-5 1999 :cdI1:cdD1
## 128 14-5 2004 :cdI2:cdD2
## 172 14-5 2009 :crI1
## 57 15-1 1971 :cdI2:cdD2
## 1014 15-1 1976 :cdI1:cdD1
## 282 15-1 1994 :crI1
## 38 15-1 2004 :crI2
## 98 15-2 1984 :crI2
## 129 15-2 1987 :cdI1:cdD1
## 262 15-2 2001 :cdI2
## 325 15-2 2007 :cdD2
## 34 15-2 2009 :crI1
## 615 15-3 1987 :cdI1:cdD1
## 1015 15-3 1991 :crI2
## 136 15-3 1994 :cdD2
## 158 15-3 1996 :crI1
## 208 15-3 2001 :cdI2
## 616 15-4 1994 :crI2
## 1210 15-4 2000 :cdI1:cdD1
## 217 15-4 2009 :crI1
## 617 16-3 1987 :cdI1:cdD1
## 1211 16-3 1993 :crI2
## 209 16-3 2001 :cdI2:cdD2
## 256 16-3 2006 :crI1
## 415 16-4 1991 :cdI2:cdD2
## 148 16-4 2001 :crI1
## 167 16-4 2003 :cdI1:cdD1
## 416 17-2 1999 :cdI1:cdD1
## 813 17-2 2003 :crI1
## 173 17-2 2012 :crI2
## 618 17-3 2004 :crI2
## 159 17-3 2013 :crI1
## 78 18-2 1989 :crI2
## 99 18-2 1991 :cdI1:cdD1
## 168 18-2 1998 :cdI2:cdD2
## 257 18-2 2007 :crI1
## 619 18-3 2000 :cdD1
## 137 18-3 2007 :crI1
## 620 19-1 1973 :cdI1:cdD1
## 233 19-1 1990 :cdI2:cdD2
## 31 19-1 1998 :crI2
## 421 19-1 2009 :crI1
## 621 19-2 1987 :cdI1:cdD1
## 814 19-2 1989 :crI2
## 1212 19-2 1993 :crI1
## 149 19-2 1995 :cdD2
## 169 19-2 1997 :cdI2
## 1410 19-3 2002 :crI2
## 1510 19-3 2003 :cdD1
## 227 19-3 2010 :crI1
## 243 19-3 2012 :cdI1:cdD2
## 1411 20-1 1980 :cdI1:cdD1
## 258 20-1 1991 :crI2
## 326 20-1 1998 :cdI2:cdD2
## 461 20-1 2012 :crI1
## 815 20-2 1988 :cdI1:cdD1
## 138 20-2 1993 :crI2
## 1412 20-2 1994 :cdI2:cdD2
## 234 20-2 2003 :crI1
## 622 20-3 1998 :cdI2:cdD2
## 816 20-3 2000 :crI1
## 1413 20-3 2006 :cdI1:cdD1
## 417 21-2 1990 :cdI1
## 910 21-2 1995 :cdD1
## 174 21-2 2003 :crI1
## 195 21-2 2005 :cdI2:cdD2
## 244 21-2 2010 :crI2
## 58 22-2 1992 :cdI1:cdD1
## 1016 22-2 1997 :crI1
## 186 22-2 2005 :cdI2:cdD2
## 2010 22-2 2007 :crI2
## 1213 23-2 1992 :crI1
## 139 23-2 1993 :cdI1:cdD1
## 235 23-2 2003 :cdI2:cdD2
## 275 23-2 2007 :crI2
## 623 23-3 1999 :cdI1:cdD2
## 1017 23-3 2003 :crI1
## 1610 23-3 2009 :cdI2:cdD1
## 187 23-3 2011 :crI2
## 817 23-4 2005 :cdI2:cdD2
## 1018 23-4 2007 :crI1
## 1511 23-4 2012 :cdI1:cdD1
## 59 24-2 1995 :cdI1:cdD1
## 1214 24-2 2002 :crI2
## 1512 24-2 2005 :cdI2:cdD2
## 188 24-2 2008 :crI1
## 624 24-3 1999 :crI1
## 818 24-3 2001 :cdI1:cdD1
## 1019 24-3 2003 :crI2
## 1215 24-3 2005 :cdI2:cdD2
## 510 25-2 1993 :cdI1:cdD1
## 1513 25-2 2003 :cdI2:cdD2
## 196 25-2 2007 :crI2
## 259 25-2 2013 :crI1
## 511 25-3 1999 :crI1
## 625 25-3 2000 :cdD1
## 1414 25-3 2008 :cdI1:cdD2
## 1514 25-3 2009 :crI2
## 626 26-1 1973 :cdI1:cdD1
## 283 26-1 1995 :cdI2:cdD2
## 391 26-1 2006 :crI1
## 441 26-1 2011 :crI2
## 512 26-3 1999 :cdI1:cdD1
## 1020 26-3 2004 :cdI2:cdD2
## 79 27-2 1996 :cdI1:cdD1
## 1216 27-2 2001 :crI1
## 236 27-2 2012 :cdI2:cdD2
## 627 27-3 1998 :cdI1:cdD1
## 119 27-3 2003 :crI1
## 1415 27-3 2006 :cdI2:cdD2
## 189 27-3 2010 :crI2
## 710 28-1 1982 :cdI1:cdD1
## 1021 28-1 1985 :crI1
## 1416 28-1 1989 :cdI2
## 245 28-1 1999 :crI2
## 263 28-1 2001 :cdD2
## 819 29-1 1977 :cdI1:cdD1
## 911 29-1 1978 :crI2
## 1417 29-1 1983 :cdI2:cdD2
## 264 29-1 1995 :crI1
## 418 29-3 1986 :cdI1:cdD1
## 1310 29-3 1995 :cdI2:cdD2
## 1515 29-3 1997 :crI2
## 284 29-3 2010 :crI1
## 628 29-4 1994 :crI2
## 820 29-4 1996 :cdI1:cdD1
## 1022 29-4 1998 :crI1
## 1516 29-4 2003 :cdI2:cdD2
## 1517 30-2 1994 :cdI1:cdD1
## 1810 30-2 1997 :crI1
## 228 30-2 2001 :crI2
## 285 30-2 2007 :cdI2
## 296 30-2 2008 :cdD2
## 513 30-3 1996 :cdI1:cdD1
## 175 30-3 2008 :crI1
## 197 30-3 2010 :cdI2:cdD2
## 419 31-3 1995 :cdI1
## 912 31-3 2000 :cdI2:cdD1
## 1110 31-3 2002 :crI1
## 176 31-3 2008 :cdD2
## 711 31-4 2004 :crI2
## 821 31-4 2005 :cdI1:cdD1
## 1311 31-4 2010 :crI1
## 1518 31-4 2012 :cdI2:cdD2
## 1418 32-2 2000 :cdI1:cdD1
## 198 32-2 2005 :crI2
## 218 32-2 2007 :cdD2
## 276 32-2 2013 :crI1
## 629 32-3 1991 :cdI1:cdD1
## 1519 32-3 2000 :crI1
## 237 32-3 2008 :crI2
## 1419 32-4 2004 :crI2
## 2011 32-4 2010 :crI1
## 229 32-4 2012 :cdI1:cdD1
## 420 32-5 1995 :crI1
## 630 32-5 1997 :cdI1:cdD1
## 1111 32-5 2002 :cdI2
## 219 32-5 2012 :crI2
## 514 32-6 1995 :cdI1:cdD1
## 1312 32-6 2003 :crI1
## 177 32-6 2007 :cdI2
## 515 32-7 1998 :crI2
## 822 32-7 2001 :cdI1:cdD1
## 1611 32-7 2009 :crI1
## 1811 32-7 2011 :cdI2
## 516 33-1 1971 :cdI1:cdD1
## 1612 33-1 1982 :cdI2
## 238 33-1 1989 :crI1
## 297 33-1 1995 :cdD2
## 327 33-1 1998 :crI2
## 2510 33-2 2001 :crI2
## 311 33-2 2007 :crI1
## 361 33-2 2012 :cdI1:cdD1
## 823 33-3 1991 :cdI1:cdD1
## 913 33-3 1992 :crI1
## 1613 33-3 1999 :cdD2
## 199 33-3 2002 :crI2
## 239 33-3 2006 :cdI2
## 914 33-5 1993 :cdI1:cdD1
## 1023 33-5 1994 :crI1
## 2012 33-5 2004 :crI2
## 2210 33-5 2006 :cdI2:cdD2
## 517 33-6 1995 :cdI1:cdD1
## 1217 33-6 2002 :crI2
## 1614 33-6 2006 :crI1
## 1910 33-6 2009 :cdI2:cdD2
## 1218 33-7 2006 :crI2
## 1615 33-7 2010 :cdI1:cdD1
## 1911 33-7 2013 :crI1
## 422 34-2 1985 :crI2
## 712 34-2 1988 :cdI2:cdD1
## 1112 34-2 1992 :crI1
## 1313 34-2 1994 :cdD2
## 1520 34-2 1996 :cdI1
## 631 34-3 1991 :cdI1:cdD1
## 1113 34-3 1996 :cdI2:cdD2
## 178 34-3 2002 :crI1
## 265 34-3 2011 :crI2
## 632 35-2 1995 :crI2
## 713 35-2 1996 :cdI1:cdD1
## 2110 35-2 2010 :crI1
## 714 36-1 1975 :cdD1
## 1114 36-1 1979 :cdI1:cdD2
## 2211 36-1 1990 :crI1
## 277 36-1 1995 :crI2
## 312 36-1 1999 :cdI2
## 518 36-3 1994 :cdI2:cdD1
## 1024 36-3 1999 :cdI1:cdD2
## 1420 36-3 2003 :crI2
## 2013 36-3 2009 :crI1
## 824 36-4 2000 :crI1
## 1521 36-4 2007 :cdI1:cdD1
## 915 36-5 2004 :cdI1:cdD1
## 1115 36-5 2006 :crI1
## 1314 36-5 2008 :cdI2:cdD2
## 1522 36-5 2010 :crI2
## 633 37-1 1972 :cdI1
## 715 37-1 1973 :cdD1
## 4110 37-1 2007 :crI2
## 451 37-1 2011 :crI1
## 471 37-1 2013 :cdI2:cdD2
## 1025 37-2 1988 :crI2
## 1912 37-2 1997 :crI1
## 278 37-2 2005 :cdI1:cdD1
## 334 37-2 2011 :cdI2:cdD2
## 716 37-3 1991 :cdI1:cdD1
## 2111 37-3 2005 :crI1
## 279 37-3 2011 :crI2
## 286 37-3 2012 :cdI2:cdD2
## 1026 37-4 2001 :cdI1:cdD1
## 1421 37-4 2005 :crI2
## 2112 37-4 2012 :crI1
## 2212 37-4 2013 :cdI2:cdD2
## 634 38-2 1980 :cdI2:cdD2
## 1116 38-2 1985 :crI1
## 1315 38-2 1987 :cdI1:cdD1
## 179 38-2 1991 :crI2
## 717 38-3 1988 :cdI1:cdD1
## 916 38-3 1990 :crI1
## 2310 38-3 2004 :crI2
## 2511 38-3 2006 :cdI2:cdD2
## 519 38-4 1993 :cdI1:cdD1
## 1117 38-4 1999 :cdD2
## 1219 38-4 2000 :cdI2
## 1913 38-4 2007 :crI1
## 2512 38-4 2013 :crI2
## 423 38-5 1997 :crI2
## 635 38-5 1999 :cdI1:cdD1
## 1316 38-5 2006 :crI1
## 1710 38-5 2010 :cdI2:cdD2
## 917 38-6 2004 :crI2
## 1118 38-6 2006 :cdD2
## 1523 38-6 2010 :cdI1:cdD1
## 1711 38-6 2012 :crI1
## 636 39-1 1974 :cdI1:cdD1
## 1422 39-1 1982 :crI2
## 1616 39-1 1984 :cdI2
## 298 39-1 1997 :cdD2
## 362 39-1 2004 :crI1
## 1220 39-2 1994 :crI1
## 1617 39-2 1998 :crI2
## 1712 39-2 1999 :cdD1
## 2213 39-2 2004 :cdI1
## 520 39-3 1989 :crI1
## 1524 39-3 1999 :cdI1:cdD1
## 1914 39-3 2003 :crI2
## 2014 39-3 2004 :cdI2:cdD2
## 424 39-4 1990 :cdI1
## 1713 39-4 2003 :cdI2:cdD1
## 2015 39-4 2006 :crI1
## 637 40-2 1980 :cdI1:cdD1
## 825 40-2 1982 :crI1
## 1317 40-2 1987 :cdI2:cdD2
## 1915 40-2 1993 :crI2
## 918 40-3 1992 :crI2
## 1119 40-3 1994 :cdI1:cdD1
## 1318 40-3 1996 :crI1
## 304 40-3 2013 :cdI2:cdD2
## 1027 40-5 2006 :crI1
## 1525 40-5 2011 :cdI1:cdD1
## 718 41-2 2000 :cdI1:cdD1
## 1319 41-2 2006 :crI1
## 1423 41-2 2007 :cdD2
## 1526 41-2 2008 :cdI2
## 425 42-2 1984 :cdD2
## 1028 42-2 1990 :crI1
## 2016 42-2 2000 :cdI1:cdD1
## 2311 42-2 2003 :crI2
## 1221 43-1 1981 :cdI2:cdD2
## 1527 43-1 1984 :crI2
## 2017 43-1 1989 :crI1
## 328 43-1 2001 :cdI1:cdD1
## 1222 43-2 1998 :crI2
## 1714 43-2 2003 :crI1
## 1916 43-2 2005 :cdI1:cdD1
## 246 43-2 2010 :cdI2:cdD2
## 521 44-2 1987 :cdI1:cdD1
## 1223 44-2 1994 :crI2
## 1424 44-2 1996 :cdI2:cdD2
## 287 44-2 2010 :crI1
## 826 44-3 1995 :cdI1:cdD1
## 1917 44-3 2006 :crI2
## 2113 44-3 2008 :cdD2
## 2214 44-3 2009 :cdI2
## 2513 44-3 2012 :crI1
## 919 44-4 1998 :crI1
## 1528 44-4 2004 :cdI1:cdD1
## 2215 44-4 2011 :cdD2
## 2312 44-4 2012 :cdI2
## 247 44-4 2013 :crI2
## 638 44-5 1998 :crI2
## 1320 44-5 2005 :cdI1:cdD1
## 1812 44-5 2010 :crI1
## 522 45-2 1989 :cdI1:cdD1
## 1321 45-2 1997 :cdI2:cdD2
## 1425 45-2 1998 :crI2
## 2216 45-2 2006 :crI1
## 827 46-1 1977 :crI1
## 1322 46-1 1982 :cdI2
## 266 46-1 1995 :cdI1:cdD1
## 313 46-1 2000 :crI2
## 4111 46-1 2010 :cdD2
## 426 46-2 1982 :cdI1:cdD1
## 828 46-2 1986 :cdI2:cdD2
## 2710 46-2 2005 :crI2
## 352 46-2 2013 :crI1
## 523 46-3 1990 :cdD2
## 920 46-3 1994 :cdI2
## 1426 46-3 1999 :cdI1:cdD1
## 1813 46-3 2003 :crI2
## 2313 46-3 2008 :crI1
## 427 46-4 1997 :cdI2:cdD2
## 1029 46-4 2003 :crI1
## 1715 46-4 2010 :cdI1:cdD1
library(googlesheets)
suppressMessages(library(dplyr))
gsn <- "RotelleVer3"
gsurl <- "https://docs.google.com/spreadsheets/d/19QBPUmwnREaTlZ5Zbw46askcnmPSwc6wW17UELbhmBg/edit#gid=2034395174"
gs_ls(gsn)
## # A tibble: 1 × 10
## sheet_title author perm version updated
## <chr> <chr> <chr> <chr> <dttm>
## 1 RotelleVer3 scotti rw old 2017-08-20 09:48:51
## # ... with 5 more variables: sheet_key <chr>, ws_feed <chr>,
## # alternate <chr>, self <chr>, alt_key <chr>
Rv3 <- gs_url(gsurl)
## Sheet-identifying info appears to be a browser URL.
## googlesheets will attempt to extract sheet key from the URL.
## Putative key: 19QBPUmwnREaTlZ5Zbw46askcnmPSwc6wW17UELbhmBg
## Sheet successfully identified: "RotelleVer3"
# Rv3 <- Rv3 %>% gs_ws_new(ws_title = "CorrezioniProposte", input = pcsim)
La tabella prodotta (‘CorrezioniProposte’, file:'RotelleVer3‘) espone il risultato dell’analisi effettuata su tutte le rotelle teoricamente complete sui due lati, che però presentano, sul lato ’b’, un anello in meno che sul lato ‘a’ (oppure, equivalentemente, un anello di troppo sul lato ‘a’).
TeeeSector modify_y how 1-1 1971 :cdI1:cdD2
1-1 1995 :cdI2:cdD1
1-1 1996 :crI2
1-1 2010 :crI1
1-2 1985 :cdD1
1-2 1994 :cdI1:cdD2 ……
Come puoi vedere nello spezzone di tabella riportato come esempio qui sopra, per ogni rotella (individuata con la sigla “TreeSection”, Fusto-Rotella) vengono presentate diverse possibili opzioni, tra loro alternative, di correzione della sequenza delle misurazioni effettuate.
La colonna ‘modify_y’ individua su quale anello intervenire,
la colonna ‘how’ specifica il tipo di correzzione proposto. I codici utilizzati nella colonna ‘how’ hanno i seguenti significati.
I due punti “:” iniziano una proposta, in molti casi c’è più di una proposta di intervento relativa allo stesso anello (anno).
Le lettere maiuscole “I” e “D” indicano rispettivamento ‘Insertion’ e ‘Delition’.
Le due lettere minuscole iniziali indicano il criterio in base al quale si è ottenuta l’indicazione presentata: “cd” è quello analogo al DTW (basato sulle distanze punto-punto), “cr” è un criterio originale basato sulla ‘correlazione locale tra segmenti di serie’.
Infine, il numero in chiusura indica la priorità:
1 = prima opzione da considerare (per quella correzione in base a quel criterio),
2 = seconda opzione da considerare.
In pratica
Delle rotelle considerate in questa tabella prenderne alcune, casualmente, fra quelle che si possono rileggere almeno sulla foto, se non dal vivo. (Se è possibile arrivare a 30 rotelle sarebbe ideale) Per ciscuna di queste, aiutandosi con la tabella di registarazione delle misurazioni(^1), individuare gli anelli corrispondenti agli anni selezionati dall’analisi (‘modify_y’). Se ‘how’ contiene una ‘I’, esaminare il lato ‘b’ e valutare se, in effetti, giusto prima dell’anello considerato c èra stato saltato un anello nelle misurazioni registrate.
Se ‘how’ contiene una ‘D’, esaminare il lato ‘a’ e valutare se, in effetti, la misurazione relativa all’anno individuato non corrisponde ad un anello effettivo e sarebbe quindi da eliminare.
Valutata la situazione per tutti gli anni selezionati dall’analisi scegliere quale delle correzioni proposte è la più convincente e registrare la scelta in una colonna aggiuntiva, replicando la sigla dell’intervento. (^2)
(^1) La tabella da utilizzare quella nel foglio ‘DatabaseV2’ del tabellone Google ‘RotelleVer2’ raggiungibile all’indirizzo https://docs.google.com/spreadsheets/d/15ZLnI780oKr4QKuc4k4UAwZ6w6YmEE8tj4c2sU44xLQ/edit#gid=1996889235 In questa tabella puoi inserire commenti ma non puoi modificare i dati. Se ti è più comodo puoi utilizzare una copia in formato Excel di quel tabellone (ne inivio una io).
(^2) Ho preparato un tabellone con la colonna dove replicare il codice della correzione che hai valutato migliore per ciascuna delle sezioni che potrai esaminare. La trovi all’indirizzo https://docs.google.com/spreadsheets/d/19QBPUmwnREaTlZ5Zbw46askcnmPSwc6wW17UELbhmBg/edit#gid=2034395174 (Se non è possibile inserire i risultati della tua analisi su questo tabellone in rete, invio copia in Excel)