Pyvista question: Why I cannot see my data in result?

70 Views Asked by At

Background

I have been using pyvista to visualize 2D image (GPR image) by following this and this.

Problem

I ran the code without any error, but no data was displayed. enter image description here

Data

Let's assume the stucture of a raw data, (row, column), is (10, 8). One row in the raw data is composed of (X, Y, Z, 5 values) exported from Fortran90 code. X, Y, Z mean coodinates (latitude, longitude, elevation). The values indicate the measurment data. The examplary lines are below.

[38.5, 120.5, 150.0, 1, 2, 3, 4, 5] - 1 row

. . .

[38.3, 120.3, 150.3, 5, 6, 7, 8, 9] - 10 row

Code

In the script below, after reading the raw data, I separated it into group 1 and group 2. The structure of group 1 is (10, 3) including X, Y, and Z.

Group 1 (Coordinate)

[38.5, 120.5, 150.0] - 1 row

. . .

[38.3, 120.3, 150.3] - 10 row

The structure of group 2 is (10, 5) related to the measurment values.

Group 2 (Measurement data)

[1, 2, 3, 4, 5] - 1 row

. . .

[5, 6, 7, 8, 9] - 10 row

import pyvista as pv
import numpy as np
import matplotlib.pyplot as plt 
import os
import pandas as pd

cp = os.getcwd()
cp2 = cp + "/data/"


# Load the provided .txt file
with open(cp2 + 'raw_data.txt', 'r') as file:
    txt_content = file.readlines()

data_list = [list(filter(None, line.split())) for line in txt_content]

# Convert the data list to a numpy array
raw_data = np.array(data_list, dtype=float)

# Seperate coordinates and data
cor = raw_data[:,0:3]    # coordinates
data = raw_data[:,3:].T  # measurement data

# Grab the number of rows and columns
nrows, ncols = data.shape 
# Might be opposite for your data, pay attention here
 

# Define the Z spacing of your 2D section
z = 2.0
z_spacing = z / nrows 


# Create structured points draping down from the coordiantes
points = np.repeat(cor, nrows, axis=0)


# repeat the Z locations across
tp = np.arange(0, z_spacing*nrows, z_spacing)
tp = cor[:,2][:,None] - tp
points[:,-1] = tp.ravel()

# Make a StructuredGrid from the structured points
grid = pv.StructuredGrid()
grid.points = points
grid.dimensions = nrows, ncols, 1


# Add the data array - note the ordering!
grid["values"] = data.ravel(order="F")
grid.plot(cmap="seismic", clim=[-1*10**6,1*10**6])
0

There are 0 best solutions below