code: def recalculate_psd(self):
          
  
          seg_len = self.sample_rate * self.psd_segment_length
          e = len(self.strain)
          s = e - ((self.psd_samples + 1) * self.psd_segment_length / 2) * self.sample_rate
          psd = pycbc.psd.welch(self.strain[s:e], seg_len=seg_len, seg_stride=seg_len / 2)
  
          psd.dist = spa_distance(psd, 1.4, 1.4, self.low_frequency_cutoff) * pycbc.DYN_RANGE_FAC
  
          # If the new psd is similar to the old one, don't replace it
          if self.psd and self.psd_recalculate_difference:
              if abs(self.psd.dist - psd.dist) / self.psd.dist < self.psd_recalculate_difference:
                  logging.info("Skipping recalculation of %s PSD, %s-%s",
                               self.detector, self.psd.dist, psd.dist)
                  return True
  
          # If the new psd is *really* different than the old one, return an error
          if self.psd and self.psd_abort_difference:
              if abs(self.psd.dist - psd.dist) / self.psd.dist > self.psd_abort_difference:
                  logging.info("%s PSD is CRAZY, aborting!!!!, %s-%s",
                               self.detector, self.psd.dist, psd.dist)
                  self.psd = psd
                  self.psds = {}
                  return False
  
          # If the new estimate replaces the current one, invalide the ineterpolate PSDs
          self.psd = psd
          self.psds = {}
          logging.info("Recalculating %s PSD, %s", self.detector, psd.dist)
          return True
docs: Recalculate the psd