code: def calibrate_data(params, raw_data, calib_data):
      
      start = calib_data.before(datetime.max)
      if start is None:
          start = datetime.min
      start = raw_data.after(start + SECOND)
      if start is None:
          return start
      del calib_data[start:]
      calibrator = Calib(params, raw_data)
      def calibgen(inputdata):
          """Internal generator function"""
          count = 0
          for data in inputdata:
              idx = data['idx']
              count += 1
              if count % 10000 == 0:
                  logger.info("calib: %s", idx.isoformat(' '))
              elif count % 500 == 0:
                  logger.debug("calib: %s", idx.isoformat(' '))
              for key in ('rain', 'abs_pressure', 'temp_in'):
                  if data[key] is None:
                      logger.error('Ignoring invalid data at %s', idx.isoformat(' '))
                      break
              else:
                  yield calibrator.calib(data)
      calib_data.update(calibgen(raw_data[start:]))
      return start
docs: Calibrate' raw data, using a user-supplied function.