def detect_plates_vzcheck(step, seuil_memz):
v_z = step.fields['<STR_LIT>'][<NUM_LIT:0>, :, :, <NUM_LIT:0>]<EOL>v_x = step.fields['<STR_LIT>'][<NUM_LIT:0>, :, :, <NUM_LIT:0>]<EOL>tcell = step.fields['<STR_LIT:T>'][<NUM_LIT:0>, :, :, <NUM_LIT:0>]<EOL>n_z = step.geom.nztot<EOL>nphi = step.geom.nptot  <EOL>rcmb = max(<NUM_LIT:0>, step.geom.rcmb)<EOL>radius = step.geom.r_coord + rcmb<EOL>radiusgrid = step.geom.rgeom[:, <NUM_LIT:0>] + rcmb<EOL>dphi = <NUM_LIT:1> / nphi<EOL>vz_mean = <NUM_LIT:0><EOL>tgrid = np.zeros((nphi, n_z + <NUM_LIT:1>))<EOL>tgrid[:, <NUM_LIT:0>] = <NUM_LIT:1><EOL>for i_z in range(<NUM_LIT:1>, n_z):<EOL><INDENT>for phi in range(nphi):<EOL><INDENT>tgrid[phi, i_z] = (<EOL>tcell[phi, i_z - <NUM_LIT:1>] *<EOL>(radiusgrid[i_z] - radius[i_z - <NUM_LIT:1>]) + tcell[phi, i_z] *<EOL>(-radiusgrid[i_z] + radius[i_z])) / (radius[i_z] -<EOL>radius[i_z - <NUM_LIT:1>])<EOL>vz_mean += abs(v_z[phi, i_z]) / (nphi * n_z)<EOL><DEDENT><DEDENT>flux_c = n_z * [<NUM_LIT:0>]<EOL>for i_z in range(<NUM_LIT:1>, n_z - <NUM_LIT:1>):<EOL><INDENT>for phi in range(nphi):<EOL><INDENT>flux_c[i_z] += (tgrid[phi, i_z] - step.timeinfo.loc['<STR_LIT>']) *v_z[phi, i_z] * radiusgrid[i_z] * dphi<EOL><DEDENT><DEDENT>if all(abs(flux_c[i_z]) <= np.max(flux_c) / <NUM_LIT:50><EOL>for i_z in range(n_z - n_z // <NUM_LIT:20>, n_z)):<EOL><INDENT>raise error.StagnantLidError(step.sdat)<EOL><DEDENT>else:<EOL><INDENT>dvphi = nphi * [<NUM_LIT:0>]<EOL>dvx_thres = <NUM_LIT:16> * step.timeinfo.loc['<STR_LIT>']<EOL>for phi in range(<NUM_LIT:0>, nphi):<EOL><INDENT>dvphi[phi] = (v_x[phi, n_z - <NUM_LIT:1>] -<EOL>v_x[phi - <NUM_LIT:1>, n_z - <NUM_LIT:1>]) / ((<NUM_LIT:1> + rcmb) * dphi)<EOL><DEDENT>limits = []<EOL>for phi in range(<NUM_LIT:0>, nphi - nphi // <NUM_LIT>):<EOL><INDENT>mark = all(abs(dvphi[i]) <= abs(dvphi[phi])<EOL>for i in range(phi - nphi // <NUM_LIT>, phi + nphi // <NUM_LIT>))<EOL>if mark and abs(dvphi[phi]) >= dvx_thres:<EOL><INDENT>limits.append(phi)<EOL><DEDENT><DEDENT>for phi in range(nphi - nphi // <NUM_LIT> + <NUM_LIT:1>, nphi):<EOL><INDENT>mark = all(abs(dvphi[i]) <= abs(dvphi[phi])<EOL>for i in range(phi - nphi // <NUM_LIT> - nphi,<EOL>phi + nphi // <NUM_LIT> - nphi))<EOL>if mark and abs(dvphi[phi]) >= dvx_thres:<EOL><INDENT>limits.append(phi)<EOL><DEDENT><DEDENT>k = <NUM_LIT:0><EOL>for i in range(len(limits)):<EOL><INDENT>vzm = <NUM_LIT:0><EOL>phi = limits[i - k]<EOL>for i_z in range(<NUM_LIT:1> if phi == nphi - <NUM_LIT:1> else <NUM_LIT:0>, n_z):<EOL><INDENT>vzm += (abs(v_z[phi, i_z]) +<EOL>abs(v_z[phi - <NUM_LIT:1>, i_z]) +<EOL>abs(v_z[(phi + <NUM_LIT:1>) % nphi, i_z])) / (n_z * <NUM_LIT:3>)<EOL><DEDENT>vz_thres = vz_mean * <NUM_LIT:0.1> + seuil_memz / <NUM_LIT:2> if seuil_memz else <NUM_LIT:0><EOL>if vzm < vz_thres:<EOL><INDENT>limits.remove(phi)<EOL>k += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return limits, nphi, dvphi, vz_thres, v_x[:, n_z - <NUM_LIT:1>]<EOL>
detect plates and check with vz and plate size