groupeLIAMG / ttcr

Codes to do raytracing for geophysical applications
GNU General Public License v3.0
85 stars 33 forks source link

An error when using Mesh3d.data_kernel_straight_rays #53

Closed CSUPZW closed 1 year ago

CSUPZW commented 1 year ago

Dear sir, I got an error when using function "data_kernel_straight_rays" of Mesh3d. I had read the help of "Mesh3d.data_kernel_straight_rays", and it did not tell me what type of data I should use if 'numpy.ndarray' was not allowed. Here is the error:


TypeError Traceback (most recent call last)

in ----> 1 C = Mesh3d.data_kernel_straight_rays(src, rcv) TypeError: descriptor 'data_kernel_straight_rays' for 'ttcrpy.tmesh.Mesh3d' objects doesn't apply to a 'numpy.ndarray' object --------------------------------------------------------------------------- Here is the help of "Mesh3d.data_kernel_straight_rays": --------------------------------------------------------------------------- Help on method_descriptor: data_kernel_straight_rays(...) data_kernel_straight_rays(Tx, Rx) -> L Raytracing with straight rays in 3D Parameters ---------- Tx : np.ndarray source coordinates, nTx by 3 - 1st column contains X coordinates, - 2nd contains Y coordinates - 3rd contains Z coordinates Rx : np.ndarray receiver coordinates, nTx by 3 - 1st column contains X coordinates, - 2nd contains Y coordinates - 3rd contains Z coordinates Returns ------- L : scipy csr_matrix data kernel matrix (tt = L*slowness) Note ---- Tx and Rx should contain the same number of rows, each row corresponding to a source-receiver pair --------------------------------------------------------------------------- Thank you very much!
bernard-giroux commented 1 year ago

Well, what is the problem with using numpy arrays for passing the Tx & Rx parameters? How do you create Tx & Rx?

CSUPZW commented 1 year ago

I create Tx & Rx by using np.loadtxt to load the file. The parts of Tx and Rx are shown in following:

Tx : array([[ 4.4, 41.1, 22. ], [ 4.4, 41.1, 22. ], [ 4.4, 41.1, 22. ]])

Rx: array([[ 5.6, 27.5, 21.6], [16.2, 40.2, 15.9], [15.7, 25.8, 15.5]])


It does not have any problem when Tx and Rx are passed to function "Mesh3d.raytrace". However, when they are passed to the function "Mesh3d.data_kernel_straight_rays", it shows problem mentioned above. The files are attached following. . Error when using Mesh3D.data_kernel_straight_rays.ipynb.zip

bernard-giroux commented 1 year ago

Sorry for the long delay to reply. The problem arises because data_kernel_straight_rays is not a static method for meshes (contrary to rgrid). You should pass your mesh as first argument, or use it with an instance, e.g.

tm = Mesh3D(...) tm.data_kernel_straight_rays(Tx, Rx)