<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _vis_calibrate(data, chn, calib_type, pre_launch_coeffs=False, calib_coeffs=None, mask=False):
 """Visible channel calibration only. *calib_type* in count, reflectance, radiance """

    # Calibration count to albedo, the calibration is performed separately for
    # two value ranges.

    if calib_type not in ['counts', 'radiance', 'reflectance']:
        raise ValueError('Calibration ' + calib_type + ' unknown!')

    arr = data["hrpt"][:, :, chn]
    mask |= arr == 0

    channel = arr.astype(np.float)
    if calib_type == 'counts':
        return channel

    if calib_type == 'radiance':
        logger.info("Radiances are not yet supported for " +
                    "the VIS/NIR channels!")

    if pre_launch_coeffs:
        coeff_idx = 2
    else:
        # check that coeffs are valid
        if np.all(data["calvis"][:, chn, 0, 4] == 0):
            logger.info(
                "No valid operational coefficients, fall back to pre-launch")
            coeff_idx = 2
        else:
            coeff_idx = 0

    intersection = data["calvis"][:, chn, coeff_idx, 4]

    if calib_coeffs is not None:
        logger.info("Updating from external calibration coefficients.")
        # intersection = np.expand_dims
        slope1 = np.expand_dims(calib_coeffs[0], 1)
        intercept1 = np.expand_dims(calib_coeffs[1], 1)
        slope2 = np.expand_dims(calib_coeffs[2], 1)
        intercept2 = np.expand_dims(calib_coeffs[3], 1)
    else:
        slope1 = np.expand_dims(data["calvis"][:, chn, coeff_idx, 0] * 1e-10,
                                1)
        intercept1 = np.expand_dims(data["calvis"][:, chn, coeff_idx, 1] *
                                    1e-7, 1)
        slope2 = np.expand_dims(data["calvis"][:, chn, coeff_idx, 2] * 1e-10,
                                1)
        intercept2 = np.expand_dims(data["calvis"][:, chn, coeff_idx, 3] *
                                    1e-7, 1)

        if chn == 2:
            slope2[slope2 < 0] += 0.4294967296

    mask1 = channel <= np.expand_dims(intersection, 1)
    mask2 = channel > np.expand_dims(intersection, 1)

    channel[mask1] = (channel * slope1 + intercept1)[mask1]

    channel[mask2] = (channel * slope2 + intercept2)[mask2]

    channel = channel.clip(min=0)

    return np.where(mask, np.nan, channel)