[bozza non finita]

Aim

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, acually, 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

Evaluating matching indicators

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.

Compute Sections synthesis (final code of ‘FromGS2at.R’) and Ring Widths

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)

Evaluating similarity measures

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")

Sequential evaluation of insertions and delitions on sections with ‘one year difference’ sides

library(splus2R)
tmp <- sqldf("select A.* from rw_all A natural join Sects_sy where max_b_year = 2016")
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)")

start_time <- Sys.time()
pcsim <- data.frame()
ts <- with(rw_1yd, paste(TreeId, SectId, sep="-"))
for (i in unique(ts)) {
  print(i)
  ls <- rw_1yd[ts==i & rw_1yd$side=='a',]  # LongSeries
  N <- nrow(ls)
  ss <- rw_1yd[ts==i & rw_1yd$side=='b',]  # ShortSeries (len=N-1)
  csim <- data.frame()
  #  (partial) cumulated differences/correlations squared
#  for (y in min(ls$gyear):(min(ls$gyear))) { # compute cumulative 'similarity' I and D in position j
  for (y in min(ls$gyear):(max(ls$gyear)-1)) { # compute cumulative 'similarity' I and D in position j
    
    # Insert (after y, splitting rw[y] in two, shifting +1 following years) - in ss
    ssI <- ss[ss$gyear <= y, ]
    rw <- ss$rrw[ss$gyear == y]
    ssI <- rbind(ssI, ss[ss$gyear == y, ])
    ssI$rrw[ssI$gyear == y] <- rw/2
    p <- nrow(ssI)
    ssI <- rbind(ssI, ss[ss$gyear > y,])
    ssI$gyear[p:nrow(ssI)] <- 1 + ssI$gyear[p:nrow(ssI)]
    
    # Delete (ring y: sum j and j+1, till N-1) from long series
    if (y < max(ls$gyear)) {
      lsD <- ls[ls$gyear <= y,]
      lsD$rrw[lsD$gyear == y] <- lsD$rrw[lsD$gyear == y] + ls$rrw[ls$gyear == y+1]
      p <- nrow(lsD)
      lsD <- rbind(lsD, ls[ls$gyear > y+1,])
      lsD$gyear[p:nrow(lsD)] <- lsD$gyear[p:nrow(lsD)] -1
    } else {lsD = NULL}
    
    n <- 3
    csim <- rbind(csim, 
                  data.frame(TeeeSector = i
                      , modify_y=y
                      , cdI = sum((ls$rrw-ssI$rrw)^2) / length(ls)
                      , cdD = sum((lsD$rrw-ss$rrw)^2) / length(lsD)
                      , crI = sum((localCor(ls$rrw, ssI$rrw, n)+1)/2) / length(ls)
                      , crD = sum((localCor(lsD$rrw, ss$rrw, 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] "1-1"
## [1] "1-2"
## [1] "1-3"
## [1] "1-4"
## [1] "1-5"
## [1] "2-2"
## [1] "2-3"
## [1] "2-4"
## [1] "2-5"
## [1] "2-6"
## [1] "3-2"
## [1] "3-3"
## [1] "3-4"
## [1] "3-5"
## [1] "3-6"
## [1] "4-2"
## [1] "4-5"
## [1] "5-1"
## [1] "5-2"
## [1] "5-3"
## [1] "6-1"
## [1] "6-2"
## [1] "6-3"
## [1] "6-4"
## [1] "7-2"
## [1] "7-3"
## [1] "7-5"
## [1] "7-6"
## [1] "8-1"
## [1] "8-2"
## [1] "8-3"
## [1] "8-4"
## [1] "8-5"
## [1] "9-3"
## [1] "9-4"
## [1] "9-6"
## [1] "10-2"
## [1] "10-3"
## [1] "10-4"
## [1] "10-5"
## [1] "10-6"
## [1] "11-1"
## [1] "11-3"
## [1] "12-1"
## [1] "12-2"
## [1] "12-3"
## [1] "12-4"
## [1] "13-2"
## [1] "13-3"
## [1] "13-4"
## [1] "13-5"
## [1] "14-2"
## [1] "14-3"
## [1] "14-4"
## [1] "14-5"
## [1] "15-1"
## [1] "15-2"
## [1] "15-3"
## [1] "15-4"
## [1] "16-3"
## [1] "16-4"
## [1] "17-2"
## [1] "17-3"
## [1] "18-2"
## [1] "18-3"
## [1] "19-1"
## [1] "19-2"
## [1] "19-3"
## [1] "20-1"
## [1] "20-2"
## [1] "20-3"
## [1] "21-2"
## [1] "22-2"
## [1] "23-2"
## [1] "23-3"
## [1] "23-4"
## [1] "24-2"
## [1] "24-3"
## [1] "25-2"
## [1] "25-3"
## [1] "26-1"
## [1] "26-3"
## [1] "27-2"
## [1] "27-3"
## [1] "28-1"
## [1] "29-1"
## [1] "29-3"
## [1] "29-4"
## [1] "30-2"
## [1] "30-3"
## [1] "31-3"
## [1] "31-4"
## [1] "32-2"
## [1] "32-3"
## [1] "32-4"
## [1] "32-5"
## [1] "32-6"
## [1] "32-7"
## [1] "33-1"
## [1] "33-2"
## [1] "33-3"
## [1] "33-5"
## [1] "33-6"
## [1] "33-7"
## [1] "34-2"
## [1] "34-3"
## [1] "35-2"
## [1] "36-1"
## [1] "36-3"
## [1] "36-4"
## [1] "36-5"
## [1] "37-1"
## [1] "37-2"
## [1] "37-3"
## [1] "37-4"
## [1] "38-2"
## [1] "38-3"
## [1] "38-4"
## [1] "38-5"
## [1] "38-6"
## [1] "39-1"
## [1] "39-2"
## [1] "39-3"
## [1] "39-4"
## [1] "40-2"
## [1] "40-3"
## [1] "40-5"
## [1] "41-2"
## [1] "42-2"
## [1] "43-1"
## [1] "43-2"
## [1] "44-2"
## [1] "44-3"
## [1] "44-4"
## [1] "44-5"
## [1] "45-2"
## [1] "46-1"
## [1] "46-2"
## [1] "46-3"
## [1] "46-4"
end_time <- Sys.time()
print(paste("start:", start_time, "- end:", end_time, "- Time elapsed:", end_time - start_time))
## [1] "start: 2017-08-17 05:08:31 - end: 2017-08-17 05:09:12 - Time elapsed: 41.2033178806305"
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      :cdD2
## 273         8-2     2004      :crI2
## 331         8-2     2010      :crI1
## 34          8-2     2011      :cdI2
## 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 :cdI1: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
## 341        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
## 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
## 218        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
## 219        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
## 2110       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
## 2111       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
## 1714       43-2     2003      :crI1
## 1916       43-2     2005 :cdI1:cdD1
## 2214       43-2     2008      :crI2
## 246        43-2     2010 :cdI2:cdD2
## 521        44-2     1987 :cdI1:cdD1
## 1222       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
## 2112       44-3     2008      :cdD2
## 2215       44-3     2009      :cdI2
## 2513       44-3     2012      :crI1
## 919        44-4     1998      :crI1
## 1528       44-4     2004 :cdI1:cdD1
## 2216       44-4     2011      :cdD2
## 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
## 2217       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
## 2312       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-17 02:48:39
## # ... 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)

Istruzioni per l’uso

Questa tabella 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’). Per ogni rotella (individuata con la sigla “TreeSection”) vengono presentate diverse possibili opzioni di correzione della sequenza delle misurazioni effettuate, tra loro alternative. 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 “:” separano possibili interventi diversi relativi 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 di è ottenuta l’indicazione presentata: “cd” è quello analogo al DTW (pasato 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, l’anello che segue è stato saltato 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)