Turbulence modulation in thermally expanding and contracting flows