def statsAndConcat(self, s, i, count, beforeAvg=True):
        """Construct array to common space for this timepoint.
           This builds upon arrays from previous calls."""
        if beforeAvg:
            xfm = s[i].getLastXfm(s[i+1]) 
        else:
            xfm = s[i].getLastXfm(s[i-1])
        """Set this transform as last xfm from input to nlin and calculate nlin to s[i] stats"""
        if self.nlinFH:
            self.xfmToCommon.insert(0, xfm)
            """ Concat transforms to get xfmToCommon and calculate statistics 
                Note that inverted transform, which is what we want, is calculated in
                the statistics module. """
            xtc = createBaseName(s[i].transformsDir, s[i].basename + "_to_" + self.commonName + ".xfm")
            xc = ma.xfmConcat(self.xfmToCommon, xtc, fh.logFromFile(s[i].logDir, xtc))
            self.p.addStage(xc)
            # here in order to visually inspect the alignment with the common
            # time point, we should resample this subject:
            inputResampledToCommon = createBaseName(s[i].resampledDir, s[i].basename + "_to_" + self.commonName + ".mnc") 
            logToCommon = fh.logFromFile(s[i].logDir, inputResampledToCommon)
            resampleCmd = ma.mincresample(s[i],
                                          self.nlinFH,
                                          likeFile=self.nlinFH,
                                          transform=xtc,
                                          output=inputResampledToCommon,
                                          logFile=logToCommon,
                                          argArray=["-sinc"])
            self.p.addStage(resampleCmd)
            s[i].addAndSetXfmToUse(self.nlinFH, xtc)
            self.statsCalculation(s[i], self.nlinFH, xfm=None, useChainStats=False)
        else:
            xtc=None
        """Calculate i to i+1 stats for all but final timePoint"""
        if count - i > 1:
            self.statsCalculation(s[i], s[i+1], xfm=xtc, useChainStats=True)
dataset/ETHPy150Open Mouse-Imaging-Centre/pydpiper/atoms_and_modules/minc_modules.py/LongitudinalStatsConcatAndResample.statsAndConcat/original