move downsample function to tools