def get_sort_val(myslice,ddim):
    """Gets the value to sort a slice by, given the changing coordinate. Can handle either
    tuples of (dicom,filename) or a simple dicom object"""

    if type(myslice) == tuple:
        return myslice[0].ImagePositionPatient[ddim]
    else:
        return myslice.ImagePositionPatient[ddim]