new code for chisqs of gradient field