def EvaluateSlopes(ithread): global istep, figure, subplot, contour istep += 1 rootprogress.find('progress_text').text = '%i' % (100. * istep / nstep) rootprogress.find('progress_frac').text = str(istep / nstep) try: xml.ElementTree(rootprogress).write(progressfile) except: pass if not LOCAL: try: with open(PATH + '../../../progress.txt', 'w') as pf: pf.write(str(istep / nstep)) except: pass UpdateProgress(time2use, ithread, 0.05, msg("Slope calculation process - Construction")) try: with open(p.folder + '/slope_points_z', 'w') as outfile: for idiv in range(p.nproc): infile = open(p.folder + '/slope_points_' + str(idiv) + '_z', 'r') lines = infile.readlines() infile.close() subprocess.call( ['rm', p.folder + '/slope_points_' + str(idiv)]) subprocess.call( ['rm', p.folder + '/slope_points_' + str(idiv) + '_z']) for line in lines: outfile.write(line) UpdateProgress(time2use, ithread, 0.15, msg("Slope calculation process - Construction")) zf = [] with open(p.folder + '/slope_points_z', 'r') as infile: lines = infile.readlines() for line in lines: zf.append(eval(line.split()[2])) UpdateProgress(time2use, ithread, 0.20, msg("Slope calculation process - Construction")) itot = -1 slopes = [] for _ in range(p.nsite): slopes.append([]) for __ in range(p.rixncalc_site): slopes[-1].append([]) for iseg in range(p.npl_site + 1): itot += 1 if iseg > 0: slope = (zf[itot] - zf[itot - 1]) / p.rixres_site slopes[-1][-1].append( np.arctan((slope)) * 180. / np.pi) UpdateProgress(time2use, ithread, 0.40, msg("Slope calculation process - Construction")) res = [] for slope_point in slopes: res.append([0.] * (p.rixncalc_site + 1)) idir = -1 for slope_dir in slope_point: idir += 1 direc = idir * 360. / p.rixncalc_site idirec = GetDirect(p.rixncalc_site, direc) for slope in slope_dir: res[-1][idirec] += abs(slope) for idir in range(p.rixncalc_site): res[-1][idir] = res[-1][idir] / p.npl_site res[-1][-1] = np.average(res[-1][0:p.rixncalc_site]) UpdateProgress(time2use, ithread, 0.60, msg("Slope calculation process - Construction")) resslopes = [] with open(PATH + '../../PROJECTS_CFD/' + p.site + '/DATA/slope_site', 'w') as f: ip = -1 for result in res: ip += 1 if abs( np.sqrt(p.xsite[ip]**2 + p.ysite[ip]**2) - (p.diamin + 1000.) / 2.) > 5.: f.write('%15.2f%15.2f%15.2f\n' % (p.xsite[ip], p.ysite[ip], result[-1])) else: f.write('%15.2f%15.2f%15.2f\n' % (p.xsite[ip], p.ysite[ip], 0.)) resslopes.append(result[-1]) resslopes = np.array(resslopes) p.slope_moy = np.average(resslopes) p.slope_max = np.max(resslopes) subprocess.call(['rm', p.folder + '/slope_points']) subprocess.call(['rm', p.folder + '/slope_points_z']) x, y, z = np.loadtxt(PATH + '../../PROJECTS_CFD/' + p.site + '/DATA/slope_site', unpack=True) autocontour = p.autocontour contourlimit = p.contourlimit results = [] step = 0.1 val = autocontour - step zmin, zmax = min(z), max(z) if zmin < val and val < zmax: VALID = False contour = None while not VALID: val += step if figure is not None: Figure.clear(figure) subplot.clear() if contour != None: del contour figure = Figure() subplot = figure.add_axes([0., 0., 1., 1.]) contour = subplot.tricontour(x, y, z, [val]) disttot = 0 results = [] for collec in contour.collections: contours = collec.get_paths() for path in contours: results.append([]) v = path.vertices xx = v[:, 0] yy = v[:, 1] dist = 0 for i in range(len(xx) - 1): dist += np.sqrt((xx[i + 1] - xx[i])**2 + (yy[i + 1] - yy[i])**2) for i in range(len(xx)): results[-1].append((xx[i], yy[i])) disttot += dist VALID = disttot < contourlimit xmlfile = p.projdir + '/contours.xml' root = xml.parse(xmlfile).getroot() bal = xml.SubElement(root, 'contour') bal.text = str(results) bal.attrib['name'] = 'Slope:Auto' bal.attrib['type'] = 'anal' bal.attrib['inp'] = 'auto' bal.attrib['variable'] = 'auto' bal.attrib['value'] = '%.1f' % val bal.attrib['comments'] = 'Automatically generated' bal.attrib['usedby'] = '[]' xml.ElementTree(root).write(xmlfile) UpdateProgress(time2use, ithread, 1.0, msg("Slope calculation process - Construction")) except: p.errors.append( msg("ERROR") + ' ' + msg("within process") + ': EvaluateSlopes') p.WriteLog(0)
def EvaluateRix(): global istep istep += 1 rootprogress.find('progress_text').text = '%i' % (100. * istep / nstep) rootprogress.find('progress_frac').text = str(istep / nstep) try: xml.ElementTree(rootprogress).write(progressfile) except: pass if not LOCAL: try: with open(PATH + '../../../progress.txt', 'w') as pf: pf.write(str(istep / nstep)) except: pass UpdateProgress(time2use, 1, 0.05, msg("RIX calculation process - Construction")) try: with open(p.folder + '/rix_points_z', 'w') as outfile: for idiv in range(p.nproc): infile = open(p.folder + '/rix_points_' + str(idiv) + '_z', 'r') lines = infile.readlines() infile.close() subprocess.call(['rm', p.folder + '/rix_points_' + str(idiv)]) subprocess.call( ['rm', p.folder + '/rix_points_' + str(idiv) + '_z']) for line in lines: outfile.write(line) zf = [] with open(p.folder + '/rix_points_z', 'r') as infile: lines = infile.readlines() for line in lines: zf.append(eval(line.split()[2])) itot = -1 slopes = [] for _ in range(p.nloc): slopes.append([]) for _ in range(p.rixncalc): slopes[-1].append([]) for iseg in range(p.npl): itot += 1 if iseg > 0: slope = (zf[itot] - zf[itot - 1]) / p.rixres slopes[-1][-1].append( np.arctan((slope)) * 180. / np.pi) res = [] for slope_point in slopes: res.append([0.] * (p.rixnsect + 2)) nres = [0] * p.rixnsect idir = -1 for slope_dir in slope_point: idir += 1 direc = idir * 360. / p.rixncalc idirec = GetDirect(p.rixnsect, direc) nres[idirec] += 1 for slope in slope_dir: if abs(slope) > p.rixslope: res[-1][idirec] += 1 for idir in range(p.rixnsect): if nres[idir] > 0: res[-1][idir] = res[-1][idir] / nres[idir] res[-1][-2] = np.average(res[-1][0:p.rixnsect]) if p.climato != 'no': res[-1][-1] = np.sum( (np.array(res[-1][0:p.rixnsect])) * np.array(p.fd)) ip = -1 if p.n_mast > 0: with open(p.folder + '/rix_mast', 'w') as f: for _ in range(p.n_mast): ip += 1 resline = '' for elem in res[ip]: resline += ('%.1f' % elem).rjust(10) f.write(resline + "\n") p.rix_mes += res[ip][-2] p.rixclim_mes += res[ip][-1] if p.n_lidar > 0: with open(p.folder + '/rix_lidar', 'w') as f: for _ in range(p.n_lidar): ip += 1 resline = '' for elem in res[ip]: resline += ('%.1f' % elem).rjust(10) f.write(resline + '\n') p.rix_mes += res[ip][-2] p.rixclim_mes += res[ip][-1] if p.n_mast + p.n_lidar > 0: p.rix_mes /= (p.n_mast + p.n_lidar) p.rixclim_mes /= (p.n_mast + p.n_lidar) if p.n_wt > 0: with open(p.folder + '/rix_wt', 'w') as f: for _ in range(p.n_wt): ip += 1 resline = '' for elem in res[ip]: resline += ('%.1f' % elem).rjust(10) f.write(resline + '\n') p.rix_mach += res[ip][-2] p.rixclim_mach += res[ip][-1] p.rix_mach /= p.n_wt p.rixclim_mach /= p.n_wt subprocess.call(['rm', p.folder + '/rix_points']) subprocess.call(['rm', p.folder + '/rix_points_z']) except: p.errors.append( msg("ERROR") + ' ' + msg("within process") + ': EvaluateRix') p.WriteLog(0)
def ReconstructOro(ithread): global istep try: istep += 1 rootprogress.find('progress_text').text = '%i' % (100. * istep / nstep) rootprogress.find('progress_frac').text = str(istep / nstep) try: xml.ElementTree(rootprogress).write(progressfile) except: pass if not LOCAL: try: with open(PATH + '../../../progress.txt', 'w') as pf: pf.write(str(istep / nstep)) except: pass UpdateProgress(time2use, ithread, 0., 'ReconstructOro') x, y, z = [], [], [] for idiv in range(100): UpdateProgress(time2use, ithread, float(idiv + 1) / 100, 'ReconstructOro') with open(p.projdir + '/DATA/loc_' + str(idiv).zfill(2) + '_z', 'r') as infile: lines = infile.readlines() subprocess.call([ 'mv', p.projdir + '/DATA/loc_' + str(idiv).zfill(2) + '_z', p.projdir + '/DATA/loc_' + str(idiv).zfill(2) ]) for line in lines: vals = line.split() x.append(eval(vals[0])) y.append(eval(vals[1])) z.append(eval(vals[2])) locdata = [] itot = -1 for elem in p.np_data: name = elem[0] npp = elem[1] if npp > 0: with open(p.projdir + '/DATA/elevations_' + name, 'w') as outfile: for _ in range(npp): itot += 1 outfile.write('%20.2f%20.2f%20.2f\n' % (x[itot], y[itot], z[itot])) if name == 'complex_glob': locdata.append(z[itot]) itot += 1 locdata = np.array(locdata) p.elevation_moy = np.average(locdata) p.elevation_deltamax = np.max(locdata) - np.min(locdata) p.elevation_std = np.std(locdata) with open(p.projdir + '/centre', 'w') as outfile: outfile.write(str(p.elevation_moy)) UpdateProgress(time2use, ithread, 1., ' ') except: p.errors.append( msg("ERROR") + ' ' + msg("within process") + ': ReconstructOro') p.WriteLog(0)
def CalcRix(ithread, num): """ Evaluates elevation data over the points related to rix calculation """ global istep istep += 1 rootprogress.find('progress_text').text = '%i' % (100. * istep / nstep) rootprogress.find('progress_frac').text = str(istep / nstep) try: xml.ElementTree(rootprogress).write(progressfile) except: pass if not LOCAL: try: with open(PATH + '../../../progress.txt', 'w') as pf: pf.write(str(istep / nstep)) except: pass UpdateProgress( time2use, ithread, 0.0, msg("RIX calculation process - Elevations") + ' - ' + num.split('_')[-1]) try: extra = '____' appli = PATH + '../../APPLI/TMP/' + extra + time2use xmlfile = PATH + '../../APPLI/TMP/logout_' + time2use + '_' + str( ithread) + '.xml' elevationfile = p.projdir + '/DATA/zsoro' infile = p.folder + '/' + num outfile = p.folder + '/' + num + '_z' it = 0 RES = False while not RES and it <= itmax: root = xml.Element('logout') xml.SubElement(root, 'progress_text').text = 'Evaluating RIX' xml.SubElement(root, 'progress_frac').text = str(0) xml.ElementTree(root).write(xmlfile) it += 1 SubprocessCall(appli, infile, elevationfile, outfile, xmlfile) RES = eval( xml.parse(xmlfile).getroot().find('progress_frac').text) == 1.0 if not RES: print 'retry CalcRix', num, it if not RES: p.errors.append( msg("ERROR") + ' ' + msg("within process") + ': CalcRix (itmax)') p.WriteLog(0, print_exc=False) UpdateProgress(time2use, ithread, 1., ' ') except: traceback.print_exc() p.errors.append( msg("ERROR") + ' ' + msg("within process") + ': CalcRix') p.WriteLog(0)
istep += 1 rootprogress.find('progress_text').text = '%i' % (100. * istep / nstep) rootprogress.find('progress_frac').text = str(istep / nstep) try: xml.ElementTree(rootprogress).write(progressfile) except: pass if not LOCAL: try: with open(PATH + '../../../progress.txt', 'w') as pf: pf.write(str(istep / nstep)) except: pass UpdateProgress(time2use, 1, 0.15, msg("RIX calculation process - Preparation")) if p.rixcalc: p.xf = [] p.yf = [] xloc = [] yloc = [] if p.n_mast > 0: with open(PATH + '../../PROJECTS_CFD/' + p.site + '/DATA/zsmast', 'r') as infile: lines = infile.readlines() for line in lines: vals = line.rstrip().split()
code = sys.argv[3] folder = sys.argv[4] message = sys.argv[5] nsmoo = int(eval(sys.argv[6])) smoocoef = eval(sys.argv[7]) insmoo = int(eval(sys.argv[8])) diadom = eval(sys.argv[9]) diaref = eval(sys.argv[10]) istep = eval(sys.argv[11]) nstep = eval(sys.argv[12]) progressfile = PATH + '../../APPLI/TMP/logout_' + time2use + '.xml' try: UpdateProgress(time2use, ithread, 0.05, message + ' - 1/4') xg, yg, zg = NP.loadtxt(folder + '/FILES/' + code + '_elevation', unpack=True) tri = NP.loadtxt(folder + '/FILES/' + code + '_elevation') n_ground_nodes = len(xg) tt = NP.loadtxt(folder + '/FILES/' + code + '_zsinfo', usecols=(2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) UpdateProgress(time2use, ithread, 1.0, ' ') istep += 1 try:
from ZS_COMMON import UpdateProgress PATH = os.path.realpath(os.path.dirname(sys.argv[0])) + '/' time2use = sys.argv[1] ithread = sys.argv[2] code = sys.argv[3] folder = sys.argv[4] message = sys.argv[5] nsect = int(eval(sys.argv[6])) diaref = eval(sys.argv[7]) try: UpdateProgress(time2use, ithread, 0.0, message) infile = open(folder + '/FILES/' + code + '_roughness', 'r') lines = infile.readlines() infile.close() xgr = [] ygr = [] rgr = [] for i in range(len(lines)): values = lines[i].split() xgr.append(eval(values[4])) ygr.append(eval(values[5])) rgr.append(eval(values[6])) ngr = len(xgr) UpdateProgress(time2use, ithread, 0.3, message)