def detect_plates(step, vrms_surface, fids, time):
vphi = step.fields['<STR_LIT>'][<NUM_LIT:0>, :, :, <NUM_LIT:0>]<EOL>ph_coord = step.geom.p_coord<EOL>if step.sdat.par['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>dsa = step.sdat.par['<STR_LIT>']['<STR_LIT>']<EOL>indsurf = np.argmin(abs((<NUM_LIT:1> - dsa) - step.geom.r_coord)) - <NUM_LIT:4><EOL><DEDENT>else:<EOL><INDENT>indsurf = -<NUM_LIT:1><EOL><DEDENT>vph2 = <NUM_LIT:0.5> * (vphi + np.roll(vphi, <NUM_LIT:1>, <NUM_LIT:0>))  <EOL>dvph2 = (np.diff(vph2[:, indsurf]) / (ph_coord[<NUM_LIT:0>] * <NUM_LIT>))<EOL>io_surface(step.isnap, time, fids[<NUM_LIT:6>], dvph2)<EOL>io_surface(step.isnap, time, fids[<NUM_LIT:7>], vph2[:-<NUM_LIT:1>, indsurf])<EOL>myorder_trench = <NUM_LIT:15> if step.sdat.par['<STR_LIT>']['<STR_LIT>'] else <NUM_LIT:10><EOL>myorder_ridge = <NUM_LIT:20>  <EOL>pom2 = np.copy(dvph2)<EOL>if step.sdat.par['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>maskbigdvel = -<NUM_LIT:30> * vrms_surface<EOL><DEDENT>else:<EOL><INDENT>maskbigdvel = -<NUM_LIT:10> * vrms_surface<EOL><DEDENT>pom2[pom2 > maskbigdvel] = maskbigdvel<EOL>argless_dv = argrelextrema(<EOL>pom2, np.less, order=myorder_trench, mode='<STR_LIT>')[<NUM_LIT:0>]<EOL>trench = ph_coord[argless_dv]<EOL>velocity_trench = vph2[argless_dv, indsurf]<EOL>dv_trench = dvph2[argless_dv]<EOL>pom2 = np.copy(dvph2)<EOL>masksmalldvel = np.amax(dvph2) * <NUM_LIT><EOL>pom2[pom2 < masksmalldvel] = masksmalldvel<EOL>arggreat_dv = argrelextrema(<EOL>pom2, np.greater, order=myorder_ridge, mode='<STR_LIT>')[<NUM_LIT:0>]<EOL>ridge = ph_coord[arggreat_dv]<EOL>argdel = []<EOL>if trench.any() and ridge.any():<EOL><INDENT>for i, ridge_i in enumerate(ridge):<EOL><INDENT>mdistance = np.amin(abs(trench - ridge_i))<EOL>if mdistance < <NUM_LIT>:<EOL><INDENT>argdel.append(i)<EOL><DEDENT><DEDENT>if argdel:<EOL><INDENT>print('<STR_LIT>', trench, ridge[argdel])<EOL>ridge = np.delete(ridge, np.array(argdel))<EOL>arggreat_dv = np.delete(arggreat_dv, np.array(argdel))<EOL><DEDENT><DEDENT>dv_ridge = dvph2[arggreat_dv]<EOL>if '<STR_LIT>' in conf.plates:<EOL><INDENT>agefld = step.fields['<STR_LIT>'][<NUM_LIT:0>, :, :, <NUM_LIT:0>]<EOL>age_surface = np.ma.masked_where(agefld[:, indsurf] < <NUM_LIT>,<EOL>agefld[:, indsurf])<EOL>age_surface_dim = age_surface * vrms_surface *conf.scaling.ttransit / conf.scaling.yearins / <NUM_LIT><EOL>agetrench = age_surface_dim[argless_dv]  <EOL><DEDENT>else:<EOL><INDENT>agetrench = np.zeros(len(argless_dv))<EOL><DEDENT>for itrench in np.arange(len(trench)):<EOL><INDENT>fids[<NUM_LIT:0>].write("<STR_LIT>" % (<EOL>step.isnap,<EOL>step.geom.ti_ad,<EOL>trench[itrench],<EOL>velocity_trench[itrench],<EOL>agetrench[itrench]<EOL>))<EOL><DEDENT>return trench, ridge, agetrench, dv_trench, dv_ridge<EOL>
detect plates using derivative of horizontal velocity