code: def mag_field(RAW_IMU, SENSOR_OFFSETS=None, ofs=None):
      '''calculate magnetic field strength from raw magnetometer'''
      mag_x = RAW_IMU.xmag
      mag_y = RAW_IMU.ymag
      mag_z = RAW_IMU.zmag
      if SENSOR_OFFSETS is not None and ofs is not None:
          mag_x += ofs[0] - SENSOR_OFFSETS.mag_ofs_x
          mag_y += ofs[1] - SENSOR_OFFSETS.mag_ofs_y
          mag_z += ofs[2] - SENSOR_OFFSETS.mag_ofs_z
      return sqrt(mag_x**2 + mag_y**2 + mag_z**2f mag_field(RAW_IMU, SENSOR_OFFSETS=None, ofs=None):
      '''calculate magnetic field strength from raw magnetometer'''
      mag_x = RAW_IMU.xmag
      mag_y = RAW_IMU.ymag
      mag_z = RAW_IMU.zmag
      if SENSOR_OFFSETS is not None and ofs is not None:
          mag_x += ofs[0] - SENSOR_OFFSETS.mag_ofs_x
          mag_y += ofs[1] - SENSOR_OFFSETS.mag_ofs_y
          mag_z += ofs[2] - SENSOR_OFFSETS.mag_ofs_z
      return sqrt(mag_x**2 + mag_y**2 + mag_z**2)
docs: calculate magnetic field strength from raw magnetometer