def get_exp_type(detector, mirifilter, subarray='FULL', datatype='SCIENCE'):
    """

    Helper function which derives an exposure type given a combination
    of detector name, filter, subarray and data type

    NOTE: This function needs to know the data type to return the
    correct exposure type for MIRI calibration data.

    :Parameters:

    detector: str
        Name of detector (MIRIMAGE, MIRIFUSHORT or MIRIFULONG)
    mirifilter: str
        Name of filter
    subarray: str, optional
        Name of subarray (defaults to 'FULL')
    datatype: str, optional
        Known data type (SCIENCE, DARK, FLAT or TARGET)
        Defaults to SCIENCE.

    :Returns:

    exp_type: str
        The exposure type string (EXP_TYPE)

    """
    assert isinstance(detector, str)
    assert isinstance(mirifilter, str)

    if 'MIRIFU' in detector:
        if (mirifilter and 'OPAQUE' in mirifilter) or (datatype == 'DARK'):
            exp_type = 'MIR_DARKMRS'
        elif datatype == 'FLAT':
            exp_type = 'MIR_FLAT-MRS'
        else:
            exp_type = 'MIR_MRS'
    elif 'IM' in detector:
        if (mirifilter and 'OPAQUE' in mirifilter) or (datatype == 'DARK'):
            exp_type = 'MIR_DARKIMG'
        elif datatype == 'FLAT':
            exp_type = 'MIR_FLAT-IMAGE'
        elif mirifilter and 'P750L' in mirifilter:
            if 'SLITLESS' in subarray:
                exp_type = 'MIR_LRS-SLITLESS'
            else:
                exp_type = 'MIR_LRS-FIXEDSLIT'
        elif subarray and 'LYOT' in subarray:
            if datatype == 'SCIENCE':
                exp_type = 'MIR_LYOT'
            elif datatype == 'TARGET':
                exp_type = 'MIR_TACQ'
            else:
                exp_type = 'MIR_CORONCAL'
        elif subarray and 'MASK' in subarray:
            if datatype == 'SCIENCE':
                exp_type = 'MIR_4QPM'
            elif datatype == 'TARGET':
                exp_type = 'MIR_TACQ'
            else:
                exp_type = 'MIR_CORONCAL'
        else:
            exp_type = 'MIR_IMAGE'
    elif datatype == 'DARK':
        exp_type = 'MIR_DARKALL'
    else:
        # Exposure type cannot be derived
        exp_type = ''
    return exp_type