else: values.append(settings.NAN_STR) else: (i, j, k), interpolator = point_interpolator int_value = settings.FMT_FLOAT.format( interpolator.dot(var[[i, j, k]])) if args.long: csvwriter.writerow(values_long + [var_ID, int_value]) else: values.append(int_value) if not args.long: csvwriter.writerow(values) parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf']) parser.add_argument('in_points', help='set of points file (*.shp)') parser.add_known_argument('out_csv') parser.add_argument( '--long', help= 'write CSV with long format (variables are also in rows) instead of wide format', action='store_true') parser.add_argument( '--vars', nargs='+', help='variable(s) to extract (by default: every variables)', default=None, metavar=('VA', 'VB')) parser.add_group_general(['force', 'verbose'])
args.shift[1], 0) ]) mesh = MeshInterpolator(output_header, True) lines = [] for poly in Shapefile.get_lines(args.outADCP_GPS, shape_type=3): lines.append(poly) nb_nonempty, indices_nonempty, line_interpolators, line_interpolators_internal = \ mesh.get_line_interpolators(lines) res = mesh.interpolate_along_lines( resin, 'M', list(range(len(resin.time))), indices_nonempty, line_interpolators, '{:.6e}') csvwriter.writerows([[folder] + x[2] for x in res]) parser = PyTelToolsArgParse(description=__doc__, add_args=['shift']) parser.add_argument("inADCP_GPS", help="GPS ADCP (_gps_ASC.txt) input filename") parser.add_argument("inADCP", help="ADCP (_ASC.txt) input filename") parser.add_argument("--inTELEMAC", help="Telemac-2D result files with M (r2d_last.slf)", nargs='*') parser.add_argument("outADCP_GPS", help="GPS ADCP (.shp) output filename") parser.add_argument("outADCP", help="ADCP (.csv) output filename") parser.add_argument("outT2DCSV", help="CSV output filename") parser.add_argument("--inEPSG", help="input EPSG", type=int, default=4326) # WGS-84 parser.add_argument("--outEPSG", help="output EPSG", type=int, default=2154) # Lambert 93 (France) if __name__ == "__main__":
bottom += args.Cmud * args.ws * args.C * \ (1 - np.clip(mean_tau/args.Tcd, a_min=None, a_max=1.)) * dt if args.Tce > 0: bottom -= args.Cmud * args.M * (np.clip( mean_tau / args.Tce, a_min=1., a_max=None) - 1.) * dt evol_bottom = bottom - initial_bottom resout.write_entire_frame(output_header, time, np.vstack((bottom, evol_bottom))) prev_time = time prev_tau = tau parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf', 'out_slf', 'shift']) help_friction_laws = ', '.join( ['%i=%s' % (i, law) for i, law in enumerate(FRICTION_LAWS)]) parser.add_argument('--friction_law', type=int, help='friction law identifier: %s' % help_friction_laws, choices=range(len(FRICTION_LAWS)), default=STRICKLER_ID) parser.add_argument('--Cmud', help='mud concentration (liquid) [kg/m³]', type=float, default=1200) group_deposition = parser.add_argument_group( 'Deposition', 'Parameters of Krone deposition law') group_deposition.add_argument('--Tcd', help='critical Shear Stress for Deposition [Pa]',
# Replace value by a linear interpolation z_int = zone.interpolate(pt_projected) new_z = zone.operator(z_int, old_z) var[pos_B, i] = new_z print("BOTTOM at node {} (zone n°{}, rescued) {} to {} (dz={})".format( i + 1, j, operator_str, new_z, new_z - old_z )) nmodif += 1 break resout.write_entire_frame(output_header, time, var) print("{} nodes were overwritten".format(nmodif)) if __name__ == '__main__': parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf', 'out_slf']) parser.add_argument("in_i3s_paths", help="i3s BlueKenue 3D polyline file", nargs='+') parser.add_argument("--operations", help="list of operations (set is used by default)", nargs='+', choices=('set', 'max', 'min')) parser.add_argument("--threshold", type=float, help="value from which to interpolate") parser.add_argument('--attr_to_shift_z', help='attribute to shift z') parser.add_argument('--rescue_distance', default=0.1, help='distance buffer (in m) to match nodes close to a zone nut not inside') parser.add_group_general(['force', 'verbose']) args = parser.parse_args() bottom(args)
for time_index, time in tqdm(resin.subset_time( args.start, args.end, args.ech), unit='frame'): values = do_calculations_in_frame(necessary_equations, resin, time_index, output_header.var_IDs, output_header.np_float_type, is_2d=output_header.is_2d, us_equation=us_equation, ori_values={}) resout.write_entire_frame(output_header, time, values) parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf', 'out_slf', 'shift']) parser.add_argument('--set_mesh_origin', type=float, nargs=2, help='Mesh origin coordinates (x, y)', metavar=('X', 'Y')) group_var = parser.add_argument_group( 'Serafin variables (optional)', 'See variables abbrevations on https://github.com/CNR-Engineering/PyTelTools/wiki/Notations-of-variables' ) group_var.add_argument('--var2del', nargs='+', help='variable(s) to delete', default=[],
sys.exit(1) for time_index, time in enumerate(resin.time): for j, var_ID in enumerate(var_IDs): values = resin.read_var_in_frame(time_index, var_ID) if time_index == 0 and i == 0: out_values[j, :] = values else: out_values[j, mask_nodes] = fun(out_values[j, mask_nodes], values[mask_nodes]) with Serafin.Write(args.out_slf, args.lang, overwrite=args.force) as resout: resout.write_header(output_header) resout.write_entire_frame(output_header, 0.0, out_values) parser = PyTelToolsArgParse(description=__doc__) parser.add_argument('in_slfs', help='List of Serafin input filenames', nargs='+') parser.add_argument('out_slf', help='Serafin output filename') parser.add_argument('--operation', help='min or max function selector', choices=('min', 'max'), default='max') parser.add_argument('--in_polygons', help='file containing polygon(s)') parser.add_argument('--vars', nargs='+', help='variable(s) to extract (by default: all variables)', default=None, metavar=('VA', 'VB')) parser.add_argument('--lang', help="Serafin language for variables detection: 'fr' or 'en'", default=settings.LANG) parser.add_group_general(['force', 'verbose']) if __name__ == '__main__': args = parser.parse_args() try:
values.append(resin.read_var_in_frame(time_index, var_ID)) for j in range(len(polylines)): intersections = calculator.intersections[j] flux = calculator.flux_in_frame(intersections, values) i_result.append(settings.FMT_FLOAT.format(flux)) result.append(i_result) # Write CSV mode = 'w' if args.force else 'x' with open(args.out_csv, mode) as out_csv: calculator.write_csv(result, out_csv, args.sep) parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf']) parser.add_argument('in_sections', help='set of lines file (*.shp, *.i2s)') parser.add_argument('--ech', type=int, help='frequency sampling of input', default=1) parser.add_argument('--scalars', nargs='*', help='scalars to integrate (up to 2)', default=[], metavar=('VA', 'VB')) parser.add_argument('--vectors', nargs=2, help='couple of vectors to integrate (X and Y vectors)', default=[], metavar=('VX', 'VY'))
label=("Mean" + col)) RMSE.append( np.sqrt(((file_df_mean['MagnitudeXY'] - file_df_mean_TEL['value'])**2).mean())) axs[1].bar(col_labels, RMSE) axs[1].set_ylabel('Root Mean Square error') axs[0].set_xlabel('Distance [m]') axs[0].set_ylabel('Vitesse [m/s]') box = axs[0].get_position() axs[0].set_position([box.x0, box.y0, box.width * 0.8, box.height]) axs[0].legend(loc='center left', bbox_to_anchor=(1, 0.5)) fig.set_size_inches(18.5, 10.5) plt.savefig(args.outGraph) plt.show() parser = PyTelToolsArgParse(description=__doc__) parser.add_argument("inADCP", help="ADCP (.csv) input filename") parser.add_argument("inT2DCSV", help="List of folder containing (.csv) files") parser.add_argument( "--Numberdiv", help= "Segments number of the line to compute average velocity on a normal grid", default=10) parser.add_argument("outGraph", help="Filename of plot (.png)") if __name__ == "__main__": args = parser.parse_args() plot_comp_ADCP_t2d(args)
from pyteltools.utils.cli_base import PyTelToolsArgParse from pyteltools.workflow.workflow_gui import WorkflowWelcomeWindow def exec_gui(window): """ Execute a simple GUI application @param window <PyQt5.QtWidgets.QWidget>: window to display """ app = QApplication(sys.argv) window = window() window.show() app.exec_() parser = PyTelToolsArgParse(description=__doc__) parser.add_argument('-c', '--interface', help='select and open corresponding GUI', choices=('classic', 'workflow')) if __name__ == '__main__': args = parser.parse_args() # suppress explicitly traceback silencing sys._excepthook = sys.excepthook sys.excepthook = exception_hook if args.interface is None: run_gui_app() else: if args.interface == 'classic': exec_gui(ClassicMainWindow)
volume = calculator.volume_in_frame_in_polygon( weight, values, calculator.polygons[j]) if calculator.volume_type == VolumeCalculator.POSITIVE: for v in volume: i_result.append(settings.FMT_FLOAT.format(v)) else: i_result.append(settings.FMT_FLOAT.format(volume)) result.append(i_result) # Write CSV mode = 'w' if args.force else 'x' with open(args.out_csv, mode) as out_csv: calculator.write_csv(result, out_csv, args.sep) parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf']) parser.add_argument('in_polygons', help='set of polygons file (*.shp, *.i2s)') parser.add_argument('--ech', type=int, help='frequency sampling of input', default=1) parser.add_argument('--upper_var', help='upper variable', metavar='VA', required=True) parser.add_argument('--lower_var', help='lower variable', metavar='VB', default=None) parser.add_argument('--detailed', help='add positive and negative volumes',
if (n1, n2, n3) != ikle[j]: raise RuntimeError("Mesh is not strictly identical") if i == 0: output_header = Serafin.SerafinHeader( title='Converted from LandXML (written by PyTelTools)') output_header.from_triangulation( np.array(nodes, dtype=np.int64), np.array(ikle, dtype=np.int64)) output_header.add_variable_str(varname, varname, '') resout.write_header(output_header) time = i * 3600.0 # FIXME: should convert time_duration to float resout.write_entire_frame(output_header, time, np.expand_dims(np.array(values), axis=0)) parser = PyTelToolsArgParse(description=__doc__) parser.add_argument('in_xml', help='input LandXML file (with .xml extension)') parser.add_known_argument('out_slf') parser.add_group_general(['force', 'verbose']) if __name__ == '__main__': args = parser.parse_args() try: landxml_to_slf(args) except (Serafin.SerafinRequestError, Serafin.SerafinValidationError): # Message is already reported by slf logger sys.exit(1)
resin.header.np_float_type, is_2d=True, us_equation=strickler_equation, ori_values=ori_values) resout.write_entire_frame(output_header, time, values) row = [time] for j in range(len(calculator.polygons)): weight = calculator.weights[j] volume = calculator.volume_in_frame_in_polygon( weight, values[pos_TAU], calculator.polygons[j]) row.append(volume) csvwriter.writerow(row) parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf', 'out_slf', 'out_csv']) parser.add_argument('in_polygons', help='polygons file (*.shp)') parser.add_argument('--in_strickler_zones', help='strickler zones file (*.shp)') parser.add_argument( '--in_strickler_attr', help='attribute to read strickler values `--in_stricker_zone`') help_friction_laws = ', '.join( ['%i=%s' % (i, law) for i, law in enumerate(FRICTION_LAWS)]) parser.add_argument('--friction_law', type=int, help='friction law identifier: %s' % help_friction_laws, choices=range(len(FRICTION_LAWS)), default=STRICKLER_ID) parser.add_group_general(['force', 'verbose'])
with open(args.out_txt, 'w', newline='') as out_txt: for i, line in enumerate(in_txt): if i < 3: out_txt.write(line) else: n1_ori, n2_ori, txt = line.split(maxsplit=2) n1_new = mesh_new.header.nearest_node( mesh_ori.header.x[int(n1_ori) - 1], mesh_ori.header.y[int(n1_ori) - 1]) n2_new = mesh_new.header.nearest_node( mesh_ori.header.x[int(n2_ori) - 1], mesh_ori.header.y[int(n2_ori) - 1]) out_txt.write('%i %i %s' % (n1_new, n2_new, txt)) parser = PyTelToolsArgParse(description=__doc__, add_args=[]) parser.add_argument('in_txt', help='Original input culverts file') parser.add_argument('out_txt', help='New output culverts file') parser.add_argument('in_slf_ori', help='Original Serafin file') parser.add_argument('in_slf_new', help='New Serafin file') parser.add_argument( '--lang', help="Serafin language for variables detection: 'fr' or 'en'", default=settings.LANG) parser.add_group_general(['force', 'verbose']) if __name__ == '__main__': args = parser.parse_args() try: update_culverts_file(args)
values = resin.read_var_in_frame(args.frame_index, var_ID) interp = mtri.LinearTriInterpolator(triang, values) data = interp( m_xi, m_yi)[::-1] # reverse array so the tif looks like the array array_list.append((var_name, data)) logger.info( "Min and max values for interpolated %s variable: [%f, %f]" % (var_name, data.min(), data.max())) # Write data in the raster output file arrays2raster(args.out_tif, (header.x.min(), header.y.max()), args.resolution, -args.resolution, array_list) parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf', 'shift']) parser.add_argument('out_tif', help='output GeoTIFF raster file (with .tif extension)') parser.add_argument('resolution', type=float, help='sampling space step (in meters)') parser.add_argument( '--vars', nargs='+', help='variable(s) to extract (by default: every variables)', default=None, metavar=('VA', 'VB')) parser.add_argument( '--frame_index', type=int, help='index of the target temporal frame (0-indexed integer)',
values = np.empty((output_header.nb_var, output_header.nb_nodes), dtype=output_header.np_float_type) with Serafin.Write(args.out_slf, args.lang, overwrite=args.force) as resout: resout.write_header(output_header) time_index = len(resin.time) - 1 time = resin.time[-1] if args.time is None else args.time for i, var_ID in enumerate(output_header.var_IDs): values[i, :] = resin.read_var_in_frame(time_index, var_ID) resout.write_entire_frame(output_header, time, values) parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf', 'out_slf', 'shift']) parser.add_argument( '--time', help='time in seconds to write last frame (set to frame time by default)', type=float) parser.add_group_general(['force', 'verbose']) if __name__ == '__main__': args = parser.parse_args() try: slf_last(args) except (Serafin.SerafinRequestError, Serafin.SerafinValidationError): # Message is already reported by slf logger sys.exit(1)
vars_2d = np.empty( (output_header.nb_var, output_header.nb_nodes_2d), dtype=output_header.np_float_type) for time_index, time in enumerate(tqdm(resin.time, unit='frame')): if args.aggregation is not None: vars_2d = vertical_calculator.max_min_mean_in_frame( time_index) else: for i, var in enumerate(output_header.var_IDs): vars_2d[i, :] = resin.read_var_in_frame_as_3d( time_index, var)[args.layer - 1, :] resout.write_entire_frame(output_header, time, vars_2d) parser = PyTelToolsArgParse(description=__doc__, add_args=['in_slf', 'out_slf', 'shift']) group = parser.add_mutually_exclusive_group(required=True) group.add_argument('--layer', help='layer number (1=lower, nb_planes=upper)', type=int, metavar=1) group.add_argument('--aggregation', help='operation over the vertical', choices=('max', 'min', 'mean')) parser.add_argument('--vars', nargs='+', help='variable(s) deduced from Z', default=[], choices=('B', 'S', 'H')) parser.add_group_general(['force', 'verbose'])