<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mag_calibration(self):
 """Perform magnetometer calibration for current IMU."""

        self.calibration_state = self.CAL_MAG
        self.mag_dialog = SK8MagDialog(self.sk8.get_imu(self.spinIMU.value()), self)
        if self.mag_dialog.exec_() == QDialog.Rejected:
            return

        self.calculate_mag_calibration(self.mag_dialog.samples)