def clonar_repositorio(directorio, url): if os.path.exists(os.path.join('..', directorio)): console.log(" Evitando clonar %s porque ya existe." % (directorio)) os.system('cd ..; git pull ') else: console.success("Clonando %s ..." % (directorio)) os.system('git clone ' + url + " " + directorio)
def clonar_repositorio(directorio, url): if os.path.exists(os.path.join('..', directorio)): console.log(" Evitando clonar %s porque ya existe." %(directorio)) os.system('cd ..; git pull ') else: console.success("Clonando %s ..." %(directorio)) os.system('cd ..; git clone ' + url + " " + directorio)
def SlopeReclass(bassin, zone, workdir, overwrite): """ Reclassification des pentes en 4 classes """ from qgis_helper import execute from processing.tools.system import getTempDirInTempFolder dem = os.path.join(workdir, bassin, zone, 'DEM5M.tif') # slope = os.path.join(workdir, bassin, zone, 'SLOPE.tif') output = os.path.join(workdir, bassin, zone, 'SLOPE_CLS.tif') if os.path.exists(output) and not overwrite: important('Output already exists : %s' % output) return info('Smooth DEM using 5x5 mean filter') parameters = dict(input=dem, bands=[1], filter_type=0, size=5, output=os.path.join(getTempDirInTempFolder(), 'SMOOTHED.tif')) result = execute("fct:simplerasterfilter", **parameters) if 'OUTPUT' not in result: warning('Error :(') return info('Calculate slope') parameters = dict(input=result['OUTPUT'], z_factor=1, output=os.path.join(getTempDirInTempFolder(), 'SLOPE.tif')) result = execute("qgis:slope", **parameters) if 'OUTPUT' not in result: warning('Error :(') return info('Reclass slopes') parameters = dict(input_raster=result['OUTPUT'], raster_band=1, table=[0, 2, 1, 2, 6, 2, 6, 12, 3, 12, None, 4], no_data=0, range_boundaries=1, nodata_for_missing=True, data_type=0, output=output) result = execute('native:reclassifybytable', **parameters) if 'OUTPUT' in result: success('Saved to %s' % result['OUTPUT'])
def verify(args: argparse.Namespace): con.pretty_printing = args.colors try: print("Validating IP Address ... ", end="") ip = args.address.split(".") # Check if IP has 4 decimal point assert len(ip) == 4 # Check if any of them is empty for ad in ip: assert len(ad) != 0 assert network.ping(args.address) con.success("OK") # Verify if the path given is valid directory print("Validating directory ... ", end="") assert pathlib.Path(args.output).is_dir() con.success("OK") # Check if resume flag is enabled if args.resume: # Check if resume.json exists print("Validating resume data ... ", end="") assert pathlib.Path('resume.pyb').exists() con.success("OK") return args except AssertionError: con.error("FAILED") quit(1)
def verify(args: argparse.Namespace): con.pretty_printing = args.colors try: # Verify number of ports equal the number of servers print("Validating server count ... ", end="") assert args.number == len(args.ports) con.success("OK") print("Validating server ports ... ") for port in args.ports: print("\t{} ... ".format(port), end="") assert network.check_sock(network.get_local_ip(), port) con.success("OK") # Verify a valid file was passed print("Validating file ... ", end="") assert pathlib.Path(args.file).is_file() con.success("OK") return args except AssertionError: con.error("FAILED") quit(1)
#!/usr/bin/python import os import console console.success("Bajando dependencias ...") def clonar_repositorio(directorio, url): if os.path.exists(os.path.join('..', directorio)): console.log(" Evitando clonar %s porque ya existe." %(directorio)) os.system('cd ..; git pull ') else: console.success("Clonando %s ..." %(directorio)) os.system('cd ..; git clone ' + url + " " + directorio) clonar_repositorio('pilasweb', 'https://github.com/hugoruscitti/pilasweb.git') clonar_repositorio('blockly', 'https://github.com/Program-AR/blockly.git') clonar_repositorio('closure-library', 'https://github.com/google/closure-library.git') clonar_repositorio('ejerciciosPilas', 'https://github.com/Program-AR/ejerciciosPilas.git')
def ExtractZoneHydro(bassin, zone, **options): """ Re-délimitation des zones hydrographiques BDC à la résolution du MNT 1. Rastérise le réseau hydro cartographié en utilisant le même algorithme que celui utilisé dans l'algorithme `StreamToRaster` de la FCT 2. Calcule le plan de drainage en utilisant la variante de l'algorithme Priority Flood de Lindsay 3. Réalise une analyse de bassin versant (Watershed Analysis) 4. Vectorize le polygone correspondant à la zone indiquée """ root = options.get('workdir', '.') overwrite = options.get('overwrite', False) basename = options.get('output', 'ZONEHYDRO5M.shp') flowdir = options.get('flowdir', 'FLOW.tif') epsg = options.get('epsg', 2154) info('Processing zone %s' % zone) info('Working Directory = %s' % root) raster_template = os.path.join(root, bassin, zone, 'DEM5M.tif') stream_network = os.path.join(root, bassin, zone, 'StreamNetwork.shp') output = os.path.join(root, bassin, zone, basename) if os.path.exists(output) and not overwrite: important('Output already exists : %s' % output) return feedback = ta.ConsoleFeedback() with rio.open(raster_template) as ds: info('Rasterize Stream Network') elevations = ds.read(1) transform = ds.transform cdzonecnt = itertools.count(1) cdzones = defaultdict(lambda: next(cdzonecnt)) fill_value = 0 # burn_value = 1 junctions = np.zeros((ds.height, ds.width), dtype=np.uint8) streams = RasterizeStream(elevations, ds.transform, ds.nodata, stream_network, fill_value, cdzones, junctions) # filename = os.path.join(root, bassin, zone, 'STREAMS.tif') # info('Write %s' % filename) # profile = ds.profile.copy() # profile.update(compress='deflate') # with rio.open(filename, 'w', **profile) as dst: # dst.write(streams, 1) # filename = os.path.join(root, bassin, zone, 'JUNCTIONS.tif') # info(' Write %s' % filename) # profile.update(dtype=np.uint8, nodata=255, compress='deflate') # with rio.open(filename, 'w', **profile) as dst: # dst.write(junctions, 1) flow_raster = os.path.join(root, bassin, zone, flowdir) info('Read Flow Direction from %s' % flow_raster) with rio.open(flow_raster) as src: flow = src.read(1) info('Calculate Watersheds') watersheds = np.copy(streams) ta.watershed(flow, watersheds, fill_value, feedback) feedback.setProgress(100) # filename = os.path.join(root, bassin, zone, 'WATERSHEDS.tif') # info('Write %s' % filename) # profile = ds.profile.copy() # profile.update(dtype=np.int32, nodata=0, compress='deflate') # with rio.open(filename, 'w', **profile) as dst: # dst.write(np.int32(watersheds), 1) info('Vectorize Polygons') watersheds = sieve(np.int32(watersheds), 400) schema = {'geometry': 'Polygon', 'properties': [('CdZoneHydr', 'str:4')]} crs = fiona.crs.from_epsg(epsg) CdToZones = {v: k for k, v in cdzones.items()} polygons = shapes(watersheds, (watersheds == cdzones[zone]), connectivity=8, transform=transform) options = dict(driver='ESRI Shapefile', crs=crs, schema=schema) with fiona.open(output, 'w', **options) as dst: for polygon, value in polygons: if value > 0: geom = asShape(polygon).buffer(0.0) feature = { 'geometry': geom.__geo_interface__, 'properties': { 'CdZoneHydr': CdToZones[value] } } dst.write(feature) success('Everything Ok')
#!/usr/bin/python import os import console console.success("Generando lista de imagenes ...") current_path = os.path.dirname(os.path.realpath(__file__)) image_path = os.path.join(current_path, '..', 'node_modules', 'pilas-bloques-exercises','dist', 'data') output_path = os.path.join(current_path, '..', 'app', 'components', 'listaImagenes.js') image_names = [x for x in os.listdir(image_path) if x.endswith('.png')] content = [ '// Autogenerado por scripts/generarListaImagenes.py', '// Todo cambio se sobreescribira.', 'export default [', ] for name in sorted(image_names): content.append(' "%s",' %(name)) content.append('];'); jsFile = open(output_path, "w+") jsFile.write('\n'.join(content)) jsFile.close() console.success("Se encontraron %d imagenes" %(len(image_names)))
def SlopeContinuity(bassin, zone, workdir, overwrite): """ DCOME """ from rasterio.features import sieve basename = 'SLOPE_CLS_CONTINUOUS.tif' flow_raster = os.path.join(workdir, bassin, zone, 'FLOW.tif') slope_raster = os.path.join(workdir, bassin, zone, 'SLOPE_CLS.tif') stream_network = os.path.join(workdir, bassin, zone, 'StreamNetwork.shp') output = os.path.join(workdir, bassin, zone, basename) if os.path.exists(output) and not overwrite: important('Output already exists : %s' % output) return with rio.open(slope_raster) as ds: slopes = sieve(ds.read(1), 800) streams = RasterizeStream(slopes, ds.transform, ds.nodata, stream_network, 0) # data = np.float32(slopes) + 1 # data[slopes == ds.nodata] = ds.nodata # data[streams == 1] = 0 # feedback = ta.ConsoleFeedback() # distance = np.float32(ta.shortest_distance(data, ds.nodata, 0, feedback=feedback)) # out = np.zeros_like(slopes, dtype=np.float32) # data[distance < 100] = 1 # data[streams == 1] = 0 # feedback = ta.ConsoleFeedback() # ta.shortest_max(data, ds.nodata, 0, out=out, feedback=feedback) # out = np.uint8(out) - 1 # out[distance < 100] = slopes[distance < 100] # out[slopes == ds.nodata] = ds.nodata out = np.zeros_like(slopes, dtype=np.float32) out[streams == 1] = 1 with rio.open(flow_raster) as ds2: flow = ds2.read(1) feedback = ta.ConsoleFeedback() ta.watershed_max(flow, out, np.float32(slopes), fill_value=0, feedback=feedback) out = np.uint8(out) # out[streams == 1] = slopes[streams == 1] out[slopes == ds.nodata] = ds.nodata profile = ds.profile.copy() profile.update(compress='deflate') with rio.open(output, 'w', **profile) as dst: dst.write(out, 1) success('Saved result to %s' % output)
#!/usr/bin/python import os import console console.success("Generating Image List ...") current_path = os.path.dirname(os.path.realpath(__file__)) image_path = os.path.join(current_path, '..', 'src', 'assets') output_path = os.path.join(current_path, '..', 'dist', 'imageList.js') image_names = [x for x in os.listdir(image_path) if x.endswith('.png')] content = [ '// Autogenerated by %s' % (os.path.basename(__file__)), '// Changes to this file will be overwritten', 'export let imageList = [', ] for name in sorted(image_names): content.append(' "%s",' % (name)) content.append('];') jsFile = open(output_path, "w+") jsFile.write('\n'.join(content)) jsFile.close() console.success("Found %d images" % (len(image_names)))
#!/usr/bin/python import os import console console.success("Bajando dependencias ...") def clonar_repositorio(directorio, url): if os.path.exists(os.path.join('..', directorio)): console.log(" Evitando clonar %s porque ya existe." % (directorio)) os.system('cd ..; git pull ') else: console.success("Clonando %s ..." % (directorio)) os.system('git clone ' + url + " " + directorio) clonar_repositorio('blockly', 'https://github.com/Program-AR/blockly.git') clonar_repositorio('closure-library', 'https://github.com/google/closure-library.git')