def RequestData(): # R.0.2018.117 import sys sys.path.insert(0, "EMC_SRC_PATH") from paraview.simple import RenameSource, GetActiveViewOrCreate, ColorBy, GetDisplayProperties, GetActiveSource import numpy as np import csv import os from vtk.util import numpy_support as nps import IrisEMC_Paraview_Lib as lib if Depth_Begin > Depth_End: raise Exception('Begin Depth < End Depth! Aborting.') Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End = lib.getArea( Area, Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End) if len(Latitude_Variable.strip()) <= 0 or len( Longitude_Variable.strip()) <= 0 or len( Depth_Variable.strip()) <= 0: raise Exception('Latitude, Longitude and Depth variable are required') # make sure we have input files fileFound, address, source = lib.findFile(FileName, loc='EMC_MODELS_PATH') if not fileFound: raise Exception('model file "' + address + '" not found! Aborting.') filename = lib.fileName(FileName) if len(Label.strip()) <= 0: if source == filename: Label = "%s " % (filename) else: Label = "%s from %s " % (filename, source) sg = self.GetOutput() # vtkPolyData X, Y, Z, V, meta = lib.read_netCdfEarthModel( address, Latitude_Variable, Longitude_Variable, Depth_Variable, (Latitude_Begin, Longitude_Begin), (Latitude_End, Longitude_End), Depth_Begin, Depth_End, inc=Sampling) nx = len(X) if nx <= 0: raise Exception('No data found!') ny = len(X[0]) nz = len(X[0][0]) sg.SetDimensions(nx, ny, nz) # # make geometry # points = vtk.vtkPoints() for k in range(nz): for j in range(ny): for i in range(nx): points.InsertNextPoint((X[i, j, k], Y[i, j, k], Z[i, j, k])) sg.SetPoints(points) # # make geometry # count = 0 for var in V.keys(): scalars = vtk.vtkFloatArray() scalars.SetNumberOfComponents(1) scalars.SetName(var) for k in range(nz): for j in range(ny): for i in range(nx): if V[var][i, j, k] > 999.0: scalars.InsertNextValue(float('nan')) else: scalars.InsertNextValue(V[var][i, j, k]) if count == 0: sg.GetPointData().SetScalars(scalars) else: sg.GetPointData().AddArray(scalars) count += 1 # store boundary metadata fieldData = sg.GetFieldData() fieldData.AllocateArrays(3) # number of fields data = vtk.vtkFloatArray() data.SetName('Latitude\nRange (deg)') data.InsertNextValue(meta['lat'][0]) data.InsertNextValue(meta['lat'][1]) fieldData.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Longitude\nRange (deg)') data.InsertNextValue(meta['lon'][0]) data.InsertNextValue(meta['lon'][1]) fieldData.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Depths (km)') for d in sorted(meta['depth']): data.InsertNextValue(d) fieldData.AddArray(data) data = vtk.vtkStringArray() data.SetName('Source') data.InsertNextValue(FileName) fieldData.AddArray(data) Label2 = " - %s (lat:%0.1f,%0.1f, lon:%0.1f,%0.1f, depth:%0.1f - %0.1f)" % ( lib.areaValues[Area], meta['lat'][0], meta['lat'][1], meta['lon'][0], meta['lon'][1], meta['depth'][0], meta['depth'][-1]) RenameSource(' '.join([Label.strip(), Label2.strip()])) sg.SetFieldData(fieldData)
def RequestData(): # R.0.2018.080 import sys sys.path.insert(0, "EMC_SRC_PATH") from paraview.simple import RenameSource, GetActiveViewOrCreate, ColorBy, GetDisplayProperties, GetActiveSource import numpy as np import csv import os from vtk.util import numpy_support as nps import IrisEMC_Paraview_Lib as lib FileName = lib.etopo5File # make sure we have input files fileFound, address, source = lib.findFile(FileName, loc='EMC_MODELS_PATH') if not fileFound: raise Exception('Etopo5 file "' + address + '" not found! Aborting.') filename = lib.fileName(FileName) sg = self.GetOutput() # vtkPolyData Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End = lib.getArea( Area, Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End) Label2 = " - %s (%0.1f,%0.1f,%0.1f,%0.1f)" % ( lib.areaValues[Area], Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End) X, Y, Z, V, label = lib.readTopoFile(address, (Latitude_Begin, Longitude_Begin), (Latitude_End, Longitude_End), Sampling) nx = len(X) ny = len(X[0]) nz = len(X[0][0]) sg.SetDimensions(nx, ny, nz) # # make geometry # points = vtk.vtkPoints() for k in range(nz): for j in range(ny): for i in range(nx): points.InsertNextPoint((X[i, j, k], Y[i, j, k], Z[i, j, k])) sg.SetPoints(points) # # make geometry # count = 0 for var in V.keys(): scalars = vtk.vtkFloatArray() scalars.SetNumberOfComponents(1) scalars.SetName(var) for k in range(nz): for j in range(ny): for i in range(nx): scalars.InsertNextValue(V[var][i, j, k]) if count == 0: sg.GetPointData().SetScalars(scalars) else: sg.GetPointData().AddArray(scalars) count += 1 # store metadata fieldData = sg.GetFieldData() fieldData.AllocateArrays(3) # number of fields data = vtk.vtkFloatArray() data.SetName('Latitude\nRange (deg)') data.InsertNextValue(Latitude_Begin) data.InsertNextValue(Latitude_End) fieldData.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Longitude\nRange (deg)') data.InsertNextValue(Longitude_Begin) data.InsertNextValue(Longitude_End) fieldData.AddArray(data) data = vtk.vtkStringArray() data.SetName('Source') data.InsertNextValue(source) fieldData.AddArray(data) RenameSource(' '.join( [label.strip(), 'from', source.strip(), Label2.strip()]))
def RequestData(): # R.0.2018.080 import sys sys.path.insert(0, "EMC_SRC_PATH") from paraview.simple import RenameSource, GetActiveViewOrCreate, ColorBy, GetDisplayProperties, GetActiveSource import numpy as np import csv import os from vtk.util import numpy_support as nps import IrisEMC_Paraview_Lib as lib import urlparse USGS = True if len(Alternate_FileName.strip()) > 0: FileName = Alternate_FileName Label = ' '.join(['SLAB', lib.fileName(Alternate_FileName).strip()]) USGS = False else: FileName = lib.usgsSlabKeys[Slab] depthFactor = -1 Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End = lib.getArea( Area, Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End) Label2 = " - %s (lat:%0.1f,%0.1f, lon:%0.1f,%0.1f)" % ( lib.areaValues[Area], Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End) # Make sure we have input files fileFound, address, source = lib.findFile(FileName, loc='EMC_SLABS_PATH') if not fileFound: raise Exception('model file "' + address + '" not found! Aborting.') sg = self.GetOutput() # vtkPolyData X, Y, Z, V, label = lib.readSlabFile(address, (Latitude_Begin, Longitude_Begin), (Latitude_End, Longitude_End), inc=Sampling) nx = len(X) ny = len(X[0]) nz = len(X[0][0]) sg.SetDimensions(nx, ny, nz) # # make geometry # points = vtk.vtkPoints() for k in range(nz): for j in range(ny): for i in range(nx): points.InsertNextPoint((X[i, j, k], Y[i, j, k], Z[i, j, k])) sg.SetPoints(points) # # make geometry # count = 0 for var in V.keys(): scalars = vtk.vtkFloatArray() scalars.SetNumberOfComponents(1) scalars.SetName(var) for k in range(nz): for j in range(ny): for i in range(nx): scalars.InsertNextValue(depthFactor * V[var][i, j, k]) if count == 0: sg.GetPointData().SetScalars(scalars) else: sg.GetPointData().AddArray(scalars) count += 1 # store USGS metadata if USGS: fieldData = sg.GetFieldData() fieldData.AllocateArrays(3) # number of fields data = vtk.vtkFloatArray() data.SetName('Latitude\nRange (deg)') data.InsertNextValue( lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['Y'][0]) data.InsertNextValue( lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['Y'][1]) fieldData.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Longitude\nRange (deg)') minX = lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['X'][0] if minX > 180: minX -= 360 maxX = lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['X'][1] if maxX > 180: maxX -= 360 xMin = min([minX, maxX]) xMax = max([minX, maxX]) data.InsertNextValue(xMin) data.InsertNextValue(xMax) fieldData.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Depth to Slab\nRange (km)') data.InsertNextValue( abs(lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['Z'][1])) data.InsertNextValue( abs(lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['Z'][0])) fieldData.AddArray(data) data = vtk.vtkStringArray() data.SetName('Source') data.InsertNextValue(lib.usgsSlab_URL) Label = ' '.join([ 'USGS Slab 1.0:', lib.usgsSlabValues[Slab].strip(), 'from', urlparse.urlparse(lib.usgsSlab_URL).netloc.strip() ]) data.InsertNextValue(lib.usgsSlabKeys[Slab]) fieldData.AddArray(data) RenameSource(' '.join([Label.strip(), Label2.strip()]))
import os from paraview.simple import OpenDataFile, RenameSource, Show surfdir = "postProcessing/surfaces" times = sorted(os.listdir(surfdir)) files = os.listdir(os.path.join(surfdir, times[0])) for f in files: file_list = [os.path.join(surfdir, t, f) for t in times] OpenDataFile(file_list) RenameSource(f.replace(".vtk", ""))
def RequestData(): # V.2019.079 import sys sys.path.insert(0, r'EMC_SRC_PATH') from paraview.simple import RenameSource, GetActiveViewOrCreate, ColorBy, GetDisplayProperties, GetActiveSource import numpy as np import csv import os from os.path import splitext from vtk.util import numpy_support as nps import IrisEMC_Paraview_Lib as lib import IrisEMC_Paraview_Utils as utils import IrisEMC_Paraview_Param as param File_name = File_name.strip() ext = None if File_name in list(param.filesDict.values()) or not ( File_name.lower().endswith(param.filesExtDict['ssl'].lower()) or File_name.lower().endswith(param.filesExtDict['geo'].lower())): if utils.support_nc(): ext = param.filesExtDict['ssl'] else: ext = param.filesExtDict['geo'] depth_begin = float(Depth_begin) depth_end = float(Depth_end) if depth_begin > depth_end: raise Exception('Begin Depth < End Depth! Aborting.') Latitude_begin, Latitude_end, Longitude_begin, Longitude_end = lib.get_area( Area, Latitude_begin, Latitude_end, Longitude_begin, Longitude_end) if len(Latitude_variable.strip()) <= 0 or len( Longitude_variable.strip()) <= 0 or len( Depth_variable.strip()) <= 0: raise Exception('Latitude, Longitude and Depth variable are required') # make sure we have input files fileFound, address, source = lib.find_file(File_name, loc=r'EMC_MODELS_PATH', ext=ext) if not fileFound: raise Exception('model file "' + address + '" not found! Aborting.') filename = lib.file_name(File_name) if len(Label.strip()) <= 0: if source == filename: Label = "%s " % (filename) else: Label = "%s from %s " % (filename, source) sg = self.GetOutput() # vtkPolyData this_filename, extension = splitext(address) if extension.lower() in ['.nc', '.grd']: X, Y, Z, V, meta = lib.read_netcdf_model( address, Latitude_variable, Longitude_variable, Depth_variable, (Latitude_begin, Longitude_begin), (Latitude_end, Longitude_end), depth_begin, depth_end, Vertical_Scaling, Sampling) else: try: X, Y, Z, V, meta = lib.read_geocsv_model_3d( address, (Latitude_begin, Longitude_begin), (Latitude_end, Longitude_end), depth_begin, depth_end, Vertical_Scaling, Sampling) except Exception as e: raise Exception('cannot recognize model file "' + address + '"! Aborting.\n' + str(e)) nx = len(X) if nx <= 0: raise Exception('No data found!') ny = len(X[0]) nz = len(X[0][0]) sg.SetDimensions(nx, ny, nz) # make geometry points = vtk.vtkPoints() for k in range(nz): for j in range(ny): for i in range(nx): points.InsertNextPoint((X[i, j, k], Y[i, j, k], Z[i, j, k])) sg.SetPoints(points) # make geometry count = 0 for var in list(V.keys()): scalars = vtk.vtkFloatArray() scalars.SetNumberOfComponents(1) scalars.SetName(var) for k in range(nz): for j in range(ny): for i in range(nx): if V[var][i, j, k] == float('nan'): scalars.InsertNextValue(float('nan')) else: scalars.InsertNextValue(V[var][i, j, k]) if count == 0: sg.GetPointData().SetScalars(scalars) else: sg.GetPointData().AddArray(scalars) count += 1 # store boundary metadata field_data = sg.GetFieldData() field_data.AllocateArrays(3) # number of fields data = vtk.vtkFloatArray() data.SetName('Latitude\nRange (deg)') data.InsertNextValue(meta['lat'][0]) data.InsertNextValue(meta['lat'][1]) field_data.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Longitude\nRange (deg)') data.InsertNextValue(meta['lon'][0]) data.InsertNextValue(meta['lon'][1]) field_data.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Depths (km)') for d in sorted(meta['depth']): data.InsertNextValue(d) field_data.AddArray(data) data = vtk.vtkStringArray() data.SetName('Source') data.InsertNextValue(File_name) field_data.AddArray(data) label_2 = " - %s (lat:%0.1f,%0.1f, lon:%0.1f,%0.1f, depth:%0.1f - %0.1f)" % ( lib.areaValues[Area], meta['lat'][0], meta['lat'][1], meta['lon'][0], meta['lon'][1], meta['depth'][0], meta['depth'][-1]) RenameSource(' '.join([Label.strip(), label_2.strip()])) sg.SetFieldData(field_data)
def RequestData(): # V.2019.030 import sys sys.path.insert(0, r'EMC_SRC_PATH') from paraview.simple import RenameSource, GetActiveViewOrCreate, ColorBy, GetDisplayProperties, GetActiveSource import numpy as np import csv import os from os.path import splitext from vtk.util import numpy_support as nps import IrisEMC_Paraview_Lib as lib import IrisEMC_Paraview_Utils as utils import IrisEMC_Paraview_Param as param # elevation units in meters Roughness = -1 * float(Roughness) baseline = float(Depth_Bias) if len(Alternate_FileName.strip()) > 0: file_name = Alternate_FileName.strip() label = ' '.join(['Topo', lib.file_name(Alternate_FileName).strip()]) else: file_name = lib.topoKeys[TopoFile] label = lib.topoValues[TopoFile] file_name = file_name.strip() ext = None if file_name in list(param.topoDict.keys()): if utils.support_nc(): ext = param.topoExtDict['ssl'] else: ext = param.topoExtDict['geo'] # make sure we have input files file_found, address, source = lib.find_file(file_name, loc=r'EMC_MODELS_PATH', ext=ext) if not file_found: raise Exception('Topo file "' + address + '" not found! Aborting.') this_filename, extension = splitext(address) sg = self.GetOutput() # vtkPolyData Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End = lib.get_area( Area, Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End) label2 = " - %s (%0.1f,%0.1f,%0.1f,%0.1f)" % ( lib.areaValues[Area], Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End) if extension.lower() in ['.nc', '.grd']: X, Y, Z, V, label = lib.read_netcdf_topo_file( address, (Latitude_Begin, Longitude_Begin), (Latitude_End, Longitude_End), Sampling, Roughness, base=baseline, lon_var=Longitude_Variable, lat_var=Latitude_Variable, elev_var=Elevation_Variable, unit_factor=float(Unit_Factor), extent=False) else: try: X, Y, Z, V, meta = lib.read_geocsv_model_2d( address, (Latitude_Begin, Longitude_Begin), (Latitude_End, Longitude_End), Sampling, Roughness, base=baseline, unit_factor=float(Unit_Factor), extent=False) except Exception: raise Exception('cannot recognize model file "' + address + '"! Aborting.') nx = len(X) ny = len(X[0]) nz = len(X[0][0]) sg.SetDimensions(nx, ny, nz) # # make geometry # points = vtk.vtkPoints() for k in range(nz): for j in range(ny): for i in range(nx): points.InsertNextPoint((X[i, j, k], Y[i, j, k], Z[i, j, k])) sg.SetPoints(points) # # make geometry # count = 0 for var in list(V.keys()): scalars = vtk.vtkFloatArray() scalars.SetNumberOfComponents(1) scalars.SetName(var) for k in range(nz): for j in range(ny): for i in range(nx): scalars.InsertNextValue(V[var][i, j, k]) if count == 0: sg.GetPointData().SetScalars(scalars) else: sg.GetPointData().AddArray(scalars) count += 1 # store metadata fieldData = sg.GetFieldData() fieldData.AllocateArrays(3) # number of fields data = vtk.vtkFloatArray() data.SetName('Latitude\nRange (deg)') data.InsertNextValue(Latitude_Begin) data.InsertNextValue(Latitude_End) fieldData.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Longitude\nRange (deg)') data.InsertNextValue(Longitude_Begin) data.InsertNextValue(Longitude_End) fieldData.AddArray(data) data = vtk.vtkStringArray() data.SetName('Source') data.InsertNextValue(source) fieldData.AddArray(data) RenameSource(' '.join( [label.strip(), 'from', source.strip(), label2.strip()]))
def RequestData(): # R.1.2018.346 import sys sys.path.insert(0, r'EMC_SRC_PATH') from paraview.simple import RenameSource, GetActiveViewOrCreate, ColorBy, GetDisplayProperties, GetActiveSource import numpy as np import csv import os from os.path import splitext from vtk.util import numpy_support as nps import IrisEMC_Paraview_Lib as lib import urllib.parse import IrisEMC_Paraview_Utils as utils import IrisEMC_Paraview_Param as param USGS = True if len(Alternate_FileName.strip()) > 0: FileName = Alternate_FileName.strip() Label = ' '.join(['SLAB', lib.file_name(Alternate_FileName).strip()]) USGS = False else: FileName = lib.usgsSlabKeys[Slab] FileName = FileName.strip() ext = None if FileName in list(param.usgsSlabDict.keys()): if utils.support_nc(): ext = param.usgsSlabExtDict['ssl'] else: ext = param.usgsSlabExtDict['geo'] depthFactor = -1 Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End = lib.get_area( Area, Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End) Label2 = " - %s (lat:%0.1f,%0.1f, lon:%0.1f,%0.1f)" % ( lib.areaValues[Area], Latitude_Begin, Latitude_End, Longitude_Begin, Longitude_End, ) # Make sure we have input files fileFound, address, source = lib.find_file(FileName, loc=r'EMC_SLABS_PATH', ext=ext) if not fileFound: raise Exception('model file "' + address + '" not found! Aborting.') this_filename, extension = splitext(address) sg = self.GetOutput() # vtkPolyData if extension.lower() == '.grd': X, Y, Z, V, label = lib.read_slab_file( address, (Latitude_Begin, Longitude_Begin), (Latitude_End, Longitude_End), inc=Sampling, depth_factor=depthFactor, extent=False) elif extension.lower() == '.csv': X, Y, Z, V, meta = lib.read_geocsv_model_2d( address, (Latitude_Begin, Longitude_Begin), (Latitude_End, Longitude_End), Sampling, 1, base=0, unit_factor=depthFactor, extent=False) label = '' else: raise Exception('cannot recognize model file "' + address + '"! Aborting.') nx = len(X) ny = len(X[0]) nz = len(X[0][0]) sg.SetDimensions(nx, ny, nz) # # make geometry # points = vtk.vtkPoints() for k in range(nz): for j in range(ny): for i in range(nx): points.InsertNextPoint((X[i, j, k], Y[i, j, k], Z[i, j, k])) sg.SetPoints(points) # # make geometry # count = 0 for var in list(V.keys()): scalars = vtk.vtkFloatArray() scalars.SetNumberOfComponents(1) scalars.SetName(var) for k in range(nz): for j in range(ny): for i in range(nx): scalars.InsertNextValue(depthFactor * V[var][i, j, k]) if count == 0: sg.GetPointData().SetScalars(scalars) else: sg.GetPointData().AddArray(scalars) count += 1 # store USGS metadata if USGS: fieldData = sg.GetFieldData() fieldData.AllocateArrays(3) # number of fields data = vtk.vtkFloatArray() data.SetName('Latitude\nRange (deg)') data.InsertNextValue( lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['Y'][0]) data.InsertNextValue( lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['Y'][1]) fieldData.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Longitude\nRange (deg)') minX = lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['X'][0] if minX > 180: minX -= 360 maxX = lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['X'][1] if maxX > 180: maxX -= 360 xMin = min([minX, maxX]) xMax = max([minX, maxX]) data.InsertNextValue(xMin) data.InsertNextValue(xMax) fieldData.AddArray(data) data = vtk.vtkFloatArray() data.SetName('Depth to Slab\nRange (km)') data.InsertNextValue( abs(lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['Z'][1])) data.InsertNextValue( abs(lib.usgsSlabRangeDict[lib.usgsSlabKeys[Slab]]['Z'][0])) fieldData.AddArray(data) data = vtk.vtkStringArray() data.SetName('Source') data.InsertNextValue(lib.usgsSlab_URL) Label = ' '.join([ 'USGS Slab 1.0:', lib.usgsSlabValues[Slab].strip(), 'from', urllib.parse.urlparse(lib.usgsSlab_URL).netloc.strip() ]) data.InsertNextValue(lib.usgsSlabKeys[Slab]) fieldData.AddArray(data) RenameSource(' '.join([Label.strip(), Label2.strip()]))
except ImportError: pvloaded = False casename = "free" for f in ["turbine", "walls"]: wd = "rvat-log-" + casename + "/" + f folders = sorted(os.listdir(wd)) for folder in folders: files = os.listdir(wd + "/" + folder) files = sorted( [int((file.replace("step_", "").split(".")[0])) for file in files]) files = ["step_" + str(file) + ".vtk" for file in files] if pvloaded: OpenDataFile([wd + "/" + folder + "/" + file for file in files]) RenameSource(folder) else: print(files) # Load velocity if os.path.isdir("rvat-log-" + casename + "/velocity"): wd = "rvat-log-" + casename + "/velocity" files = os.listdir(wd) filesn = [] for f in files: try: filesn.append(int(f.replace(".vtk", ""))) except ValueError: filesn.append(float(f.replace(".vtk", ""))) files = [str(file) + ".vtk" for file in sorted(filesn)] if pvloaded: