This paper proposes a new method to calculate a safety factor, q, profile from gridded data of a poloidal flux, Ψ, efficiently and accurately. Difficulties of calculating q are derived from a difficulty of specifying a contour line of Ψ and a singularity at a magnetic axis. In order to solve the first difficulty, the proposed method interpolates knots, which are located on a target Ψ, by utilizing a normalized arc length and constraints expressed by a magnetic field. Regarding the second difficulty, the proposed method identifies q0 by extrapolating a q profile around a magnetic axis with a constraint of dq/dρ = 0 at the magnetic axis. Accuracy assessments of the proposed method are carried out by utilizing the Solov'ev-type equilibrium. The results show the validity and high performance of the proposed method.