rotation function preprocesses NaNs and ensures all interpolated data stays within the max and min of the input data.