def RequestData(self, request, inInfo, outInfo): logger.info("Loading waveform data...") start_time = time.time() output = dsa.WrapDataObject(vtkTable.GetData(outInfo)) if (self._filename is not None and self._subfile is not None and len(self.mode_names) > 0): with h5py.File(self._filename, "r") as f: strain = f[self._subfile] t = strain["Y_l2_m2.dat"][:, 0] col_time = vtknp.numpy_to_vtk(t, deep=False) col_time.SetName("Time") output.AddColumn(col_time) for mode_name in self.mode_names: logger.debug(f"Reading mode '{mode_name}'...") col_mode = vtknp.numpy_to_vtk(strain[mode_name + ".dat"][:, 1:], deep=False) col_mode.SetName(mode_name) output.AddColumn(col_mode) logger.info( f"Waveform data loaded in {time.time() - start_time:.3f}s.") return 1
def RequestData(self, request, inInfoVec, outInfoVec): from vtkmodules.vtkCommonDataModel import vtkTable from vtkmodules.numpy_interface import dataset_adapter as dsa table = dsa.WrapDataObject(vtkTable.GetData(inInfoVec[0], 0)) kwargs = {} for aname in table.RowData.keys(): kwargs[aname] = table.RowData[aname] import numpy numpy.savez_compressed(self._filename, **kwargs) return 1
def RequestData(self, request, inInfoVec, outInfoVec): from vtkmodules.vtkCommonDataModel import vtkTable from vtkmodules.numpy_interface import dataset_adapter as dsa data_time = self._get_update_time(outInfoVec.GetInformationObject(0)) raw_data = self._get_raw_data(data_time) output = dsa.WrapDataObject(vtkTable.GetData(outInfoVec, 0)) for name in raw_data.dtype.names: if self._arrayselection.ArrayIsEnabled(name): output.RowData.append(raw_data[name], name) if data_time is not None: output.GetInformation().Set(output.DATA_TIME_STEP(), data_time) return 1
def RequestData(self, request, inInfoVec, outInfoVec): from vtkmodules.vtkCommonDataModel import vtkTable from vtk.util import numpy_support from vtk import vtkPolyData, vtkPoints, vtkCellArray, vtkFloatArray, VTK_FLOAT import pandas as pd import numpy as np import lasio import math import time t0 = time.time() las = lasio.read(self._filename) # DEPTH is index df_curves = las.df() headers = [] for (section, items) in las.sections.items(): if items is None or items in ('',[]): continue if isinstance(items, (str,unicode)): headers.append((section,'','',items,'')) elif isinstance(items, (list)): for item in items: headers.append((section,item['mnemonic'],item['unit'],item['value'],item['descr'])) else: print ("Unknown LAS header section type", type(items), iyems) df_header = pd.DataFrame(headers, columns=('Section','Mnemonic','Unit','Value','Description')) vtk_arrays = _NcubeDataFrameToVTKArrays(df_header) vtk_table_header = vtkTable() for vtk_arr in vtk_arrays: vtk_table_header.AddColumn(vtk_arr) outputHeader = vtkTable.GetData(outInfoVec, 0) outputHeader.ShallowCopy(vtk_table_header) # define scale factor by depth units unit = las.curves[0]['unit'] if unit in ['FT','ft']: scale = 0.3048 elif unit in ['M','m']: scale = 1.0 else: # we can use additional ParaView filter to fix it later scale = 1.0 print ("Unknown LAS header unit", unit) # set of vtk arrays with column names vtk_arrays = _NcubeDataFrameToVTKArrays(df_curves) # https://github.com/mobigroup/gis-snippets/blob/master/ParaView/ProgrammableFilter/vtkMultiblockDataSet.md # https://en.wikipedia.org/wiki/Spherical_coordinate_system # Spherical coordinates (r, θ, φ) as often used in mathematics: # radial distance r, azimuthal angle θ, and polar angle φ. theta = 1./2*math.pi - math.pi*self._az/180 phi = math.pi*(90 - self._dip)/180 #print ("theta",theta,"phi",phi) df_curves['dx'] = np.round(scale*df_curves.index*np.sin(phi)*np.cos(theta),10) df_curves['dy'] = np.round(scale*df_curves.index*np.sin(phi)*np.sin(theta),10) df_curves['dz'] = np.round(scale*df_curves.index*np.cos(phi),10) vtk_polyData = vtkPolyData() vtk_points = vtkPoints() vtk_cells = vtkCellArray() vtk_cells.InsertNextCell(len(df_curves)) for row in df_curves.itertuples(index=False): pointId = vtk_points.InsertNextPoint(self._x+row.dx, self._y+row.dy, self._z+row.dz) vtk_cells.InsertCellPoint(pointId) vtk_polyData.SetPoints(vtk_points) vtk_polyData.SetLines(vtk_cells) for vtk_arr in vtk_arrays: # vtk_polyData.GetCellData().AddArray(vtk_arr) vtk_polyData.GetPointData().AddArray(vtk_arr) # vtk_polyData.GetPointData().SetActiveScalars("DEPTH") # print (df_curves['DEPTH'].dtype) # vtk_array = numpy_support.numpy_to_vtk(num_array=df_curves['DEPTH'].values, deep=True, array_type=VTK_FLOAT) # vtk_array.SetName("DEPTH") # vtk_polyData.GetPointData().SetScalars(vtk_array) outputCurves = vtkPolyData.GetData(outInfoVec, 1) outputCurves.ShallowCopy(vtk_polyData) t1 = time.time() print ("t1-t0", t1-t0) return 1