convert the noisegen_grad logic to a switch statement.